altos/lisp: Finish first pass through r7rs
[fw/altos] / src / lisp / ao_lisp.h
1 /*
2  * Copyright © 2016 Keith Packard <keithp@keithp.com>
3  *
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.
8  *
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.
13  */
14
15 #ifndef _AO_LISP_H_
16 #define _AO_LISP_H_
17
18 #define DBG_MEM         0
19 #define DBG_EVAL        0
20
21 #include <stdint.h>
22 #include <string.h>
23 #include <ao_lisp_os.h>
24
25 typedef uint16_t        ao_poly;
26 typedef int16_t         ao_signed_poly;
27
28 #ifdef AO_LISP_SAVE
29
30 struct ao_lisp_os_save {
31         ao_poly         atoms;
32         ao_poly         globals;
33         uint16_t        const_checksum;
34         uint16_t        const_checksum_inv;
35 };
36
37 #define AO_LISP_POOL_EXTRA      (sizeof(struct ao_lisp_os_save))
38 #define AO_LISP_POOL    ((int) (AO_LISP_POOL_TOTAL - AO_LISP_POOL_EXTRA))
39
40 int
41 ao_lisp_os_save(void);
42
43 int
44 ao_lisp_os_restore_save(struct ao_lisp_os_save *save, int offset);
45
46 int
47 ao_lisp_os_restore(void);
48
49 #endif
50
51 #ifdef AO_LISP_MAKE_CONST
52 #define AO_LISP_POOL_CONST      16384
53 extern uint8_t ao_lisp_const[AO_LISP_POOL_CONST] __attribute__((aligned(4)));
54 #define ao_lisp_pool ao_lisp_const
55 #define AO_LISP_POOL AO_LISP_POOL_CONST
56
57 #define _atom(n) ao_lisp_atom_poly(ao_lisp_atom_intern(n))
58 #define _bool(v) ao_lisp_bool_poly(ao_lisp_bool_get(v))
59
60 #define _ao_lisp_bool_true      _bool(1)
61 #define _ao_lisp_bool_false     _bool(0)
62
63 #define _ao_lisp_atom_eof       _atom("eof")
64 #define _ao_lisp_atom_else      _atom("else")
65
66 #define AO_LISP_BUILTIN_ATOMS
67 #include "ao_lisp_builtin.h"
68
69 #else
70 #include "ao_lisp_const.h"
71 #ifndef AO_LISP_POOL
72 #define AO_LISP_POOL    3072
73 #endif
74 extern uint8_t          ao_lisp_pool[AO_LISP_POOL + AO_LISP_POOL_EXTRA] __attribute__((aligned(4)));
75 #endif
76
77 /* Primitive types */
78 #define AO_LISP_CONS            0
79 #define AO_LISP_INT             1
80 #define AO_LISP_STRING          2
81 #define AO_LISP_OTHER           3
82
83 #define AO_LISP_TYPE_MASK       0x0003
84 #define AO_LISP_TYPE_SHIFT      2
85 #define AO_LISP_REF_MASK        0x7ffc
86 #define AO_LISP_CONST           0x8000
87
88 /* These have a type value at the start of the struct */
89 #define AO_LISP_ATOM            4
90 #define AO_LISP_BUILTIN         5
91 #define AO_LISP_FRAME           6
92 #define AO_LISP_LAMBDA          7
93 #define AO_LISP_STACK           8
94 #define AO_LISP_BOOL            9
95 #define AO_LISP_NUM_TYPE        10
96
97 /* Leave two bits for types to use as they please */
98 #define AO_LISP_OTHER_TYPE_MASK 0x3f
99
100 #define AO_LISP_NIL     0
101
102 extern uint16_t         ao_lisp_top;
103
104 #define AO_LISP_OOM             0x01
105 #define AO_LISP_DIVIDE_BY_ZERO  0x02
106 #define AO_LISP_INVALID         0x04
107 #define AO_LISP_UNDEFINED       0x08
108 #define AO_LISP_EOF             0x10
109 #define AO_LISP_EXIT            0x20
110
111 extern uint8_t          ao_lisp_exception;
112
113 static inline int
114 ao_lisp_is_const(ao_poly poly) {
115         return poly & AO_LISP_CONST;
116 }
117
118 #define AO_LISP_IS_CONST(a)     (ao_lisp_const <= ((uint8_t *) (a)) && ((uint8_t *) (a)) < ao_lisp_const + AO_LISP_POOL_CONST)
119 #define AO_LISP_IS_POOL(a)      (ao_lisp_pool <= ((uint8_t *) (a)) && ((uint8_t *) (a)) < ao_lisp_pool + AO_LISP_POOL)
120 #define AO_LISP_IS_INT(p)       (ao_lisp_poly_base_type(p) == AO_LISP_INT)
121
122 void *
123 ao_lisp_ref(ao_poly poly);
124
125 ao_poly
126 ao_lisp_poly(const void *addr, ao_poly type);
127
128 struct ao_lisp_type {
129         int     (*size)(void *addr);
130         void    (*mark)(void *addr);
131         void    (*move)(void *addr);
132         char    name[];
133 };
134
135 struct ao_lisp_cons {
136         ao_poly         car;
137         ao_poly         cdr;
138 };
139
140 struct ao_lisp_atom {
141         uint8_t         type;
142         uint8_t         pad[1];
143         ao_poly         next;
144         char            name[];
145 };
146
147 struct ao_lisp_val {
148         ao_poly         atom;
149         ao_poly         val;
150 };
151
152 struct ao_lisp_frame {
153         uint8_t                 type;
154         uint8_t                 num;
155         ao_poly                 prev;
156         struct ao_lisp_val      vals[];
157 };
158
159 struct ao_lisp_bool {
160         uint8_t                 type;
161         uint8_t                 value;
162         uint16_t                pad;
163 };
164
165 /* Set on type when the frame escapes the lambda */
166 #define AO_LISP_FRAME_MARK      0x80
167 #define AO_LISP_FRAME_PRINT     0x40
168
169 static inline int ao_lisp_frame_marked(struct ao_lisp_frame *f) {
170         return f->type & AO_LISP_FRAME_MARK;
171 }
172
173 static inline struct ao_lisp_frame *
174 ao_lisp_poly_frame(ao_poly poly) {
175         return ao_lisp_ref(poly);
176 }
177
178 static inline ao_poly
179 ao_lisp_frame_poly(struct ao_lisp_frame *frame) {
180         return ao_lisp_poly(frame, AO_LISP_OTHER);
181 }
182
183 enum eval_state {
184         eval_sexpr,             /* Evaluate an sexpr */
185         eval_val,               /* Value computed */
186         eval_formal,            /* Formal computed */
187         eval_exec,              /* Start a lambda evaluation */
188         eval_apply,             /* Execute apply */
189         eval_cond,              /* Start next cond clause */
190         eval_cond_test,         /* Check cond condition */
191         eval_progn,             /* Start next progn entry */
192         eval_while,             /* Start while condition */
193         eval_while_test,        /* Check while condition */
194         eval_macro,             /* Finished with macro generation */
195 };
196
197 struct ao_lisp_stack {
198         uint8_t                 type;           /* AO_LISP_STACK */
199         uint8_t                 state;          /* enum eval_state */
200         ao_poly                 prev;           /* previous stack frame */
201         ao_poly                 sexprs;         /* expressions to evaluate */
202         ao_poly                 values;         /* values computed */
203         ao_poly                 values_tail;    /* end of the values list for easy appending */
204         ao_poly                 frame;          /* current lookup frame */
205         ao_poly                 list;           /* most recent function call */
206 };
207
208 #define AO_LISP_STACK_MARK      0x80    /* set on type when a reference has been taken */
209 #define AO_LISP_STACK_PRINT     0x40    /* stack is being printed */
210
211 static inline int ao_lisp_stack_marked(struct ao_lisp_stack *s) {
212         return s->type & AO_LISP_STACK_MARK;
213 }
214
215 static inline void ao_lisp_stack_mark(struct ao_lisp_stack *s) {
216         s->type |= AO_LISP_STACK_MARK;
217 }
218
219 static inline struct ao_lisp_stack *
220 ao_lisp_poly_stack(ao_poly p)
221 {
222         return ao_lisp_ref(p);
223 }
224
225 static inline ao_poly
226 ao_lisp_stack_poly(struct ao_lisp_stack *stack)
227 {
228         return ao_lisp_poly(stack, AO_LISP_OTHER);
229 }
230
231 extern ao_poly                  ao_lisp_v;
232
233 #define AO_LISP_FUNC_LAMBDA     0
234 #define AO_LISP_FUNC_NLAMBDA    1
235 #define AO_LISP_FUNC_MACRO      2
236 #define AO_LISP_FUNC_LEXPR      3
237
238 #define AO_LISP_FUNC_FREE_ARGS  0x80
239 #define AO_LISP_FUNC_MASK       0x7f
240
241 #define AO_LISP_FUNC_F_LAMBDA   (AO_LISP_FUNC_FREE_ARGS | AO_LISP_FUNC_LAMBDA)
242 #define AO_LISP_FUNC_F_NLAMBDA  (AO_LISP_FUNC_FREE_ARGS | AO_LISP_FUNC_NLAMBDA)
243 #define AO_LISP_FUNC_F_MACRO    (AO_LISP_FUNC_FREE_ARGS | AO_LISP_FUNC_MACRO)
244 #define AO_LISP_FUNC_F_LEXPR    (AO_LISP_FUNC_FREE_ARGS | AO_LISP_FUNC_LEXPR)
245
246 struct ao_lisp_builtin {
247         uint8_t         type;
248         uint8_t         args;
249         uint16_t        func;
250 };
251
252 #define AO_LISP_BUILTIN_ID
253 #include "ao_lisp_builtin.h"
254
255 typedef ao_poly (*ao_lisp_func_t)(struct ao_lisp_cons *cons);
256
257 extern const ao_lisp_func_t     ao_lisp_builtins[];
258
259 static inline ao_lisp_func_t
260 ao_lisp_func(struct ao_lisp_builtin *b)
261 {
262         return ao_lisp_builtins[b->func];
263 }
264
265 struct ao_lisp_lambda {
266         uint8_t         type;
267         uint8_t         args;
268         ao_poly         code;
269         ao_poly         frame;
270 };
271
272 static inline struct ao_lisp_lambda *
273 ao_lisp_poly_lambda(ao_poly poly)
274 {
275         return ao_lisp_ref(poly);
276 }
277
278 static inline ao_poly
279 ao_lisp_lambda_poly(struct ao_lisp_lambda *lambda)
280 {
281         return ao_lisp_poly(lambda, AO_LISP_OTHER);
282 }
283
284 static inline void *
285 ao_lisp_poly_other(ao_poly poly) {
286         return ao_lisp_ref(poly);
287 }
288
289 static inline uint8_t
290 ao_lisp_other_type(void *other) {
291 #if DBG_MEM
292         if ((*((uint8_t *) other) & AO_LISP_OTHER_TYPE_MASK) >= AO_LISP_NUM_TYPE)
293                 ao_lisp_abort();
294 #endif
295         return *((uint8_t *) other) & AO_LISP_OTHER_TYPE_MASK;
296 }
297
298 static inline ao_poly
299 ao_lisp_other_poly(const void *other)
300 {
301         return ao_lisp_poly(other, AO_LISP_OTHER);
302 }
303
304 static inline int
305 ao_lisp_size_round(int size)
306 {
307         return (size + 3) & ~3;
308 }
309
310 static inline int
311 ao_lisp_size(const struct ao_lisp_type *type, void *addr)
312 {
313         return ao_lisp_size_round(type->size(addr));
314 }
315
316 #define AO_LISP_OTHER_POLY(other) ((ao_poly)(other) + AO_LISP_OTHER)
317
318 static inline int ao_lisp_poly_base_type(ao_poly poly) {
319         return poly & AO_LISP_TYPE_MASK;
320 }
321
322 static inline int ao_lisp_poly_type(ao_poly poly) {
323         int     type = poly & AO_LISP_TYPE_MASK;
324         if (type == AO_LISP_OTHER)
325                 return ao_lisp_other_type(ao_lisp_poly_other(poly));
326         return type;
327 }
328
329 static inline struct ao_lisp_cons *
330 ao_lisp_poly_cons(ao_poly poly)
331 {
332         return ao_lisp_ref(poly);
333 }
334
335 static inline ao_poly
336 ao_lisp_cons_poly(struct ao_lisp_cons *cons)
337 {
338         return ao_lisp_poly(cons, AO_LISP_CONS);
339 }
340
341 static inline int
342 ao_lisp_poly_int(ao_poly poly)
343 {
344         return (int) ((ao_signed_poly) poly >> AO_LISP_TYPE_SHIFT);
345 }
346
347 static inline ao_poly
348 ao_lisp_int_poly(int i)
349 {
350         return ((ao_poly) i << 2) | AO_LISP_INT;
351 }
352
353 static inline char *
354 ao_lisp_poly_string(ao_poly poly)
355 {
356         return ao_lisp_ref(poly);
357 }
358
359 static inline ao_poly
360 ao_lisp_string_poly(char *s)
361 {
362         return ao_lisp_poly(s, AO_LISP_STRING);
363 }
364
365 static inline struct ao_lisp_atom *
366 ao_lisp_poly_atom(ao_poly poly)
367 {
368         return ao_lisp_ref(poly);
369 }
370
371 static inline ao_poly
372 ao_lisp_atom_poly(struct ao_lisp_atom *a)
373 {
374         return ao_lisp_poly(a, AO_LISP_OTHER);
375 }
376
377 static inline struct ao_lisp_builtin *
378 ao_lisp_poly_builtin(ao_poly poly)
379 {
380         return ao_lisp_ref(poly);
381 }
382
383 static inline ao_poly
384 ao_lisp_builtin_poly(struct ao_lisp_builtin *b)
385 {
386         return ao_lisp_poly(b, AO_LISP_OTHER);
387 }
388
389 static inline ao_poly
390 ao_lisp_bool_poly(struct ao_lisp_bool *b)
391 {
392         return ao_lisp_poly(b, AO_LISP_OTHER);
393 }
394
395 static inline struct ao_lisp_bool *
396 ao_lisp_poly_bool(ao_poly poly)
397 {
398         return ao_lisp_ref(poly);
399 }
400 /* memory functions */
401
402 extern int ao_lisp_collects[2];
403 extern int ao_lisp_freed[2];
404 extern int ao_lisp_loops[2];
405
406 /* returns 1 if the object was already marked */
407 int
408 ao_lisp_mark(const struct ao_lisp_type *type, void *addr);
409
410 /* returns 1 if the object was already marked */
411 int
412 ao_lisp_mark_memory(const struct ao_lisp_type *type, void *addr);
413
414 void *
415 ao_lisp_move_map(void *addr);
416
417 /* returns 1 if the object was already moved */
418 int
419 ao_lisp_move(const struct ao_lisp_type *type, void **ref);
420
421 /* returns 1 if the object was already moved */
422 int
423 ao_lisp_move_memory(const struct ao_lisp_type *type, void **ref);
424
425 void *
426 ao_lisp_alloc(int size);
427
428 #define AO_LISP_COLLECT_FULL            1
429 #define AO_LISP_COLLECT_INCREMENTAL     0
430
431 int
432 ao_lisp_collect(uint8_t style);
433
434 void
435 ao_lisp_cons_stash(int id, struct ao_lisp_cons *cons);
436
437 struct ao_lisp_cons *
438 ao_lisp_cons_fetch(int id);
439
440 void
441 ao_lisp_poly_stash(int id, ao_poly poly);
442
443 ao_poly
444 ao_lisp_poly_fetch(int id);
445
446 void
447 ao_lisp_string_stash(int id, char *string);
448
449 char *
450 ao_lisp_string_fetch(int id);
451
452 static inline void
453 ao_lisp_stack_stash(int id, struct ao_lisp_stack *stack) {
454         ao_lisp_poly_stash(id, ao_lisp_stack_poly(stack));
455 }
456
457 static inline struct ao_lisp_stack *
458 ao_lisp_stack_fetch(int id) {
459         return ao_lisp_poly_stack(ao_lisp_poly_fetch(id));
460 }
461
462 /* bool */
463
464 extern const struct ao_lisp_type ao_lisp_bool_type;
465
466 void
467 ao_lisp_bool_write(ao_poly v);
468
469 #ifdef AO_LISP_MAKE_CONST
470 struct ao_lisp_bool     *ao_lisp_true, *ao_lisp_false;
471
472 struct ao_lisp_bool *
473 ao_lisp_bool_get(uint8_t value);
474 #endif
475
476 /* cons */
477 extern const struct ao_lisp_type ao_lisp_cons_type;
478
479 struct ao_lisp_cons *
480 ao_lisp_cons_cons(ao_poly car, ao_poly cdr);
481
482 ao_poly
483 ao_lisp__cons(ao_poly car, ao_poly cdr);
484
485 extern struct ao_lisp_cons *ao_lisp_cons_free_list;
486
487 void
488 ao_lisp_cons_free(struct ao_lisp_cons *cons);
489
490 void
491 ao_lisp_cons_write(ao_poly);
492
493 void
494 ao_lisp_cons_display(ao_poly);
495
496 int
497 ao_lisp_cons_length(struct ao_lisp_cons *cons);
498
499 /* string */
500 extern const struct ao_lisp_type ao_lisp_string_type;
501
502 char *
503 ao_lisp_string_copy(char *a);
504
505 char *
506 ao_lisp_string_cat(char *a, char *b);
507
508 ao_poly
509 ao_lisp_string_pack(struct ao_lisp_cons *cons);
510
511 ao_poly
512 ao_lisp_string_unpack(char *a);
513
514 void
515 ao_lisp_string_write(ao_poly s);
516
517 void
518 ao_lisp_string_display(ao_poly s);
519
520 /* atom */
521 extern const struct ao_lisp_type ao_lisp_atom_type;
522
523 extern struct ao_lisp_atom      *ao_lisp_atoms;
524 extern struct ao_lisp_frame     *ao_lisp_frame_global;
525 extern struct ao_lisp_frame     *ao_lisp_frame_current;
526
527 void
528 ao_lisp_atom_write(ao_poly a);
529
530 struct ao_lisp_atom *
531 ao_lisp_atom_intern(char *name);
532
533 ao_poly *
534 ao_lisp_atom_ref(struct ao_lisp_frame *frame, ao_poly atom);
535
536 ao_poly
537 ao_lisp_atom_get(ao_poly atom);
538
539 ao_poly
540 ao_lisp_atom_set(ao_poly atom, ao_poly val);
541
542 /* int */
543 void
544 ao_lisp_int_write(ao_poly i);
545
546 /* prim */
547 void
548 ao_lisp_poly_write(ao_poly p);
549
550 void
551 ao_lisp_poly_display(ao_poly p);
552
553 int
554 ao_lisp_poly_mark(ao_poly p, uint8_t note_cons);
555
556 /* returns 1 if the object has already been moved */
557 int
558 ao_lisp_poly_move(ao_poly *p, uint8_t note_cons);
559
560 /* eval */
561
562 void
563 ao_lisp_eval_clear_globals(void);
564
565 int
566 ao_lisp_eval_restart(void);
567
568 ao_poly
569 ao_lisp_eval(ao_poly p);
570
571 ao_poly
572 ao_lisp_set_cond(struct ao_lisp_cons *cons);
573
574 /* builtin */
575 void
576 ao_lisp_builtin_write(ao_poly b);
577
578 extern const struct ao_lisp_type ao_lisp_builtin_type;
579
580 /* Check argument count */
581 ao_poly
582 ao_lisp_check_argc(ao_poly name, struct ao_lisp_cons *cons, int min, int max);
583
584 /* Check argument type */
585 ao_poly
586 ao_lisp_check_argt(ao_poly name, struct ao_lisp_cons *cons, int argc, int type, int nil_ok);
587
588 /* Fetch an arg (nil if off the end) */
589 ao_poly
590 ao_lisp_arg(struct ao_lisp_cons *cons, int argc);
591
592 char *
593 ao_lisp_args_name(uint8_t args);
594
595 /* read */
596 extern struct ao_lisp_cons      *ao_lisp_read_cons;
597 extern struct ao_lisp_cons      *ao_lisp_read_cons_tail;
598 extern struct ao_lisp_cons      *ao_lisp_read_stack;
599
600 ao_poly
601 ao_lisp_read(void);
602
603 /* rep */
604 ao_poly
605 ao_lisp_read_eval_print(void);
606
607 /* frame */
608 extern const struct ao_lisp_type ao_lisp_frame_type;
609
610 #define AO_LISP_FRAME_FREE      6
611
612 extern struct ao_lisp_frame     *ao_lisp_frame_free_list[AO_LISP_FRAME_FREE];
613
614 ao_poly
615 ao_lisp_frame_mark(struct ao_lisp_frame *frame);
616
617 ao_poly *
618 ao_lisp_frame_ref(struct ao_lisp_frame *frame, ao_poly atom);
619
620 struct ao_lisp_frame *
621 ao_lisp_frame_new(int num);
622
623 void
624 ao_lisp_frame_free(struct ao_lisp_frame *frame);
625
626 void
627 ao_lisp_frame_bind(struct ao_lisp_frame *frame, int num, ao_poly atom, ao_poly val);
628
629 int
630 ao_lisp_frame_add(struct ao_lisp_frame **frame, ao_poly atom, ao_poly val);
631
632 void
633 ao_lisp_frame_write(ao_poly p);
634
635 /* lambda */
636 extern const struct ao_lisp_type ao_lisp_lambda_type;
637
638 extern const char *ao_lisp_state_names[];
639
640 struct ao_lisp_lambda *
641 ao_lisp_lambda_new(ao_poly cons);
642
643 void
644 ao_lisp_lambda_write(ao_poly lambda);
645
646 ao_poly
647 ao_lisp_lambda_eval(void);
648
649 /* stack */
650
651 extern const struct ao_lisp_type ao_lisp_stack_type;
652 extern struct ao_lisp_stack     *ao_lisp_stack;
653 extern struct ao_lisp_stack     *ao_lisp_stack_free_list;
654
655 void
656 ao_lisp_stack_reset(struct ao_lisp_stack *stack);
657
658 int
659 ao_lisp_stack_push(void);
660
661 void
662 ao_lisp_stack_pop(void);
663
664 void
665 ao_lisp_stack_clear(void);
666
667 void
668 ao_lisp_stack_write(ao_poly stack);
669
670 ao_poly
671 ao_lisp_stack_eval(void);
672
673 /* error */
674
675 void
676 ao_lisp_error_poly(char *name, ao_poly poly, ao_poly last);
677
678 void
679 ao_lisp_error_frame(int indent, char *name, struct ao_lisp_frame *frame);
680
681 ao_poly
682 ao_lisp_error(int error, char *format, ...);
683
684 /* builtins */
685
686 #define AO_LISP_BUILTIN_DECLS
687 #include "ao_lisp_builtin.h"
688
689 /* debugging macros */
690
691 #if DBG_EVAL
692 #define DBG_CODE        1
693 int ao_lisp_stack_depth;
694 #define DBG_DO(a)       a
695 #define DBG_INDENT()    do { int _s; for(_s = 0; _s < ao_lisp_stack_depth; _s++) printf("  "); } while(0)
696 #define DBG_IN()        (++ao_lisp_stack_depth)
697 #define DBG_OUT()       (--ao_lisp_stack_depth)
698 #define DBG_RESET()     (ao_lisp_stack_depth = 0)
699 #define DBG(...)        printf(__VA_ARGS__)
700 #define DBGI(...)       do { DBG("%4d: ", __LINE__); DBG_INDENT(); DBG(__VA_ARGS__); } while (0)
701 #define DBG_CONS(a)     ao_lisp_cons_write(ao_lisp_cons_poly(a))
702 #define DBG_POLY(a)     ao_lisp_poly_write(a)
703 #define OFFSET(a)       ((a) ? (int) ((uint8_t *) a - ao_lisp_pool) : -1)
704 #define DBG_STACK()     ao_lisp_stack_write(ao_lisp_stack_poly(ao_lisp_stack))
705 static inline void
706 ao_lisp_frames_dump(void)
707 {
708         struct ao_lisp_stack *s;
709         DBGI(".. current frame: "); DBG_POLY(ao_lisp_frame_poly(ao_lisp_frame_current)); DBG("\n");
710         for (s = ao_lisp_stack; s; s = ao_lisp_poly_stack(s->prev)) {
711                 DBGI(".. stack frame: "); DBG_POLY(s->frame); DBG("\n");
712         }
713 }
714 #define DBG_FRAMES()    ao_lisp_frames_dump()
715 #else
716 #define DBG_DO(a)
717 #define DBG_INDENT()
718 #define DBG_IN()
719 #define DBG_OUT()
720 #define DBG(...)
721 #define DBGI(...)
722 #define DBG_CONS(a)
723 #define DBG_POLY(a)
724 #define DBG_RESET()
725 #define DBG_STACK()
726 #define DBG_FRAMES()
727 #endif
728
729 #define DBG_MEM_START   1
730
731 #if DBG_MEM
732
733 #include <assert.h>
734 extern int dbg_move_depth;
735 #define MDBG_DUMP 1
736 #define MDBG_OFFSET(a)  ((int) ((uint8_t *) (a) - ao_lisp_pool))
737
738 extern int dbg_mem;
739
740 #define MDBG_DO(a)      a
741 #define MDBG_MOVE(...) do { if (dbg_mem) { int d; for (d = 0; d < dbg_move_depth; d++) printf ("  "); printf(__VA_ARGS__); } } while (0)
742 #define MDBG_MORE(...) do { if (dbg_mem) printf(__VA_ARGS__); } while (0)
743 #define MDBG_MOVE_IN()  (dbg_move_depth++)
744 #define MDBG_MOVE_OUT() (assert(--dbg_move_depth >= 0))
745
746 #else
747
748 #define MDBG_DO(a)
749 #define MDBG_MOVE(...)
750 #define MDBG_MORE(...)
751 #define MDBG_MOVE_IN()
752 #define MDBG_MOVE_OUT()
753
754 #endif
755
756 #endif /* _AO_LISP_H_ */