From 32ba30ddefcac7e5358f37d85f0f08a336c12b59 Mon Sep 17 00:00:00 2001 From: Ruben Ayrapetyan Date: Tue, 26 Aug 2014 20:20:33 +0400 Subject: [PATCH] Extracting interpreter loop from run_int_from_pos. --- src/libcoreint/interpreter.c | 74 ++++++++++++++++++++---------------- src/libcoreint/interpreter.h | 1 + 2 files changed, 43 insertions(+), 32 deletions(-) diff --git a/src/libcoreint/interpreter.c b/src/libcoreint/interpreter.c index 5eff346b8..4b43fb334 100644 --- a/src/libcoreint/interpreter.c +++ b/src/libcoreint/interpreter.c @@ -99,6 +99,40 @@ run_int (void) JERRY_UNREACHABLE (); } +ecma_completion_value_t +run_int_loop (int_data_t *int_data) +{ + while (true) + { + ecma_completion_value_t completion; + + do + { + const opcode_t *curr = &__program[int_data->pos]; + completion = __opfuncs[curr->op_idx] (*curr, int_data); + + JERRY_ASSERT (!ecma_is_completion_value_normal (completion) + || ecma_is_empty_completion_value (completion)); + } + while (completion.type == ECMA_COMPLETION_TYPE_NORMAL); + + if (completion.type == ECMA_COMPLETION_TYPE_BREAK) + { + JERRY_UNIMPLEMENTED (); + + continue; + } + else if (completion.type == ECMA_COMPLETION_TYPE_CONTINUE) + { + JERRY_UNIMPLEMENTED (); + + continue; + } + + return completion; + } +} + ecma_completion_value_t run_int_from_pos (opcode_counter_t start_pos, ecma_value_t this_binding_value, @@ -133,40 +167,16 @@ run_int_from_pos (opcode_counter_t start_pos, int_data.max_reg_num = max_reg_num; int_data.regs_p = regs; - while (true) + completion = run_int_loop (&int_data); + + for (uint32_t reg_index = 0; + reg_index < regs_num; + reg_index++) { - do - { - const opcode_t *curr = &__program[int_data.pos]; - completion = __opfuncs[curr->op_idx] (*curr, &int_data); - - JERRY_ASSERT (!ecma_is_completion_value_normal (completion) - || ecma_is_empty_completion_value (completion)); - } - while (completion.type == ECMA_COMPLETION_TYPE_NORMAL); - - if (completion.type == ECMA_COMPLETION_TYPE_BREAK) - { - JERRY_UNIMPLEMENTED (); - - continue; - } - else if (completion.type == ECMA_COMPLETION_TYPE_CONTINUE) - { - JERRY_UNIMPLEMENTED (); - - continue; - } - - for (uint32_t reg_index = 0; - reg_index < regs_num; - reg_index++) - { - ecma_free_value (regs[ reg_index ], true); - } - - return completion; + ecma_free_value (regs[ reg_index ], true); } + + return completion; } /** diff --git a/src/libcoreint/interpreter.h b/src/libcoreint/interpreter.h index 9f0825826..50ab09b08 100644 --- a/src/libcoreint/interpreter.h +++ b/src/libcoreint/interpreter.h @@ -22,6 +22,7 @@ void init_int (const opcode_t* program_p); bool run_int (void); +ecma_completion_value_t run_int_loop (int_data_t *int_data); ecma_completion_value_t run_int_from_pos (opcode_counter_t start_pos, ecma_value_t this_binding_value, ecma_object_t *lex_env_p,