Add literal property to the byte code list. (#2397)

Initializing a property with a constant is frequent in object initializers.

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
This commit is contained in:
Zoltan Herczeg
2018-06-20 09:06:59 +02:00
committed by GitHub
parent 7f56756e11
commit acdbbf2261
4 changed files with 14 additions and 4 deletions
+1 -1
View File
@@ -41,7 +41,7 @@ typedef struct
/** /**
* Jerry snapshot format version. * Jerry snapshot format version.
*/ */
#define JERRY_SNAPSHOT_VERSION (13u) #define JERRY_SNAPSHOT_VERSION (14u)
/** /**
* Snapshot configuration flags. * Snapshot configuration flags.
+2
View File
@@ -317,6 +317,8 @@
VM_OC_RET) \ VM_OC_RET) \
CBC_OPCODE (CBC_RETURN_WITH_LITERAL, CBC_HAS_LITERAL_ARG, 0, \ CBC_OPCODE (CBC_RETURN_WITH_LITERAL, CBC_HAS_LITERAL_ARG, 0, \
VM_OC_RET | VM_OC_GET_LITERAL) \ VM_OC_RET | VM_OC_GET_LITERAL) \
CBC_OPCODE (CBC_SET_LITERAL_PROPERTY, CBC_HAS_LITERAL_ARG | CBC_HAS_LITERAL_ARG2, 0, \
VM_OC_SET_PROPERTY | VM_OC_GET_LITERAL_LITERAL) \
CBC_OPCODE (CBC_BREAKPOINT_ENABLED, CBC_NO_FLAG, 0, \ CBC_OPCODE (CBC_BREAKPOINT_ENABLED, CBC_NO_FLAG, 0, \
VM_OC_BREAKPOINT_ENABLED) \ VM_OC_BREAKPOINT_ENABLED) \
CBC_OPCODE (CBC_BREAKPOINT_DISABLED, CBC_NO_FLAG, 0, \ CBC_OPCODE (CBC_BREAKPOINT_DISABLED, CBC_NO_FLAG, 0, \
+9 -1
View File
@@ -430,7 +430,15 @@ parser_parse_object_literal (parser_context_t *context_p) /**< context */
lexer_next_token (context_p); lexer_next_token (context_p);
parser_parse_expression (context_p, PARSE_EXPR_NO_COMMA); parser_parse_expression (context_p, PARSE_EXPR_NO_COMMA);
parser_emit_cbc_literal (context_p, CBC_SET_PROPERTY, literal_index); if (context_p->last_cbc_opcode == CBC_PUSH_LITERAL)
{
context_p->last_cbc_opcode = CBC_SET_LITERAL_PROPERTY;
context_p->last_cbc.value = literal_index;
}
else
{
parser_emit_cbc_literal (context_p, CBC_SET_PROPERTY, literal_index);
}
} }
if (context_p->token.type == LEXER_RIGHT_BRACE) if (context_p->token.type == LEXER_RIGHT_BRACE)
+2 -2
View File
@@ -216,12 +216,12 @@ main (void)
/* Check the snapshot data. Unused bytes should be filled with zeroes */ /* Check the snapshot data. Unused bytes should be filled with zeroes */
const uint8_t expected_data[] = const uint8_t expected_data[] =
{ {
0x4A, 0x52, 0x52, 0x59, 0x0D, 0x00, 0x00, 0x00, 0x4A, 0x52, 0x52, 0x59, 0x0E, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x48, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x48, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00,
0x03, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x03, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
0x00, 0x00, 0x00, 0x01, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x18, 0x00, 0x00, 0x00,
0x28, 0x00, 0xB7, 0x46, 0x00, 0x00, 0x00, 0x00, 0x28, 0x00, 0xB8, 0x46, 0x00, 0x00, 0x00, 0x00,
0x03, 0x00, 0x01, 0x00, 0x41, 0x00, 0x00, 0x00, 0x03, 0x00, 0x01, 0x00, 0x41, 0x00, 0x00, 0x00,
0x00, 0x00, 0x01, 0x01, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x07, 0x00, 0x00, 0x00,
0x47, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x47, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,