1
0
mirror of https://github.com/stedolan/jq.git synced 2024-05-11 05:55:39 +00:00

Move cfunction invocation code to the interpreter loop.

This commit is contained in:
Stephen Dolan
2013-06-21 12:06:28 +01:00
parent b49d65a276
commit 7af88962ee
4 changed files with 22 additions and 25 deletions

View File

@@ -241,6 +241,8 @@ static void jq_reset(jq_state *jq) {
}
void print_error(jv value) {
assert(!jv_is_valid(value));
jv msg = jv_invalid_get_msg(value);
@@ -601,12 +603,26 @@ jv jq_next(jq_state *jq) {
case CALL_BUILTIN: {
int nargs = *pc++;
jv top = stack_pop(jq);
cfunc_input[0] = top;
jv* in = cfunc_input;
in[0] = top;
for (int i = 1; i < nargs; i++) {
cfunc_input[i] = stack_pop(jq);
in[i] = stack_pop(jq);
}
struct cfunction* func = &frame_current(jq)->bc->globals->cfunctions[*pc++];
top = cfunction_invoke(func, cfunc_input);
struct cfunction* function = &frame_current(jq)->bc->globals->cfunctions[*pc++];
typedef jv (*func_1)(jv);
typedef jv (*func_2)(jv,jv);
typedef jv (*func_3)(jv,jv,jv);
typedef jv (*func_4)(jv,jv,jv,jv);
typedef jv (*func_5)(jv,jv,jv,jv,jv);
switch (function->nargs) {
case 1: top = ((func_1)function->fptr)(in[0]); break;
case 2: top = ((func_2)function->fptr)(in[0], in[1]); break;
case 3: top = ((func_3)function->fptr)(in[0], in[1], in[2]); break;
case 4: top = ((func_4)function->fptr)(in[0], in[1], in[2], in[3]); break;
case 5: top = ((func_5)function->fptr)(in[0], in[1], in[2], in[3], in[4]); break;
default: return jv_invalid_with_msg(jv_string("Function takes too many arguments"));
}
if (jv_is_valid(top)) {
stack_push(jq, top);
} else {