diff options
| author | Keith Packard <keithp@keithp.com> | 2016-11-17 16:08:15 -0800 | 
|---|---|---|
| committer | Keith Packard <keithp@keithp.com> | 2017-02-20 11:16:51 -0800 | 
| commit | eaa528e4e62ba1d9765888760d387303487b2e01 (patch) | |
| tree | 02fc89072aafcad60d48c9933d325aedcc45a387 /src/lisp/ao_lisp_lambda.c | |
| parent | ffaf73407bcdf6bc4120c90212de4a2f52cf7991 (diff) | |
altos/lisp: Make lambda, cond and while all have implicit progns
This lets all of these execute more than one sexpr, returning the
value of the last.
Signed-off-by: Keith Packard <keithp@keithp.com>
Diffstat (limited to 'src/lisp/ao_lisp_lambda.c')
| -rw-r--r-- | src/lisp/ao_lisp_lambda.c | 22 | 
1 files changed, 14 insertions, 8 deletions
| diff --git a/src/lisp/ao_lisp_lambda.c b/src/lisp/ao_lisp_lambda.c index 186236f6..e2053a6f 100644 --- a/src/lisp/ao_lisp_lambda.c +++ b/src/lisp/ao_lisp_lambda.c @@ -78,8 +78,9 @@ ao_lisp_lambda_alloc(struct ao_lisp_cons *code, int args)  	if (!lambda)  		return AO_LISP_NIL; -	if (!ao_lisp_check_argc(_ao_lisp_atom_lambda, code, 2, 2)) -		return AO_LISP_NIL; +	if (!code->cdr) +		return ao_lisp_error(AO_LISP_INVALID, "missing parameters to lambda"); +  	if (!ao_lisp_check_argt(_ao_lisp_atom_lambda, code, 0, AO_LISP_CONS, 1))  		return AO_LISP_NIL;  	f = 0; @@ -135,7 +136,7 @@ ao_lisp_lambda_eval(void)  	int			args_wanted;  	int			args_provided;  	int			f; -	struct ao_lisp_cons	*vals +	struct ao_lisp_cons	*vals;  	DBGI("lambda "); DBG_POLY(ao_lisp_lambda_poly(lambda)); DBG("\n"); @@ -161,6 +162,10 @@ ao_lisp_lambda_eval(void)  	args = ao_lisp_poly_cons(ao_lisp_arg(code, 0));  	vals = ao_lisp_poly_cons(cons->cdr); +	next_frame->prev = lambda->frame; +	ao_lisp_frame_current = next_frame; +	ao_lisp_stack->frame = ao_lisp_frame_poly(ao_lisp_frame_current); +  	switch (lambda->args) {  	case AO_LISP_FUNC_LAMBDA:  		for (f = 0; f < args_wanted; f++) { @@ -171,6 +176,7 @@ ao_lisp_lambda_eval(void)  			vals = ao_lisp_poly_cons(vals->cdr);  		}  		ao_lisp_cons_free(cons); +		cons = NULL;  		break;  	case AO_LISP_FUNC_LEXPR:  	case AO_LISP_FUNC_NLAMBDA: @@ -182,15 +188,15 @@ ao_lisp_lambda_eval(void)  			args = ao_lisp_poly_cons(args->cdr);  			vals = ao_lisp_poly_cons(vals->cdr);  		} -		DBGI("bind "); DBG_POLY(args->car); DBG(" = "); DBG_POLY(); DBG("\n"); +		DBGI("bind "); DBG_POLY(args->car); DBG(" = "); DBG_POLY(ao_lisp_cons_poly(vals)); DBG("\n");  		next_frame->vals[f].atom = args->car;  		next_frame->vals[f].val = ao_lisp_cons_poly(vals);  		break; +	default: +		break;  	} -	next_frame->prev = lambda->frame;  	DBGI("eval frame: "); DBG_POLY(ao_lisp_frame_poly(next_frame)); DBG("\n"); -	ao_lisp_frame_current = next_frame; -	ao_lisp_stack->frame = ao_lisp_frame_poly(ao_lisp_frame_current);  	DBG_STACK(); -	return ao_lisp_arg(code, 1); +	DBGI("eval code: "); DBG_POLY(code->cdr); DBG("\n"); +	return code->cdr;  } | 
