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 #ifndef AO_SCHEME_POOL_EXTRA
81 #define AO_SCHEME_POOL_EXTRA 0
83 extern uint8_t ao_scheme_pool[AO_SCHEME_POOL + AO_SCHEME_POOL_EXTRA] __attribute__((aligned(4)));
87 #define AO_SCHEME_CONS 0
88 #define AO_SCHEME_INT 1
89 #define AO_SCHEME_STRING 2
90 #define AO_SCHEME_OTHER 3
92 #define AO_SCHEME_TYPE_MASK 0x0003
93 #define AO_SCHEME_TYPE_SHIFT 2
94 #define AO_SCHEME_REF_MASK 0x7ffc
95 #define AO_SCHEME_CONST 0x8000
97 /* These have a type value at the start of the struct */
98 #define AO_SCHEME_ATOM 4
99 #define AO_SCHEME_BUILTIN 5
100 #define AO_SCHEME_FRAME 6
101 #define AO_SCHEME_FRAME_VALS 7
102 #define AO_SCHEME_LAMBDA 8
103 #define AO_SCHEME_STACK 9
104 #define AO_SCHEME_BOOL 10
105 #define AO_SCHEME_BIGINT 11
106 #define AO_SCHEME_FLOAT 12
107 #define AO_SCHEME_NUM_TYPE 13
109 /* Leave two bits for types to use as they please */
110 #define AO_SCHEME_OTHER_TYPE_MASK 0x3f
112 #define AO_SCHEME_NIL 0
114 extern uint16_t ao_scheme_top;
116 #define AO_SCHEME_OOM 0x01
117 #define AO_SCHEME_DIVIDE_BY_ZERO 0x02
118 #define AO_SCHEME_INVALID 0x04
119 #define AO_SCHEME_UNDEFINED 0x08
120 #define AO_SCHEME_REDEFINED 0x10
121 #define AO_SCHEME_EOF 0x20
122 #define AO_SCHEME_EXIT 0x40
124 extern uint8_t ao_scheme_exception;
127 ao_scheme_is_const(ao_poly poly) {
128 return poly & AO_SCHEME_CONST;
131 #define AO_SCHEME_IS_CONST(a) (ao_scheme_const <= ((uint8_t *) (a)) && ((uint8_t *) (a)) < ao_scheme_const + AO_SCHEME_POOL_CONST)
132 #define AO_SCHEME_IS_POOL(a) (ao_scheme_pool <= ((uint8_t *) (a)) && ((uint8_t *) (a)) < ao_scheme_pool + AO_SCHEME_POOL)
133 #define AO_SCHEME_IS_INT(p) (ao_scheme_poly_base_type(p) == AO_SCHEME_INT)
136 ao_scheme_ref(ao_poly poly);
139 ao_scheme_poly(const void *addr, ao_poly type);
141 struct ao_scheme_type {
142 int (*size)(void *addr);
143 void (*mark)(void *addr);
144 void (*move)(void *addr);
148 struct ao_scheme_cons {
153 struct ao_scheme_atom {
160 struct ao_scheme_val {
165 struct ao_scheme_frame_vals {
168 struct ao_scheme_val vals[];
171 struct ao_scheme_frame {
178 struct ao_scheme_bool {
184 struct ao_scheme_bigint {
188 struct ao_scheme_float {
195 #if __BYTE_ORDER == __LITTLE_ENDIAN
196 static inline uint32_t
197 ao_scheme_int_bigint(int32_t i) {
198 return AO_SCHEME_BIGINT | (i << 8);
200 static inline int32_t
201 ao_scheme_bigint_int(uint32_t bi) {
202 return (int32_t) bi >> 8;
205 static inline uint32_t
206 ao_scheme_int_bigint(int32_t i) {
207 return (uint32_t) (i & 0xffffff) | (AO_SCHEME_BIGINT << 24);
209 static inlint int32_t
210 ao_scheme_bigint_int(uint32_t bi) {
211 return (int32_t) (bi << 8) >> 8;
215 #define AO_SCHEME_MIN_INT (-(1 << (15 - AO_SCHEME_TYPE_SHIFT)))
216 #define AO_SCHEME_MAX_INT ((1 << (15 - AO_SCHEME_TYPE_SHIFT)) - 1)
217 #define AO_SCHEME_MIN_BIGINT (-(1 << 24))
218 #define AO_SCHEME_MAX_BIGINT ((1 << 24) - 1)
220 #define AO_SCHEME_NOT_INTEGER 0x7fffffff
222 /* Set on type when the frame escapes the lambda */
223 #define AO_SCHEME_FRAME_MARK 0x80
224 #define AO_SCHEME_FRAME_PRINT 0x40
226 static inline int ao_scheme_frame_marked(struct ao_scheme_frame *f) {
227 return f->type & AO_SCHEME_FRAME_MARK;
230 static inline struct ao_scheme_frame *
231 ao_scheme_poly_frame(ao_poly poly) {
232 return ao_scheme_ref(poly);
235 static inline ao_poly
236 ao_scheme_frame_poly(struct ao_scheme_frame *frame) {
237 return ao_scheme_poly(frame, AO_SCHEME_OTHER);
240 static inline struct ao_scheme_frame_vals *
241 ao_scheme_poly_frame_vals(ao_poly poly) {
242 return ao_scheme_ref(poly);
245 static inline ao_poly
246 ao_scheme_frame_vals_poly(struct ao_scheme_frame_vals *vals) {
247 return ao_scheme_poly(vals, AO_SCHEME_OTHER);
251 eval_sexpr, /* Evaluate an sexpr */
252 eval_val, /* Value computed */
253 eval_formal, /* Formal computed */
254 eval_exec, /* Start a lambda evaluation */
255 eval_apply, /* Execute apply */
256 eval_cond, /* Start next cond clause */
257 eval_cond_test, /* Check cond condition */
258 eval_begin, /* Start next begin entry */
259 eval_while, /* Start while condition */
260 eval_while_test, /* Check while condition */
261 eval_macro, /* Finished with macro generation */
264 struct ao_scheme_stack {
265 uint8_t type; /* AO_SCHEME_STACK */
266 uint8_t state; /* enum eval_state */
267 ao_poly prev; /* previous stack frame */
268 ao_poly sexprs; /* expressions to evaluate */
269 ao_poly values; /* values computed */
270 ao_poly values_tail; /* end of the values list for easy appending */
271 ao_poly frame; /* current lookup frame */
272 ao_poly list; /* most recent function call */
275 #define AO_SCHEME_STACK_MARK 0x80 /* set on type when a reference has been taken */
276 #define AO_SCHEME_STACK_PRINT 0x40 /* stack is being printed */
278 static inline int ao_scheme_stack_marked(struct ao_scheme_stack *s) {
279 return s->type & AO_SCHEME_STACK_MARK;
282 static inline void ao_scheme_stack_mark(struct ao_scheme_stack *s) {
283 s->type |= AO_SCHEME_STACK_MARK;
286 static inline struct ao_scheme_stack *
287 ao_scheme_poly_stack(ao_poly p)
289 return ao_scheme_ref(p);
292 static inline ao_poly
293 ao_scheme_stack_poly(struct ao_scheme_stack *stack)
295 return ao_scheme_poly(stack, AO_SCHEME_OTHER);
298 extern ao_poly ao_scheme_v;
300 #define AO_SCHEME_FUNC_LAMBDA 0
301 #define AO_SCHEME_FUNC_NLAMBDA 1
302 #define AO_SCHEME_FUNC_MACRO 2
304 #define AO_SCHEME_FUNC_FREE_ARGS 0x80
305 #define AO_SCHEME_FUNC_MASK 0x7f
307 #define AO_SCHEME_FUNC_F_LAMBDA (AO_SCHEME_FUNC_FREE_ARGS | AO_SCHEME_FUNC_LAMBDA)
308 #define AO_SCHEME_FUNC_F_NLAMBDA (AO_SCHEME_FUNC_FREE_ARGS | AO_SCHEME_FUNC_NLAMBDA)
309 #define AO_SCHEME_FUNC_F_MACRO (AO_SCHEME_FUNC_FREE_ARGS | AO_SCHEME_FUNC_MACRO)
311 struct ao_scheme_builtin {
317 #define AO_SCHEME_BUILTIN_ID
318 #include "ao_scheme_builtin.h"
320 typedef ao_poly (*ao_scheme_func_t)(struct ao_scheme_cons *cons);
322 extern const ao_scheme_func_t ao_scheme_builtins[];
324 static inline ao_scheme_func_t
325 ao_scheme_func(struct ao_scheme_builtin *b)
327 return ao_scheme_builtins[b->func];
330 struct ao_scheme_lambda {
337 static inline struct ao_scheme_lambda *
338 ao_scheme_poly_lambda(ao_poly poly)
340 return ao_scheme_ref(poly);
343 static inline ao_poly
344 ao_scheme_lambda_poly(struct ao_scheme_lambda *lambda)
346 return ao_scheme_poly(lambda, AO_SCHEME_OTHER);
350 ao_scheme_poly_other(ao_poly poly) {
351 return ao_scheme_ref(poly);
354 static inline uint8_t
355 ao_scheme_other_type(void *other) {
357 if ((*((uint8_t *) other) & AO_SCHEME_OTHER_TYPE_MASK) >= AO_SCHEME_NUM_TYPE)
360 return *((uint8_t *) other) & AO_SCHEME_OTHER_TYPE_MASK;
363 static inline ao_poly
364 ao_scheme_other_poly(const void *other)
366 return ao_scheme_poly(other, AO_SCHEME_OTHER);
370 ao_scheme_size_round(int size)
372 return (size + 3) & ~3;
376 ao_scheme_size(const struct ao_scheme_type *type, void *addr)
378 return ao_scheme_size_round(type->size(addr));
381 #define AO_SCHEME_OTHER_POLY(other) ((ao_poly)(other) + AO_SCHEME_OTHER)
383 static inline int ao_scheme_poly_base_type(ao_poly poly) {
384 return poly & AO_SCHEME_TYPE_MASK;
387 static inline int ao_scheme_poly_type(ao_poly poly) {
388 int type = poly & AO_SCHEME_TYPE_MASK;
389 if (type == AO_SCHEME_OTHER)
390 return ao_scheme_other_type(ao_scheme_poly_other(poly));
395 ao_scheme_is_cons(ao_poly poly) {
396 return (ao_scheme_poly_base_type(poly) == AO_SCHEME_CONS);
400 ao_scheme_is_pair(ao_poly poly) {
401 return poly != AO_SCHEME_NIL && (ao_scheme_poly_base_type(poly) == AO_SCHEME_CONS);
404 static inline struct ao_scheme_cons *
405 ao_scheme_poly_cons(ao_poly poly)
407 return ao_scheme_ref(poly);
410 static inline ao_poly
411 ao_scheme_cons_poly(struct ao_scheme_cons *cons)
413 return ao_scheme_poly(cons, AO_SCHEME_CONS);
416 static inline int32_t
417 ao_scheme_poly_int(ao_poly poly)
419 return (int32_t) ((ao_signed_poly) poly >> AO_SCHEME_TYPE_SHIFT);
422 static inline ao_poly
423 ao_scheme_int_poly(int32_t i)
425 return ((ao_poly) i << 2) | AO_SCHEME_INT;
428 static inline struct ao_scheme_bigint *
429 ao_scheme_poly_bigint(ao_poly poly)
431 return ao_scheme_ref(poly);
434 static inline ao_poly
435 ao_scheme_bigint_poly(struct ao_scheme_bigint *bi)
437 return ao_scheme_poly(bi, AO_SCHEME_OTHER);
441 ao_scheme_poly_string(ao_poly poly)
443 return ao_scheme_ref(poly);
446 static inline ao_poly
447 ao_scheme_string_poly(char *s)
449 return ao_scheme_poly(s, AO_SCHEME_STRING);
452 static inline struct ao_scheme_atom *
453 ao_scheme_poly_atom(ao_poly poly)
455 return ao_scheme_ref(poly);
458 static inline ao_poly
459 ao_scheme_atom_poly(struct ao_scheme_atom *a)
461 return ao_scheme_poly(a, AO_SCHEME_OTHER);
464 static inline struct ao_scheme_builtin *
465 ao_scheme_poly_builtin(ao_poly poly)
467 return ao_scheme_ref(poly);
470 static inline ao_poly
471 ao_scheme_builtin_poly(struct ao_scheme_builtin *b)
473 return ao_scheme_poly(b, AO_SCHEME_OTHER);
476 static inline ao_poly
477 ao_scheme_bool_poly(struct ao_scheme_bool *b)
479 return ao_scheme_poly(b, AO_SCHEME_OTHER);
482 static inline struct ao_scheme_bool *
483 ao_scheme_poly_bool(ao_poly poly)
485 return ao_scheme_ref(poly);
488 static inline ao_poly
489 ao_scheme_float_poly(struct ao_scheme_float *f)
491 return ao_scheme_poly(f, AO_SCHEME_OTHER);
494 static inline struct ao_scheme_float *
495 ao_scheme_poly_float(ao_poly poly)
497 return ao_scheme_ref(poly);
501 ao_scheme_poly_number(ao_poly p);
503 /* memory functions */
505 extern int ao_scheme_collects[2];
506 extern int ao_scheme_freed[2];
507 extern int ao_scheme_loops[2];
509 /* returns 1 if the object was already marked */
511 ao_scheme_mark(const struct ao_scheme_type *type, void *addr);
513 /* returns 1 if the object was already marked */
515 ao_scheme_mark_memory(const struct ao_scheme_type *type, void *addr);
518 ao_scheme_move_map(void *addr);
520 /* returns 1 if the object was already moved */
522 ao_scheme_move(const struct ao_scheme_type *type, void **ref);
524 /* returns 1 if the object was already moved */
526 ao_scheme_move_memory(const struct ao_scheme_type *type, void **ref);
529 ao_scheme_alloc(int size);
531 #define AO_SCHEME_COLLECT_FULL 1
532 #define AO_SCHEME_COLLECT_INCREMENTAL 0
535 ao_scheme_collect(uint8_t style);
539 ao_scheme_cons_check(struct ao_scheme_cons *cons);
543 ao_scheme_cons_stash(int id, struct ao_scheme_cons *cons);
545 struct ao_scheme_cons *
546 ao_scheme_cons_fetch(int id);
549 ao_scheme_poly_stash(int id, ao_poly poly);
552 ao_scheme_poly_fetch(int id);
555 ao_scheme_string_stash(int id, char *string);
558 ao_scheme_string_fetch(int id);
561 ao_scheme_stack_stash(int id, struct ao_scheme_stack *stack) {
562 ao_scheme_poly_stash(id, ao_scheme_stack_poly(stack));
565 static inline struct ao_scheme_stack *
566 ao_scheme_stack_fetch(int id) {
567 return ao_scheme_poly_stack(ao_scheme_poly_fetch(id));
571 ao_scheme_frame_stash(int id, struct ao_scheme_frame *frame);
573 struct ao_scheme_frame *
574 ao_scheme_frame_fetch(int id);
578 extern const struct ao_scheme_type ao_scheme_bool_type;
581 ao_scheme_bool_write(ao_poly v);
583 #ifdef AO_SCHEME_MAKE_CONST
584 struct ao_scheme_bool *ao_scheme_true, *ao_scheme_false;
586 struct ao_scheme_bool *
587 ao_scheme_bool_get(uint8_t value);
591 extern const struct ao_scheme_type ao_scheme_cons_type;
593 struct ao_scheme_cons *
594 ao_scheme_cons_cons(ao_poly car, ao_poly cdr);
596 /* Return a cons or NULL for a proper list, else error */
597 struct ao_scheme_cons *
598 ao_scheme_cons_cdr(struct ao_scheme_cons *cons);
601 ao_scheme__cons(ao_poly car, ao_poly cdr);
603 extern struct ao_scheme_cons *ao_scheme_cons_free_list;
606 ao_scheme_cons_free(struct ao_scheme_cons *cons);
609 ao_scheme_cons_write(ao_poly);
612 ao_scheme_cons_display(ao_poly);
615 ao_scheme_cons_length(struct ao_scheme_cons *cons);
618 extern const struct ao_scheme_type ao_scheme_string_type;
621 ao_scheme_string_copy(char *a);
624 ao_scheme_string_cat(char *a, char *b);
627 ao_scheme_string_pack(struct ao_scheme_cons *cons);
630 ao_scheme_string_unpack(char *a);
633 ao_scheme_string_write(ao_poly s);
636 ao_scheme_string_display(ao_poly s);
639 extern const struct ao_scheme_type ao_scheme_atom_type;
641 extern struct ao_scheme_atom *ao_scheme_atoms;
642 extern struct ao_scheme_frame *ao_scheme_frame_global;
643 extern struct ao_scheme_frame *ao_scheme_frame_current;
646 ao_scheme_atom_write(ao_poly a);
648 struct ao_scheme_atom *
649 ao_scheme_atom_intern(char *name);
652 ao_scheme_atom_ref(ao_poly atom, struct ao_scheme_frame **frame_ref);
655 ao_scheme_atom_get(ao_poly atom);
658 ao_scheme_atom_set(ao_poly atom, ao_poly val);
661 ao_scheme_atom_def(ao_poly atom, ao_poly val);
665 ao_scheme_int_write(ao_poly i);
668 ao_scheme_poly_integer(ao_poly p);
671 ao_scheme_integer_poly(int32_t i);
674 ao_scheme_integer_typep(uint8_t t)
676 return (t == AO_SCHEME_INT) || (t == AO_SCHEME_BIGINT);
680 ao_scheme_bigint_write(ao_poly i);
682 extern const struct ao_scheme_type ao_scheme_bigint_type;
685 ao_scheme_poly_write(ao_poly p);
688 ao_scheme_poly_display(ao_poly p);
691 ao_scheme_poly_mark(ao_poly p, uint8_t note_cons);
693 /* returns 1 if the object has already been moved */
695 ao_scheme_poly_move(ao_poly *p, uint8_t note_cons);
700 ao_scheme_eval_clear_globals(void);
703 ao_scheme_eval_restart(void);
706 ao_scheme_eval(ao_poly p);
709 ao_scheme_set_cond(struct ao_scheme_cons *cons);
712 extern const struct ao_scheme_type ao_scheme_float_type;
715 ao_scheme_float_write(ao_poly p);
718 ao_scheme_float_get(float value);
720 static inline uint8_t
721 ao_scheme_number_typep(uint8_t t)
723 return ao_scheme_integer_typep(t) || (t == AO_SCHEME_FLOAT);
727 ao_scheme_poly_number(ao_poly p);
731 ao_scheme_builtin_write(ao_poly b);
733 extern const struct ao_scheme_type ao_scheme_builtin_type;
735 /* Check argument count */
737 ao_scheme_check_argc(ao_poly name, struct ao_scheme_cons *cons, int min, int max);
739 /* Check argument type */
741 ao_scheme_check_argt(ao_poly name, struct ao_scheme_cons *cons, int argc, int type, int nil_ok);
743 /* Fetch an arg (nil if off the end) */
745 ao_scheme_arg(struct ao_scheme_cons *cons, int argc);
748 ao_scheme_args_name(uint8_t args);
751 extern int ao_scheme_read_list;
752 extern struct ao_scheme_cons *ao_scheme_read_cons;
753 extern struct ao_scheme_cons *ao_scheme_read_cons_tail;
754 extern struct ao_scheme_cons *ao_scheme_read_stack;
757 ao_scheme_read(void);
761 ao_scheme_read_eval_print(void);
764 extern const struct ao_scheme_type ao_scheme_frame_type;
765 extern const struct ao_scheme_type ao_scheme_frame_vals_type;
767 #define AO_SCHEME_FRAME_FREE 6
769 extern struct ao_scheme_frame *ao_scheme_frame_free_list[AO_SCHEME_FRAME_FREE];
772 ao_scheme_frame_mark(struct ao_scheme_frame *frame);
775 ao_scheme_frame_ref(struct ao_scheme_frame *frame, ao_poly atom);
777 struct ao_scheme_frame *
778 ao_scheme_frame_new(int num);
781 ao_scheme_frame_free(struct ao_scheme_frame *frame);
784 ao_scheme_frame_bind(struct ao_scheme_frame *frame, int num, ao_poly atom, ao_poly val);
787 ao_scheme_frame_add(struct ao_scheme_frame *frame, ao_poly atom, ao_poly val);
790 ao_scheme_frame_write(ao_poly p);
793 ao_scheme_frame_init(void);
796 extern const struct ao_scheme_type ao_scheme_lambda_type;
798 extern const char * const ao_scheme_state_names[];
800 struct ao_scheme_lambda *
801 ao_scheme_lambda_new(ao_poly cons);
804 ao_scheme_lambda_write(ao_poly lambda);
807 ao_scheme_lambda_eval(void);
811 extern const struct ao_scheme_type ao_scheme_stack_type;
812 extern struct ao_scheme_stack *ao_scheme_stack;
813 extern struct ao_scheme_stack *ao_scheme_stack_free_list;
816 ao_scheme_stack_reset(struct ao_scheme_stack *stack);
819 ao_scheme_stack_push(void);
822 ao_scheme_stack_pop(void);
825 ao_scheme_stack_clear(void);
828 ao_scheme_stack_write(ao_poly stack);
831 ao_scheme_stack_eval(void);
836 ao_scheme_vprintf(char *format, va_list args);
839 ao_scheme_printf(char *format, ...);
842 ao_scheme_error_poly(char *name, ao_poly poly, ao_poly last);
845 ao_scheme_error_frame(int indent, char *name, struct ao_scheme_frame *frame);
848 ao_scheme_error(int error, char *format, ...);
852 #define AO_SCHEME_BUILTIN_DECLS
853 #include "ao_scheme_builtin.h"
855 /* debugging macros */
857 #if DBG_EVAL || DBG_READ || DBG_MEM
859 int ao_scheme_stack_depth;
861 #define DBG_INDENT() do { int _s; for(_s = 0; _s < ao_scheme_stack_depth; _s++) printf(" "); } while(0)
862 #define DBG_IN() (++ao_scheme_stack_depth)
863 #define DBG_OUT() (--ao_scheme_stack_depth)
864 #define DBG_RESET() (ao_scheme_stack_depth = 0)
865 #define DBG(...) ao_scheme_printf(__VA_ARGS__)
866 #define DBGI(...) do { printf("%4d: ", __LINE__); DBG_INDENT(); DBG(__VA_ARGS__); } while (0)
867 #define DBG_CONS(a) ao_scheme_cons_write(ao_scheme_cons_poly(a))
868 #define DBG_POLY(a) ao_scheme_poly_write(a)
869 #define OFFSET(a) ((a) ? (int) ((uint8_t *) a - ao_scheme_pool) : -1)
870 #define DBG_STACK() ao_scheme_stack_write(ao_scheme_stack_poly(ao_scheme_stack))
872 ao_scheme_frames_dump(void)
874 struct ao_scheme_stack *s;
875 DBGI(".. current frame: "); DBG_POLY(ao_scheme_frame_poly(ao_scheme_frame_current)); DBG("\n");
876 for (s = ao_scheme_stack; s; s = ao_scheme_poly_stack(s->prev)) {
877 DBGI(".. stack frame: "); DBG_POLY(s->frame); DBG("\n");
880 #define DBG_FRAMES() ao_scheme_frames_dump()
896 #define RDBGI(...) DBGI(__VA_ARGS__)
897 #define RDBG_IN() DBG_IN()
898 #define RDBG_OUT() DBG_OUT()
905 #define DBG_MEM_START 1
910 extern int dbg_move_depth;
912 #define MDBG_OFFSET(a) ((a) ? (int) ((uint8_t *) (a) - ao_scheme_pool) : -1)
916 #define MDBG_DO(a) DBG_DO(a)
917 #define MDBG_MOVE(...) do { if (dbg_mem) { int d; for (d = 0; d < dbg_move_depth; d++) printf (" "); printf(__VA_ARGS__); } } while (0)
918 #define MDBG_MORE(...) do { if (dbg_mem) printf(__VA_ARGS__); } while (0)
919 #define MDBG_MOVE_IN() (dbg_move_depth++)
920 #define MDBG_MOVE_OUT() (assert(--dbg_move_depth >= 0))
925 #define MDBG_MOVE(...)
926 #define MDBG_MORE(...)
927 #define MDBG_MOVE_IN()
928 #define MDBG_MOVE_OUT()
932 #endif /* _AO_SCHEME_H_ */