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_frame.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_frame.c')
| -rw-r--r-- | src/scheme/ao_scheme_frame.c | 55 | 
1 files changed, 38 insertions, 17 deletions
| diff --git a/src/scheme/ao_scheme_frame.c b/src/scheme/ao_scheme_frame.c index 3f4c9157..46f941e6 100644 --- a/src/scheme/ao_scheme_frame.c +++ b/src/scheme/ao_scheme_frame.c @@ -142,32 +142,53 @@ const struct ao_scheme_type ao_scheme_frame_type = {  	.name = "frame",  }; +int ao_scheme_frame_print_indent; + +static void +ao_scheme_frame_indent(int extra) +{ +	int				i; +	putchar('\n'); +	for (i = 0; i < ao_scheme_frame_print_indent+extra; i++) +		putchar('\t'); +} +  void -ao_scheme_frame_write(ao_poly p) +ao_scheme_frame_write(ao_poly p, bool write)  {  	struct ao_scheme_frame		*frame = ao_scheme_poly_frame(p); +	struct ao_scheme_frame		*clear = frame;  	struct ao_scheme_frame_vals	*vals = ao_scheme_poly_frame_vals(frame->vals);  	int				f; +	int				written = 0; -	printf ("{"); -	if (frame) { -		if (frame->type & AO_SCHEME_FRAME_PRINT) +	ao_scheme_print_start(); +	while (frame) { +		if (written != 0) +			printf(", "); +		if (ao_scheme_print_mark_addr(frame)) {  			printf("recurse..."); -		else { -			frame->type |= AO_SCHEME_FRAME_PRINT; -			for (f = 0; f < frame->num; f++) { -				if (f != 0) -					printf(", "); -				ao_scheme_poly_write(vals->vals[f].atom); -				printf(" = "); -				ao_scheme_poly_write(vals->vals[f].val); -			} -			if (frame->prev) -				ao_scheme_poly_write(frame->prev); -			frame->type &= ~AO_SCHEME_FRAME_PRINT; +			break; +		} + +		putchar('{'); +		written++; +		for (f = 0; f < frame->num; f++) { +			ao_scheme_frame_indent(1); +			ao_scheme_poly_write(vals->vals[f].atom, write); +			printf(" = "); +			ao_scheme_poly_write(vals->vals[f].val, write); +		} +		frame = ao_scheme_poly_frame(frame->prev); +		ao_scheme_frame_indent(0); +		putchar('}'); +	} +	if (ao_scheme_print_stop()) { +		while (written--) { +			ao_scheme_print_clear_addr(clear); +			clear = ao_scheme_poly_frame(clear->prev);  		}  	} -	printf("}");  }  static int | 
