From a47b32999b8a6a754b91909548700efdad3c2dd9 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Thu, 6 Aug 2015 23:04:47 -0700 Subject: [PATCH] Fix range(value;stream) (fix #886) --- builtin.c | 10 ++++++++-- tests/jq.test | 8 ++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/builtin.c b/builtin.c index 52f469d..2fa498b 100644 --- a/builtin.c +++ b/builtin.c @@ -1339,9 +1339,15 @@ static block bind_bytecoded_builtins(block b) { { // Note that we can now define `range` as a jq-coded function block rangevar = gen_op_var_fresh(STOREV, "rangevar"); - block init = BLOCK(gen_op_simple(DUP), gen_call("start", gen_noop()), rangevar); - block range = BLOCK(init, + block rangestart = gen_op_var_fresh(STOREV, "rangestart"); + block range = BLOCK(gen_op_simple(DUP), + gen_call("start", gen_noop()), + rangestart, gen_call("end", gen_noop()), + gen_op_simple(DUP), + gen_op_bound(LOADV, rangestart), + // Reset rangevar for every value generated by "end" + rangevar, gen_op_bound(RANGE, rangevar)); builtins = BLOCK(builtins, gen_function("range", BLOCK(gen_param("start"), gen_param("end")), diff --git a/tests/jq.test b/tests/jq.test index e6f5671..a9347fe 100644 --- a/tests/jq.test +++ b/tests/jq.test @@ -231,6 +231,10 @@ null null [0,1,2,3,4,5,6,7,8,9] +[range(0,1;3,4)] +null +[0,1,2, 0,1,2,3, 1,2, 1,2,3] + [range(0;10;3)] null [0,3,6,9] @@ -243,6 +247,10 @@ null null [0,-1,-2,-3,-4] +[range(0,1;4,5;1,2)] +null +[0,1,2,3,0,2, 0,1,2,3,4,0,2,4, 1,2,3,1,3, 1,2,3,4,1,3] + [while(.<100; .*2)] 1 [1,2,4,8,16,32,64] -- 2.40.0