Add try-catch-finally support: parse and generate opcodes for this construct
Fix varg generation: generate *_n opcodes with parameters in following meta opcodes Add stack internal structure: dimanically allocated stack. Use dynamically allocated memory in parser: every local and global variables are stored in dinamically allocated stacks. Use dynamically allocated memory in serializer: opcodes are also stored in stack. Change is_true_jmp and is_false_jmp opcodes to relative. Change *jmp* opcodes to be able to store opcode_counter_t instead of idx_t.
This commit is contained in:
@@ -20,15 +20,16 @@
|
||||
* 'Jump if true' opcode handler.
|
||||
*
|
||||
* Note:
|
||||
* the opcode changes current opcode position to specified opcode index
|
||||
* current opcode's position changes by adding specified offset
|
||||
* if argument evaluates to true.
|
||||
*/
|
||||
ecma_completion_value_t
|
||||
opfunc_is_true_jmp (opcode_t opdata, /**< operation data */
|
||||
int_data_t *int_data) /**< interpreter context */
|
||||
opfunc_is_true_jmp_down (opcode_t opdata, /**< operation data */
|
||||
int_data_t *int_data) /**< interpreter context */
|
||||
{
|
||||
const idx_t cond_var_idx = opdata.data.is_true_jmp.value;
|
||||
const idx_t dst_opcode_idx = opdata.data.is_true_jmp.opcode;
|
||||
const idx_t cond_var_idx = opdata.data.is_true_jmp_down.value;
|
||||
const opcode_counter_t offset = calc_opcode_counter_from_idx_idx (opdata.data.is_true_jmp_down.opcode_1,
|
||||
opdata.data.is_true_jmp_down.opcode_2);
|
||||
|
||||
ecma_completion_value_t ret_value;
|
||||
|
||||
@@ -39,7 +40,8 @@ opfunc_is_true_jmp (opcode_t opdata, /**< operation data */
|
||||
|
||||
if (ecma_is_value_true (to_bool_completion.u.value))
|
||||
{
|
||||
int_data->pos = dst_opcode_idx;
|
||||
JERRY_ASSERT (offset != 0);
|
||||
int_data->pos = (opcode_counter_t) (int_data->pos + offset);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -51,21 +53,55 @@ opfunc_is_true_jmp (opcode_t opdata, /**< operation data */
|
||||
ECMA_FINALIZE (cond_value);
|
||||
|
||||
return ret_value;
|
||||
} /* opfunc_is_true_jmp */
|
||||
}
|
||||
|
||||
/* Likewise to opfunc_is_true_jmp_down, but jumps up. */
|
||||
ecma_completion_value_t
|
||||
opfunc_is_true_jmp_up (opcode_t opdata, /**< operation data */
|
||||
int_data_t *int_data) /**< interpreter context */
|
||||
{
|
||||
const idx_t cond_var_idx = opdata.data.is_true_jmp_up.value;
|
||||
const opcode_counter_t offset = calc_opcode_counter_from_idx_idx (opdata.data.is_true_jmp_up.opcode_1,
|
||||
opdata.data.is_true_jmp_up.opcode_2);
|
||||
|
||||
ecma_completion_value_t ret_value;
|
||||
|
||||
ECMA_TRY_CATCH (cond_value, get_variable_value (int_data, cond_var_idx, false), ret_value);
|
||||
|
||||
ecma_completion_value_t to_bool_completion = ecma_op_to_boolean (cond_value.u.value);
|
||||
JERRY_ASSERT (ecma_is_completion_value_normal (to_bool_completion));
|
||||
|
||||
if (ecma_is_value_true (to_bool_completion.u.value))
|
||||
{
|
||||
JERRY_ASSERT (offset != 0 && int_data->pos >= offset);
|
||||
int_data->pos = (opcode_counter_t) (int_data->pos - offset);
|
||||
}
|
||||
else
|
||||
{
|
||||
int_data->pos++;
|
||||
}
|
||||
|
||||
ret_value = ecma_make_empty_completion_value ();
|
||||
|
||||
ECMA_FINALIZE (cond_value);
|
||||
|
||||
return ret_value;
|
||||
}
|
||||
|
||||
/**
|
||||
* 'Jump if false' opcode handler.
|
||||
*
|
||||
* Note:
|
||||
* the opcode changes current opcode position to specified opcode index
|
||||
* current opcode's position changes by adding specified offset
|
||||
* if argument evaluates to false.
|
||||
*/
|
||||
ecma_completion_value_t
|
||||
opfunc_is_false_jmp (opcode_t opdata, /**< operation data */
|
||||
int_data_t *int_data) /**< interpreter context */
|
||||
opfunc_is_false_jmp_down (opcode_t opdata, /**< operation data */
|
||||
int_data_t *int_data) /**< interpreter context */
|
||||
{
|
||||
const idx_t cond_var_idx = opdata.data.is_false_jmp.value;
|
||||
const idx_t dst_opcode_idx = opdata.data.is_false_jmp.opcode;
|
||||
const idx_t cond_var_idx = opdata.data.is_false_jmp_down.value;
|
||||
const opcode_counter_t offset = calc_opcode_counter_from_idx_idx (opdata.data.is_false_jmp_down.opcode_1,
|
||||
opdata.data.is_false_jmp_down.opcode_2);
|
||||
|
||||
ecma_completion_value_t ret_value;
|
||||
|
||||
@@ -76,7 +112,8 @@ opfunc_is_false_jmp (opcode_t opdata, /**< operation data */
|
||||
|
||||
if (!ecma_is_value_true (to_bool_completion.u.value))
|
||||
{
|
||||
int_data->pos = dst_opcode_idx;
|
||||
JERRY_ASSERT (offset != 0);
|
||||
int_data->pos = (opcode_counter_t) (int_data->pos + offset);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -88,22 +125,40 @@ opfunc_is_false_jmp (opcode_t opdata, /**< operation data */
|
||||
ECMA_FINALIZE (cond_value);
|
||||
|
||||
return ret_value;
|
||||
} /* opfunc_is_false_jmp */
|
||||
}
|
||||
|
||||
/**
|
||||
* 'Jump' opcode handler.
|
||||
*
|
||||
* Note:
|
||||
* the opcode changes current opcode position to specified opcode index
|
||||
*/
|
||||
/* Likewise to opfunc_is_false_jmp_down, but jumps up. */
|
||||
ecma_completion_value_t
|
||||
opfunc_jmp (opcode_t opdata, /**< operation data */
|
||||
int_data_t *int_data) /**< interpreter context */
|
||||
opfunc_is_false_jmp_up (opcode_t opdata, /**< operation data */
|
||||
int_data_t *int_data) /**< interpreter context */
|
||||
{
|
||||
int_data->pos = opdata.data.jmp.opcode_idx;
|
||||
const idx_t cond_var_idx = opdata.data.is_false_jmp_up.value;
|
||||
const opcode_counter_t offset = calc_opcode_counter_from_idx_idx (opdata.data.is_false_jmp_up.opcode_1,
|
||||
opdata.data.is_false_jmp_up.opcode_2);
|
||||
|
||||
return ecma_make_empty_completion_value ();
|
||||
} /* opfunc_jmp */
|
||||
ecma_completion_value_t ret_value;
|
||||
|
||||
ECMA_TRY_CATCH (cond_value, get_variable_value (int_data, cond_var_idx, false), ret_value);
|
||||
|
||||
ecma_completion_value_t to_bool_completion = ecma_op_to_boolean (cond_value.u.value);
|
||||
JERRY_ASSERT (ecma_is_completion_value_normal (to_bool_completion));
|
||||
|
||||
if (!ecma_is_value_true (to_bool_completion.u.value))
|
||||
{
|
||||
JERRY_ASSERT (offset != 0 && int_data->pos >= offset);
|
||||
int_data->pos = (opcode_counter_t) (int_data->pos - offset);
|
||||
}
|
||||
else
|
||||
{
|
||||
int_data->pos++;
|
||||
}
|
||||
|
||||
ret_value = ecma_make_empty_completion_value ();
|
||||
|
||||
ECMA_FINALIZE (cond_value);
|
||||
|
||||
return ret_value;
|
||||
}
|
||||
|
||||
/**
|
||||
* 'Jump down' opcode handler.
|
||||
@@ -115,12 +170,15 @@ ecma_completion_value_t
|
||||
opfunc_jmp_down (opcode_t opdata, /**< operation data */
|
||||
int_data_t *int_data) /**< interpreter context */
|
||||
{
|
||||
JERRY_ASSERT (int_data->pos <= int_data->pos + opdata.data.jmp_up.opcode_count);
|
||||
const opcode_counter_t offset = calc_opcode_counter_from_idx_idx (opdata.data.jmp_down.opcode_1,
|
||||
opdata.data.jmp_down.opcode_2);
|
||||
|
||||
int_data->pos = (opcode_counter_t) (int_data->pos + opdata.data.jmp_down.opcode_count);
|
||||
JERRY_ASSERT (offset != 0);
|
||||
|
||||
int_data->pos = (opcode_counter_t) (int_data->pos + offset);
|
||||
|
||||
return ecma_make_empty_completion_value ();
|
||||
} /* opfunc_jmp_down */
|
||||
}
|
||||
|
||||
/**
|
||||
* 'Jump up' opcode handler.
|
||||
@@ -132,9 +190,11 @@ ecma_completion_value_t
|
||||
opfunc_jmp_up (opcode_t opdata, /**< operation data */
|
||||
int_data_t *int_data) /**< interpreter context */
|
||||
{
|
||||
JERRY_ASSERT (int_data->pos >= opdata.data.jmp_up.opcode_count);
|
||||
const opcode_counter_t offset = calc_opcode_counter_from_idx_idx (opdata.data.jmp_up.opcode_1,
|
||||
opdata.data.jmp_up.opcode_2);
|
||||
JERRY_ASSERT (offset != 0 && int_data->pos >= offset);
|
||||
|
||||
int_data->pos = (opcode_counter_t) (int_data->pos - opdata.data.jmp_down.opcode_count);
|
||||
int_data->pos = (opcode_counter_t) (int_data->pos - offset);
|
||||
|
||||
return ecma_make_empty_completion_value ();
|
||||
} /* opfunc_jmp_up */
|
||||
}
|
||||
|
||||
@@ -165,12 +165,13 @@ opcode_counter_t read_meta_opcode_counter (opcode_meta_type expected_type, int_d
|
||||
p##_3 (a, remainder, dst, var_left, var_right)
|
||||
|
||||
#define OP_JUMPS(p, a) \
|
||||
p##_1 (a, jmp, opcode_idx) \
|
||||
p##_1 (a, jmp_up, opcode_count) \
|
||||
p##_1 (a, jmp_down, opcode_count) \
|
||||
p##_2 (a, jmp_up, opcode_1, opcode_2) \
|
||||
p##_2 (a, jmp_down, opcode_1, opcode_2) \
|
||||
p##_0 (a, nop) \
|
||||
p##_2 (a, is_true_jmp, value, opcode) \
|
||||
p##_2 (a, is_false_jmp, value, opcode)
|
||||
p##_3 (a, is_true_jmp_up, value, opcode_1, opcode_2) \
|
||||
p##_3 (a, is_true_jmp_down, value, opcode_1, opcode_2) \
|
||||
p##_3 (a, is_false_jmp_up, value, opcode_1, opcode_2) \
|
||||
p##_3 (a, is_false_jmp_down, value, opcode_1, opcode_2)
|
||||
|
||||
#define OP_LIST_FULL(p, a) \
|
||||
OP_CALLS_AND_ARGS (p, a) \
|
||||
|
||||
Reference in New Issue
Block a user