mirror of
https://github.com/ashinn/chibi-scheme.git
synced 2025-05-20 22:29:16 +02:00
updating some individual opcodes to new API
This commit is contained in:
parent
ded9bbf0b6
commit
9a3c863630
6 changed files with 48 additions and 47 deletions
|
@ -134,7 +134,6 @@ typedef struct sexp_struct *sexp;
|
|||
#endif
|
||||
|
||||
/* procedure types */
|
||||
typedef sexp (*sexp_proc0) (void);
|
||||
typedef sexp (*sexp_proc1) (sexp sexp_api_params(self, n));
|
||||
typedef sexp (*sexp_proc2) (sexp sexp_api_params(self, n), sexp);
|
||||
typedef sexp (*sexp_proc3) (sexp sexp_api_params(self, n), sexp, sexp);
|
||||
|
@ -921,6 +920,7 @@ SEXP_API sexp sexp_finalize_c_type (sexp ctx sexp_api_params(self, n), sexp obj)
|
|||
#define sexp_get_output_string(ctx, out) sexp_get_output_string_op(ctx sexp_api_pass(NULL, 1), out)
|
||||
#define sexp_expt(ctx, a, b) sexp_expt_op(ctx sexp_api_pass(NULL, 2), a, b)
|
||||
#define sexp_register_simple_type(ctx, a, b) sexp_register_simple_type_op(ctx sexp_api_pass(NULL, 2), a, b)
|
||||
#define sexp_register_type(ctx, a, b, c, d, e, f, g, h, i, j) sexp_register_type_op(ctx sexp_api_pass(NULL, 10), a, b, c, d, e, f, g, h, i, j)
|
||||
#define sexp_make_type_predicate(ctx, a, b) sexp_make_type_predicate_op(ctx sexp_api_pass(NULL, 2), a, b)
|
||||
#define sexp_make_constructor(ctx, a, b) sexp_make_constructor_op(ctx sexp_api_pass(NULL, 2), a, b)
|
||||
#define sexp_make_getter(ctx, a, b, c) sexp_make_getter_op(ctx sexp_api_pass(NULL, 3), a, b, c)
|
||||
|
|
|
@ -37,17 +37,17 @@ typedef struct random_data sexp_random_t;
|
|||
static sexp_uint_t rs_type_id;
|
||||
static sexp default_random_source;
|
||||
|
||||
static sexp sexp_rs_random_integer (sexp ctx, sexp rs, sexp bound) {
|
||||
static sexp sexp_rs_random_integer (sexp ctx sexp_api_params(self, n), sexp rs, sexp bound) {
|
||||
sexp res;
|
||||
int32_t n;
|
||||
int32_t m;
|
||||
#if SEXP_USE_BIGNUMS
|
||||
int32_t hi, mod, len, i, *data;
|
||||
#endif
|
||||
if (! sexp_random_source_p(rs))
|
||||
res = sexp_type_exception(ctx, "not a random-source", rs);
|
||||
if (sexp_fixnump(bound)) {
|
||||
sexp_call_random(rs, n);
|
||||
res = sexp_make_fixnum(n % sexp_unbox_fixnum(bound));
|
||||
sexp_call_random(rs, m);
|
||||
res = sexp_make_fixnum(m % sexp_unbox_fixnum(bound));
|
||||
#if SEXP_USE_BIGNUMS
|
||||
} else if (sexp_bignump(bound)) {
|
||||
hi = sexp_bignum_hi(bound);
|
||||
|
@ -55,13 +55,13 @@ static sexp sexp_rs_random_integer (sexp ctx, sexp rs, sexp bound) {
|
|||
res = sexp_make_bignum(ctx, hi);
|
||||
data = (int32_t*) sexp_bignum_data(res);
|
||||
for (i=0; i<len-1; i++) {
|
||||
sexp_call_random(rs, n);
|
||||
data[i] = n;
|
||||
sexp_call_random(rs, m);
|
||||
data[i] = m;
|
||||
}
|
||||
sexp_call_random(rs, n);
|
||||
sexp_call_random(rs, m);
|
||||
mod = sexp_bignum_data(bound)[hi-1] * sizeof(int32_t) / sizeof(sexp_uint_t);
|
||||
if (mod)
|
||||
data[i] = n % mod;
|
||||
data[i] = m % mod;
|
||||
#endif
|
||||
} else {
|
||||
res = sexp_type_exception(ctx, "random-integer: not an integer", bound);
|
||||
|
@ -69,11 +69,11 @@ static sexp sexp_rs_random_integer (sexp ctx, sexp rs, sexp bound) {
|
|||
return res;
|
||||
}
|
||||
|
||||
static sexp sexp_random_integer (sexp ctx, sexp bound) {
|
||||
return sexp_rs_random_integer(ctx, default_random_source, bound);
|
||||
static sexp sexp_random_integer (sexp ctx sexp_api_params(self, n), sexp bound) {
|
||||
return sexp_rs_random_integer(ctx sexp_api_pass(self, n), default_random_source, bound);
|
||||
}
|
||||
|
||||
static sexp sexp_rs_random_real (sexp ctx, sexp rs) {
|
||||
static sexp sexp_rs_random_real (sexp ctx sexp_api_params(self, n), sexp rs) {
|
||||
int32_t res;
|
||||
if (! sexp_random_source_p(rs))
|
||||
return sexp_type_exception(ctx, "not a random-source", rs);
|
||||
|
@ -81,27 +81,27 @@ static sexp sexp_rs_random_real (sexp ctx, sexp rs) {
|
|||
return sexp_make_flonum(ctx, (double)res / (double)RAND_MAX);
|
||||
}
|
||||
|
||||
static sexp sexp_random_real (sexp ctx) {
|
||||
return sexp_rs_random_real(ctx, default_random_source);
|
||||
static sexp sexp_random_real (sexp ctx sexp_api_params(self, n)) {
|
||||
return sexp_rs_random_real(ctx sexp_api_pass(self, n), default_random_source);
|
||||
}
|
||||
|
||||
#if SEXP_BSD
|
||||
|
||||
static sexp sexp_make_random_source (sexp ctx) {
|
||||
static sexp sexp_make_random_source (sexp ctx sexp_api_params(self, n)) {
|
||||
sexp res;
|
||||
res = sexp_alloc_tagged(ctx, sexp_sizeof_random, rs_type_id);
|
||||
*sexp_random_data(res) = 1;
|
||||
return res;
|
||||
}
|
||||
|
||||
static sexp sexp_random_source_state_ref (sexp ctx, sexp rs) {
|
||||
static sexp sexp_random_source_state_ref (sexp ctx sexp_api_params(self, n), sexp rs) {
|
||||
if (! sexp_random_source_p(rs))
|
||||
return sexp_type_exception(ctx, "not a random-source", rs);
|
||||
else
|
||||
return sexp_make_integer(ctx, *sexp_random_data(rs));
|
||||
}
|
||||
|
||||
static sexp sexp_random_source_state_set (sexp ctx, sexp rs, sexp state) {
|
||||
static sexp sexp_random_source_state_set (sexp ctx sexp_api_params(self, n), sexp rs, sexp state) {
|
||||
if (! sexp_random_source_p(rs))
|
||||
return sexp_type_exception(ctx, "not a random-source", rs);
|
||||
else if (sexp_fixnump(state))
|
||||
|
@ -118,7 +118,7 @@ static sexp sexp_random_source_state_set (sexp ctx, sexp rs, sexp state) {
|
|||
|
||||
#else
|
||||
|
||||
static sexp sexp_make_random_source (sexp ctx) {
|
||||
static sexp sexp_make_random_source (sexp ctx sexp_api_params(self, n)) {
|
||||
sexp res;
|
||||
sexp_gc_var1(state);
|
||||
sexp_gc_preserve1(ctx, state);
|
||||
|
@ -130,14 +130,14 @@ static sexp sexp_make_random_source (sexp ctx) {
|
|||
return res;
|
||||
}
|
||||
|
||||
static sexp sexp_random_source_state_ref (sexp ctx, sexp rs) {
|
||||
static sexp sexp_random_source_state_ref (sexp ctx sexp_api_params(self, n), sexp rs) {
|
||||
if (! sexp_random_source_p(rs))
|
||||
return sexp_type_exception(ctx, "not a random-source", rs);
|
||||
else
|
||||
return sexp_substring(ctx, sexp_random_state(rs), ZERO, STATE_SIZE);
|
||||
}
|
||||
|
||||
static sexp sexp_random_source_state_set (sexp ctx, sexp rs, sexp state) {
|
||||
static sexp sexp_random_source_state_set (sexp ctx sexp_api_params(self, n), sexp rs, sexp state) {
|
||||
if (! sexp_random_source_p(rs))
|
||||
return sexp_type_exception(ctx, "not a random-source", rs);
|
||||
else if (! (sexp_stringp(state)
|
||||
|
@ -150,14 +150,14 @@ static sexp sexp_random_source_state_set (sexp ctx, sexp rs, sexp state) {
|
|||
|
||||
#endif
|
||||
|
||||
static sexp sexp_random_source_randomize (sexp ctx, sexp rs) {
|
||||
static sexp sexp_random_source_randomize (sexp ctx sexp_api_params(self, n), sexp rs) {
|
||||
if (! sexp_random_source_p(rs))
|
||||
return sexp_type_exception(ctx, "not a random-source", rs);
|
||||
sexp_seed_random(time(NULL), rs);
|
||||
return SEXP_VOID;
|
||||
}
|
||||
|
||||
static sexp sexp_random_source_pseudo_randomize (sexp ctx, sexp rs, sexp seed) {
|
||||
static sexp sexp_random_source_pseudo_randomize (sexp ctx sexp_api_params(self, n), sexp rs, sexp seed) {
|
||||
if (! sexp_random_source_p(rs))
|
||||
return sexp_type_exception(ctx, "not a random-source", rs);
|
||||
if (! sexp_fixnump(seed))
|
||||
|
@ -193,10 +193,10 @@ sexp sexp_init_library (sexp ctx sexp_api_params(self, n), sexp env) {
|
|||
sexp_define_foreign(ctx, env, "random-source-randomize!", 1, sexp_random_source_randomize);
|
||||
sexp_define_foreign(ctx, env, "random-source-pseudo-randomize!", 2, sexp_random_source_pseudo_randomize);
|
||||
|
||||
default_random_source = op = sexp_make_random_source(ctx);
|
||||
default_random_source = op = sexp_make_random_source(ctx sexp_api_pass(NULL, 0));
|
||||
name = sexp_intern(ctx, "default-random-source", -1);
|
||||
sexp_env_define(ctx, env, name, default_random_source);
|
||||
sexp_random_source_randomize(ctx, default_random_source);
|
||||
sexp_random_source_randomize(ctx sexp_api_pass(NULL, 0), default_random_source);
|
||||
|
||||
sexp_gc_release2(ctx);
|
||||
return SEXP_VOID;
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
#define sexp_bignum_normalize(x) x
|
||||
#endif
|
||||
|
||||
static sexp sexp_bit_and (sexp ctx, sexp x, sexp y) {
|
||||
static sexp sexp_bit_and (sexp ctx sexp_api_params(self, n), sexp x, sexp y) {
|
||||
sexp res;
|
||||
#if SEXP_USE_BIGNUMS
|
||||
sexp_sint_t len, i;
|
||||
|
@ -21,7 +21,7 @@ static sexp sexp_bit_and (sexp ctx, sexp x, sexp y) {
|
|||
res = (sexp) ((sexp_uint_t)x & (sexp_uint_t)y);
|
||||
#if SEXP_USE_BIGNUMS
|
||||
else if (sexp_bignump(y))
|
||||
res = sexp_bit_and(ctx, y, x);
|
||||
res = sexp_bit_and(ctx sexp_api_pass(self, n), y, x);
|
||||
#endif
|
||||
else
|
||||
res = sexp_type_exception(ctx, "bitwise-and: not an integer", y);
|
||||
|
@ -47,7 +47,7 @@ static sexp sexp_bit_and (sexp ctx, sexp x, sexp y) {
|
|||
return sexp_bignum_normalize(res);
|
||||
}
|
||||
|
||||
static sexp sexp_bit_ior (sexp ctx, sexp x, sexp y) {
|
||||
static sexp sexp_bit_ior (sexp ctx sexp_api_params(self, n), sexp x, sexp y) {
|
||||
sexp res;
|
||||
#if SEXP_USE_BIGNUMS
|
||||
sexp_sint_t len, i;
|
||||
|
@ -57,7 +57,7 @@ static sexp sexp_bit_ior (sexp ctx, sexp x, sexp y) {
|
|||
res = (sexp) ((sexp_uint_t)x | (sexp_uint_t)y);
|
||||
#if SEXP_USE_BIGNUMS
|
||||
else if (sexp_bignump(y))
|
||||
res = sexp_bit_ior(ctx, y, x);
|
||||
res = sexp_bit_ior(ctx sexp_api_pass(self, n), y, x);
|
||||
#endif
|
||||
else
|
||||
res = sexp_type_exception(ctx, "bitwise-ior: not an integer", y);
|
||||
|
@ -87,7 +87,7 @@ static sexp sexp_bit_ior (sexp ctx, sexp x, sexp y) {
|
|||
return sexp_bignum_normalize(res);
|
||||
}
|
||||
|
||||
static sexp sexp_bit_xor (sexp ctx, sexp x, sexp y) {
|
||||
static sexp sexp_bit_xor (sexp ctx sexp_api_params(self, n), sexp x, sexp y) {
|
||||
sexp res;
|
||||
#if SEXP_USE_BIGNUMS
|
||||
sexp_sint_t len, i;
|
||||
|
@ -97,7 +97,7 @@ static sexp sexp_bit_xor (sexp ctx, sexp x, sexp y) {
|
|||
res = sexp_make_fixnum(sexp_unbox_fixnum(x) ^ sexp_unbox_fixnum(y));
|
||||
#if SEXP_USE_BIGNUMS
|
||||
else if (sexp_bignump(y))
|
||||
res = sexp_bit_xor(ctx, y, x);
|
||||
res = sexp_bit_xor(ctx sexp_api_pass(self, n), y, x);
|
||||
#endif
|
||||
else
|
||||
res = sexp_type_exception(ctx, "bitwise-xor: not an integer", y);
|
||||
|
@ -129,7 +129,7 @@ static sexp sexp_bit_xor (sexp ctx, sexp x, sexp y) {
|
|||
|
||||
/* should probably split into left and right shifts, that's a better */
|
||||
/* interface anyway */
|
||||
static sexp sexp_arithmetic_shift (sexp ctx, sexp i, sexp count) {
|
||||
static sexp sexp_arithmetic_shift (sexp ctx sexp_api_params(self, n), sexp i, sexp count) {
|
||||
sexp_uint_t tmp;
|
||||
sexp_sint_t c;
|
||||
#if SEXP_USE_BIGNUMS
|
||||
|
@ -156,7 +156,7 @@ static sexp sexp_arithmetic_shift (sexp ctx, sexp i, sexp count) {
|
|||
} else {
|
||||
sexp_gc_preserve1(ctx, res);
|
||||
res = sexp_fixnum_to_bignum(ctx, i);
|
||||
res = sexp_arithmetic_shift(ctx, res, count);
|
||||
res = sexp_arithmetic_shift(ctx sexp_api_pass(self, n), res, count);
|
||||
sexp_gc_release1(ctx);
|
||||
}
|
||||
#endif
|
||||
|
@ -208,7 +208,7 @@ static sexp_uint_t bit_count (sexp_uint_t i) {
|
|||
>> (sizeof(i) - 1) * CHAR_BIT);
|
||||
}
|
||||
|
||||
static sexp sexp_bit_count (sexp ctx, sexp x) {
|
||||
static sexp sexp_bit_count (sexp ctx sexp_api_params(self, n), sexp x) {
|
||||
sexp res;
|
||||
sexp_sint_t i;
|
||||
#if SEXP_USE_BIGNUMS
|
||||
|
@ -250,7 +250,7 @@ static sexp_uint_t integer_log2 (sexp_uint_t x) {
|
|||
return (t = x >> 8) ? 8 + log_table_256[t] : log_table_256[x];
|
||||
}
|
||||
|
||||
static sexp sexp_integer_length (sexp ctx, sexp x) {
|
||||
static sexp sexp_integer_length (sexp ctx sexp_api_params(self, n), sexp x) {
|
||||
sexp_sint_t tmp;
|
||||
#if SEXP_USE_BIGNUMS
|
||||
sexp_sint_t hi;
|
||||
|
@ -269,7 +269,7 @@ static sexp sexp_integer_length (sexp ctx, sexp x) {
|
|||
}
|
||||
}
|
||||
|
||||
static sexp sexp_bit_set_p (sexp ctx, sexp i, sexp x) {
|
||||
static sexp sexp_bit_set_p (sexp ctx sexp_api_params(self, n), sexp i, sexp x) {
|
||||
#if SEXP_USE_BIGNUMS
|
||||
sexp_uint_t pos;
|
||||
#endif
|
||||
|
|
|
@ -23,7 +23,7 @@ static sexp_uint_t string_hash (char *str, sexp_uint_t bound) {
|
|||
return acc % bound;
|
||||
}
|
||||
|
||||
static sexp sexp_string_hash (sexp ctx, sexp str, sexp bound) {
|
||||
static sexp sexp_string_hash (sexp ctx sexp_api_params(self, n), sexp str, sexp bound) {
|
||||
if (! sexp_stringp(str))
|
||||
return sexp_type_exception(ctx, "string-hash: not a string", str);
|
||||
else if (! sexp_integerp(bound))
|
||||
|
@ -38,7 +38,7 @@ static sexp_uint_t string_ci_hash (char *str, sexp_uint_t bound) {
|
|||
return acc % bound;
|
||||
}
|
||||
|
||||
static sexp sexp_string_ci_hash (sexp ctx, sexp str, sexp bound) {
|
||||
static sexp sexp_string_ci_hash (sexp ctx sexp_api_params(self, n), sexp str, sexp bound) {
|
||||
if (! sexp_stringp(str))
|
||||
return sexp_type_exception(ctx, "string-ci-hash: not a string", str);
|
||||
else if (! sexp_integerp(bound))
|
||||
|
@ -89,13 +89,13 @@ static sexp_uint_t hash_one (sexp ctx, sexp obj, sexp_uint_t bound, sexp_sint_t
|
|||
return (bound ? acc % bound : acc);
|
||||
}
|
||||
|
||||
static sexp sexp_hash (sexp ctx, sexp obj, sexp bound) {
|
||||
static sexp sexp_hash (sexp ctx sexp_api_params(self, n), sexp obj, sexp bound) {
|
||||
if (! sexp_exact_integerp(bound))
|
||||
return sexp_type_exception(ctx, "hash: not an integer", bound);
|
||||
return sexp_make_fixnum(hash_one(ctx, obj, sexp_unbox_fixnum(bound), HASH_DEPTH));
|
||||
}
|
||||
|
||||
static sexp sexp_hash_by_identity (sexp ctx, sexp obj, sexp bound) {
|
||||
static sexp sexp_hash_by_identity (sexp ctx sexp_api_params(self, n), sexp obj, sexp bound) {
|
||||
if (! sexp_exact_integerp(bound))
|
||||
return sexp_type_exception(ctx, "hash-by-identity: not an integer", bound);
|
||||
return sexp_make_fixnum((sexp_uint_t)obj % sexp_unbox_fixnum(bound));
|
||||
|
@ -106,9 +106,9 @@ static sexp sexp_get_bucket (sexp ctx, sexp buckets, sexp hash_fn, sexp obj) {
|
|||
sexp res;
|
||||
sexp_uint_t len = sexp_vector_length(buckets);
|
||||
if (hash_fn == sexp_make_fixnum(1))
|
||||
res = sexp_hash_by_identity(ctx, obj, sexp_make_fixnum(len));
|
||||
res = sexp_hash_by_identity(ctx sexp_api_pass(NULL, 2), obj, sexp_make_fixnum(len));
|
||||
else if (hash_fn == sexp_make_fixnum(2))
|
||||
res = sexp_hash(ctx, obj, sexp_make_fixnum(len));
|
||||
res = sexp_hash(ctx sexp_api_pass(NULL, 2), obj, sexp_make_fixnum(len));
|
||||
else {
|
||||
sexp_gc_preserve1(ctx, args);
|
||||
args = sexp_list2(ctx, obj, sexp_make_fixnum(len));
|
||||
|
@ -180,7 +180,7 @@ static void sexp_regrow_hash_table (sexp ctx, sexp ht, sexp oldbuckets, sexp has
|
|||
sexp_gc_release1(ctx);
|
||||
}
|
||||
|
||||
static sexp sexp_hash_table_cell (sexp ctx, sexp ht, sexp obj, sexp createp) {
|
||||
static sexp sexp_hash_table_cell (sexp ctx sexp_api_params(self, n), sexp ht, sexp obj, sexp createp) {
|
||||
sexp buckets, eq_fn, hash_fn, i;
|
||||
sexp_uint_t size;
|
||||
sexp_gc_var1(res);
|
||||
|
@ -209,7 +209,7 @@ static sexp sexp_hash_table_cell (sexp ctx, sexp ht, sexp obj, sexp createp) {
|
|||
return res;
|
||||
}
|
||||
|
||||
static sexp sexp_hash_table_delete (sexp ctx, sexp ht, sexp obj) {
|
||||
static sexp sexp_hash_table_delete (sexp ctx sexp_api_params(self, n), sexp ht, sexp obj) {
|
||||
sexp buckets=sexp_hash_table_buckets(ht), eq_fn=sexp_hash_table_eq_fn(ht),
|
||||
hash_fn=sexp_hash_table_hash_fn(ht), i, p, res;
|
||||
i = sexp_get_bucket(ctx, buckets, hash_fn, obj);
|
||||
|
|
|
@ -134,7 +134,8 @@ static sexp sexp_qsort_less (sexp ctx, sexp *vec,
|
|||
return res;
|
||||
}
|
||||
|
||||
static sexp sexp_sort_x (sexp ctx, sexp seq, sexp less, sexp key) {
|
||||
static sexp sexp_sort_x (sexp ctx sexp_api_params(self, n), sexp seq,
|
||||
sexp less, sexp key) {
|
||||
sexp_sint_t len;
|
||||
sexp res, *data;
|
||||
sexp_gc_var1(vec);
|
||||
|
|
6
sexp.c
6
sexp.c
|
@ -122,9 +122,9 @@ static sexp_uint_t sexp_type_array_size = SEXP_NUM_CORE_TYPES;
|
|||
#define SEXP_INIT_NUM_TYPES (SEXP_NUM_CORE_TYPES*2)
|
||||
#endif
|
||||
|
||||
sexp sexp_register_type (sexp ctx, sexp name, sexp fb, sexp felb, sexp flb,
|
||||
sexp flo, sexp fls, sexp sb, sexp so, sexp sc,
|
||||
sexp_proc2 f) {
|
||||
sexp sexp_register_type_op (sexp ctx sexp_api_params(self, n), sexp name,
|
||||
sexp fb, sexp felb, sexp flb, sexp flo, sexp fls,
|
||||
sexp sb, sexp so, sexp sc, sexp_proc2 f) {
|
||||
#if SEXP_USE_GLOBAL_TYPES
|
||||
struct sexp_struct *new, *tmp;
|
||||
#else
|
||||
|
|
Loading…
Add table
Reference in a new issue