Now we have the ability to define a generator in jq:
def for(cond; update):
def _for:
if cond then ., (update | _for) else . end;
_for;
for(. < 10; . + 1) # generates numbers between `.` and 10
Running this by hand with --debug-dump-disasm (with a fix for that
coming up next) we can see that the call to _for is optimized:
_for:0:
0000 DUP
0001 CALL_JQ cond:0^1
0005 JUMP_F 0022
0007 POP
0008 FORK 0012
0010 JUMP 0020
0012 CALL_JQ update:1^1
0016 TAIL_CALL_JQ _for:0^1
0020 JUMP 0023
0022 POP
0023 RET
And timing this with 1000, 10000, 100000 iterations shows that
indeed we must be applying TCO; otherwise, without TCO, this gets
very slow very quickly.
Currently tested by disassembling and tracing various recursive jq
programs by hand under valgrind. An improved test framework that
can test for errors and specific bytecode patterns is in
development.
Zhiming Wang [Mon, 30 Jun 2014 02:48:01 +0000 (19:48 -0700)]
Let @uri produce uppercase hexadecimal digits...
instead of lowercase ones.
According to RFC 3986,
The uppercase hexadecimal digits 'A' through 'F' are equivalent to
the lowercase digits 'a' through 'f', respectively. If two URIs
differ only in the case of hexadecimal digits used in percent-encoded
octets, they are equivalent. For consistency, URI producers and
normalizers should use uppercase hexadecimal digits for all percent-
encodings.
See https://github.com/stedolan/jq/issues/451 for details.
Test suite and manual are also updated to reflect this change.
Signed-off-by: Nicolas Williams <nico@cryptonector.com>
Nicolas Williams [Tue, 24 Jun 2014 00:59:00 +0000 (19:59 -0500)]
Improve TCO
Instead of checking for self-recursion check that the thing we're
calling is a function and not a closure, therefore the new frame will
have the same env as the current frame.
Nicolas Williams [Tue, 17 Jun 2014 22:00:23 +0000 (17:00 -0500)]
Fix #419, improve Cannot index message (sortof)
jv_get() doesn't know if it's being called in the context of a jq
program or not, so it can't produce a very useful error message when the
types of the to-be-indexed value and the key don't agree. For now,
including the key (when it is a short string) in the error message is as
significant an improvement as is easy to make.
Nico Williams [Thu, 12 Jun 2014 20:55:41 +0000 (15:55 -0500)]
Merge pull request #400 from kdeme/master
Heuristic IEEE754 endianness autoconf detection
Use AC_C_BIGENDIAN, though it's not really the correct approach. Autoconf ought to have provided a test specifically for IEEE754 endianness, since it can differ from integer/pointer endianness!
There are too many odd bugs in this mode, and it turns out to be a bad
idea anyways. Instead, in the future a better option will be to pursue
alternative parsers, such as:
- streaming parser that outputs only when a new leaf value is added or
an array/object is opened/closed; options here include whether to
include a path in each output;
- parsers for binary JSON encodings (there's a variety of them).
Then one might run jq with a streaming parser and use `reduce` to
coalesce inputs from some depth down (instead of from one level down as
the reverted commit had intended).
Besides, a fully streaming parser is desirable in some cases, therefore
we should have such a thing as an option.
I've explored modifying the current parser to support a streaming
option, but it only makes the code very difficult to follow, which is
one reason that alternate parsers makes sense. At any rate, this is all
for the future. For now there's no streaming of individual texts, just
text sequences.
And Solaris 8 and 9 too, no doubt. The problem was that non-standard
vsnprintf()s that return -1 when the buffer is too small were not
properly supported.
Nicolas Williams [Fri, 18 Apr 2014 01:17:06 +0000 (20:17 -0500)]
Make pthread tls configurable for Mingw build
For the Mingw build we don't want to pull in the pthread DLL just
because we can autodetect pthread support. That would make the jq.exe
binary not self-contained.
Arrays, objects, numbers, strings, booleans, nulls, values (non-nulls)
-- these builtins filter out those inputs that don't match the name of
the builtin.