From ef51126aaba987453709ec1bd798221fa53bdf30 Mon Sep 17 00:00:00 2001 From: Ruben Ayrapetyan Date: Fri, 18 Jul 2014 12:27:17 +0400 Subject: [PATCH] Adding boolean return value, indicating whether script execution finished with success or failure, to run_int. Moving opcode loop from run_int to run_int_from_pos. --- src/libcoreint/interpreter.c | 91 ++++++++++++++++++++++++++++++------ src/libcoreint/interpreter.h | 10 ++-- 2 files changed, 80 insertions(+), 21 deletions(-) diff --git a/src/libcoreint/interpreter.c b/src/libcoreint/interpreter.c index aa94b445b..d0e0e60e5 100644 --- a/src/libcoreint/interpreter.c +++ b/src/libcoreint/interpreter.c @@ -13,36 +13,100 @@ * limitations under the License. */ +#include "ecma-helpers.h" #include "interpreter.h" -void -init_int (void) -{ -#define INIT_OP_FUNC(name) __opfuncs[ __op__idx_##name ] = opfunc_##name ; - JERRY_STATIC_ASSERT (sizeof (OPCODE) <= 4); - +#define INIT_OP_FUNC(name) [ __op__idx_##name ] = opfunc_##name, +static const opfunc __opfuncs[LAST_OP] = { OP_LIST (INIT_OP_FUNC) -} +}; +#undef INIT_OP_FUNC +JERRY_STATIC_ASSERT (sizeof (OPCODE) <= 4); + +const OPCODE *__program = NULL; + +/** + * Initialize interpreter. + */ void +init_int( const OPCODE *program_p) /**< pointer to byte-code program */ +{ + JERRY_ASSERT( __program == NULL ); + + __program = program_p; +} /* init_int */ + +bool run_int (void) { - init_int (); + JERRY_ASSERT( __program != NULL ); struct __int_data int_data; int_data.pos = 0; + int_data.this_binding_p = NULL; + int_data.lex_env_p = ecma_CreateLexicalEnvironment( NULL, + ECMA_LEXICAL_ENVIRONMENT_DECLARATIVE); - while (true) + ecma_CompletionValue_t completion = run_int_from_pos( &int_data); + + switch ( (ecma_CompletionType_t)completion.type ) { - run_int_from_pos (&int_data); + case ECMA_COMPLETION_TYPE_NORMAL: + { + JERRY_UNREACHABLE(); + } + case ECMA_COMPLETION_TYPE_EXIT: + { + return ecma_IsValueTrue( completion.value); + } + case ECMA_COMPLETION_TYPE_BREAK: + case ECMA_COMPLETION_TYPE_CONTINUE: + case ECMA_COMPLETION_TYPE_RETURN: + { + TODO( Throw SyntaxError ); + + JERRY_UNIMPLEMENTED(); + } + case ECMA_COMPLETION_TYPE_THROW: + { + TODO( Handle unhandled exception ); + + JERRY_UNIMPLEMENTED(); + } } + + JERRY_UNREACHABLE(); } -void +ecma_CompletionValue_t run_int_from_pos (struct __int_data *int_data) { - OPCODE *curr = &__program[int_data->pos]; - __opfuncs[curr->op_idx](*curr, int_data); + ecma_CompletionValue_t completion; + + while ( true ) + { + do + { + const OPCODE *curr = &__program[int_data->pos]; + completion = __opfuncs[curr->op_idx](*curr, int_data); + } 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; + } } /** @@ -68,7 +132,6 @@ try_get_string_by_idx(T_IDX idx, /**< literal id */ } // TODO - buffer_p[0] = (ecma_Char_t) ('a' + idx); buffer_p[1] = 0; diff --git a/src/libcoreint/interpreter.h b/src/libcoreint/interpreter.h index 7bf733f69..bdc3b9b91 100644 --- a/src/libcoreint/interpreter.h +++ b/src/libcoreint/interpreter.h @@ -20,10 +20,6 @@ #include "globals.h" #include "opcodes.h" -OPCODE __program[128]; - -opfunc __opfuncs[LAST_OP]; - struct __int_data { int pos; /**< current opcode to execute */ @@ -32,9 +28,9 @@ struct __int_data int *root_op_addr; /**< pointer to first opcode saved */ }; -void init_int (void); -void run_int (void); -void run_int_from_pos (struct __int_data *); +void init_int (const OPCODE* program_p); +bool run_int (void); +ecma_CompletionValue_t run_int_from_pos (struct __int_data *); ssize_t try_get_string_by_idx( T_IDX idx, ecma_Char_t *buffer_p, ssize_t buffer_size);