From 225a2807f10ac02844eb2a7a65fdf7999a62ba66 Mon Sep 17 00:00:00 2001 From: Jo-Philipp Wich Date: Thu, 12 Nov 2020 18:56:45 +0100 Subject: ast: simplify declaration AST structure Do not emit dummy T_ASSIGN nodes for plain variable declarations without initialization (`let foo` or `local foo`). This also allows simplifying `ut_check_for_in()` since we only need to deal with one common structure for both `for (... in ...)` and `for (local ... in ...)` cases. Signed-off-by: Jo-Philipp Wich --- eval.c | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) (limited to 'eval.c') diff --git a/eval.c b/eval.c index 7a76dde..50986e0 100644 --- a/eval.c +++ b/eval.c @@ -416,22 +416,34 @@ ut_execute_local(struct ut_state *state, uint32_t off) { struct ut_op *op = ut_get_op(state, off), *asop, *alop; uint32_t as = op ? op->tree.operand[0] : 0; - struct json_object *label, *val, *rv = NULL; + struct json_object *val, *rv = NULL; while (as) { asop = ut_get_op(state, as); - alop = asop ? ut_get_child(state, as, 0) : NULL; as = asop ? asop->tree.next : 0; - if (alop) { - label = alop->val; - val = asop->tree.operand[1] ? ut_execute_op_sequence(state, asop->tree.operand[1]) : NULL; + switch (asop ? asop->type : 0) { + case T_ASSIGN: + alop = ut_get_op(state, asop->tree.operand[0]); + val = ut_execute_op_sequence(state, asop->tree.operand[1]); if (ut_is_type(val, T_EXCEPTION)) return val; + break; + + case T_LABEL: + alop = asop; + val = NULL; + break; + + default: + continue; + } + + if (alop) { json_object_put(rv); - rv = ut_setval(state->scope->scope, label, val); + rv = ut_setval(state->scope->scope, alop->val, val); } } -- cgit v1.2.3