Nicolas Williams
9deee38dc8
Fix off-by-one in TCO
...
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.
2014-07-01 22:40:40 -05:00
Nicolas Williams
436941d48b
TCO to the max!
...
Close #446 .
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.
2014-06-30 23:41:20 -05:00
Nicolas Williams
1204e328df
Add much commentary about CALL_JQ and call frames
2014-06-30 19:40:56 -05:00
Nicolas Williams
beb0d081bb
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.
2014-06-23 19:59:00 -05:00
Nicolas Williams
4b7c701fdd
Tail call optimization ( close #437 )
2014-06-22 00:24:02 -05:00
Nicolas Williams
fe29d3d3fa
Add ?
, .[]?
, and ..
operators
...
Make XPath-like `//a/b` recursive structure traversal easier in jq,
which then becomes:
..|.a?.b?
The `?` operator suppresses errors about . not being an array or object.
The `..` operator is equivalent to calling the new `recurse_down`
built-in, which in turn is equivalent to
recurse(.[]?)
Note that `..a` is not supported; neither is `...a`. That could be add
added, but it doesn't seem worth the trouble of saving the need to type
a '|'.
2014-02-20 15:33:07 -06:00
David R. MacIver
17a319d120
args to jq_compile_args were not getting freed when there were errors in the compile
2013-12-08 15:28:29 +00:00
Nicolas Williams
3a1dab5396
Fix double-free typo in print_error()
2013-12-06 23:25:06 -06:00
Nicolas Williams
eb165459aa
Add callback interface for errors
...
Printing to stderr is not the right answer for a library.
2013-12-04 18:21:41 -06:00
Stephen Dolan
1c9e03f800
Merge branch 'header-cleanup' into libjq
...
Conflicts:
Makefile.am
2013-06-22 23:27:16 +01:00
Nicolas Williams
298b2a6033
Add libjq autoconf goo
2013-06-21 11:57:12 -05:00
Stephen Dolan
7af88962ee
Move cfunction invocation code to the interpreter loop.
2013-06-21 12:06:28 +01:00
Stephen Dolan
b49d65a276
Fold opcode.{c,h} into bytecode.{c,h}
2013-06-18 01:36:18 +01:00
Stephen Dolan
8c4d29ee38
Remove some initialise-to-zero code.
...
This lets valgrind find more bugs - if a field isn't given a
well-defined value valgrind will now find it instead of seeing it
set to zero with memset.
2013-06-18 00:17:20 +01:00
Stephen Dolan
94931040a8
Merge branch 'stack-refactor'
...
Conflicts:
execute.c
2013-06-18 00:06:00 +01:00
Nicolas Williams
3f86e97f70
Fixup API to get closer to a libjq
2013-06-15 17:37:15 -05:00
Stephen Dolan
05d90517b0
Clean up lots of stack and frame logic.
...
Move frame defs to execute.c
2013-06-14 22:08:18 +01:00
Stephen Dolan
5f5c1dc5a6
Simplify frame logic.
2013-06-14 01:20:24 +01:00
Stephen Dolan
e0524644f8
Unify all stacks. Passes tests, but needs cleanup.
2013-06-13 21:50:32 +01:00
Stephen Dolan
25bf1a0169
Unify frame and data stacks
2013-06-10 01:17:58 +01:00
Brendan Macmillan
6e373942e5
Load library from ~/.jq
2013-05-29 15:05:40 +10:00
Stephen Dolan
fd1ac5dd79
EACH need not make a backtrack point on the last iteration
2013-05-17 22:49:08 +01:00
Stephen Dolan
8fbee891b3
Add LOADVN opcode.
...
Does a variable load, but sets the variable to be null afterwards.
2013-05-16 15:02:18 +01:00
Stephen Dolan
1e2851cdb3
Remove the YIELD opcode (use RET instead)
2013-05-15 01:23:06 +01:00
Stephen Dolan
81be37b236
Add the range function
2013-05-14 16:09:10 +01:00
Stephen Dolan
e13f24ab45
Better error handling for INSERT opcode
...
jq 'null | {(.a): 1}' no longer crashes.
2013-05-13 15:42:57 +01:00
Stephen Dolan
34a63246ab
Remove the is_backtrack_frame special case hack.
2013-05-13 15:37:57 +01:00
Stephen Dolan
8c708f3c7a
Refactor path logic.
2013-05-13 15:00:05 +01:00
Stephen Dolan
e29db8d272
Fix bug with path handling (used in assignments).
...
Closes #67
2013-05-11 18:10:21 +01:00
Stephen Dolan
898dc8978b
Add a redundant intialisation to squash a gcc warning.
2013-05-09 11:30:49 +01:00
Stephen Dolan
2363246eea
Merge remote-tracking branch 'stagrlee/master' into autotools
...
Conflicts:
Makefile
jq_test.c
2013-05-08 00:52:24 +01:00
Stephen Dolan
5be97463ec
Add a --arg option to allow variables to be passed from the cmdline.
...
Closes #107
2013-05-06 14:21:00 +01:00
Stephen Dolan
1741d8c161
Remove JQ_DEBUG #define and jq_test binary, simplifying build.
...
The debugging features previously available via JQ_DEBUG are now
command-line options.
2013-05-05 23:12:10 +01:00
Nicolas Williams
87e9c64003
Remove globals/make jq_init/next/teardown() an API
2013-04-28 18:46:21 -05:00
Lee Thompson
f62184855b
use AM_SILENT_RULES
2013-02-03 00:09:47 -06:00
Stephen Dolan
c013b557a2
Change APPEND opcode to directly modify a variable.
...
Avoids a big O(n^2) loop in constructing arrays. Fixes #61 .
2013-01-03 12:51:33 +00:00
Stephen Dolan
d5fdf70434
Refactor assignment.
...
New version is much more elegant and probably slower. Uses
library functions implemented in jq rather than dedicated opcodes.
2012-12-29 16:43:36 +00:00
Stephen Dolan
79c9c418c6
Path manipulation (path/getpath/setpath/delpath) and docs.
...
del function should fix #37 .
2012-12-28 16:08:29 +00:00
Stephen Dolan
5968f54f55
Fix a bug in stack reallocation during deep recursion.
2012-12-18 17:36:24 +00:00
Stephen Dolan
04daafbde3
Add wrappers for malloc/realloc/free. See #43 .
2012-12-18 16:53:51 +00:00
Stephen Dolan
a88d53d2fd
Extend {foo}
syntax to allow {"foo"}
as well.
...
Useful when "foo" contains unusual characters. Should help with
the issues #7 , #38 , #40 , #42 .
2012-12-03 20:31:40 +00:00
Stephen Dolan
ea9db414ed
Clean up implementation of builtin functions.
2012-12-02 22:12:08 +00:00
Stephen Dolan
b6f2fbbe62
Move all the includes one place to the left
2012-12-02 21:25:54 +00:00
Stephen Dolan
125e278502
Clean up calls to C functions, unify opcodes
2012-12-02 20:45:55 +00:00
Stephen Dolan
251f221b85
Refactor of function call codegen. Separate codegen for C and jq calls.
2012-12-02 20:45:06 +00:00
Stephen Dolan
d56370f734
Move some higher-level JSON manipulation functions into jv_aux.{c,h}
2012-11-26 22:22:45 +00:00
Stephen Dolan
4747f8681b
Transparent handling for CBV arguments to C functions.
...
C function arguments closures are inlined before the call.
2012-11-26 01:36:55 +00:00
Stephen Dolan
3e3fe51959
Clean up function creation API and epilogue generation.
2012-11-26 00:39:01 +00:00
Stephen Dolan
20e45f363c
Separate the tests and the main program.
2012-09-18 22:17:13 +01:00
Stephen Dolan
a4eea165bb
Move everything around - delete old Haskell code, clean up build.
2012-09-18 17:44:43 +01:00