Parser optimizations.
- parser is now non-recursive (i.e. parse function is not called recursively in any case);
- byte-code is now more compact:
- constants are now not immediately dumped upon occurence, but later - where necessary;
- assignments are combined with unary / binary operations;
- binary operations are encoded more compactly in many cases;
- byte-code arrays are now allocated separately for each scope (so, GC of the scopes now becomes possible);
- byte-code is dumped directly into corresponding byte-code arrays:
- linked lists of op_meta are not now used for main code of a scope.
JerryScript-DCO-1.0-Signed-off-by: Ruben Ayrapetyan r.ayrapetyan@samsung.com
JerryScript-DCO-1.0-Signed-off-by: Andrey Shitov a.shitov@samsung.com
This commit is contained in:
committed by
Ruben Ayrapetyan
parent
b1de93abd6
commit
50d124bfc3
@@ -19,7 +19,6 @@
|
||||
#include "linked-list.h"
|
||||
#include "lexer.h"
|
||||
#include "ecma-globals.h"
|
||||
#include "hash-table.h"
|
||||
#include "opcodes.h"
|
||||
#include "lit-id-hash-table.h"
|
||||
#include "lit-literal.h"
|
||||
@@ -39,15 +38,13 @@ typedef struct
|
||||
|
||||
typedef struct tree_header
|
||||
{
|
||||
struct tree_header *parent;
|
||||
linked_list children;
|
||||
uint8_t children_num;
|
||||
} tree_header;
|
||||
|
||||
/**
|
||||
* Scope type
|
||||
*/
|
||||
typedef enum
|
||||
typedef enum __attr_packed___
|
||||
{
|
||||
SCOPE_TYPE_GLOBAL, /**< the Global code scope */
|
||||
SCOPE_TYPE_FUNCTION, /**< a function code scope */
|
||||
@@ -59,16 +56,27 @@ typedef enum
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
tree_header t; /**< header */
|
||||
linked_list instrs; /**< instructions */
|
||||
mem_cpointer_t next_scope_cp; /**< next scope with same parent */
|
||||
|
||||
mem_cpointer_t bc_header_cp; /**< pointer to corresponding byte-code header
|
||||
* (after bc_dump_single_scope) */
|
||||
uint16_t child_scopes_num; /**< number of child scopes */
|
||||
uint16_t child_scopes_processed_num; /**< number of child scopes, for which
|
||||
* byte-code headers were already constructed */
|
||||
|
||||
uint16_t max_uniq_literals_num; /**< upper estimate number of entries
|
||||
* in idx-literal hash table */
|
||||
|
||||
vm_instr_counter_t instrs_count; /**< count of instructions */
|
||||
|
||||
linked_list var_decls; /**< instructions for variable declarations */
|
||||
|
||||
scope_type_t type : 2; /**< scope type */
|
||||
bool strict_mode: 1; /**< flag, indicating that scope's code should be executed in strict mode */
|
||||
bool ref_arguments: 1; /**< flag, indicating that "arguments" variable is used inside the scope
|
||||
* (not depends on subscopes) */
|
||||
bool ref_eval: 1; /**< flag, indicating that "eval" is used inside the scope
|
||||
* (not depends on subscopes) */
|
||||
* (not depends on subscopes) */
|
||||
bool contains_with: 1; /**< flag, indicationg whether 'with' statement is contained in the scope
|
||||
* (not depends on subscopes) */
|
||||
bool contains_try: 1; /**< flag, indicationg whether 'try' statement is contained in the scope
|
||||
@@ -76,25 +84,23 @@ typedef struct
|
||||
bool contains_delete: 1; /**< flag, indicationg whether 'delete' operator is contained in the scope
|
||||
* (not depends on subscopes) */
|
||||
bool contains_functions: 1; /**< flag, indicating that the scope contains a function declaration / expression */
|
||||
bool is_vars_and_args_to_regs_possible : 1; /**< the function's variables / arguments can be moved to registers */
|
||||
} scopes_tree_int;
|
||||
|
||||
typedef scopes_tree_int *scopes_tree;
|
||||
|
||||
scopes_tree scopes_tree_init (scopes_tree, scope_type_t);
|
||||
void scopes_tree_free (scopes_tree);
|
||||
void scopes_tree_init (void);
|
||||
void scopes_tree_finalize (void);
|
||||
scopes_tree scopes_tree_new_scope (scopes_tree, scope_type_t);
|
||||
void scopes_tree_free_scope (scopes_tree);
|
||||
void scopes_tree_finish_build (void);
|
||||
size_t scopes_tree_child_scopes_num (scopes_tree);
|
||||
vm_instr_counter_t scopes_tree_instrs_num (scopes_tree);
|
||||
vm_instr_counter_t scopes_tree_var_decls_num (scopes_tree);
|
||||
void scopes_tree_add_op_meta (scopes_tree, op_meta);
|
||||
void scopes_tree_add_var_decl (scopes_tree, op_meta);
|
||||
void scopes_tree_set_op_meta (scopes_tree, vm_instr_counter_t, op_meta);
|
||||
void scopes_tree_set_instrs_num (scopes_tree, vm_instr_counter_t);
|
||||
op_meta scopes_tree_op_meta (scopes_tree, vm_instr_counter_t);
|
||||
op_meta scopes_tree_var_decl (scopes_tree, vm_instr_counter_t);
|
||||
void scopes_tree_remove_op_meta (scopes_tree tree, vm_instr_counter_t oc);
|
||||
size_t scopes_tree_count_literals_in_blocks (scopes_tree);
|
||||
vm_instr_counter_t scopes_tree_count_instructions (scopes_tree);
|
||||
bool scopes_tree_variable_declaration_exists (scopes_tree, lit_cpointer_t);
|
||||
vm_instr_t *scopes_tree_raw_data (scopes_tree, uint8_t *, size_t, lit_id_hash_table *);
|
||||
void scopes_tree_dump_var_decls (scopes_tree, lit_cpointer_t *);
|
||||
void scopes_tree_set_strict_mode (scopes_tree, bool);
|
||||
void scopes_tree_set_arguments_used (scopes_tree);
|
||||
void scopes_tree_set_eval_used (scopes_tree);
|
||||
@@ -103,5 +109,4 @@ void scopes_tree_set_contains_try (scopes_tree);
|
||||
void scopes_tree_set_contains_delete (scopes_tree);
|
||||
void scopes_tree_set_contains_functions (scopes_tree);
|
||||
bool scopes_tree_strict_mode (scopes_tree);
|
||||
|
||||
#endif /* SCOPES_TREE_H */
|
||||
|
||||
Reference in New Issue
Block a user