Fixes for interpreter.*
This commit is contained in:
@@ -24,7 +24,8 @@
|
||||
#include "jerry-libc.h"
|
||||
|
||||
#define INIT_OP_FUNC(name) [ __op__idx_##name ] = opfunc_##name,
|
||||
static const opfunc __opfuncs[LAST_OP] = {
|
||||
static const opfunc __opfuncs[LAST_OP] =
|
||||
{
|
||||
OP_LIST (INIT_OP_FUNC)
|
||||
};
|
||||
#undef INIT_OP_FUNC
|
||||
@@ -37,9 +38,9 @@ const OPCODE *__program = NULL;
|
||||
* Initialize interpreter.
|
||||
*/
|
||||
void
|
||||
init_int( const OPCODE *program_p) /**< pointer to byte-code program */
|
||||
init_int (const OPCODE *program_p) /**< pointer to byte-code program */
|
||||
{
|
||||
JERRY_ASSERT( __program == NULL );
|
||||
JERRY_ASSERT (__program == NULL);
|
||||
|
||||
__program = program_p;
|
||||
} /* init_int */
|
||||
@@ -47,12 +48,12 @@ init_int( const OPCODE *program_p) /**< pointer to byte-code program */
|
||||
bool
|
||||
run_int (void)
|
||||
{
|
||||
JERRY_ASSERT( __program != NULL );
|
||||
JERRY_ASSERT (__program != NULL);
|
||||
|
||||
const opcode_counter_t start_pos = 0;
|
||||
ecma_value_t this_binding_value = ecma_make_simple_value( ECMA_SIMPLE_VALUE_UNDEFINED);
|
||||
ecma_object_t *lex_env_p = ecma_op_create_global_environment();
|
||||
FIXME( Strict mode );
|
||||
ecma_value_t this_binding_value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_UNDEFINED);
|
||||
ecma_object_t *lex_env_p = ecma_op_create_global_environment ();
|
||||
FIXME (Strict mode);
|
||||
const bool is_strict = false;
|
||||
|
||||
ecma_completion_value_t completion = run_int_from_pos (start_pos,
|
||||
@@ -60,37 +61,37 @@ run_int (void)
|
||||
lex_env_p,
|
||||
is_strict);
|
||||
|
||||
switch ( (ecma_completion_type_t)completion.type )
|
||||
switch ((ecma_completion_type_t) completion.type)
|
||||
{
|
||||
case ECMA_COMPLETION_TYPE_NORMAL:
|
||||
{
|
||||
JERRY_UNREACHABLE();
|
||||
}
|
||||
{
|
||||
JERRY_UNREACHABLE ();
|
||||
}
|
||||
case ECMA_COMPLETION_TYPE_EXIT:
|
||||
{
|
||||
ecma_deref_object( lex_env_p);
|
||||
ecma_finalize();
|
||||
ecma_gc_run( ECMA_GC_GEN_COUNT - 1);
|
||||
{
|
||||
ecma_deref_object (lex_env_p);
|
||||
ecma_finalize ();
|
||||
ecma_gc_run (ECMA_GC_GEN_COUNT - 1);
|
||||
|
||||
return ecma_is_value_true( completion.value);
|
||||
}
|
||||
return ecma_is_value_true (completion.value);
|
||||
}
|
||||
case ECMA_COMPLETION_TYPE_BREAK:
|
||||
case ECMA_COMPLETION_TYPE_CONTINUE:
|
||||
case ECMA_COMPLETION_TYPE_RETURN:
|
||||
{
|
||||
TODO( Throw SyntaxError );
|
||||
{
|
||||
TODO (Throw SyntaxError);
|
||||
|
||||
JERRY_UNIMPLEMENTED();
|
||||
}
|
||||
JERRY_UNIMPLEMENTED ();
|
||||
}
|
||||
case ECMA_COMPLETION_TYPE_THROW:
|
||||
{
|
||||
TODO( Handle unhandled exception );
|
||||
{
|
||||
TODO (Handle unhandled exception);
|
||||
|
||||
JERRY_UNIMPLEMENTED();
|
||||
}
|
||||
JERRY_UNIMPLEMENTED ();
|
||||
}
|
||||
}
|
||||
|
||||
JERRY_UNREACHABLE();
|
||||
JERRY_UNREACHABLE ();
|
||||
}
|
||||
|
||||
ecma_completion_value_t
|
||||
@@ -102,19 +103,19 @@ run_int_from_pos (opcode_counter_t start_pos,
|
||||
ecma_completion_value_t completion;
|
||||
|
||||
const OPCODE *curr = &__program[start_pos];
|
||||
JERRY_ASSERT( curr->op_idx == __op__idx_reg_var_decl );
|
||||
JERRY_ASSERT (curr->op_idx == __op__idx_reg_var_decl);
|
||||
|
||||
const T_IDX min_reg_num = curr->data.reg_var_decl.min;
|
||||
const T_IDX max_reg_num = curr->data.reg_var_decl.max;
|
||||
JERRY_ASSERT( max_reg_num >= min_reg_num );
|
||||
JERRY_ASSERT (max_reg_num >= min_reg_num);
|
||||
|
||||
const uint32_t regs_num = (uint32_t) (max_reg_num - min_reg_num + 1);
|
||||
|
||||
ecma_value_t regs[ regs_num ];
|
||||
|
||||
/* memseting with zero initializes each 'register' to empty value */
|
||||
__memset (regs, 0, sizeof(regs));
|
||||
JERRY_ASSERT( ecma_is_value_empty( regs[0]) );
|
||||
__memset (regs, 0, sizeof (regs));
|
||||
JERRY_ASSERT (ecma_is_value_empty (regs[0]));
|
||||
|
||||
struct __int_data int_data;
|
||||
int_data.pos = (opcode_counter_t) (start_pos + 1);
|
||||
@@ -125,39 +126,40 @@ run_int_from_pos (opcode_counter_t start_pos,
|
||||
int_data.max_reg_num = max_reg_num;
|
||||
int_data.regs_p = regs;
|
||||
|
||||
while ( true )
|
||||
while (true)
|
||||
{
|
||||
do
|
||||
{
|
||||
do
|
||||
{
|
||||
const OPCODE *curr = &__program[int_data.pos];
|
||||
completion = __opfuncs[curr->op_idx](*curr, &int_data);
|
||||
const OPCODE *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;
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -167,25 +169,27 @@ run_int_from_pos (opcode_counter_t start_pos,
|
||||
* otherwise (buffer size is not enough) - negated minimum required buffer size.
|
||||
*/
|
||||
ssize_t
|
||||
try_get_string_by_idx(T_IDX idx, /**< literal id */
|
||||
ecma_char_t *buffer_p, /**< buffer */
|
||||
ssize_t buffer_size) /**< buffer size */
|
||||
try_get_string_by_idx (T_IDX idx, /**< literal id */
|
||||
ecma_char_t *buffer_p, /**< buffer */
|
||||
ssize_t buffer_size) /**< buffer size */
|
||||
{
|
||||
TODO( Actual string literal retrievement );
|
||||
TODO (Actual string literal retrievement);
|
||||
|
||||
const ecma_char_t *str_p = deserialize_string_by_id( idx);
|
||||
JERRY_ASSERT( str_p != NULL );
|
||||
const ecma_char_t *str_p = deserialize_string_by_id (idx);
|
||||
JERRY_ASSERT (str_p != NULL);
|
||||
|
||||
FIXME (ecma_char_t strlen);
|
||||
|
||||
FIXME( strlen for ecma_char_t );
|
||||
ssize_t req_length = (ssize_t)__strlen( (const char*)str_p) + 1;
|
||||
ssize_t req_length = (ssize_t)__strlen ((const char*)str_p) + 1;
|
||||
|
||||
if ( buffer_size < req_length )
|
||||
if (buffer_size < req_length)
|
||||
{
|
||||
return -req_length;
|
||||
}
|
||||
|
||||
FIXME( strncpy for ecma_char_t );
|
||||
__strncpy( (char*)buffer_p, (const char*)str_p, (size_t)req_length);
|
||||
FIXME (ecma_char_t strncpy);
|
||||
|
||||
__strncpy ((char*)buffer_p, (const char*)str_p, (size_t)req_length);
|
||||
|
||||
return req_length;
|
||||
} /* try_get_string_by_idx */
|
||||
@@ -196,12 +200,12 @@ try_get_string_by_idx(T_IDX idx, /**< literal id */
|
||||
* @return value of number literal, corresponding to specified literal id
|
||||
*/
|
||||
ecma_number_t
|
||||
get_number_by_idx(T_IDX idx) /**< literal id */
|
||||
get_number_by_idx (T_IDX idx) /**< literal id */
|
||||
{
|
||||
TODO( Actual number literal retrievement );
|
||||
TODO (Actual number literal retrievement);
|
||||
|
||||
FIXME( /* conversion of value returned from deserialize_num_by_id to ecma_number_t */ );
|
||||
ecma_number_t num = (ecma_number_t) deserialize_num_by_id( idx);
|
||||
FIXME (/* conversion of value returned from deserialize_num_by_id to ecma_number_t */);
|
||||
ecma_number_t num = (ecma_number_t) deserialize_num_by_id (idx);
|
||||
|
||||
return num;
|
||||
} /* get_number_by_idx */
|
||||
@@ -210,7 +214,7 @@ get_number_by_idx(T_IDX idx) /**< literal id */
|
||||
* Get specified opcode from the program.
|
||||
*/
|
||||
OPCODE
|
||||
read_opcode(opcode_counter_t counter) /**< opcode counter */
|
||||
read_opcode (opcode_counter_t counter) /**< opcode counter */
|
||||
{
|
||||
return __program[ counter ];
|
||||
} /* read_opcode */
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
*/
|
||||
|
||||
#ifndef INTERPRETER_H
|
||||
#define INTERPRETER_H
|
||||
#define INTERPRETER_H
|
||||
|
||||
#include "ecma-globals.h"
|
||||
#include "globals.h"
|
||||
@@ -40,10 +40,10 @@ ecma_completion_value_t run_int_from_pos (opcode_counter_t start_pos,
|
||||
ecma_object_t *lex_env_p,
|
||||
bool is_strict);
|
||||
|
||||
ssize_t try_get_string_by_idx( T_IDX idx, ecma_char_t *buffer_p, ssize_t buffer_size);
|
||||
ecma_number_t get_number_by_idx(T_IDX idx);
|
||||
ssize_t try_get_string_by_idx (T_IDX idx, ecma_char_t *buffer_p, ssize_t buffer_size);
|
||||
ecma_number_t get_number_by_idx (T_IDX idx);
|
||||
|
||||
OPCODE read_opcode(opcode_counter_t counter);
|
||||
OPCODE read_opcode (opcode_counter_t counter);
|
||||
|
||||
#endif /* INTERPRETER_H */
|
||||
#endif /* INTERPRETER_H */
|
||||
|
||||
|
||||
Reference in New Issue
Block a user