1
0
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:
Stephen Dolan
2012-09-16 17:08:56 +01:00
parent 539156430a
commit 50ebb036c4
4 changed files with 13 additions and 4 deletions

View 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);
}

View File

@ -2,7 +2,8 @@
#define BUILTIN_H
#include "bytecode.h"
#include "compile.h"
extern struct symbol_table builtins;
block builtins_bind(block);
#endif

View 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

View File

@ -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);
}