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