#endif
void
-ao_scheme_cons_stash(int id, struct ao_scheme_cons *cons);
+ao_scheme_poly_stash(ao_poly poly);
-struct ao_scheme_cons *
-ao_scheme_cons_fetch(int id);
+ao_poly
+ao_scheme_poly_fetch(void);
-void
-ao_scheme_poly_stash(int id, ao_poly poly);
+static inline void
+ao_scheme_cons_stash(struct ao_scheme_cons *cons) {
+ ao_scheme_poly_stash(ao_scheme_cons_poly(cons));
+}
-ao_poly
-ao_scheme_poly_fetch(int id);
+static inline struct ao_scheme_cons *
+ao_scheme_cons_fetch(void) {
+ return ao_scheme_poly_cons(ao_scheme_poly_fetch());
+}
-void
-ao_scheme_string_stash(int id, struct ao_scheme_string *string);
+static inline void
+ao_scheme_atom_stash(struct ao_scheme_atom *atom) {
+ ao_scheme_poly_stash(ao_scheme_atom_poly(atom));
+}
-struct ao_scheme_string *
-ao_scheme_string_fetch(int id);
+static inline struct ao_scheme_atom *
+ao_scheme_atom_fetch(void) {
+ return ao_scheme_poly_atom(ao_scheme_poly_fetch());
+}
+
+static inline void
+ao_scheme_string_stash(struct ao_scheme_string *string) {
+ ao_scheme_poly_stash(ao_scheme_string_poly(string));
+}
+static inline struct ao_scheme_string *
+ao_scheme_string_fetch(void) {
+ return ao_scheme_poly_string(ao_scheme_poly_fetch());
+}
+
+#ifdef AO_SCHEME_FEATURE_VECTOR
static inline void
-ao_scheme_stack_stash(int id, struct ao_scheme_stack *stack) {
- ao_scheme_poly_stash(id, ao_scheme_stack_poly(stack));
+ao_scheme_vector_stash(struct ao_scheme_vector *vector) {
+ ao_scheme_poly_stash(ao_scheme_vector_poly(vector));
+}
+
+static inline struct ao_scheme_vector *
+ao_scheme_vector_fetch(void) {
+ return ao_scheme_poly_vector(ao_scheme_poly_fetch());
+}
+#endif
+
+static inline void
+ao_scheme_stack_stash(struct ao_scheme_stack *stack) {
+ ao_scheme_poly_stash(ao_scheme_stack_poly(stack));
}
static inline struct ao_scheme_stack *
-ao_scheme_stack_fetch(int id) {
- return ao_scheme_poly_stack(ao_scheme_poly_fetch(id));
+ao_scheme_stack_fetch(void) {
+ return ao_scheme_poly_stack(ao_scheme_poly_fetch());
}
-void
-ao_scheme_frame_stash(int id, struct ao_scheme_frame *frame);
+static inline void
+ao_scheme_frame_stash(struct ao_scheme_frame *frame) {
+ ao_scheme_poly_stash(ao_scheme_frame_poly(frame));
+}
-struct ao_scheme_frame *
-ao_scheme_frame_fetch(int id);
+static inline struct ao_scheme_frame *
+ao_scheme_frame_fetch(void) {
+ return ao_scheme_poly_frame(ao_scheme_poly_fetch());
+}
/* bool */
if (atom)
return atom;
- ao_scheme_string_stash(0, string);
+ ao_scheme_string_stash(string);
atom = ao_scheme_alloc(name_size(string->val));
- string = ao_scheme_string_fetch(0);
+ string = ao_scheme_string_fetch();
ao_scheme_atom_init(atom, string->val);
return atom;
}
if (cons == orig_cons) {
ret = car;
- ao_scheme_cons_stash(0, cons);
+ ao_scheme_cons_stash(cons);
if (cons->cdr == AO_SCHEME_NIL) {
switch (op) {
case builtin_minus:
break;
}
}
- cons = ao_scheme_cons_fetch(0);
+ cons = ao_scheme_cons_fetch();
} else if (ao_scheme_integer_typep(rt) && ao_scheme_integer_typep(ct)) {
int32_t r = ao_scheme_poly_integer(ret, NULL);
int32_t c = ao_scheme_poly_integer(car, NULL);
default:
break;
}
- ao_scheme_cons_stash(0, cons);
+ ao_scheme_cons_stash(cons);
ret = ao_scheme_integer_poly(r);
- cons = ao_scheme_cons_fetch(0);
+ cons = ao_scheme_cons_fetch();
#ifdef AO_SCHEME_FEATURE_FLOAT
} else if (ao_scheme_number_typep(rt) && ao_scheme_number_typep(ct)) {
float r, c;
default:
break;
}
- ao_scheme_cons_stash(0, cons);
+ ao_scheme_cons_stash(cons);
ret = ao_scheme_float_get(r);
- cons = ao_scheme_cons_fetch(0);
+ cons = ao_scheme_cons_fetch();
#endif
}
else if (rt == AO_SCHEME_STRING && ct == AO_SCHEME_STRING && op == builtin_plus) {
- ao_scheme_cons_stash(0, cons);
+ ao_scheme_cons_stash(cons);
ret = ao_scheme_string_poly(ao_scheme_string_cat(ao_scheme_poly_string(ret),
ao_scheme_poly_string(car)));
- cons = ao_scheme_cons_fetch(0);
+ cons = ao_scheme_cons_fetch();
if (!ret)
return ret;
}
cons = ao_scheme_cons_free_list;
ao_scheme_cons_free_list = ao_scheme_poly_cons(cons->cdr);
} else {
- ao_scheme_poly_stash(0, car);
- ao_scheme_poly_stash(1, cdr);
+ ao_scheme_poly_stash(car);
+ ao_scheme_poly_stash(cdr);
cons = ao_scheme_alloc(sizeof (struct ao_scheme_cons));
- cdr = ao_scheme_poly_fetch(1);
- car = ao_scheme_poly_fetch(0);
+ cdr = ao_scheme_poly_fetch();
+ car = ao_scheme_poly_fetch();
if (!cons)
return NULL;
}
struct ao_scheme_cons *new;
ao_poly cdr;
- ao_scheme_cons_stash(0, cons);
- ao_scheme_cons_stash(1, head);
- ao_scheme_poly_stash(0, ao_scheme_cons_poly(tail));
+ ao_scheme_cons_stash(cons);
+ ao_scheme_cons_stash(head);
+ ao_scheme_cons_stash(tail);
new = ao_scheme_alloc(sizeof (struct ao_scheme_cons));
- cons = ao_scheme_cons_fetch(0);
- head = ao_scheme_cons_fetch(1);
- tail = ao_scheme_poly_cons(ao_scheme_poly_fetch(0));
+ tail = ao_scheme_cons_fetch();
+ head = ao_scheme_cons_fetch();
+ cons = ao_scheme_cons_fetch();
if (!new)
return AO_SCHEME_NIL;
new->car = cons->car;
frame->num = 0;
frame->prev = AO_SCHEME_NIL;
frame->vals = AO_SCHEME_NIL;
- ao_scheme_frame_stash(0, frame);
+ ao_scheme_frame_stash(frame);
vals = ao_scheme_frame_vals_new(num);
- frame = ao_scheme_frame_fetch(0);
+ frame = ao_scheme_frame_fetch();
if (!vals)
return NULL;
frame->vals = ao_scheme_frame_vals_poly(vals);
if (new_num == frame->num)
return frame;
- ao_scheme_frame_stash(0, frame);
+ ao_scheme_frame_stash(frame);
new_vals = ao_scheme_frame_vals_new(new_num);
- frame = ao_scheme_frame_fetch(0);
+ frame = ao_scheme_frame_fetch();
if (!new_vals)
return NULL;
vals = ao_scheme_poly_frame_vals(frame->vals);
if (!ref) {
int f = frame->num;
- ao_scheme_poly_stash(0, atom);
- ao_scheme_poly_stash(1, val);
+ ao_scheme_poly_stash(atom);
+ ao_scheme_poly_stash(val);
frame = ao_scheme_frame_realloc(frame, f + 1);
- val = ao_scheme_poly_fetch(1);
- atom = ao_scheme_poly_fetch(0);
+ val = ao_scheme_poly_fetch();
+ atom = ao_scheme_poly_fetch();
if (!frame)
return AO_SCHEME_NIL;
ao_scheme_frame_bind(frame, frame->num - 1, atom, val);
}
}
- ao_scheme_cons_stash(0, code);
+ ao_scheme_cons_stash(code);
lambda = ao_scheme_alloc(sizeof (struct ao_scheme_lambda));
- code = ao_scheme_cons_fetch(0);
+ code = ao_scheme_cons_fetch();
if (!lambda)
return AO_SCHEME_NIL;
return ao_scheme_error(AO_SCHEME_INVALID, "need at least %d args, got %d", args_wanted, args_provided);
}
- ao_scheme_poly_stash(1, varargs);
+ ao_scheme_poly_stash(varargs);
next_frame = ao_scheme_frame_new(args_wanted + (varargs != AO_SCHEME_NIL));
- varargs = ao_scheme_poly_fetch(1);
+ varargs = ao_scheme_poly_fetch();
if (!next_frame)
return AO_SCHEME_NIL;
void **addr;
};
-static struct ao_scheme_cons *save_cons[2];
-static struct ao_scheme_string *save_string[2];
-static struct ao_scheme_frame *save_frame[1];
-static ao_poly save_poly[3];
+#define AO_SCHEME_NUM_STASH 6
+static ao_poly stash_poly[AO_SCHEME_NUM_STASH];
+static int stash_poly_ptr;
static const struct ao_scheme_root ao_scheme_root[] = {
{
- .type = &ao_scheme_cons_type,
- .addr = (void **) &save_cons[0],
- },
- {
- .type = &ao_scheme_cons_type,
- .addr = (void **) &save_cons[1],
- },
- {
- .type = &ao_scheme_string_type,
- .addr = (void **) &save_string[0],
+ .type = NULL,
+ .addr = (void **) (void *) &stash_poly[0]
},
{
- .type = &ao_scheme_string_type,
- .addr = (void **) &save_string[1],
+ .type = NULL,
+ .addr = (void **) (void *) &stash_poly[1]
},
{
- .type = &ao_scheme_frame_type,
- .addr = (void **) &save_frame[0],
+ .type = NULL,
+ .addr = (void **) (void *) &stash_poly[2]
},
{
.type = NULL,
- .addr = (void **) (void *) &save_poly[0]
+ .addr = (void **) (void *) &stash_poly[3]
},
{
.type = NULL,
- .addr = (void **) (void *) &save_poly[1]
+ .addr = (void **) (void *) &stash_poly[4]
},
{
.type = NULL,
- .addr = (void **) (void *) &save_poly[2]
+ .addr = (void **) (void *) &stash_poly[5]
},
{
.type = &ao_scheme_atom_type,
}
void
-ao_scheme_cons_stash(int id, struct ao_scheme_cons *cons)
-{
- assert(save_cons[id] == 0);
- save_cons[id] = cons;
-}
-
-struct ao_scheme_cons *
-ao_scheme_cons_fetch(int id)
-{
- struct ao_scheme_cons *cons = save_cons[id];
- save_cons[id] = NULL;
- return cons;
-}
-
-void
-ao_scheme_poly_stash(int id, ao_poly poly)
+ao_scheme_poly_stash(ao_poly p)
{
- assert(save_poly[id] == AO_SCHEME_NIL);
- save_poly[id] = poly;
+ assert(stash_poly_ptr < AO_SCHEME_NUM_STASH);
+ stash_poly[stash_poly_ptr++] = p;
}
ao_poly
-ao_scheme_poly_fetch(int id)
-{
- ao_poly poly = save_poly[id];
- save_poly[id] = AO_SCHEME_NIL;
- return poly;
-}
-
-void
-ao_scheme_string_stash(int id, struct ao_scheme_string *string)
+ao_scheme_poly_fetch(void)
{
- assert(save_string[id] == NULL);
- save_string[id] = string;
-}
+ ao_poly p;
-struct ao_scheme_string *
-ao_scheme_string_fetch(int id)
-{
- struct ao_scheme_string *string = save_string[id];
- save_string[id] = NULL;
- return string;
-}
-
-void
-ao_scheme_frame_stash(int id, struct ao_scheme_frame *frame)
-{
- assert(save_frame[id] == NULL);
- save_frame[id] = frame;
-}
-
-struct ao_scheme_frame *
-ao_scheme_frame_fetch(int id)
-{
- struct ao_scheme_frame *frame = save_frame[id];
- save_frame[id] = NULL;
- return frame;
+ assert (stash_poly_ptr > 0);
+ p = stash_poly[--stash_poly_ptr];
+ stash_poly[stash_poly_ptr] = AO_SCHEME_NIL;
+ return p;
}
int
struct ao_scheme_stack *n, *prev = NULL;
while (old) {
- ao_scheme_stack_stash(0, old);
- ao_scheme_stack_stash(1, new);
- ao_scheme_stack_stash(2, prev);
+ ao_scheme_stack_stash(old);
+ ao_scheme_stack_stash(new);
+ ao_scheme_stack_stash(prev);
n = ao_scheme_stack_new();
- prev = ao_scheme_stack_fetch(2);
- new = ao_scheme_stack_fetch(1);
- old = ao_scheme_stack_fetch(0);
+ prev = ao_scheme_stack_fetch();
+ new = ao_scheme_stack_fetch();
+ old = ao_scheme_stack_fetch();
if (!n)
return NULL;
int alen = strlen(a->val);
struct ao_scheme_string *r;
- ao_scheme_string_stash(0, a);
+ ao_scheme_string_stash(a);
r = ao_scheme_string_alloc(alen);
- a = ao_scheme_string_fetch(0);
+ a = ao_scheme_string_fetch();
if (!r)
return NULL;
strcpy(r->val, a->val);
int alen = strlen(a->name);
struct ao_scheme_string *r;
- ao_scheme_poly_stash(0, ao_scheme_atom_poly(a));
+ ao_scheme_atom_stash(a);
r = ao_scheme_string_alloc(alen);
- a = ao_scheme_poly_atom(ao_scheme_poly_fetch(0));
+ a = ao_scheme_atom_fetch();
if (!r)
return NULL;
strcpy(r->val, a->name);
int blen = strlen(b->val);
struct ao_scheme_string *r;
- ao_scheme_string_stash(0, a);
- ao_scheme_string_stash(1, b);
+ ao_scheme_string_stash(a);
+ ao_scheme_string_stash(b);
r = ao_scheme_string_alloc(alen + blen);
- a = ao_scheme_string_fetch(0);
- b = ao_scheme_string_fetch(1);
+ b = ao_scheme_string_fetch();
+ a = ao_scheme_string_fetch();
if (!r)
return NULL;
strcpy(r->val, a->val);
int len;
len = ao_scheme_cons_length(cons);
- ao_scheme_cons_stash(0, cons);
+ ao_scheme_cons_stash(cons);
r = ao_scheme_string_alloc(len);
- cons = ao_scheme_cons_fetch(0);
+ cons = ao_scheme_cons_fetch();
if (!r)
return AO_SCHEME_NIL;
rval = r->val;
for (i = 0; (c = a->val[i]); i++) {
struct ao_scheme_cons *n;
- ao_scheme_cons_stash(0, cons);
- ao_scheme_cons_stash(1, tail);
- ao_scheme_string_stash(0, a);
+ ao_scheme_cons_stash(cons);
+ ao_scheme_cons_stash(tail);
+ ao_scheme_string_stash(a);
n = ao_scheme_cons_cons(ao_scheme_int_poly(c), AO_SCHEME_NIL);
- a = ao_scheme_string_fetch(0);
- cons = ao_scheme_cons_fetch(0);
- tail = ao_scheme_cons_fetch(1);
+ a = ao_scheme_string_fetch();
+ tail = ao_scheme_cons_fetch();
+ cons = ao_scheme_cons_fetch();
if (!n) {
cons = NULL;
if (ao_scheme_exception)
return NULL;
- ao_scheme_cons_stash(0, cons);
+ ao_scheme_cons_stash(cons);
vector = ao_scheme_vector_alloc(length, AO_SCHEME_NIL);
- cons = ao_scheme_cons_fetch(0);
+ cons = ao_scheme_cons_fetch();
if (!vector)
return NULL;
i = 0;
struct ao_scheme_cons *cons = NULL;
for (i = length; i-- > 0;) {
- ao_scheme_poly_stash(2, ao_scheme_vector_poly(vector));
+ ao_scheme_vector_stash(vector);
cons = ao_scheme_cons_cons(vector->vals[i], ao_scheme_cons_poly(cons));
- vector = ao_scheme_poly_vector(ao_scheme_poly_fetch(2));
+ vector = ao_scheme_vector_fetch();
if (!cons)
return NULL;
}