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