2 * Copyright © 2016 Keith Packard <keithp@keithp.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
21 #define DBG_FREE_CONS 0
26 #include <ao_scheme_os.h>
31 typedef uint16_t ao_poly;
32 typedef int16_t ao_signed_poly;
36 struct ao_scheme_os_save {
39 uint16_t const_checksum;
40 uint16_t const_checksum_inv;
43 #define AO_SCHEME_POOL_EXTRA (sizeof(struct ao_scheme_os_save))
44 #define AO_SCHEME_POOL ((int) (AO_SCHEME_POOL_TOTAL - AO_SCHEME_POOL_EXTRA))
47 ao_scheme_os_save(void);
50 ao_scheme_os_restore_save(struct ao_scheme_os_save *save, int offset);
53 ao_scheme_os_restore(void);
57 #ifdef AO_SCHEME_MAKE_CONST
58 #define AO_SCHEME_POOL_CONST 16384
59 extern uint8_t ao_scheme_const[AO_SCHEME_POOL_CONST] __attribute__((aligned(4)));
60 #define ao_scheme_pool ao_scheme_const
61 #define AO_SCHEME_POOL AO_SCHEME_POOL_CONST
63 #define _atom(n) ao_scheme_atom_poly(ao_scheme_atom_intern(n))
64 #define _bool(v) ao_scheme_bool_poly(ao_scheme_bool_get(v))
66 #define _ao_scheme_bool_true _bool(1)
67 #define _ao_scheme_bool_false _bool(0)
69 #define _ao_scheme_atom_eof _atom("eof")
70 #define _ao_scheme_atom_else _atom("else")
72 #define AO_SCHEME_BUILTIN_ATOMS
73 #include "ao_scheme_builtin.h"
76 #include "ao_scheme_const.h"
77 #ifndef AO_SCHEME_POOL
78 #define AO_SCHEME_POOL 3072
80 extern uint8_t ao_scheme_pool[AO_SCHEME_POOL + AO_SCHEME_POOL_EXTRA] __attribute__((aligned(4)));
84 #define AO_SCHEME_CONS 0
85 #define AO_SCHEME_INT 1
86 #define AO_SCHEME_STRING 2
87 #define AO_SCHEME_OTHER 3
89 #define AO_SCHEME_TYPE_MASK 0x0003
90 #define AO_SCHEME_TYPE_SHIFT 2
91 #define AO_SCHEME_REF_MASK 0x7ffc
92 #define AO_SCHEME_CONST 0x8000
94 /* These have a type value at the start of the struct */
95 #define AO_SCHEME_ATOM 4
96 #define AO_SCHEME_BUILTIN 5
97 #define AO_SCHEME_FRAME 6
98 #define AO_SCHEME_FRAME_VALS 7
99 #define AO_SCHEME_LAMBDA 8
100 #define AO_SCHEME_STACK 9
101 #define AO_SCHEME_BOOL 10
102 #define AO_SCHEME_BIGINT 11
103 #define AO_SCHEME_FLOAT 12
104 #define AO_SCHEME_NUM_TYPE 13
106 /* Leave two bits for types to use as they please */
107 #define AO_SCHEME_OTHER_TYPE_MASK 0x3f
109 #define AO_SCHEME_NIL 0
111 extern uint16_t ao_scheme_top;
113 #define AO_SCHEME_OOM 0x01
114 #define AO_SCHEME_DIVIDE_BY_ZERO 0x02
115 #define AO_SCHEME_INVALID 0x04
116 #define AO_SCHEME_UNDEFINED 0x08
117 #define AO_SCHEME_REDEFINED 0x10
118 #define AO_SCHEME_EOF 0x20
119 #define AO_SCHEME_EXIT 0x40
121 extern uint8_t ao_scheme_exception;
124 ao_scheme_is_const(ao_poly poly) {
125 return poly & AO_SCHEME_CONST;
128 #define AO_SCHEME_IS_CONST(a) (ao_scheme_const <= ((uint8_t *) (a)) && ((uint8_t *) (a)) < ao_scheme_const + AO_SCHEME_POOL_CONST)
129 #define AO_SCHEME_IS_POOL(a) (ao_scheme_pool <= ((uint8_t *) (a)) && ((uint8_t *) (a)) < ao_scheme_pool + AO_SCHEME_POOL)
130 #define AO_SCHEME_IS_INT(p) (ao_scheme_poly_base_type(p) == AO_SCHEME_INT)
133 ao_scheme_ref(ao_poly poly);
136 ao_scheme_poly(const void *addr, ao_poly type);
138 struct ao_scheme_type {
139 int (*size)(void *addr);
140 void (*mark)(void *addr);
141 void (*move)(void *addr);
145 struct ao_scheme_cons {
150 struct ao_scheme_atom {
157 struct ao_scheme_val {
162 struct ao_scheme_frame_vals {
165 struct ao_scheme_val vals[];
168 struct ao_scheme_frame {
175 struct ao_scheme_bool {
181 struct ao_scheme_bigint {
185 struct ao_scheme_float {
192 #if __BYTE_ORDER == __LITTLE_ENDIAN
193 static inline uint32_t
194 ao_scheme_int_bigint(int32_t i) {
195 return AO_SCHEME_BIGINT | (i << 8);
197 static inline int32_t
198 ao_scheme_bigint_int(uint32_t bi) {
199 return (int32_t) bi >> 8;
202 static inline uint32_t
203 ao_scheme_int_bigint(int32_t i) {
204 return (uint32_t) (i & 0xffffff) | (AO_SCHEME_BIGINT << 24);
206 static inlint int32_t
207 ao_scheme_bigint_int(uint32_t bi) {
208 return (int32_t) (bi << 8) >> 8;
212 #define AO_SCHEME_MIN_INT (-(1 << (15 - AO_SCHEME_TYPE_SHIFT)))
213 #define AO_SCHEME_MAX_INT ((1 << (15 - AO_SCHEME_TYPE_SHIFT)) - 1)
214 #define AO_SCHEME_MIN_BIGINT (-(1 << 24))
215 #define AO_SCHEME_MAX_BIGINT ((1 << 24) - 1)
217 #define AO_SCHEME_NOT_INTEGER 0x7fffffff
219 /* Set on type when the frame escapes the lambda */
220 #define AO_SCHEME_FRAME_MARK 0x80
221 #define AO_SCHEME_FRAME_PRINT 0x40
223 static inline int ao_scheme_frame_marked(struct ao_scheme_frame *f) {
224 return f->type & AO_SCHEME_FRAME_MARK;
227 static inline struct ao_scheme_frame *
228 ao_scheme_poly_frame(ao_poly poly) {
229 return ao_scheme_ref(poly);
232 static inline ao_poly
233 ao_scheme_frame_poly(struct ao_scheme_frame *frame) {
234 return ao_scheme_poly(frame, AO_SCHEME_OTHER);
237 static inline struct ao_scheme_frame_vals *
238 ao_scheme_poly_frame_vals(ao_poly poly) {
239 return ao_scheme_ref(poly);
242 static inline ao_poly
243 ao_scheme_frame_vals_poly(struct ao_scheme_frame_vals *vals) {
244 return ao_scheme_poly(vals, AO_SCHEME_OTHER);
248 eval_sexpr, /* Evaluate an sexpr */
249 eval_val, /* Value computed */
250 eval_formal, /* Formal computed */
251 eval_exec, /* Start a lambda evaluation */
252 eval_apply, /* Execute apply */
253 eval_cond, /* Start next cond clause */
254 eval_cond_test, /* Check cond condition */
255 eval_begin, /* Start next begin entry */
256 eval_while, /* Start while condition */
257 eval_while_test, /* Check while condition */
258 eval_macro, /* Finished with macro generation */
261 struct ao_scheme_stack {
262 uint8_t type; /* AO_SCHEME_STACK */
263 uint8_t state; /* enum eval_state */
264 ao_poly prev; /* previous stack frame */
265 ao_poly sexprs; /* expressions to evaluate */
266 ao_poly values; /* values computed */
267 ao_poly values_tail; /* end of the values list for easy appending */
268 ao_poly frame; /* current lookup frame */
269 ao_poly list; /* most recent function call */
272 #define AO_SCHEME_STACK_MARK 0x80 /* set on type when a reference has been taken */
273 #define AO_SCHEME_STACK_PRINT 0x40 /* stack is being printed */
275 static inline int ao_scheme_stack_marked(struct ao_scheme_stack *s) {
276 return s->type & AO_SCHEME_STACK_MARK;
279 static inline void ao_scheme_stack_mark(struct ao_scheme_stack *s) {
280 s->type |= AO_SCHEME_STACK_MARK;
283 static inline struct ao_scheme_stack *
284 ao_scheme_poly_stack(ao_poly p)
286 return ao_scheme_ref(p);
289 static inline ao_poly
290 ao_scheme_stack_poly(struct ao_scheme_stack *stack)
292 return ao_scheme_poly(stack, AO_SCHEME_OTHER);
295 extern ao_poly ao_scheme_v;
297 #define AO_SCHEME_FUNC_LAMBDA 0
298 #define AO_SCHEME_FUNC_NLAMBDA 1
299 #define AO_SCHEME_FUNC_MACRO 2
301 #define AO_SCHEME_FUNC_FREE_ARGS 0x80
302 #define AO_SCHEME_FUNC_MASK 0x7f
304 #define AO_SCHEME_FUNC_F_LAMBDA (AO_SCHEME_FUNC_FREE_ARGS | AO_SCHEME_FUNC_LAMBDA)
305 #define AO_SCHEME_FUNC_F_NLAMBDA (AO_SCHEME_FUNC_FREE_ARGS | AO_SCHEME_FUNC_NLAMBDA)
306 #define AO_SCHEME_FUNC_F_MACRO (AO_SCHEME_FUNC_FREE_ARGS | AO_SCHEME_FUNC_MACRO)
308 struct ao_scheme_builtin {
314 #define AO_SCHEME_BUILTIN_ID
315 #include "ao_scheme_builtin.h"
317 typedef ao_poly (*ao_scheme_func_t)(struct ao_scheme_cons *cons);
319 extern const ao_scheme_func_t ao_scheme_builtins[];
321 static inline ao_scheme_func_t
322 ao_scheme_func(struct ao_scheme_builtin *b)
324 return ao_scheme_builtins[b->func];
327 struct ao_scheme_lambda {
334 static inline struct ao_scheme_lambda *
335 ao_scheme_poly_lambda(ao_poly poly)
337 return ao_scheme_ref(poly);
340 static inline ao_poly
341 ao_scheme_lambda_poly(struct ao_scheme_lambda *lambda)
343 return ao_scheme_poly(lambda, AO_SCHEME_OTHER);
347 ao_scheme_poly_other(ao_poly poly) {
348 return ao_scheme_ref(poly);
351 static inline uint8_t
352 ao_scheme_other_type(void *other) {
354 if ((*((uint8_t *) other) & AO_SCHEME_OTHER_TYPE_MASK) >= AO_SCHEME_NUM_TYPE)
357 return *((uint8_t *) other) & AO_SCHEME_OTHER_TYPE_MASK;
360 static inline ao_poly
361 ao_scheme_other_poly(const void *other)
363 return ao_scheme_poly(other, AO_SCHEME_OTHER);
367 ao_scheme_size_round(int size)
369 return (size + 3) & ~3;
373 ao_scheme_size(const struct ao_scheme_type *type, void *addr)
375 return ao_scheme_size_round(type->size(addr));
378 #define AO_SCHEME_OTHER_POLY(other) ((ao_poly)(other) + AO_SCHEME_OTHER)
380 static inline int ao_scheme_poly_base_type(ao_poly poly) {
381 return poly & AO_SCHEME_TYPE_MASK;
384 static inline int ao_scheme_poly_type(ao_poly poly) {
385 int type = poly & AO_SCHEME_TYPE_MASK;
386 if (type == AO_SCHEME_OTHER)
387 return ao_scheme_other_type(ao_scheme_poly_other(poly));
392 ao_scheme_is_cons(ao_poly poly) {
393 return (ao_scheme_poly_base_type(poly) == AO_SCHEME_CONS);
397 ao_scheme_is_pair(ao_poly poly) {
398 return poly != AO_SCHEME_NIL && (ao_scheme_poly_base_type(poly) == AO_SCHEME_CONS);
401 static inline struct ao_scheme_cons *
402 ao_scheme_poly_cons(ao_poly poly)
404 return ao_scheme_ref(poly);
407 static inline ao_poly
408 ao_scheme_cons_poly(struct ao_scheme_cons *cons)
410 return ao_scheme_poly(cons, AO_SCHEME_CONS);
413 static inline int32_t
414 ao_scheme_poly_int(ao_poly poly)
416 return (int32_t) ((ao_signed_poly) poly >> AO_SCHEME_TYPE_SHIFT);
419 static inline ao_poly
420 ao_scheme_int_poly(int32_t i)
422 return ((ao_poly) i << 2) | AO_SCHEME_INT;
425 static inline struct ao_scheme_bigint *
426 ao_scheme_poly_bigint(ao_poly poly)
428 return ao_scheme_ref(poly);
431 static inline ao_poly
432 ao_scheme_bigint_poly(struct ao_scheme_bigint *bi)
434 return ao_scheme_poly(bi, AO_SCHEME_OTHER);
438 ao_scheme_poly_string(ao_poly poly)
440 return ao_scheme_ref(poly);
443 static inline ao_poly
444 ao_scheme_string_poly(char *s)
446 return ao_scheme_poly(s, AO_SCHEME_STRING);
449 static inline struct ao_scheme_atom *
450 ao_scheme_poly_atom(ao_poly poly)
452 return ao_scheme_ref(poly);
455 static inline ao_poly
456 ao_scheme_atom_poly(struct ao_scheme_atom *a)
458 return ao_scheme_poly(a, AO_SCHEME_OTHER);
461 static inline struct ao_scheme_builtin *
462 ao_scheme_poly_builtin(ao_poly poly)
464 return ao_scheme_ref(poly);
467 static inline ao_poly
468 ao_scheme_builtin_poly(struct ao_scheme_builtin *b)
470 return ao_scheme_poly(b, AO_SCHEME_OTHER);
473 static inline ao_poly
474 ao_scheme_bool_poly(struct ao_scheme_bool *b)
476 return ao_scheme_poly(b, AO_SCHEME_OTHER);
479 static inline struct ao_scheme_bool *
480 ao_scheme_poly_bool(ao_poly poly)
482 return ao_scheme_ref(poly);
485 static inline ao_poly
486 ao_scheme_float_poly(struct ao_scheme_float *f)
488 return ao_scheme_poly(f, AO_SCHEME_OTHER);
491 static inline struct ao_scheme_float *
492 ao_scheme_poly_float(ao_poly poly)
494 return ao_scheme_ref(poly);
498 ao_scheme_poly_number(ao_poly p);
500 /* memory functions */
502 extern int ao_scheme_collects[2];
503 extern int ao_scheme_freed[2];
504 extern int ao_scheme_loops[2];
506 /* returns 1 if the object was already marked */
508 ao_scheme_mark(const struct ao_scheme_type *type, void *addr);
510 /* returns 1 if the object was already marked */
512 ao_scheme_mark_memory(const struct ao_scheme_type *type, void *addr);
515 ao_scheme_move_map(void *addr);
517 /* returns 1 if the object was already moved */
519 ao_scheme_move(const struct ao_scheme_type *type, void **ref);
521 /* returns 1 if the object was already moved */
523 ao_scheme_move_memory(const struct ao_scheme_type *type, void **ref);
526 ao_scheme_alloc(int size);
528 #define AO_SCHEME_COLLECT_FULL 1
529 #define AO_SCHEME_COLLECT_INCREMENTAL 0
532 ao_scheme_collect(uint8_t style);
536 ao_scheme_cons_check(struct ao_scheme_cons *cons);
540 ao_scheme_cons_stash(int id, struct ao_scheme_cons *cons);
542 struct ao_scheme_cons *
543 ao_scheme_cons_fetch(int id);
546 ao_scheme_poly_stash(int id, ao_poly poly);
549 ao_scheme_poly_fetch(int id);
552 ao_scheme_string_stash(int id, char *string);
555 ao_scheme_string_fetch(int id);
558 ao_scheme_stack_stash(int id, struct ao_scheme_stack *stack) {
559 ao_scheme_poly_stash(id, ao_scheme_stack_poly(stack));
562 static inline struct ao_scheme_stack *
563 ao_scheme_stack_fetch(int id) {
564 return ao_scheme_poly_stack(ao_scheme_poly_fetch(id));
568 ao_scheme_frame_stash(int id, struct ao_scheme_frame *frame);
570 struct ao_scheme_frame *
571 ao_scheme_frame_fetch(int id);
575 extern const struct ao_scheme_type ao_scheme_bool_type;
578 ao_scheme_bool_write(ao_poly v);
580 #ifdef AO_SCHEME_MAKE_CONST
581 struct ao_scheme_bool *ao_scheme_true, *ao_scheme_false;
583 struct ao_scheme_bool *
584 ao_scheme_bool_get(uint8_t value);
588 extern const struct ao_scheme_type ao_scheme_cons_type;
590 struct ao_scheme_cons *
591 ao_scheme_cons_cons(ao_poly car, ao_poly cdr);
593 /* Return a cons or NULL for a proper list, else error */
594 struct ao_scheme_cons *
595 ao_scheme_cons_cdr(struct ao_scheme_cons *cons);
598 ao_scheme__cons(ao_poly car, ao_poly cdr);
600 extern struct ao_scheme_cons *ao_scheme_cons_free_list;
603 ao_scheme_cons_free(struct ao_scheme_cons *cons);
606 ao_scheme_cons_write(ao_poly);
609 ao_scheme_cons_display(ao_poly);
612 ao_scheme_cons_length(struct ao_scheme_cons *cons);
615 extern const struct ao_scheme_type ao_scheme_string_type;
618 ao_scheme_string_copy(char *a);
621 ao_scheme_string_cat(char *a, char *b);
624 ao_scheme_string_pack(struct ao_scheme_cons *cons);
627 ao_scheme_string_unpack(char *a);
630 ao_scheme_string_write(ao_poly s);
633 ao_scheme_string_display(ao_poly s);
636 extern const struct ao_scheme_type ao_scheme_atom_type;
638 extern struct ao_scheme_atom *ao_scheme_atoms;
639 extern struct ao_scheme_frame *ao_scheme_frame_global;
640 extern struct ao_scheme_frame *ao_scheme_frame_current;
643 ao_scheme_atom_write(ao_poly a);
645 struct ao_scheme_atom *
646 ao_scheme_atom_intern(char *name);
649 ao_scheme_atom_ref(ao_poly atom, struct ao_scheme_frame **frame_ref);
652 ao_scheme_atom_get(ao_poly atom);
655 ao_scheme_atom_set(ao_poly atom, ao_poly val);
658 ao_scheme_atom_def(ao_poly atom, ao_poly val);
662 ao_scheme_int_write(ao_poly i);
665 ao_scheme_poly_integer(ao_poly p);
668 ao_scheme_integer_poly(int32_t i);
671 ao_scheme_integer_typep(uint8_t t)
673 return (t == AO_SCHEME_INT) || (t == AO_SCHEME_BIGINT);
677 ao_scheme_bigint_write(ao_poly i);
679 extern const struct ao_scheme_type ao_scheme_bigint_type;
682 ao_scheme_poly_write(ao_poly p);
685 ao_scheme_poly_display(ao_poly p);
688 ao_scheme_poly_mark(ao_poly p, uint8_t note_cons);
690 /* returns 1 if the object has already been moved */
692 ao_scheme_poly_move(ao_poly *p, uint8_t note_cons);
697 ao_scheme_eval_clear_globals(void);
700 ao_scheme_eval_restart(void);
703 ao_scheme_eval(ao_poly p);
706 ao_scheme_set_cond(struct ao_scheme_cons *cons);
709 extern const struct ao_scheme_type ao_scheme_float_type;
712 ao_scheme_float_write(ao_poly p);
715 ao_scheme_float_get(float value);
717 static inline uint8_t
718 ao_scheme_number_typep(uint8_t t)
720 return ao_scheme_integer_typep(t) || (t == AO_SCHEME_FLOAT);
724 ao_scheme_poly_number(ao_poly p);
728 ao_scheme_builtin_write(ao_poly b);
730 extern const struct ao_scheme_type ao_scheme_builtin_type;
732 /* Check argument count */
734 ao_scheme_check_argc(ao_poly name, struct ao_scheme_cons *cons, int min, int max);
736 /* Check argument type */
738 ao_scheme_check_argt(ao_poly name, struct ao_scheme_cons *cons, int argc, int type, int nil_ok);
740 /* Fetch an arg (nil if off the end) */
742 ao_scheme_arg(struct ao_scheme_cons *cons, int argc);
745 ao_scheme_args_name(uint8_t args);
748 extern struct ao_scheme_cons *ao_scheme_read_cons;
749 extern struct ao_scheme_cons *ao_scheme_read_cons_tail;
750 extern struct ao_scheme_cons *ao_scheme_read_stack;
753 ao_scheme_read(void);
757 ao_scheme_read_eval_print(void);
760 extern const struct ao_scheme_type ao_scheme_frame_type;
761 extern const struct ao_scheme_type ao_scheme_frame_vals_type;
763 #define AO_SCHEME_FRAME_FREE 6
765 extern struct ao_scheme_frame *ao_scheme_frame_free_list[AO_SCHEME_FRAME_FREE];
768 ao_scheme_frame_mark(struct ao_scheme_frame *frame);
771 ao_scheme_frame_ref(struct ao_scheme_frame *frame, ao_poly atom);
773 struct ao_scheme_frame *
774 ao_scheme_frame_new(int num);
777 ao_scheme_frame_free(struct ao_scheme_frame *frame);
780 ao_scheme_frame_bind(struct ao_scheme_frame *frame, int num, ao_poly atom, ao_poly val);
783 ao_scheme_frame_add(struct ao_scheme_frame *frame, ao_poly atom, ao_poly val);
786 ao_scheme_frame_write(ao_poly p);
789 ao_scheme_frame_init(void);
792 extern const struct ao_scheme_type ao_scheme_lambda_type;
794 extern const char * const ao_scheme_state_names[];
796 struct ao_scheme_lambda *
797 ao_scheme_lambda_new(ao_poly cons);
800 ao_scheme_lambda_write(ao_poly lambda);
803 ao_scheme_lambda_eval(void);
807 extern const struct ao_scheme_type ao_scheme_stack_type;
808 extern struct ao_scheme_stack *ao_scheme_stack;
809 extern struct ao_scheme_stack *ao_scheme_stack_free_list;
812 ao_scheme_stack_reset(struct ao_scheme_stack *stack);
815 ao_scheme_stack_push(void);
818 ao_scheme_stack_pop(void);
821 ao_scheme_stack_clear(void);
824 ao_scheme_stack_write(ao_poly stack);
827 ao_scheme_stack_eval(void);
832 ao_scheme_vprintf(char *format, va_list args);
835 ao_scheme_printf(char *format, ...);
838 ao_scheme_error_poly(char *name, ao_poly poly, ao_poly last);
841 ao_scheme_error_frame(int indent, char *name, struct ao_scheme_frame *frame);
844 ao_scheme_error(int error, char *format, ...);
848 #define AO_SCHEME_BUILTIN_DECLS
849 #include "ao_scheme_builtin.h"
851 /* debugging macros */
853 #if DBG_EVAL || DBG_READ || DBG_MEM
855 int ao_scheme_stack_depth;
857 #define DBG_INDENT() do { int _s; for(_s = 0; _s < ao_scheme_stack_depth; _s++) printf(" "); } while(0)
858 #define DBG_IN() (++ao_scheme_stack_depth)
859 #define DBG_OUT() (--ao_scheme_stack_depth)
860 #define DBG_RESET() (ao_scheme_stack_depth = 0)
861 #define DBG(...) ao_scheme_printf(__VA_ARGS__)
862 #define DBGI(...) do { printf("%4d: ", __LINE__); DBG_INDENT(); DBG(__VA_ARGS__); } while (0)
863 #define DBG_CONS(a) ao_scheme_cons_write(ao_scheme_cons_poly(a))
864 #define DBG_POLY(a) ao_scheme_poly_write(a)
865 #define OFFSET(a) ((a) ? (int) ((uint8_t *) a - ao_scheme_pool) : -1)
866 #define DBG_STACK() ao_scheme_stack_write(ao_scheme_stack_poly(ao_scheme_stack))
868 ao_scheme_frames_dump(void)
870 struct ao_scheme_stack *s;
871 DBGI(".. current frame: "); DBG_POLY(ao_scheme_frame_poly(ao_scheme_frame_current)); DBG("\n");
872 for (s = ao_scheme_stack; s; s = ao_scheme_poly_stack(s->prev)) {
873 DBGI(".. stack frame: "); DBG_POLY(s->frame); DBG("\n");
876 #define DBG_FRAMES() ao_scheme_frames_dump()
892 #define RDBGI(...) DBGI(__VA_ARGS__)
893 #define RDBG_IN() DBG_IN()
894 #define RDBG_OUT() DBG_OUT()
901 #define DBG_MEM_START 1
906 extern int dbg_move_depth;
908 #define MDBG_OFFSET(a) ((a) ? (int) ((uint8_t *) (a) - ao_scheme_pool) : -1)
912 #define MDBG_DO(a) DBG_DO(a)
913 #define MDBG_MOVE(...) do { if (dbg_mem) { int d; for (d = 0; d < dbg_move_depth; d++) printf (" "); printf(__VA_ARGS__); } } while (0)
914 #define MDBG_MORE(...) do { if (dbg_mem) printf(__VA_ARGS__); } while (0)
915 #define MDBG_MOVE_IN() (dbg_move_depth++)
916 #define MDBG_MOVE_OUT() (assert(--dbg_move_depth >= 0))
921 #define MDBG_MOVE(...)
922 #define MDBG_MORE(...)
923 #define MDBG_MOVE_IN()
924 #define MDBG_MOVE_OUT()
928 #endif /* _AO_SCHEME_H_ */