From 217a496c9f18e0b3c492edf77ab1786c4b8901c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakob=20L=C3=B6w?= Date: Thu, 16 Aug 2018 14:45:33 +0200 Subject: [PATCH] implement nesting in the interpreter backend --- jit/jit-insn.c | 11 ++++++++++- jit/jit-interp-opcodes.ops | 5 ----- jit/jit-rules-interp.c | 17 ++++++++++++----- 3 files changed, 22 insertions(+), 11 deletions(-) diff --git a/jit/jit-insn.c b/jit/jit-insn.c index 9198d8f..7f044d6 100644 --- a/jit/jit-insn.c +++ b/jit/jit-insn.c @@ -6308,7 +6308,16 @@ jit_insn_get_frame_pointer(jit_function_t func) break; } } - jit_insn_incoming_reg(func, value, reg); + + if(reg < JIT_NUM_REGS) + { + jit_insn_incoming_reg(func, value, reg); + } + else + { + jit_insn_incoming_frame_posn(func, value, 0); + value = jit_insn_address_of(func, value); + } return value; } diff --git a/jit/jit-interp-opcodes.ops b/jit/jit-interp-opcodes.ops index 8b10f45..482c953 100644 --- a/jit/jit-interp-opcodes.ops +++ b/jit/jit-interp-opcodes.ops @@ -178,11 +178,6 @@ opcodes(JIT_INTERP_OP_, op_def("pop") { } op_def("pop_2") { } op_def("pop_3") { } - /* - * Nested function call handling. - */ - op_def("import_local") { "JIT_OPCODE_NINT_ARG_TWO" } - op_def("import_arg") { "JIT_OPCODE_NINT_ARG_TWO" } /* * Marker opcode for the end of a function. */ diff --git a/jit/jit-rules-interp.c b/jit/jit-rules-interp.c index 3b08ce3..0aace4b 100644 --- a/jit/jit-rules-interp.c +++ b/jit/jit-rules-interp.c @@ -287,11 +287,18 @@ int _jit_create_entry_insns(jit_function_t func) flipped when we output the argument opcodes for interpretation */ offset = -1; - /* If the function is nested, then we need two extra parameters - to pass the pointer to the parent's local variables and arguments */ + /* If the function is nested, then we an extra parameter + to pass the pointer to the parent's frame */ if(func->nested_parent) { - offset -= 2; + value = jit_value_create(func, jit_type_void_ptr); + if(!jit_insn_incoming_frame_posn(func, value, offset)) + { + return 0; + } + + jit_function_set_parent_frame(func, value); + --offset; } /* Allocate the structure return pointer */ @@ -974,7 +981,7 @@ load_value(jit_gencode_t gen, jit_value_t value, int index) default: return; } - opcode = _jit_load_opcode(opcode, value->type, value, 0); + opcode = _jit_load_opcode(opcode, value->type); offset = value->frame_offset; } else @@ -994,7 +1001,7 @@ load_value(jit_gencode_t gen, jit_value_t value, int index) default: return; } - opcode = _jit_load_opcode(opcode, value->type, value, 0); + opcode = _jit_load_opcode(opcode, value->type); offset = -(value->frame_offset + 1); }