From: Stephen Dolan Date: Mon, 26 Nov 2012 18:53:47 +0000 (+0000) Subject: Define bytecoded builtins more concisely. X-Git-Tag: jq-1.2~37 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=334a79b7040df4b5942da9688fbee0e5d3af9fd7;p=jq Define bytecoded builtins more concisely. --- diff --git a/builtin.c b/builtin.c index e1144e3..657a7a1 100644 --- a/builtin.c +++ b/builtin.c @@ -251,27 +251,6 @@ static void f_type(jv input[], jv output[]) { jv_free(input[0]); } -static block j_empty() { - return gen_function("empty", gen_op_simple(BACKTRACK)); -} - -static block j_false() { - return gen_function("false", gen_op_const(LOADK, jv_false())); -} - -static block j_true() { - return gen_function("true", gen_op_const(LOADK, jv_true())); -} - -static block j_null() { - return gen_function("null", gen_op_const(LOADK, jv_null())); -} - -static block j_not() { - return gen_function("not", gen_condbranch(gen_op_const(LOADK, jv_false()), - gen_op_const(LOADK, jv_true()))); -} - static struct cfunction function_list[] = { {f_plus, "_plus", CALL_BUILTIN_3_1}, {f_minus, "_minus", CALL_BUILTIN_3_1}, @@ -294,13 +273,22 @@ static struct cfunction function_list[] = { static struct symbol_table cbuiltins = {function_list, sizeof(function_list)/sizeof(function_list[0])}; typedef block (*bytecoded_builtin)(); -static bytecoded_builtin bytecoded_builtins[] = { - j_empty, - j_false, - j_true, - j_null, - j_not, -}; +struct bytecoded_builtin { const char* name; block code; }; +static block bind_bytecoded_builtins(block b) { + struct bytecoded_builtin builtin_defs[] = { + {"empty", gen_op_simple(BACKTRACK)}, + {"false", gen_op_const(LOADK, jv_false())}, + {"true", gen_op_const(LOADK, jv_true())}, + {"null", gen_op_const(LOADK, jv_null())}, + {"not", gen_condbranch(gen_op_const(LOADK, jv_false()), + gen_op_const(LOADK, jv_true()))} + }; + block builtins = gen_noop(); + for (unsigned i=0; i