From 50ebb036c4bfff28e6288e69751efbd9e7298f4f Mon Sep 17 00:00:00 2001 From: Stephen Dolan Date: Sun, 16 Sep 2012 17:08:56 +0100 Subject: [PATCH] Bind builtin functions in a slightly less ugly way. --- c/builtin.c | 8 ++++++-- c/builtin.h | 3 ++- c/compile.h | 4 ++++ c/main.c | 2 +- 4 files changed, 13 insertions(+), 4 deletions(-) diff --git a/c/builtin.c b/c/builtin.c index 39d3f24d..9be18208 100644 --- a/c/builtin.c +++ b/c/builtin.c @@ -143,7 +143,7 @@ static void f_length(jv input[], jv output[]) { } } -struct cfunction function_list[] = { +static struct cfunction function_list[] = { {f_true, "true", CALL_BUILTIN_1_1}, {f_false, "false", CALL_BUILTIN_1_1}, {f_null, "null", CALL_BUILTIN_1_1}, @@ -155,4 +155,8 @@ struct cfunction function_list[] = { {f_equal, "_equal", CALL_BUILTIN_3_1}, {f_length, "length", CALL_BUILTIN_1_1}, }; -struct symbol_table builtins = {function_list, sizeof(function_list)/sizeof(function_list[0])}; +static struct symbol_table builtins = {function_list, sizeof(function_list)/sizeof(function_list[0])}; + +block builtins_bind(block b) { + return gen_cbinding(&builtins, b); +} diff --git a/c/builtin.h b/c/builtin.h index 5b0d3702..fe2ac6ac 100644 --- a/c/builtin.h +++ b/c/builtin.h @@ -2,7 +2,8 @@ #define BUILTIN_H #include "bytecode.h" +#include "compile.h" -extern struct symbol_table builtins; +block builtins_bind(block); #endif diff --git a/c/compile.h b/c/compile.h index bdaf6a88..28249e8f 100644 --- a/c/compile.h +++ b/c/compile.h @@ -1,3 +1,5 @@ +#ifndef COMPILE_H +#define COMPILE_H #include #include "bytecode.h" #include "opcode.h" @@ -47,3 +49,5 @@ int block_compile(block, struct locfile*, struct bytecode**); void block_free(block); + +#endif diff --git a/c/main.c b/c/main.c index f87a5112..b65d820f 100644 --- a/c/main.c +++ b/c/main.c @@ -21,7 +21,7 @@ struct bytecode* jq_compile(const char* str) { int nerrors = jq_parse(&locations, &program); if (nerrors == 0) { block_append(&program, block_join(gen_op_simple(YIELD), gen_op_simple(BACKTRACK))); - program = gen_cbinding(&builtins, program); + program = builtins_bind(program); nerrors = block_compile(program, &locations, &bc); block_free(program); }