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.
This commit is contained in:
@@ -13,36 +13,100 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "ecma-helpers.h"
|
||||||
#include "interpreter.h"
|
#include "interpreter.h"
|
||||||
|
|
||||||
void
|
#define INIT_OP_FUNC(name) [ __op__idx_##name ] = opfunc_##name,
|
||||||
init_int (void)
|
static const opfunc __opfuncs[LAST_OP] = {
|
||||||
{
|
|
||||||
#define INIT_OP_FUNC(name) __opfuncs[ __op__idx_##name ] = opfunc_##name ;
|
|
||||||
JERRY_STATIC_ASSERT (sizeof (OPCODE) <= 4);
|
|
||||||
|
|
||||||
OP_LIST (INIT_OP_FUNC)
|
OP_LIST (INIT_OP_FUNC)
|
||||||
}
|
};
|
||||||
|
#undef INIT_OP_FUNC
|
||||||
|
|
||||||
|
JERRY_STATIC_ASSERT (sizeof (OPCODE) <= 4);
|
||||||
|
|
||||||
|
const OPCODE *__program = NULL;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialize interpreter.
|
||||||
|
*/
|
||||||
void
|
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)
|
run_int (void)
|
||||||
{
|
{
|
||||||
init_int ();
|
JERRY_ASSERT( __program != NULL );
|
||||||
|
|
||||||
struct __int_data int_data;
|
struct __int_data int_data;
|
||||||
int_data.pos = 0;
|
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)
|
run_int_from_pos (struct __int_data *int_data)
|
||||||
{
|
{
|
||||||
OPCODE *curr = &__program[int_data->pos];
|
ecma_CompletionValue_t completion;
|
||||||
__opfuncs[curr->op_idx](*curr, int_data);
|
|
||||||
|
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
|
// TODO
|
||||||
|
|
||||||
buffer_p[0] = (ecma_Char_t) ('a' + idx);
|
buffer_p[0] = (ecma_Char_t) ('a' + idx);
|
||||||
buffer_p[1] = 0;
|
buffer_p[1] = 0;
|
||||||
|
|
||||||
|
|||||||
@@ -20,10 +20,6 @@
|
|||||||
#include "globals.h"
|
#include "globals.h"
|
||||||
#include "opcodes.h"
|
#include "opcodes.h"
|
||||||
|
|
||||||
OPCODE __program[128];
|
|
||||||
|
|
||||||
opfunc __opfuncs[LAST_OP];
|
|
||||||
|
|
||||||
struct __int_data
|
struct __int_data
|
||||||
{
|
{
|
||||||
int pos; /**< current opcode to execute */
|
int pos; /**< current opcode to execute */
|
||||||
@@ -32,9 +28,9 @@ struct __int_data
|
|||||||
int *root_op_addr; /**< pointer to first opcode saved */
|
int *root_op_addr; /**< pointer to first opcode saved */
|
||||||
};
|
};
|
||||||
|
|
||||||
void init_int (void);
|
void init_int (const OPCODE* program_p);
|
||||||
void run_int (void);
|
bool run_int (void);
|
||||||
void run_int_from_pos (struct __int_data *);
|
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);
|
ssize_t try_get_string_by_idx( T_IDX idx, ecma_Char_t *buffer_p, ssize_t buffer_size);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user