diff options
| author | Keith Packard <keithp@keithp.com> | 2016-11-02 14:18:54 -0700 | 
|---|---|---|
| committer | Keith Packard <keithp@keithp.com> | 2017-02-20 11:16:49 -0800 | 
| commit | 9e1a787f8828fb7b750ad3310c89a89536ea5286 (patch) | |
| tree | f39297fc7f73c9c391b0c6bd4e93d8ddcb675d95 /src/lisp/ao_lisp_make_const.c | |
| parent | 8362393a621ea78a96e7f65f602f4bfc7bbd1158 (diff) | |
altos/lisp: add set/setq and ' in reader
Along with other small fixes
Signed-off-by: Keith Packard <keithp@keithp.com>
Diffstat (limited to 'src/lisp/ao_lisp_make_const.c')
| -rw-r--r-- | src/lisp/ao_lisp_make_const.c | 23 | 
1 files changed, 22 insertions, 1 deletions
| diff --git a/src/lisp/ao_lisp_make_const.c b/src/lisp/ao_lisp_make_const.c index 21e000bf..8d3e03a9 100644 --- a/src/lisp/ao_lisp_make_const.c +++ b/src/lisp/ao_lisp_make_const.c @@ -14,6 +14,7 @@  #include "ao_lisp.h"  #include <stdlib.h> +#include <ctype.h>  static struct ao_lisp_builtin *  ao_lisp_make_builtin(enum ao_lisp_builtin_id func, int args) { @@ -36,6 +37,8 @@ struct builtin_func funcs[] = {  	"cdr",		AO_LISP_LEXPR,	builtin_cdr,  	"cons",		AO_LISP_LEXPR,	builtin_cons,  	"quote",	AO_LISP_NLAMBDA,builtin_quote, +	"set",		AO_LISP_LEXPR,	builtin_set, +	"setq",		AO_LISP_MACRO,	builtin_setq,  	"print",	AO_LISP_LEXPR,	builtin_print,  	"+",		AO_LISP_LEXPR,	builtin_plus,  	"-",		AO_LISP_LEXPR,	builtin_minus, @@ -51,6 +54,7 @@ main(int argc, char **argv)  {  	int	f, o;  	ao_poly	atom, val; +	struct ao_lisp_atom	*a;  	for (f = 0; f < N_FUNC; f++) {  		struct ao_lisp_builtin	*b = ao_lisp_make_builtin(funcs[f].func, funcs[f].args); @@ -76,14 +80,31 @@ main(int argc, char **argv)  	printf("#define AO_LISP_POOL_CONST %d\n", ao_lisp_top);  	printf("extern const uint8_t ao_lisp_const[AO_LISP_POOL_CONST] __attribute__((aligned(4)));\n");  	printf("#define ao_builtin_atoms 0x%04x\n", ao_lisp_atom_poly(ao_lisp_atoms)); + +	for (a = ao_lisp_atoms; a; a = ao_lisp_poly_atom(a->next)) { +		char	*n = a->name, c; +		printf ("#define _ao_lisp_atom_"); +		while ((c = *n++)) { +			if (isalnum(c)) +				printf("%c", c); +			else +				printf("%02x", c); +		} +		printf("  0x%04x\n", ao_lisp_atom_poly(a)); +	}  	printf("#ifdef AO_LISP_CONST_BITS\n");  	printf("const uint8_t ao_lisp_const[] = {");  	for (o = 0; o < ao_lisp_top; o++) { +		uint8_t	c;  		if ((o & 0xf) == 0)  			printf("\n\t");  		else  			printf(" "); -		printf("0x%02x,", ao_lisp_const[o]); +		c = ao_lisp_const[o]; +		if (' ' < c && c <= '~' && c != '\'') +			printf (" '%c',", c); +		else +			printf("0x%02x,", c);  	}  	printf("\n};\n");  	printf("#endif /* AO_LISP_CONST_BITS */\n"); | 
