Reduce try context stack consumption to 1 from 2. (#3898)
JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
This commit is contained in:
@@ -189,7 +189,9 @@
|
||||
/* Stack consumption of opcodes with context. */
|
||||
|
||||
/* PARSER_TRY_CONTEXT_STACK_ALLOCATION must be <= 3 */
|
||||
#define PARSER_TRY_CONTEXT_STACK_ALLOCATION 2
|
||||
#define PARSER_TRY_CONTEXT_STACK_ALLOCATION 1
|
||||
/* PARSER_FINALLY_CONTEXT_STACK_ALLOCATION must be <= 3 */
|
||||
#define PARSER_FINALLY_CONTEXT_STACK_ALLOCATION 2
|
||||
/* PARSER_FOR_IN_CONTEXT_STACK_ALLOCATION must be <= 4 */
|
||||
#define PARSER_FOR_IN_CONTEXT_STACK_ALLOCATION 4
|
||||
/* PARSER_FOR_OF_CONTEXT_STACK_ALLOCATION must be <= 3 */
|
||||
@@ -199,6 +201,12 @@
|
||||
/* PARSER_BLOCK_CONTEXT_STACK_ALLOCATION must be <= 3 */
|
||||
#define PARSER_BLOCK_CONTEXT_STACK_ALLOCATION 1
|
||||
|
||||
/**
|
||||
* Extra stack consumption for finally context.
|
||||
*/
|
||||
#define PARSER_FINALLY_CONTEXT_EXTRA_STACK_ALLOCATION \
|
||||
(PARSER_FINALLY_CONTEXT_STACK_ALLOCATION - PARSER_TRY_CONTEXT_STACK_ALLOCATION)
|
||||
|
||||
/**
|
||||
* Opcode definitions.
|
||||
*/
|
||||
@@ -552,7 +560,7 @@
|
||||
VM_OC_CATCH) \
|
||||
CBC_OPCODE (CBC_EXT_RESOLVE_BASE, CBC_NO_FLAG, 0, \
|
||||
VM_OC_RESOLVE_BASE_FOR_CALL) \
|
||||
CBC_FORWARD_BRANCH (CBC_EXT_FINALLY, 0, \
|
||||
CBC_FORWARD_BRANCH (CBC_EXT_FINALLY, PARSER_FINALLY_CONTEXT_EXTRA_STACK_ALLOCATION, \
|
||||
VM_OC_FINALLY) \
|
||||
CBC_OPCODE (CBC_EXT_INITIALIZER_PUSH_PROP, CBC_NO_FLAG, 0, \
|
||||
VM_OC_INITIALIZER_PUSH_PROP | VM_OC_GET_STACK) \
|
||||
|
||||
@@ -1886,9 +1886,9 @@ parser_parse_try_statement_end (parser_context_t *context_p) /**< context */
|
||||
if (try_statement.type == parser_finally_block)
|
||||
{
|
||||
parser_flush_cbc (context_p);
|
||||
PARSER_MINUS_EQUAL_U16 (context_p->stack_depth, PARSER_TRY_CONTEXT_STACK_ALLOCATION);
|
||||
PARSER_MINUS_EQUAL_U16 (context_p->stack_depth, PARSER_FINALLY_CONTEXT_STACK_ALLOCATION);
|
||||
#ifndef JERRY_NDEBUG
|
||||
PARSER_MINUS_EQUAL_U16 (context_p->context_stack_depth, PARSER_TRY_CONTEXT_STACK_ALLOCATION);
|
||||
PARSER_MINUS_EQUAL_U16 (context_p->context_stack_depth, PARSER_FINALLY_CONTEXT_STACK_ALLOCATION);
|
||||
#endif /* !JERRY_NDEBUG */
|
||||
|
||||
parser_emit_cbc (context_p, CBC_CONTEXT_END);
|
||||
@@ -1919,11 +1919,15 @@ parser_parse_try_statement_end (parser_context_t *context_p) /**< context */
|
||||
try_statement.type = parser_finally_block;
|
||||
}
|
||||
}
|
||||
else if (try_statement.type == parser_try_block
|
||||
&& context_p->token.type != LEXER_KEYW_CATCH
|
||||
&& context_p->token.type != LEXER_KEYW_FINALLY)
|
||||
else
|
||||
{
|
||||
parser_raise_error (context_p, PARSER_ERR_CATCH_FINALLY_EXPECTED);
|
||||
JERRY_ASSERT (try_statement.type == parser_try_block);
|
||||
|
||||
if (context_p->token.type != LEXER_KEYW_CATCH
|
||||
&& context_p->token.type != LEXER_KEYW_FINALLY)
|
||||
{
|
||||
parser_raise_error (context_p, PARSER_ERR_CATCH_FINALLY_EXPECTED);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2029,6 +2033,10 @@ parser_parse_try_statement_end (parser_context_t *context_p) /**< context */
|
||||
parser_raise_error (context_p, PARSER_ERR_LEFT_BRACE_EXPECTED);
|
||||
}
|
||||
|
||||
#ifndef JERRY_NDEBUG
|
||||
PARSER_PLUS_EQUAL_U16 (context_p->context_stack_depth, PARSER_FINALLY_CONTEXT_EXTRA_STACK_ALLOCATION);
|
||||
#endif /* !JERRY_NDEBUG */
|
||||
|
||||
try_statement.type = parser_finally_block;
|
||||
parser_emit_cbc_ext_forward_branch (context_p,
|
||||
CBC_EXT_FINALLY,
|
||||
|
||||
@@ -964,6 +964,11 @@ parser_post_processing (parser_context_t *context_p) /**< context */
|
||||
PARSER_MINUS_EQUAL_U16 (context_p->context_stack_depth, PARSER_TRY_CONTEXT_STACK_ALLOCATION);
|
||||
#endif /* !JERRY_NDEBUG */
|
||||
|
||||
if (context_p->stack_limit < PARSER_FINALLY_CONTEXT_STACK_ALLOCATION)
|
||||
{
|
||||
context_p->stack_limit = PARSER_FINALLY_CONTEXT_STACK_ALLOCATION;
|
||||
}
|
||||
|
||||
parser_branch_t branch;
|
||||
|
||||
parser_stack_pop (context_p, &branch, sizeof (parser_branch_t));
|
||||
|
||||
Reference in New Issue
Block a user