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:
10
builtin.c
10
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")),
|
||||
|
@ -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]
|
||||
|
Reference in New Issue
Block a user