diff options
author | Jo-Philipp Wich <jo@mein.io> | 2020-11-12 18:56:45 +0100 |
---|---|---|
committer | Jo-Philipp Wich <jo@mein.io> | 2020-11-12 18:56:45 +0100 |
commit | 225a2807f10ac02844eb2a7a65fdf7999a62ba66 (patch) | |
tree | 1d7a80adbd25096e9f55a0ee652d3286cb76de6a /eval.c | |
parent | c447e58ebf3b04f129009f642d5d1be4ca8cee92 (diff) |
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 <jo@mein.io>
Diffstat (limited to 'eval.c')
-rw-r--r-- | eval.c | 24 |
1 files changed, 18 insertions, 6 deletions
@@ -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); } } |