diff options
| author | Keith Packard <keithp@keithp.com> | 2017-12-19 11:33:36 -0800 | 
|---|---|---|
| committer | Keith Packard <keithp@keithp.com> | 2017-12-19 11:33:36 -0800 | 
| commit | 431165e5fa72ba6dffd477de32960745cdec332c (patch) | |
| tree | e27c174d5d6cea72caf92de3a4fe2c97e9249ddf /src/scheme/ao_scheme_stack.c | |
| parent | 5628b983497d9d03e10cccee157419210a49cfa9 (diff) | |
altos/scheme: Rework display/write code
Unify output functions and add bool to switch between write and
display mode. Make that only affect strings (as per r⁷rs).
Use print recursion detection in frame and stack code, eliminating
PRINT flags in type field.
Signed-off-by: Keith Packard <keithp@keithp.com>
Diffstat (limited to 'src/scheme/ao_scheme_stack.c')
| -rw-r--r-- | src/scheme/ao_scheme_stack.c | 31 | 
1 files changed, 20 insertions, 11 deletions
| diff --git a/src/scheme/ao_scheme_stack.c b/src/scheme/ao_scheme_stack.c index e062a093..e29e2b68 100644 --- a/src/scheme/ao_scheme_stack.c +++ b/src/scheme/ao_scheme_stack.c @@ -158,26 +158,35 @@ ao_scheme_stack_clear(void)  }  void -ao_scheme_stack_write(ao_poly poly) +ao_scheme_stack_write(ao_poly poly, bool write)  { -	struct ao_scheme_stack *s = ao_scheme_poly_stack(poly); +	struct ao_scheme_stack 	*s = ao_scheme_poly_stack(poly); +	struct ao_scheme_stack	*clear = s; +	int			written = 0; +	(void) write; +	ao_scheme_print_start(); +	ao_scheme_frame_print_indent += 2;  	while (s) { -		if (s->type & AO_SCHEME_STACK_PRINT) { +		if (ao_scheme_print_mark_addr(s)) {  			printf("[recurse...]"); -			return; +			break;  		} -		s->type |= AO_SCHEME_STACK_PRINT; +		written++;  		printf("\t[\n"); -		printf("\t\texpr:   "); ao_scheme_poly_write(s->list); printf("\n"); -		printf("\t\tstate:  %s\n", ao_scheme_state_names[s->state]); -		ao_scheme_error_poly ("values: ", s->values, s->values_tail); -		ao_scheme_error_poly ("sexprs: ", s->sexprs, AO_SCHEME_NIL); -		ao_scheme_error_frame(2, "frame:  ", ao_scheme_poly_frame(s->frame)); +		ao_scheme_printf("\t\texpr:     %v\n", s->list); +		ao_scheme_printf("\t\tvalues:   %v\n", s->values); +		ao_scheme_printf("\t\tframe:    %v\n", s->frame);  		printf("\t]\n"); -		s->type &= ~AO_SCHEME_STACK_PRINT;  		s = ao_scheme_poly_stack(s->prev);  	} +	ao_scheme_frame_print_indent -= 2; +	if (ao_scheme_print_stop()) { +		while (written--) { +			ao_scheme_print_clear_addr(clear); +			clear = ao_scheme_poly_stack(clear->prev); +		} +	}  }  /* | 
