summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephen Dolan <mu@netsoc.tcd.ie>2013-05-13 16:04:30 +0100
committerStephen Dolan <mu@netsoc.tcd.ie>2013-05-13 16:04:30 +0100
commitd8706fd4607ee1b5b56debd4da39e3314739f126 (patch)
treef9f4d4309c573074cc2da0be8c1cabe3eade6364
parente13f24ab45c2bc6fead9d698bdeaa84746761692 (diff)
Fix the //= operator.
Closes #62.
-rw-r--r--parser.y12
-rw-r--r--tests/all.test7
2 files changed, 14 insertions, 5 deletions
diff --git a/parser.y b/parser.y
index 2889977d..378c0740 100644
--- a/parser.y
+++ b/parser.y
@@ -163,6 +163,16 @@ static block gen_binop(block a, block b, int op) {
static block gen_format(block a, jv fmt) {
return BLOCK(a, gen_call("format", BLOCK(gen_lambda(gen_const(fmt)))));
}
+
+static block gen_definedor_assign(block object, block val) {
+ 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_definedor(gen_noop(),
+ gen_op_var_bound(LOADV, tmp))))));
+}
static block gen_update(block object, block val, int optype) {
block tmp = block_bind(gen_op_var_unbound(STOREV, "tmp"),
@@ -235,7 +245,7 @@ Exp "//" Exp {
} |
Exp "//=" Exp {
- $$ = gen_update($1, gen_definedor(gen_noop(), $3), 0);
+ $$ = gen_definedor_assign($1, $3);
} |
Exp "|=" Exp {
diff --git a/tests/all.test b/tests/all.test
index 97af7e55..5b38709b 100644
--- a/tests/all.test
+++ b/tests/all.test
@@ -475,10 +475,9 @@ def inc(x): x |= .+1; inc(.[].a)
[{"foo":[1,2], "bar": 42}, {"foo":[1], "bar": null}, {"foo":[null,false,3], "bar": 18}, {"foo":[], "bar":42}, {"foo": [null,false,null], "bar": 41}]
[[1,2], [1], [3], [42], [41]]
-# FIXME: behaviour of update operators
-# .[] //= .[0]
-# ["hello",true,false,[false],null]
-# ["hello",true,"hello",[false],"hello"]
+.[] //= .[0]
+["hello",true,false,[false],null]
+["hello",true,"hello",[false],"hello"]
.[] | [.[0] and .[1], .[0] or .[1]]
[[true,[]], [false,1], [42,null], [null,false]]