diff options
author | Stephen Dolan <mu@netsoc.tcd.ie> | 2012-12-29 16:43:36 +0000 |
---|---|---|
committer | Stephen Dolan <mu@netsoc.tcd.ie> | 2012-12-29 16:43:36 +0000 |
commit | d5fdf70434a243e6f3bd6967dbc2d28c9144cb29 (patch) | |
tree | 17901a90c2a2ff0a2219fa9bab9a340af95e36c7 /parser.y | |
parent | 465a4ec565a106e0e4cc1d64214fb2d6d791c8dc (diff) |
Refactor assignment.
New version is much more elegant and probably slower. Uses
library functions implemented in jq rather than dedicated opcodes.
Diffstat (limited to 'parser.y')
-rw-r--r-- | parser.y | 19 |
1 files changed, 12 insertions, 7 deletions
@@ -164,11 +164,16 @@ static block gen_format(block a, jv fmt) { return BLOCK(a, gen_call("format", BLOCK(gen_lambda(gen_const(fmt))))); } -static block gen_update(block a, block op, int optype) { - if (optype) { - op = gen_binop(gen_noop(), op, optype); - } - return gen_assign(BLOCK(a, gen_op_simple(DUP), op)); +static block gen_update(block object, block val, int optype) { + block tmp = block_bind(gen_op_var_unbound(STOREV, "tmp"), + gen_noop(), OP_HAS_VARIABLE); + return BLOCK(gen_op_simple(DUP), + val, + tmp, + gen_call("_modify", BLOCK(gen_lambda(object), + gen_lambda(gen_binop(gen_noop(), + gen_op_var_bound(LOADV, tmp), + optype))))); } %} @@ -216,7 +221,7 @@ Term "as" '$' IDENT '|' Exp { } | Exp '=' Exp { - $$ = gen_assign(BLOCK(gen_op_simple(DUP), $3, gen_op_simple(SWAP), $1, gen_op_simple(SWAP))); + $$ = gen_call("_assign", BLOCK(gen_lambda($1), gen_lambda($3))); } | Exp "or" Exp { @@ -236,7 +241,7 @@ Exp "//=" Exp { } | Exp "|=" Exp { - $$ = gen_update($1, $3, 0); + $$ = gen_call("_modify", BLOCK(gen_lambda($1), gen_lambda($3))); } | Exp '|' Exp { |