mirror of
https://github.com/stedolan/jq.git
synced 2024-05-11 05:55:39 +00:00
Bind builtin functions in a slightly less ugly way.
This commit is contained in:
@ -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);
|
||||
}
|
||||
|
@ -2,7 +2,8 @@
|
||||
#define BUILTIN_H
|
||||
|
||||
#include "bytecode.h"
|
||||
#include "compile.h"
|
||||
|
||||
extern struct symbol_table builtins;
|
||||
block builtins_bind(block);
|
||||
|
||||
#endif
|
||||
|
@ -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
|
||||
|
2
c/main.c
2
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);
|
||||
}
|
||||
|
Reference in New Issue
Block a user