1
0
mirror of https://github.com/stedolan/jq.git synced 2024-05-11 05:55:39 +00:00

Fix range(value;stream) (fix #886)

This commit is contained in:
David Tolnay
2015-08-06 23:04:47 -07:00
parent d66fbd218b
commit a47b32999b
2 changed files with 16 additions and 2 deletions

View File

@ -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")),

View File

@ -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]