230804.3 · 3b6e7ddd72d6080959a44bdcca068c3a200eb2ef
Constant fold all kinds of constants
This patch exports all the binary operator builtins functions from builtin.c and uses them for constant folding in the parser, allowing constant folding to work will all kinds and combinations of constants.
Now string*number, $ARGS+$ARGS, string/string, etc will also be constant folded and the implementation of constant folded operators and runtime operators will be the same.
And thanks to the new ERRORK bytecode operation, errors are constant folded too! (e.g. 1 / 0 [] * {} etc)
reading declarations
Changes to src/builtin.h. All files
@@ -7,4 +7,22 @@ int builtins_bind(jq_state *, block*); +#define BINOPS \+ BINOP(plus) \+ BINOP(minus) \+ BINOP(multiply) \+ BINOP(divide) \+ BINOP(mod) \+ BINOP(equal) \+ BINOP(notequal) \+ BINOP(less) \+ BINOP(lesseq) \+ BINOP(greater) \+ BINOP(greatereq) \+++#define BINOP(name) jv binop_ ## name(jv, jv);+BINOPS+#undef BINOP+ #endif