Refactor assignment.

New version is much more elegant and probably slower. Uses
library functions implemented in jq rather than dedicated opcodes.
This commit is contained in:
Stephen Dolan committed 2012-12-29 16:43:36 +00:00
1 parent 465a4ec565
commit d5fdf70434
7 files changed
+19 -53

No files matched your search

+12 -7
View File
@@ -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 {