Commit Graph
35 Commits
Author SHA1 Message Date
Muh Muhten 3ea0199e03 Restore cfunction arity in builtins/0
Count arguments up-front at definition/invocation instead of doing it at
bind time, which comes after generating builtins/0 since e843a4f.
2019-02-26 22:39:57 -06:00
Muh Muhten abed751e96 Bind libraries backward for consistent shadowing 2019-02-26 21:57:08 -06:00
Muh Muhten 141bb78e96 Fix regression on ~/.jq being a directory 2019-02-26 21:57:08 -06:00
Muh Muhten 30afc86af1 Fix alpine build 2019-02-26 21:40:59 -06:00
Muh Muhten 76e72a301d Simplify and optimize SQLish builtins 2019-02-26 11:05:25 -06:00
Muh Muhten a1626adb7e Fix bizarre bsearch/1 behaviour with a stream argument 2019-02-26 11:05:25 -06:00
Muh Muhten d1a07cbdc1 Make tostream much more efficient
(`path(.[])` is a streaming `keys`!)
2019-02-26 11:05:25 -06:00
Muh Muhten 8c1e7175ec Reimplement fromstream/1 more compactly 2019-02-26 11:05:25 -06:00
Muh Muhten fc6df0fdc1 Simplify definition of range/3
New implementation in terms of while/2, and branches immediately on $by
to avoid checking the sign of $by *in* the loop.
2019-02-26 11:05:25 -06:00
Muh Muhten 78271b179a Simplify type-select builtins 2019-02-26 11:05:25 -06:00
Muh Muhten d3abe3a468 Add more tests for any and all 2019-02-26 11:05:25 -06:00
Muh Muhten 41b859325b Redefine isempty/1, and the all and any series
Fixes the bug where all and any evaluate one more item than needed.
2019-02-26 11:05:25 -06:00
Muh Muhten 6a0bdf6063 Remove scalars_or_empty 2019-02-26 11:05:25 -06:00
Muh Muhten 36c250a03d No need to block_drop_unreferenced after builtins
(The correctness of this change is more obvious after the rename.)
2019-02-26 10:49:08 -06:00
Muh Muhten 260879a5c3 Rename block_bind_incremental to block_bind_referenced
block_bind_incremental is block_bind_referenced in a loop backwards. For
an 1-inst block, it does the same thing and isn't too much more
expensive, so it's not really useful to keep both.

Also, block_bind_referenced was a better name for the function.
2019-02-26 10:49:08 -06:00
Muh Muhten 8537b93a43 Fix block flipping in block_drop_unreferenced
Since 605bfb3, block_drop_unreferenced actually reverses the order of
instructions in the block it's run against. This bug was hidden by the
fact that normally it's run *twice* against the main program, flipping
it back, and that order of function definitionss doesn't really matter
after symbol resolution.
2019-02-26 10:49:08 -06:00
Muh Muhten 130152a2ac Ensure limit(0; ...) is empty 2019-02-21 04:11:41 -05:00
Muh Muhten 730c730940 Rewrite _assign/2 using $argument syntax 2019-02-20 20:12:52 -06:00
Muh Muhten 85caac4473 Work around fgets()'s lack of length reporting
Stop losing \0s from the end of files because we don't know how much
fgets() read into our buffer. If we prefill the buffer with anything
other than zeroes, we can actually tell the difference between the
terminator and unused space in the buffer.

This is possibly more expensive, but at least it should be correct.

Fixes #1504
2019-02-20 20:12:52 -06:00
Muh Muhten 1ef90acb38 Bind data imports properly when already resolved 2019-02-20 20:02:41 -06:00
Muh Muhten e843a4fdf9 Make builtin binding fast again by binding only referenced symbols
Avoid doing the internal binding of top-level symbols in the parser,
leaving that work to be done in a post-processing step. For builtins,
this lets us do a reference-aware bind step (block_bind_incremental)
*after* generating builtins/0.

Libraries are a bit trickier since they may be bound multiple times, so
instead of thinking through the implications I added (block_bind_self)
to resolve all internal symbols immediately.
2019-02-20 19:43:13 -06:00
Muh Muhten b2b0bd37a1 Load ~/.jq as a library instead of with builtins
Remove the special code which loads ~/.jq in builtin.c, and instead glue
an optional include which points to the same file onto the main program
in linker.c.

Fixes a minor bug where errors in ~/.jq would be labelled <builtin>.
2019-02-20 19:16:18 -06:00
Muh Muhten 450ade4818 Add import metadata key "optional"
A library marked is imported if found, but silently skipped if missing.
This is the desired semantic for the auto-include at ~/.jq
2019-02-20 19:16:18 -06:00
Muh Muhten c814c4e001 Replace TOP-before-imports special case with assert
The case isn't actually possible afaict.
2019-02-20 19:16:18 -06:00
Muh Muhten 4f4494c770 Catch .. as the first component of a module path
Only the second and subsequent path components were being checked, which
I guess is theoretically security-relevant.

There's no apparent point to reconstructing the path after splitting it
by adding /s back in, either.
2019-02-20 19:16:18 -06:00
Muh Muhten ff014824bc Pass on the error message when rel_path is invalid
"Module path must be a string" is not a useful error message when the
reason the module path isn't a string is because the string it was got
replaced with an invalid with an error message for some other reason.

Also fixes a few memory leaks on early exits.
2019-02-20 19:16:18 -06:00
Muh Muhten 8edf58a95f Simplify definition of block_bind_referenced 2019-02-20 19:16:18 -06:00
Muh Muhten 605bfb3577 Reimplement block_drop_unreferenced in linear time 2019-02-16 20:30:20 -06:00
Muh Muhten 3f59bee3e0 Make sure to free in jv_string_indexes 2019-02-09 17:17:59 -05:00
Muh Muhten 88613f5469 Improve linking time by marking subtrees with unbound symbols 2019-02-08 22:41:31 -06:00
Muh Muhten 956d40d9dd Define error/1 in terms of error/0
The parser generates a call to error/0 on break. Having that exported
from C directly removes a language dependency on builtin.jq.

In any case, error/0 seems to be the more fundamental operation, seeing
as the old C impementation of error/1 did nothing useful with its input.
2019-02-07 11:05:06 -06:00
Muh Muhten 2fd725209e Export input/0 directly from C, removing _input/0
The distinction between input/0 and _input/0 has been unnecessary since
a9c613..7dc34b, which moved end-of-input handling into C and replaced
the jq definition of input with `def input: _input;`
2019-02-06 12:06:03 -06:00
Muh Muhten 3c5b1419a2 Unify timegm fallbacks into my_mktime
my_timegm was introduced in 1900c7 to add a mktime fallback used in
4a6241, the subsequently removed in c53823. As a result of this code
shuffling, the jq mktime function (f_mktime) wound up using a fallback
even on systems where timegm is available, with incorrect results in
some time zones with DST, e.g.

% TZ=America/New_York jq -n '"2018-08-31T00:00:00Z"|fromdate|todate'
"2018-08-31T01:00:00Z"

This undoes 1900c7 and moves the workaround it added into the #else of
my_mktime.
2019-01-30 22:05:51 -06:00
Muh Muhten 012af2186b Fix build on BSD make
Replace uses of the nonstandard $^ variable by explicitly specifying the
source filenames. This is the only obvious thing preventing the build
from running correctly on non-GNU make.
2019-01-30 09:48:04 -06:00
Muh Muhten 12a628abdc Fix include/import namespace confusion 2019-01-30 09:47:24 -06:00