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