mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-06-12 06:41:13 +02:00
* gh_test_repl.c (c_vector_test): same as gh_test_c.c
* gh_test_c.c (c_vector_test): some improvements on the vector routines test. * gh.h (gh_vector): this used to exist but do the wrong thing. Now it (almost) does the right thing, though it takes a list instead of the individual arguments. I need to see how it could be done right. (gh_list_to_vector): added this function as a macro. Corresponds to Scheme's (list->vector ...). (gh_vector_to_list): added this function as a macro. Corresponds to Scheme's (vector->list ...). * gh_data.c (gh_vector_ref): renamed from gh_vref to gh_vector_ref, so that it resembles the Scheme routines more. (gh_vector_set): renamed from gh_vset to gh_vector_set, so that it resembles the Scheme routines more. (gh_make_vector): this used to be (stupidly) called gh_vector(). This is the right name, since it does the same thing as the Scheme (make-vector ...) procedure.
This commit is contained in:
parent
da7f71d7d5
commit
e5eece747e
5 changed files with 75 additions and 19 deletions
|
@ -1,3 +1,27 @@
|
||||||
|
1997-10-12 Mark Galassi <rosalia@cygnus.com>
|
||||||
|
|
||||||
|
* gh_test_repl.c (c_vector_test): same as gh_test_c.c
|
||||||
|
|
||||||
|
* gh_test_c.c (c_vector_test): some improvements on the vector
|
||||||
|
routines test.
|
||||||
|
|
||||||
|
* gh.h (gh_vector): this used to exist but do the wrong thing.
|
||||||
|
Now it (almost) does the right thing, though it takes a list
|
||||||
|
instead of the individual arguments. I need to see how it could
|
||||||
|
be done right.
|
||||||
|
(gh_list_to_vector): added this function as a macro. Corresponds
|
||||||
|
to Scheme's (list->vector ...).
|
||||||
|
(gh_vector_to_list): added this function as a macro. Corresponds
|
||||||
|
to Scheme's (vector->list ...).
|
||||||
|
|
||||||
|
* gh_data.c (gh_vector_ref): renamed from gh_vref to
|
||||||
|
gh_vector_ref, so that it resembles the Scheme routines more.
|
||||||
|
(gh_vector_set): renamed from gh_vset to gh_vector_set, so that it
|
||||||
|
resembles the Scheme routines more.
|
||||||
|
(gh_make_vector): this used to be (stupidly) called gh_vector().
|
||||||
|
This is the right name, since it does the same thing as the Scheme
|
||||||
|
(make-vector ...) procedure.
|
||||||
|
|
||||||
Sun Oct 12 14:41:39 1997 Mikael Djurfeldt <mdj@kenneth>
|
Sun Oct 12 14:41:39 1997 Mikael Djurfeldt <mdj@kenneth>
|
||||||
|
|
||||||
* ports.h: #include "libguile/print.h"
|
* ports.h: #include "libguile/print.h"
|
||||||
|
|
|
@ -76,6 +76,7 @@ SCM gh_eval_str_with_standard_handler(char *scheme_code);
|
||||||
SCM gh_eval_str_with_stack_saving_handler(char *scheme_code);
|
SCM gh_eval_str_with_stack_saving_handler(char *scheme_code);
|
||||||
|
|
||||||
SCM gh_eval_file(char *fname);
|
SCM gh_eval_file(char *fname);
|
||||||
|
#define gh_load(fname) gh_eval_file(fname)
|
||||||
SCM gh_eval_file_with_catch(char *scheme_code, scm_catch_handler_t handler);
|
SCM gh_eval_file_with_catch(char *scheme_code, scm_catch_handler_t handler);
|
||||||
SCM gh_eval_file_with_standard_handler(char *scheme_code);
|
SCM gh_eval_file_with_standard_handler(char *scheme_code);
|
||||||
|
|
||||||
|
@ -143,10 +144,20 @@ int gh_equal_p(SCM x, SCM y);
|
||||||
|
|
||||||
SCM gh_define(char *name, SCM val);
|
SCM gh_define(char *name, SCM val);
|
||||||
|
|
||||||
SCM gh_vector(SCM length, SCM val);
|
/* vector manipulation routines */
|
||||||
|
/* note that gh_vector() does not behave quite like the Scheme (vector
|
||||||
|
obj1 obj2 ...), because the interpreter engine does not pass the
|
||||||
|
data element by element, but rather as a list. thus, gh_vector()
|
||||||
|
ends up being identical to gh_list_to_vector() */
|
||||||
|
#define gh_vector(ls) scm_vector(ls)
|
||||||
|
SCM gh_make_vector(SCM length, SCM val);
|
||||||
SCM gh_vset(SCM vec, SCM pos, SCM val);
|
SCM gh_vset(SCM vec, SCM pos, SCM val);
|
||||||
SCM gh_vref(SCM vec, SCM pos);
|
SCM gh_vref(SCM vec, SCM pos);
|
||||||
|
SCM gh_vector_set(SCM vec, SCM pos, SCM val);
|
||||||
|
SCM gh_vector_ref(SCM vec, SCM pos);
|
||||||
unsigned long gh_vector_length(SCM v);
|
unsigned long gh_vector_length(SCM v);
|
||||||
|
#define gh_list_to_vector(ls) scm_vector(ls)
|
||||||
|
#define gh_vector_to_list(v) scm_vector_to_list(ls)
|
||||||
|
|
||||||
SCM gh_lookup (char *sname);
|
SCM gh_lookup (char *sname);
|
||||||
SCM gh_module_lookup (SCM vector, char *sname);
|
SCM gh_module_lookup (SCM vector, char *sname);
|
||||||
|
|
|
@ -265,22 +265,25 @@ gh_symbol2newstr (SCM sym, int *lenp)
|
||||||
|
|
||||||
/* create a new vector of the given length, all initialized to the
|
/* create a new vector of the given length, all initialized to the
|
||||||
given value */
|
given value */
|
||||||
SCM
|
SCM
|
||||||
gh_vector (SCM length, SCM val)
|
gh_make_vector (SCM len, SCM fill)
|
||||||
{
|
{
|
||||||
return scm_make_vector (length, val, SCM_UNDEFINED);
|
/* scm_make_vector() takes a third boolean argument which should be
|
||||||
|
set to SCM_BOOL_T when you are dealing with multi-dimensional
|
||||||
|
arrays; gh_make_vector() does not do multi-dimensional arrays */
|
||||||
|
return scm_make_vector(len, fill, SCM_BOOL_F);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* set the given element of the given vector to the given value */
|
/* set the given element of the given vector to the given value */
|
||||||
SCM
|
SCM
|
||||||
gh_vset (SCM vec, SCM pos, SCM val)
|
gh_vector_set (SCM vec, SCM pos, SCM val)
|
||||||
{
|
{
|
||||||
return scm_vector_set_x (vec, pos, val);
|
return scm_vector_set_x (vec, pos, val);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* retrieve the given element of the given vector */
|
/* retrieve the given element of the given vector */
|
||||||
SCM
|
SCM
|
||||||
gh_vref (SCM vec, SCM pos)
|
gh_vector_ref (SCM vec, SCM pos)
|
||||||
{
|
{
|
||||||
return scm_vector_ref (vec, pos);
|
return scm_vector_ref (vec, pos);
|
||||||
}
|
}
|
||||||
|
|
|
@ -102,9 +102,9 @@ main_prog (int argc, char *argv[])
|
||||||
gh_eval_str_with_standard_handler ("(dosplay \"dude!\n\")");
|
gh_eval_str_with_standard_handler ("(dosplay \"dude!\n\")");
|
||||||
|
|
||||||
/* now define some new primitives in C */
|
/* now define some new primitives in C */
|
||||||
cf = gh_new_procedure1_0 ("c_factorial", c_factorial);
|
cf = gh_new_procedure1_0 ("c-factorial", c_factorial);
|
||||||
gh_new_procedure1_0 ("c_sin", c_sin);
|
gh_new_procedure1_0 ("c-sin", c_sin);
|
||||||
gh_new_procedure1_0 ("c_vector_test", c_vector_test);
|
gh_new_procedure1_0 ("c-vector-test", c_vector_test);
|
||||||
|
|
||||||
/* now try some (eval ...) action from C */
|
/* now try some (eval ...) action from C */
|
||||||
{
|
{
|
||||||
|
@ -118,8 +118,9 @@ main_prog (int argc, char *argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
printf ("testing the predicates for procedure? and vector?\n");
|
printf ("testing the predicates for procedure? and vector?\n");
|
||||||
printf ("gh_procedure_p(c_factorial) is %d, gh_vector_p(c_factorial) is %d\n",
|
printf ("gh_procedure_p(c_factorial)->%d, gh_vector_p(c_factorial)->%d\n",
|
||||||
gh_procedure_p (cf), gh_vector_p (cf));
|
gh_procedure_p (cf), gh_vector_p (cf));
|
||||||
|
gh_eval_str("(c-vector-test 200)");
|
||||||
|
|
||||||
/* Test calling procedures. */
|
/* Test calling procedures. */
|
||||||
{
|
{
|
||||||
|
@ -210,12 +211,20 @@ c_vector_test (SCM s_length)
|
||||||
unsigned long c_length;
|
unsigned long c_length;
|
||||||
|
|
||||||
c_length = gh_scm2ulong (s_length);
|
c_length = gh_scm2ulong (s_length);
|
||||||
printf ("requested length for vector: %ld\n", c_length);
|
printf ("VECTOR test -- requested length for vector: %ld", c_length);
|
||||||
|
|
||||||
/* create a vector filled witth 0.0 entries */
|
/* create a vector filled witth 0.0 entries */
|
||||||
xvec = gh_vector (c_length, gh_double2scm (0.0));
|
xvec = gh_make_vector (s_length, gh_double2scm (0.0));
|
||||||
/* set the second element in it to some floating point value */
|
/* set the second element in it to some floating point value */
|
||||||
gh_vset (xvec, 2, gh_double2scm (1.9));
|
gh_vector_set (xvec, gh_int2scm(2), gh_double2scm (1.9));
|
||||||
|
|
||||||
|
/* I think I can use == because Scheme's doubles should be the same
|
||||||
|
as C doubles, with no operations in between */
|
||||||
|
if (gh_scm2double(gh_vector_ref (xvec, gh_int2scm(2))) == 1.9) {
|
||||||
|
printf("... PASS\n");
|
||||||
|
} else {
|
||||||
|
printf("... FAIL\n");
|
||||||
|
}
|
||||||
|
|
||||||
return xvec;
|
return xvec;
|
||||||
}
|
}
|
||||||
|
|
|
@ -75,9 +75,9 @@ main_prog (int argc, char *argv[])
|
||||||
gh_eval_str ("(display (pair? s))");
|
gh_eval_str ("(display (pair? s))");
|
||||||
|
|
||||||
/* now define some new primitives in C */
|
/* now define some new primitives in C */
|
||||||
cf = gh_new_procedure1_0 ("c_factorial", c_factorial);
|
cf = gh_new_procedure1_0 ("c-factorial", c_factorial);
|
||||||
gh_new_procedure1_0 ("c_sin", c_sin);
|
gh_new_procedure1_0 ("c-sin", c_sin);
|
||||||
gh_new_procedure1_0 ("c_vector_test", c_vector_test);
|
gh_new_procedure1_0 ("c-vector-test", c_vector_test);
|
||||||
|
|
||||||
/* now try some (eval ...) action from C */
|
/* now try some (eval ...) action from C */
|
||||||
{
|
{
|
||||||
|
@ -99,6 +99,7 @@ main_prog (int argc, char *argv[])
|
||||||
printf ("testing the predicates for procedure? and vector?\n");
|
printf ("testing the predicates for procedure? and vector?\n");
|
||||||
printf ("gh_procedure_p(c_factorial) is %d, gh_vector_p(c_factorial) is %d\n",
|
printf ("gh_procedure_p(c_factorial) is %d, gh_vector_p(c_factorial) is %d\n",
|
||||||
gh_procedure_p (cf), gh_vector_p (cf));
|
gh_procedure_p (cf), gh_vector_p (cf));
|
||||||
|
gh_eval_str("(c-vector-test 200)");
|
||||||
|
|
||||||
gh_repl ();
|
gh_repl ();
|
||||||
}
|
}
|
||||||
|
@ -145,12 +146,20 @@ c_vector_test (SCM s_length)
|
||||||
unsigned long c_length;
|
unsigned long c_length;
|
||||||
|
|
||||||
c_length = gh_scm2ulong (s_length);
|
c_length = gh_scm2ulong (s_length);
|
||||||
printf ("requested length for vector: %ld\n", c_length);
|
printf ("VECTOR test -- requested length for vector: %ld", c_length);
|
||||||
|
|
||||||
/* create a vector filled witth 0.0 entries */
|
/* create a vector filled witth 0.0 entries */
|
||||||
xvec = gh_vector (c_length, gh_double2scm (0.0));
|
xvec = gh_make_vector (s_length, gh_double2scm (0.0));
|
||||||
/* set the second element in it to some floating point value */
|
/* set the second element in it to some floating point value */
|
||||||
gh_vset (xvec, 2, gh_double2scm (1.9));
|
gh_vector_set (xvec, gh_int2scm(2), gh_double2scm (1.9));
|
||||||
|
|
||||||
|
/* I think I can use == because Scheme's doubles should be the same
|
||||||
|
as C doubles, with no operations in between */
|
||||||
|
if (gh_scm2double(gh_vector_ref (xvec, gh_int2scm(2))) == 1.9) {
|
||||||
|
printf("... PASS\n");
|
||||||
|
} else {
|
||||||
|
printf("... FAIL\n");
|
||||||
|
}
|
||||||
|
|
||||||
return xvec;
|
return xvec;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue