/** * Run the code, starting from specified instruction position */ ecma_completion_value_t vm_run_from_pos (const vm_instr_t *instrs_p, /**< byte-code array */ vm_instr_counter_t start_pos, /**< position of starting instruction */ ecma_value_t this_binding_value, /**< value of 'ThisBinding' */ ecma_object_t *lex_env_p, /**< lexical environment to use */ bool is_strict, /**< is the code is strict mode code (ECMA-262 v5, 10.1.1) */ bool is_eval_code) /**< is the code is eval code (ECMA-262 v5, 10.1) */ { ecma_completion_value_t completion; const vm_instr_t *curr = &instrs_p[start_pos]; JERRY_ASSERT (curr->op_idx == VM_OP_REG_VAR_DECL); const idx_t min_reg_num = curr->data.reg_var_decl.min; const idx_t max_reg_num = curr->data.reg_var_decl.max; JERRY_ASSERT (max_reg_num >= min_reg_num); const int32_t regs_num = max_reg_num - min_reg_num + 1; MEM_DEFINE_LOCAL_ARRAY (regs, regs_num, ecma_value_t); vm_frame_ctx_t frame_ctx; frame_ctx.instrs_p = instrs_p; frame_ctx.pos = (vm_instr_counter_t) (start_pos + 1); frame_ctx.this_binding = this_binding_value; frame_ctx.lex_env_p = lex_env_p; frame_ctx.is_strict = is_strict; frame_ctx.is_eval_code = is_eval_code; frame_ctx.is_call_in_direct_eval_form = false; frame_ctx.min_reg_num = min_reg_num; frame_ctx.max_reg_num = max_reg_num; frame_ctx.tmp_num_p = ecma_alloc_number (); vm_stack_add_frame (&frame_ctx.stack_frame, regs, regs_num); vm_frame_ctx_t *prev_context_p = vm_top_context_p; vm_top_context_p = &frame_ctx; #ifdef MEM_STATS interp_mem_stats_context_enter (&frame_ctx, start_pos); #endif /* MEM_STATS */ completion = vm_loop (&frame_ctx, NULL); JERRY_ASSERT (ecma_is_completion_value_throw (completion) || ecma_is_completion_value_return (completion)); vm_top_context_p = prev_context_p; vm_stack_free_frame (&frame_ctx.stack_frame); ecma_dealloc_number (frame_ctx.tmp_num_p); #ifdef MEM_STATS interp_mem_stats_context_exit (&frame_ctx, start_pos); #endif /* MEM_STATS */ MEM_FINALIZE_LOCAL_ARRAY (regs); return completion; } /* vm_run_from_pos */
/** * Run the code, starting from specified instruction position */ ecma_completion_value_t vm_run_from_pos (const bytecode_data_header_t *header_p, /**< byte-code data header */ vm_instr_counter_t start_pos, /**< position of starting instruction */ ecma_value_t this_binding_value, /**< value of 'ThisBinding' */ ecma_object_t *lex_env_p, /**< lexical environment to use */ bool is_strict, /**< is the code is strict mode code (ECMA-262 v5, 10.1.1) */ bool is_eval_code, /**< is the code is eval code (ECMA-262 v5, 10.1) */ ecma_collection_header_t *arg_collection_p) /**< * - collection of function call arguments, * if arguments for the called function * are placed on registers; * - NULL - otherwise. */ { ecma_completion_value_t completion; const vm_instr_t *instrs_p = header_p->instrs_p; const vm_instr_t *curr = &instrs_p[start_pos]; JERRY_ASSERT (curr->op_idx == VM_OP_REG_VAR_DECL); const uint32_t tmp_regs_num = curr->data.reg_var_decl.tmp_regs_num; const uint32_t local_var_regs_num = curr->data.reg_var_decl.local_var_regs_num; const uint32_t arg_regs_num = curr->data.reg_var_decl.arg_regs_num; uint32_t regs_num = VM_SPECIAL_REGS_NUMBER + tmp_regs_num + local_var_regs_num + arg_regs_num; MEM_DEFINE_LOCAL_ARRAY (regs, regs_num, ecma_value_t); vm_frame_ctx_t frame_ctx; frame_ctx.bytecode_header_p = header_p; frame_ctx.pos = (vm_instr_counter_t) (start_pos + 1); frame_ctx.lex_env_p = lex_env_p; frame_ctx.is_strict = is_strict; frame_ctx.is_eval_code = is_eval_code; frame_ctx.is_call_in_direct_eval_form = false; frame_ctx.tmp_num_p = ecma_alloc_number (); vm_stack_add_frame (&frame_ctx.stack_frame, regs, regs_num, local_var_regs_num, arg_regs_num, arg_collection_p); vm_stack_frame_set_reg_value (&frame_ctx.stack_frame, VM_REG_SPECIAL_THIS_BINDING, ecma_copy_value (this_binding_value, false)); vm_frame_ctx_t *prev_context_p = vm_top_context_p; vm_top_context_p = &frame_ctx; #ifdef MEM_STATS interp_mem_stats_context_enter (&frame_ctx, start_pos); #endif /* MEM_STATS */ completion = vm_loop (&frame_ctx, NULL); JERRY_ASSERT (ecma_is_completion_value_throw (completion) || ecma_is_completion_value_return (completion)); vm_top_context_p = prev_context_p; vm_stack_free_frame (&frame_ctx.stack_frame); ecma_dealloc_number (frame_ctx.tmp_num_p); #ifdef MEM_STATS interp_mem_stats_context_exit (&frame_ctx, start_pos); #endif /* MEM_STATS */ MEM_FINALIZE_LOCAL_ARRAY (regs); return completion; } /* vm_run_from_pos */