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_VECTOR 13
108 #define AO_SCHEME_NUM_TYPE 14
110 /* Leave two bits for types to use as they please */
111 #define AO_SCHEME_OTHER_TYPE_MASK 0x3f
113 #define AO_SCHEME_NIL 0
115 extern uint16_t ao_scheme_top;
117 #define AO_SCHEME_OOM 0x01
118 #define AO_SCHEME_DIVIDE_BY_ZERO 0x02
119 #define AO_SCHEME_INVALID 0x04
120 #define AO_SCHEME_UNDEFINED 0x08
121 #define AO_SCHEME_REDEFINED 0x10
122 #define AO_SCHEME_EOF 0x20
123 #define AO_SCHEME_EXIT 0x40
125 extern uint8_t ao_scheme_exception;
128 ao_scheme_is_const(ao_poly poly) {
129 return poly & AO_SCHEME_CONST;
132 #define AO_SCHEME_IS_CONST(a) (ao_scheme_const <= ((uint8_t *) (a)) && ((uint8_t *) (a)) < ao_scheme_const + AO_SCHEME_POOL_CONST)
133 #define AO_SCHEME_IS_POOL(a) (ao_scheme_pool <= ((uint8_t *) (a)) && ((uint8_t *) (a)) < ao_scheme_pool + AO_SCHEME_POOL)
134 #define AO_SCHEME_IS_INT(p) (ao_scheme_poly_base_type(p) == AO_SCHEME_INT)
137 ao_scheme_ref(ao_poly poly);
140 ao_scheme_poly(const void *addr, ao_poly type);
142 struct ao_scheme_type {
143 int (*size)(void *addr);
144 void (*mark)(void *addr);
145 void (*move)(void *addr);
149 struct ao_scheme_cons {
154 struct ao_scheme_atom {
161 struct ao_scheme_val {
166 struct ao_scheme_frame_vals {
169 struct ao_scheme_val vals[];
172 struct ao_scheme_frame {
179 struct ao_scheme_bool {
185 struct ao_scheme_bigint {
189 struct ao_scheme_float {
196 struct ao_scheme_vector {
203 #if __BYTE_ORDER == __LITTLE_ENDIAN
204 static inline uint32_t
205 ao_scheme_int_bigint(int32_t i) {
206 return AO_SCHEME_BIGINT | (i << 8);
208 static inline int32_t
209 ao_scheme_bigint_int(uint32_t bi) {
210 return (int32_t) bi >> 8;
213 static inline uint32_t
214 ao_scheme_int_bigint(int32_t i) {
215 return (uint32_t) (i & 0xffffff) | (AO_SCHEME_BIGINT << 24);
217 static inlint int32_t
218 ao_scheme_bigint_int(uint32_t bi) {
219 return (int32_t) (bi << 8) >> 8;
223 #define AO_SCHEME_MIN_INT (-(1 << (15 - AO_SCHEME_TYPE_SHIFT)))
224 #define AO_SCHEME_MAX_INT ((1 << (15 - AO_SCHEME_TYPE_SHIFT)) - 1)
225 #define AO_SCHEME_MIN_BIGINT (-(1 << 24))
226 #define AO_SCHEME_MAX_BIGINT ((1 << 24) - 1)
228 #define AO_SCHEME_NOT_INTEGER 0x7fffffff
230 /* Set on type when the frame escapes the lambda */
231 #define AO_SCHEME_FRAME_MARK 0x80
232 #define AO_SCHEME_FRAME_PRINT 0x40
234 static inline int ao_scheme_frame_marked(struct ao_scheme_frame *f) {
235 return f->type & AO_SCHEME_FRAME_MARK;
238 static inline struct ao_scheme_frame *
239 ao_scheme_poly_frame(ao_poly poly) {
240 return ao_scheme_ref(poly);
243 static inline ao_poly
244 ao_scheme_frame_poly(struct ao_scheme_frame *frame) {
245 return ao_scheme_poly(frame, AO_SCHEME_OTHER);
248 static inline struct ao_scheme_frame_vals *
249 ao_scheme_poly_frame_vals(ao_poly poly) {
250 return ao_scheme_ref(poly);
253 static inline ao_poly
254 ao_scheme_frame_vals_poly(struct ao_scheme_frame_vals *vals) {
255 return ao_scheme_poly(vals, AO_SCHEME_OTHER);
259 eval_sexpr, /* Evaluate an sexpr */
260 eval_val, /* Value computed */
261 eval_formal, /* Formal computed */
262 eval_exec, /* Start a lambda evaluation */
263 eval_apply, /* Execute apply */
264 eval_cond, /* Start next cond clause */
265 eval_cond_test, /* Check cond condition */
266 eval_begin, /* Start next begin entry */
267 eval_while, /* Start while condition */
268 eval_while_test, /* Check while condition */
269 eval_macro, /* Finished with macro generation */
272 struct ao_scheme_stack {
273 uint8_t type; /* AO_SCHEME_STACK */
274 uint8_t state; /* enum eval_state */
275 ao_poly prev; /* previous stack frame */
276 ao_poly sexprs; /* expressions to evaluate */
277 ao_poly values; /* values computed */
278 ao_poly values_tail; /* end of the values list for easy appending */
279 ao_poly frame; /* current lookup frame */
280 ao_poly list; /* most recent function call */
283 #define AO_SCHEME_STACK_MARK 0x80 /* set on type when a reference has been taken */
284 #define AO_SCHEME_STACK_PRINT 0x40 /* stack is being printed */
286 static inline int ao_scheme_stack_marked(struct ao_scheme_stack *s) {
287 return s->type & AO_SCHEME_STACK_MARK;
290 static inline void ao_scheme_stack_mark(struct ao_scheme_stack *s) {
291 s->type |= AO_SCHEME_STACK_MARK;
294 static inline struct ao_scheme_stack *
295 ao_scheme_poly_stack(ao_poly p)
297 return ao_scheme_ref(p);
300 static inline ao_poly
301 ao_scheme_stack_poly(struct ao_scheme_stack *stack)
303 return ao_scheme_poly(stack, AO_SCHEME_OTHER);
306 extern ao_poly ao_scheme_v;
308 #define AO_SCHEME_FUNC_LAMBDA 0
309 #define AO_SCHEME_FUNC_NLAMBDA 1
310 #define AO_SCHEME_FUNC_MACRO 2
312 #define AO_SCHEME_FUNC_FREE_ARGS 0x80
313 #define AO_SCHEME_FUNC_MASK 0x7f
315 #define AO_SCHEME_FUNC_F_LAMBDA (AO_SCHEME_FUNC_FREE_ARGS | AO_SCHEME_FUNC_LAMBDA)
316 #define AO_SCHEME_FUNC_F_NLAMBDA (AO_SCHEME_FUNC_FREE_ARGS | AO_SCHEME_FUNC_NLAMBDA)
317 #define AO_SCHEME_FUNC_F_MACRO (AO_SCHEME_FUNC_FREE_ARGS | AO_SCHEME_FUNC_MACRO)
319 struct ao_scheme_builtin {
325 #define AO_SCHEME_BUILTIN_ID
326 #include "ao_scheme_builtin.h"
328 typedef ao_poly (*ao_scheme_func_t)(struct ao_scheme_cons *cons);
330 extern const ao_scheme_func_t ao_scheme_builtins[];
332 static inline ao_scheme_func_t
333 ao_scheme_func(struct ao_scheme_builtin *b)
335 return ao_scheme_builtins[b->func];
338 struct ao_scheme_lambda {
345 static inline struct ao_scheme_lambda *
346 ao_scheme_poly_lambda(ao_poly poly)
348 return ao_scheme_ref(poly);
351 static inline ao_poly
352 ao_scheme_lambda_poly(struct ao_scheme_lambda *lambda)
354 return ao_scheme_poly(lambda, AO_SCHEME_OTHER);
358 ao_scheme_poly_other(ao_poly poly) {
359 return ao_scheme_ref(poly);
362 static inline uint8_t
363 ao_scheme_other_type(void *other) {
365 if ((*((uint8_t *) other) & AO_SCHEME_OTHER_TYPE_MASK) >= AO_SCHEME_NUM_TYPE)
368 return *((uint8_t *) other) & AO_SCHEME_OTHER_TYPE_MASK;
371 static inline ao_poly
372 ao_scheme_other_poly(const void *other)
374 return ao_scheme_poly(other, AO_SCHEME_OTHER);
378 ao_scheme_size_round(int size)
380 return (size + 3) & ~3;
384 ao_scheme_size(const struct ao_scheme_type *type, void *addr)
386 return ao_scheme_size_round(type->size(addr));
389 #define AO_SCHEME_OTHER_POLY(other) ((ao_poly)(other) + AO_SCHEME_OTHER)
391 static inline int ao_scheme_poly_base_type(ao_poly poly) {
392 return poly & AO_SCHEME_TYPE_MASK;
395 static inline int ao_scheme_poly_type(ao_poly poly) {
396 int type = poly & AO_SCHEME_TYPE_MASK;
397 if (type == AO_SCHEME_OTHER)
398 return ao_scheme_other_type(ao_scheme_poly_other(poly));
403 ao_scheme_is_cons(ao_poly poly) {
404 return (ao_scheme_poly_base_type(poly) == AO_SCHEME_CONS);
408 ao_scheme_is_pair(ao_poly poly) {
409 return poly != AO_SCHEME_NIL && (ao_scheme_poly_base_type(poly) == AO_SCHEME_CONS);
412 static inline struct ao_scheme_cons *
413 ao_scheme_poly_cons(ao_poly poly)
415 return ao_scheme_ref(poly);
418 static inline ao_poly
419 ao_scheme_cons_poly(struct ao_scheme_cons *cons)
421 return ao_scheme_poly(cons, AO_SCHEME_CONS);
424 static inline int32_t
425 ao_scheme_poly_int(ao_poly poly)
427 return (int32_t) ((ao_signed_poly) poly >> AO_SCHEME_TYPE_SHIFT);
430 static inline ao_poly
431 ao_scheme_int_poly(int32_t i)
433 return ((ao_poly) i << 2) | AO_SCHEME_INT;
436 static inline struct ao_scheme_bigint *
437 ao_scheme_poly_bigint(ao_poly poly)
439 return ao_scheme_ref(poly);
442 static inline ao_poly
443 ao_scheme_bigint_poly(struct ao_scheme_bigint *bi)
445 return ao_scheme_poly(bi, AO_SCHEME_OTHER);
449 ao_scheme_poly_string(ao_poly poly)
451 return ao_scheme_ref(poly);
454 static inline ao_poly
455 ao_scheme_string_poly(char *s)
457 return ao_scheme_poly(s, AO_SCHEME_STRING);
460 static inline struct ao_scheme_atom *
461 ao_scheme_poly_atom(ao_poly poly)
463 return ao_scheme_ref(poly);
466 static inline ao_poly
467 ao_scheme_atom_poly(struct ao_scheme_atom *a)
469 return ao_scheme_poly(a, AO_SCHEME_OTHER);
472 static inline struct ao_scheme_builtin *
473 ao_scheme_poly_builtin(ao_poly poly)
475 return ao_scheme_ref(poly);
478 static inline ao_poly
479 ao_scheme_builtin_poly(struct ao_scheme_builtin *b)
481 return ao_scheme_poly(b, AO_SCHEME_OTHER);
484 static inline ao_poly
485 ao_scheme_bool_poly(struct ao_scheme_bool *b)
487 return ao_scheme_poly(b, AO_SCHEME_OTHER);
490 static inline struct ao_scheme_bool *
491 ao_scheme_poly_bool(ao_poly poly)
493 return ao_scheme_ref(poly);
496 static inline ao_poly
497 ao_scheme_float_poly(struct ao_scheme_float *f)
499 return ao_scheme_poly(f, AO_SCHEME_OTHER);
502 static inline struct ao_scheme_float *
503 ao_scheme_poly_float(ao_poly poly)
505 return ao_scheme_ref(poly);
509 ao_scheme_poly_number(ao_poly p);
511 static inline ao_poly
512 ao_scheme_vector_poly(struct ao_scheme_vector *v)
514 return ao_scheme_poly(v, AO_SCHEME_OTHER);
517 static inline struct ao_scheme_vector *
518 ao_scheme_poly_vector(ao_poly poly)
520 return ao_scheme_ref(poly);
523 /* memory functions */
525 extern uint64_t ao_scheme_collects[2];
526 extern uint64_t ao_scheme_freed[2];
527 extern uint64_t ao_scheme_loops[2];
529 /* returns 1 if the object was already marked */
531 ao_scheme_mark(const struct ao_scheme_type *type, void *addr);
533 /* returns 1 if the object was already marked */
535 ao_scheme_mark_memory(const struct ao_scheme_type *type, void *addr);
538 ao_scheme_move_map(void *addr);
540 /* returns 1 if the object was already moved */
542 ao_scheme_move(const struct ao_scheme_type *type, void **ref);
544 /* returns 1 if the object was already moved */
546 ao_scheme_move_memory(const struct ao_scheme_type *type, void **ref);
549 ao_scheme_alloc(int size);
551 #define AO_SCHEME_COLLECT_FULL 1
552 #define AO_SCHEME_COLLECT_INCREMENTAL 0
555 ao_scheme_collect(uint8_t style);
559 ao_scheme_cons_check(struct ao_scheme_cons *cons);
563 ao_scheme_cons_stash(int id, struct ao_scheme_cons *cons);
565 struct ao_scheme_cons *
566 ao_scheme_cons_fetch(int id);
569 ao_scheme_poly_stash(int id, ao_poly poly);
572 ao_scheme_poly_fetch(int id);
575 ao_scheme_string_stash(int id, char *string);
578 ao_scheme_string_fetch(int id);
581 ao_scheme_stack_stash(int id, struct ao_scheme_stack *stack) {
582 ao_scheme_poly_stash(id, ao_scheme_stack_poly(stack));
585 static inline struct ao_scheme_stack *
586 ao_scheme_stack_fetch(int id) {
587 return ao_scheme_poly_stack(ao_scheme_poly_fetch(id));
591 ao_scheme_frame_stash(int id, struct ao_scheme_frame *frame);
593 struct ao_scheme_frame *
594 ao_scheme_frame_fetch(int id);
598 extern const struct ao_scheme_type ao_scheme_bool_type;
601 ao_scheme_bool_write(ao_poly v);
603 #ifdef AO_SCHEME_MAKE_CONST
604 struct ao_scheme_bool *ao_scheme_true, *ao_scheme_false;
606 struct ao_scheme_bool *
607 ao_scheme_bool_get(uint8_t value);
611 extern const struct ao_scheme_type ao_scheme_cons_type;
613 struct ao_scheme_cons *
614 ao_scheme_cons_cons(ao_poly car, ao_poly cdr);
616 /* Return a cons or NULL for a proper list, else error */
617 struct ao_scheme_cons *
618 ao_scheme_cons_cdr(struct ao_scheme_cons *cons);
621 ao_scheme__cons(ao_poly car, ao_poly cdr);
623 extern struct ao_scheme_cons *ao_scheme_cons_free_list;
626 ao_scheme_cons_free(struct ao_scheme_cons *cons);
629 ao_scheme_cons_write(ao_poly);
632 ao_scheme_cons_display(ao_poly);
635 ao_scheme_cons_length(struct ao_scheme_cons *cons);
637 struct ao_scheme_cons *
638 ao_scheme_cons_copy(struct ao_scheme_cons *cons);
641 extern const struct ao_scheme_type ao_scheme_string_type;
644 ao_scheme_string_copy(char *a);
647 ao_scheme_string_cat(char *a, char *b);
650 ao_scheme_string_pack(struct ao_scheme_cons *cons);
653 ao_scheme_string_unpack(char *a);
656 ao_scheme_string_write(ao_poly s);
659 ao_scheme_string_display(ao_poly s);
662 extern const struct ao_scheme_type ao_scheme_atom_type;
664 extern struct ao_scheme_atom *ao_scheme_atoms;
665 extern struct ao_scheme_frame *ao_scheme_frame_global;
666 extern struct ao_scheme_frame *ao_scheme_frame_current;
669 ao_scheme_atom_write(ao_poly a);
671 struct ao_scheme_atom *
672 ao_scheme_atom_intern(char *name);
675 ao_scheme_atom_ref(ao_poly atom, struct ao_scheme_frame **frame_ref);
678 ao_scheme_atom_get(ao_poly atom);
681 ao_scheme_atom_set(ao_poly atom, ao_poly val);
684 ao_scheme_atom_def(ao_poly atom, ao_poly val);
688 ao_scheme_int_write(ao_poly i);
691 ao_scheme_poly_integer(ao_poly p);
694 ao_scheme_integer_poly(int32_t i);
697 ao_scheme_integer_typep(uint8_t t)
699 return (t == AO_SCHEME_INT) || (t == AO_SCHEME_BIGINT);
703 ao_scheme_bigint_write(ao_poly i);
705 extern const struct ao_scheme_type ao_scheme_bigint_type;
710 ao_scheme_vector_write(ao_poly v);
713 ao_scheme_vector_display(ao_poly v);
715 struct ao_scheme_vector *
716 ao_scheme_vector_alloc(uint16_t length, ao_poly fill);
719 ao_scheme_vector_get(ao_poly v, ao_poly i);
722 ao_scheme_vector_set(ao_poly v, ao_poly i, ao_poly p);
724 struct ao_scheme_vector *
725 ao_scheme_list_to_vector(struct ao_scheme_cons *cons);
727 struct ao_scheme_cons *
728 ao_scheme_vector_to_list(struct ao_scheme_vector *vector);
730 extern const struct ao_scheme_type ao_scheme_vector_type;
734 ao_scheme_poly_write(ao_poly p);
737 ao_scheme_poly_display(ao_poly p);
740 ao_scheme_poly_mark(ao_poly p, uint8_t note_cons);
742 /* returns 1 if the object has already been moved */
744 ao_scheme_poly_move(ao_poly *p, uint8_t note_cons);
749 ao_scheme_eval_clear_globals(void);
752 ao_scheme_eval_restart(void);
755 ao_scheme_eval(ao_poly p);
758 ao_scheme_set_cond(struct ao_scheme_cons *cons);
761 extern const struct ao_scheme_type ao_scheme_float_type;
764 ao_scheme_float_write(ao_poly p);
767 ao_scheme_float_get(float value);
769 static inline uint8_t
770 ao_scheme_number_typep(uint8_t t)
772 return ao_scheme_integer_typep(t) || (t == AO_SCHEME_FLOAT);
776 ao_scheme_poly_number(ao_poly p);
780 ao_scheme_builtin_write(ao_poly b);
782 extern const struct ao_scheme_type ao_scheme_builtin_type;
784 /* Check argument count */
786 ao_scheme_check_argc(ao_poly name, struct ao_scheme_cons *cons, int min, int max);
788 /* Check argument type */
790 ao_scheme_check_argt(ao_poly name, struct ao_scheme_cons *cons, int argc, int type, int nil_ok);
792 /* Fetch an arg (nil if off the end) */
794 ao_scheme_arg(struct ao_scheme_cons *cons, int argc);
797 ao_scheme_args_name(uint8_t args);
800 extern int ao_scheme_read_list;
801 extern struct ao_scheme_cons *ao_scheme_read_cons;
802 extern struct ao_scheme_cons *ao_scheme_read_cons_tail;
803 extern struct ao_scheme_cons *ao_scheme_read_stack;
806 ao_scheme_read(void);
810 ao_scheme_read_eval_print(void);
813 extern const struct ao_scheme_type ao_scheme_frame_type;
814 extern const struct ao_scheme_type ao_scheme_frame_vals_type;
816 #define AO_SCHEME_FRAME_FREE 6
818 extern struct ao_scheme_frame *ao_scheme_frame_free_list[AO_SCHEME_FRAME_FREE];
821 ao_scheme_frame_mark(struct ao_scheme_frame *frame);
824 ao_scheme_frame_ref(struct ao_scheme_frame *frame, ao_poly atom);
826 struct ao_scheme_frame *
827 ao_scheme_frame_new(int num);
830 ao_scheme_frame_free(struct ao_scheme_frame *frame);
833 ao_scheme_frame_bind(struct ao_scheme_frame *frame, int num, ao_poly atom, ao_poly val);
836 ao_scheme_frame_add(struct ao_scheme_frame *frame, ao_poly atom, ao_poly val);
839 ao_scheme_frame_write(ao_poly p);
842 ao_scheme_frame_init(void);
845 extern const struct ao_scheme_type ao_scheme_lambda_type;
847 extern const char * const ao_scheme_state_names[];
849 struct ao_scheme_lambda *
850 ao_scheme_lambda_new(ao_poly cons);
853 ao_scheme_lambda_write(ao_poly lambda);
856 ao_scheme_lambda_eval(void);
860 extern const struct ao_scheme_type ao_scheme_stack_type;
861 extern struct ao_scheme_stack *ao_scheme_stack;
862 extern struct ao_scheme_stack *ao_scheme_stack_free_list;
865 ao_scheme_stack_reset(struct ao_scheme_stack *stack);
868 ao_scheme_stack_push(void);
871 ao_scheme_stack_pop(void);
874 ao_scheme_stack_clear(void);
877 ao_scheme_stack_write(ao_poly stack);
880 ao_scheme_stack_eval(void);
885 ao_scheme_vprintf(char *format, va_list args);
888 ao_scheme_printf(char *format, ...);
891 ao_scheme_error_poly(char *name, ao_poly poly, ao_poly last);
894 ao_scheme_error_frame(int indent, char *name, struct ao_scheme_frame *frame);
897 ao_scheme_error(int error, char *format, ...);
901 #define AO_SCHEME_BUILTIN_DECLS
902 #include "ao_scheme_builtin.h"
904 /* debugging macros */
906 #if DBG_EVAL || DBG_READ || DBG_MEM
908 int ao_scheme_stack_depth;
910 #define DBG_INDENT() do { int _s; for(_s = 0; _s < ao_scheme_stack_depth; _s++) printf(" "); } while(0)
911 #define DBG_IN() (++ao_scheme_stack_depth)
912 #define DBG_OUT() (--ao_scheme_stack_depth)
913 #define DBG_RESET() (ao_scheme_stack_depth = 0)
914 #define DBG(...) ao_scheme_printf(__VA_ARGS__)
915 #define DBGI(...) do { printf("%4d: ", __LINE__); DBG_INDENT(); DBG(__VA_ARGS__); } while (0)
916 #define DBG_CONS(a) ao_scheme_cons_write(ao_scheme_cons_poly(a))
917 #define DBG_POLY(a) ao_scheme_poly_write(a)
918 #define OFFSET(a) ((a) ? (int) ((uint8_t *) a - ao_scheme_pool) : -1)
919 #define DBG_STACK() ao_scheme_stack_write(ao_scheme_stack_poly(ao_scheme_stack))
921 ao_scheme_frames_dump(void)
923 struct ao_scheme_stack *s;
924 DBGI(".. current frame: "); DBG_POLY(ao_scheme_frame_poly(ao_scheme_frame_current)); DBG("\n");
925 for (s = ao_scheme_stack; s; s = ao_scheme_poly_stack(s->prev)) {
926 DBGI(".. stack frame: "); DBG_POLY(s->frame); DBG("\n");
929 #define DBG_FRAMES() ao_scheme_frames_dump()
945 #define RDBGI(...) DBGI(__VA_ARGS__)
946 #define RDBG_IN() DBG_IN()
947 #define RDBG_OUT() DBG_OUT()
954 #define DBG_MEM_START 1
959 extern int dbg_move_depth;
961 #define MDBG_OFFSET(a) ((a) ? (int) ((uint8_t *) (a) - ao_scheme_pool) : -1)
965 #define MDBG_DO(a) DBG_DO(a)
966 #define MDBG_MOVE(...) do { if (dbg_mem) { int d; for (d = 0; d < dbg_move_depth; d++) printf (" "); printf(__VA_ARGS__); } } while (0)
967 #define MDBG_MORE(...) do { if (dbg_mem) printf(__VA_ARGS__); } while (0)
968 #define MDBG_MOVE_IN() (dbg_move_depth++)
969 #define MDBG_MOVE_OUT() (assert(--dbg_move_depth >= 0))
974 #define MDBG_MOVE(...)
975 #define MDBG_MORE(...)
976 #define MDBG_MOVE_IN()
977 #define MDBG_MOVE_OUT()
981 #endif /* _AO_SCHEME_H_ */