Bind builtin functions in a slightly less ugly way.
This commit is contained in:
1 parent
539156430a
commit
50ebb036c4
4 files changed
+13
-4
No files matched your search
+6
-2
@@ -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_true, "true", CALL_BUILTIN_1_1},
|
||||||
{f_false, "false", CALL_BUILTIN_1_1},
|
{f_false, "false", CALL_BUILTIN_1_1},
|
||||||
{f_null, "null", 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_equal, "_equal", CALL_BUILTIN_3_1},
|
||||||
{f_length, "length", CALL_BUILTIN_1_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);
|
||||||
|
}
|
||||||
+2
-1
@@ -2,7 +2,8 @@
|
|||||||
#define BUILTIN_H
|
#define BUILTIN_H
|
||||||
|
|
||||||
#include "bytecode.h"
|
#include "bytecode.h"
|
||||||
|
#include "compile.h"
|
||||||
|
|
||||||
extern struct symbol_table builtins;
|
block builtins_bind(block);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -1,3 +1,5 @@
|
|||||||
|
#ifndef COMPILE_H
|
||||||
|
#define COMPILE_H
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include "bytecode.h"
|
#include "bytecode.h"
|
||||||
#include "opcode.h"
|
#include "opcode.h"
|
||||||
@@ -47,3 +49,5 @@ int block_compile(block, struct locfile*, struct bytecode**);
|
|||||||
void block_free(block);
|
void block_free(block);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -21,7 +21,7 @@ struct bytecode* jq_compile(const char* str) {
|
|||||||
int nerrors = jq_parse(&locations, &program);
|
int nerrors = jq_parse(&locations, &program);
|
||||||
if (nerrors == 0) {
|
if (nerrors == 0) {
|
||||||
block_append(&program, block_join(gen_op_simple(YIELD), gen_op_simple(BACKTRACK)));
|
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);
|
nerrors = block_compile(program, &locations, &bc);
|
||||||
block_free(program);
|
block_free(program);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user