From 98a0c0f9338282b9726e44f5574259954a2db0fd Mon Sep 17 00:00:00 2001 From: Ruben Ayrapetyan Date: Mon, 21 Jul 2014 15:57:15 +0400 Subject: [PATCH] Introducing type argument in 'assignment' opcode handler. --- src/libcoreint/opcode-structures.h | 5 +++-- src/libcoreint/opcodes.c | 2 +- src/libcoreint/opcodes.h | 13 +++++++++++ src/libjsparser/bytecode-generator.c | 33 ++++++++++++++++++++++++++-- 4 files changed, 48 insertions(+), 5 deletions(-) diff --git a/src/libcoreint/opcode-structures.h b/src/libcoreint/opcode-structures.h index 7d57a764b..f9f230289 100644 --- a/src/libcoreint/opcode-structures.h +++ b/src/libcoreint/opcode-structures.h @@ -238,8 +238,9 @@ OP_CODE_DECL (greater_or_equal_than, T_IDX_IDX_IDX, // Assign value to LEFT operand based on value of RIGHT operand. /** L = R */ -OP_CODE_DECL (assignment, T_IDX_IDX, - value_left, +OP_CODE_DECL (assignment, T_IDX_IDX_IDX, + var_left, + type_value_right, value_right) // Functions calls, declarations and argument handling diff --git a/src/libcoreint/opcodes.c b/src/libcoreint/opcodes.c index 16dc54619..e2dfa1ea5 100644 --- a/src/libcoreint/opcodes.c +++ b/src/libcoreint/opcodes.c @@ -278,7 +278,7 @@ GETOP_IMPL_3 (less_than, dst, var_left, var_right) GETOP_IMPL_3 (greater_than, dst, var_left, var_right) GETOP_IMPL_3 (less_or_equal_than, dst, var_left, var_right) GETOP_IMPL_3 (greater_or_equal_than, dst, var_left, var_right) -GETOP_IMPL_2 (assignment, value_left, value_right) +GETOP_IMPL_3 (assignment, var_left, type_value_right, value_right) GETOP_IMPL_2 (call_1, name_lit_idx, arg1_lit_idx) GETOP_IMPL_3 (call_2, name_lit_idx, arg1_lit_idx, arg2_lit_idx) GETOP_IMPL_3 (call_n, name_lit_idx, arg1_lit_idx, arg2_lit_idx) diff --git a/src/libcoreint/opcodes.h b/src/libcoreint/opcodes.h index 5318a6db2..28e794446 100644 --- a/src/libcoreint/opcodes.h +++ b/src/libcoreint/opcodes.h @@ -141,5 +141,18 @@ OPCODE } __packed; +/** + * Descriptor of assignment's second argument + * that specifies type of third argument. + */ +typedef enum +{ + OPCODE_ARG_TYPE_SIMPLE, /**< ecma_SimpleValue_t */ + OPCODE_ARG_TYPE_SMALLINT, /**< small integer: from -128 to 127 */ + OPCODE_ARG_TYPE_NUMBER, /**< index of number literal */ + OPCODE_ARG_TYPE_STRING, /**< index of string literal */ + OPCODE_ARG_TYPE_VARIABLE /**< index of variable name */ +} opcode_arg_type_operand; + #endif /* OPCODES_H */ diff --git a/src/libjsparser/bytecode-generator.c b/src/libjsparser/bytecode-generator.c index 08127037b..2fc7e36b1 100644 --- a/src/libjsparser/bytecode-generator.c +++ b/src/libjsparser/bytecode-generator.c @@ -131,6 +131,33 @@ first_operand_as_literal (statement stmt) return oper.data.lit; } +static opcode_arg_type_operand +first_operand_type (statement stmt) +{ + JERRY_ASSERT (expression_has_operands (stmt)); + if (!first_operand (stmt).is_literal) + { + return OPCODE_ARG_TYPE_VARIABLE; + } + + literal lit = first_operand(stmt).data.lit; + + TODO( Small integer -> OPCODE_ARG_TYPE_SMALLINT ); + + switch ( lit.type ) + { + case LIT_NULL: + case LIT_BOOL: + return OPCODE_ARG_TYPE_SIMPLE; + case LIT_INT: + return OPCODE_ARG_TYPE_NUMBER; + case LIT_STR: + return OPCODE_ARG_TYPE_STRING; + } + + JERRY_UNREACHABLE(); +} + static uint8_t first_operand_id (statement stmt) { @@ -378,7 +405,9 @@ generator_dump_statement (statement stmt) break; case AO_EQ: - opcode = getop_assignment (lhs (stmt), first_operand_id (stmt)); + opcode = getop_assignment (lhs (stmt), + first_operand_type(stmt), + first_operand_id (stmt)); dump_opcode (&opcode); return; @@ -415,4 +444,4 @@ generator_dump_statement (statement stmt) __printf (" generator_dump_statement: %d ", stmt.type); JERRY_UNREACHABLE (); } -} \ No newline at end of file +}