diff options
author | Keith Packard <keithp@keithp.com> | 2017-12-17 22:22:50 -0800 |
---|---|---|
committer | Keith Packard <keithp@keithp.com> | 2017-12-17 22:22:50 -0800 |
commit | e1a6b3bf458f311d832aea7eec34935d42f8efed (patch) | |
tree | 7141f7e4ae75f23969722f75517f4c39cb623263 /src/scheme/ao_scheme_cons.c | |
parent | 9d1131da911f7220ac8b6cb7ba5a0afd3deef657 (diff) |
altos/scheme: Use memory manager mark code to note recursive print
This flags any object being printed and checks before recursing to
avoid infinite loops.
Signed-off-by: Keith Packard <keithp@keithp.com>
Diffstat (limited to 'src/scheme/ao_scheme_cons.c')
-rw-r--r-- | src/scheme/ao_scheme_cons.c | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/src/scheme/ao_scheme_cons.c b/src/scheme/ao_scheme_cons.c index 912100a9..0b3cbf80 100644 --- a/src/scheme/ao_scheme_cons.c +++ b/src/scheme/ao_scheme_cons.c @@ -181,16 +181,17 @@ ao_scheme_cons_write(ao_poly c) ao_poly cdr; int first = 1; + ao_scheme_print_start(); printf("("); while (cons) { if (!first) printf(" "); - ao_scheme_poly_write(cons->car); - cdr = cons->cdr; - if (cdr == c) { - printf(" ..."); + if (ao_scheme_print_mark_addr(cons)) { + printf("..."); break; } + ao_scheme_poly_write(cons->car); + cdr = cons->cdr; if (ao_scheme_poly_type(cdr) == AO_SCHEME_CONS) { cons = ao_scheme_poly_cons(cdr); first = 0; @@ -201,6 +202,7 @@ ao_scheme_cons_write(ao_poly c) } } printf(")"); + ao_scheme_print_stop(); } void @@ -209,13 +211,15 @@ ao_scheme_cons_display(ao_poly c) struct ao_scheme_cons *cons = ao_scheme_poly_cons(c); ao_poly cdr; + ao_scheme_print_start(); while (cons) { - ao_scheme_poly_display(cons->car); - cdr = cons->cdr; - if (cdr == c) { + if (ao_scheme_print_mark_addr(cons)) { printf("..."); break; } + ao_scheme_poly_display(cons->car); + + cdr = cons->cdr; if (ao_scheme_poly_type(cdr) == AO_SCHEME_CONS) cons = ao_scheme_poly_cons(cdr); else { @@ -223,6 +227,7 @@ ao_scheme_cons_display(ao_poly c) cons = NULL; } } + ao_scheme_print_stop(); } int |