Variables pushing. Now the base language is complete.

This commit is contained in:
antirez 2022-12-20 14:20:38 +01:00
parent fd274cad34
commit c86faa26ac

16
aocla.c
View file

@ -433,10 +433,21 @@ int eval(aoclactx *ctx, obj *l) {
int idx = o->l.ele[i]->str.ptr[0] - 'a';
release(ctx->frame->locals[idx]);
ctx->frame->locals[idx] =
ctx->stack[ctx->stacklen - o->l.len];
ctx->stack[ctx->stacklen+i];
}
break;
case OBJ_TYPE_SYMBOL: /* Execute procedure. */
case OBJ_TYPE_SYMBOL:
if (o->str.ptr[0] == '$' && o->str.ptr[1] >= 'a' &&
o->str.ptr[0] <= 'z')
{ /* Push local var. */
int idx = o->str.ptr[1] - 'a';
if (ctx->frame->locals[idx] == NULL) {
setError(ctx,o->str.ptr, "Unbound local var");
return 1;
}
stackPush(ctx,ctx->frame->locals[idx]);
retain(ctx->frame->locals[idx]);
} else { /* Call procedure. */
proc = lookupProc(ctx,o->str.ptr);
if (proc == NULL) {
setError(ctx,o->str.ptr,
@ -460,6 +471,7 @@ int eval(aoclactx *ctx, obj *l) {
ctx->frame = oldsf;
if (err) return err;
}
}
break;
default:
stackPush(ctx,o);