]> granicus.if.org Git - jq/commitdiff
Bind builtin functions in a slightly less ugly way.
authorStephen Dolan <mu@netsoc.tcd.ie>
Sun, 16 Sep 2012 16:08:56 +0000 (17:08 +0100)
committerStephen Dolan <mu@netsoc.tcd.ie>
Sun, 16 Sep 2012 16:08:56 +0000 (17:08 +0100)
c/builtin.c
c/builtin.h
c/compile.h
c/main.c

index 39d3f24d90e81cb05db28616b3bf32420fd86597..9be18208da982ebe91ba3887e9589f06398ef16d 100644 (file)
@@ -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);
+}
index 5b0d3702a26eee9a48124e07eec0d798af7fcb68..fe2ac6acec3dde9f6461b563181bb8bba1670495 100644 (file)
@@ -2,7 +2,8 @@
 #define BUILTIN_H
 
 #include "bytecode.h"
+#include "compile.h"
 
-extern struct symbol_table builtins;
+block builtins_bind(block);
 
 #endif
index bdaf6a88c600e5f9d0e5489b9fc95776c4de9d7c..28249e8fee308baf14997ae86a1592141eb62e50 100644 (file)
@@ -1,3 +1,5 @@
+#ifndef COMPILE_H
+#define COMPILE_H
 #include <stdint.h>
 #include "bytecode.h"
 #include "opcode.h"
@@ -47,3 +49,5 @@ int block_compile(block, struct locfile*, struct bytecode**);
 void block_free(block);
 
 
+
+#endif
index f87a51128a2622e419937d571c084880041cf38b..b65d820fd319e992482346dd9ee43612930b3498 100644 (file)
--- 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);
   }