66#define DUK_JS_COMPILER_H_INCLUDED
77
88/* ECMAScript compiler limits */
9- #define DUK_COMPILER_TOKEN_LIMIT 100000000L /* 1e8: protects against deeply nested inner functions */
9+ #define DUK_COMPILER_TOKEN_LIMIT 100000000L /* 1e8: protects against deeply nested inner functions */
1010
1111/* maximum loopcount for peephole optimization */
12- #define DUK_COMPILER_PEEPHOLE_MAXITER 3
12+ #define DUK_COMPILER_PEEPHOLE_MAXITER 3
1313
1414/* maximum bytecode length in instructions */
15- #define DUK_COMPILER_MAX_BYTECODE_LENGTH (256L * 1024L * 1024L) /* 1 GB */
15+ #define DUK_COMPILER_MAX_BYTECODE_LENGTH (256L * 1024L * 1024L) /* 1 GB */
1616
1717/*
1818 * Compiler intermediate values
2222 * either a left-hand-side or right-hand-side role (e.g. object property).
2323 */
2424
25- #define DUK_IVAL_NONE 0 /* no value */
26- #define DUK_IVAL_PLAIN 1 /* register, constant, or value */
27- #define DUK_IVAL_ARITH 2 /* binary arithmetic; DUK_OP_ADD, DUK_OP_EQ, other binary ops */
28- #define DUK_IVAL_PROP 3 /* property access */
29- #define DUK_IVAL_VAR 4 /* variable access */
25+ #define DUK_IVAL_NONE 0 /* no value */
26+ #define DUK_IVAL_PLAIN 1 /* register, constant, or value */
27+ #define DUK_IVAL_ARITH 2 /* binary arithmetic; DUK_OP_ADD, DUK_OP_EQ, other binary ops */
28+ #define DUK_IVAL_PROP 3 /* property access */
29+ #define DUK_IVAL_VAR 4 /* variable access */
3030
31- #define DUK_ISPEC_NONE 0 /* no value */
32- #define DUK_ISPEC_VALUE 1 /* value resides in 'valstack_idx' */
33- #define DUK_ISPEC_REGCONST 2 /* value resides in a register or constant */
31+ #define DUK_ISPEC_NONE 0 /* no value */
32+ #define DUK_ISPEC_VALUE 1 /* value resides in 'valstack_idx' */
33+ #define DUK_ISPEC_REGCONST 2 /* value resides in a register or constant */
3434
3535/* Bit mask which indicates that a regconst is a constant instead of a register.
3636 * Chosen so that when a regconst is cast to duk_int32_t, all consts are
3737 * negative values.
3838 */
39- #define DUK_REGCONST_CONST_MARKER DUK_INT32_MIN /* = -0x80000000 */
39+ #define DUK_REGCONST_CONST_MARKER DUK_INT32_MIN /* = -0x80000000 */
4040
4141/* Type to represent a reg/const reference during compilation, with <0
4242 * indicating a constant. Some call sites also use -1 to indicate 'none'.
4343 */
4444typedef duk_int32_t duk_regconst_t ;
4545
4646typedef struct {
47- duk_small_uint_t t ; /* DUK_ISPEC_XXX */
47+ duk_small_uint_t t ; /* DUK_ISPEC_XXX */
4848 duk_regconst_t regconst ;
49- duk_idx_t valstack_idx ; /* always set; points to a reserved valstack slot */
49+ duk_idx_t valstack_idx ; /* always set; points to a reserved valstack slot */
5050} duk_ispec ;
5151
5252typedef struct {
@@ -58,8 +58,8 @@ typedef struct {
5858 */
5959
6060 /* XXX: can be optimized for smaller footprint esp. on 32-bit environments */
61- duk_small_uint_t t ; /* DUK_IVAL_XXX */
62- duk_small_uint_t op ; /* bytecode opcode for binary ops */
61+ duk_small_uint_t t ; /* DUK_IVAL_XXX */
62+ duk_small_uint_t op ; /* bytecode opcode for binary ops */
6363 duk_ispec x1 ;
6464 duk_ispec x2 ;
6565} duk_ivalue ;
@@ -81,22 +81,22 @@ struct duk_compiler_instr {
8181 * Compiler state
8282 */
8383
84- #define DUK_LABEL_FLAG_ALLOW_BREAK (1U << 0)
85- #define DUK_LABEL_FLAG_ALLOW_CONTINUE (1U << 1)
84+ #define DUK_LABEL_FLAG_ALLOW_BREAK (1U << 0)
85+ #define DUK_LABEL_FLAG_ALLOW_CONTINUE (1U << 1)
8686
87- #define DUK_DECL_TYPE_VAR 0
88- #define DUK_DECL_TYPE_FUNC 1
87+ #define DUK_DECL_TYPE_VAR 0
88+ #define DUK_DECL_TYPE_FUNC 1
8989
9090/* XXX: optimize to 16 bytes */
9191typedef struct {
9292 duk_small_uint_t flags ;
93- duk_int_t label_id ; /* numeric label_id (-1 reserved as marker) */
94- duk_hstring * h_label ; /* borrowed label name */
95- duk_int_t catch_depth ; /* catch depth at point of definition */
96- duk_int_t pc_label ; /* pc of label statement:
97- * pc+1: break jump site
98- * pc+2: continue jump site
99- */
93+ duk_int_t label_id ; /* numeric label_id (-1 reserved as marker) */
94+ duk_hstring * h_label ; /* borrowed label name */
95+ duk_int_t catch_depth ; /* catch depth at point of definition */
96+ duk_int_t pc_label ; /* pc of label statement:
97+ * pc+1: break jump site
98+ * pc+2: continue jump site
99+ */
100100
101101 /* Fast jumps (which avoid longjmp) jump directly to the jump sites
102102 * which are always known even while the iteration/switch statement
@@ -112,22 +112,22 @@ struct duk_compiler_func {
112112 * platforms (e.g. if int is 32 bits and pointers are 64 bits).
113113 */
114114
115- duk_bufwriter_ctx bw_code ; /* bufwriter for code */
115+ duk_bufwriter_ctx bw_code ; /* bufwriter for code */
116116
117- duk_hstring * h_name ; /* function name (borrowed reference), ends up in _name */
117+ duk_hstring * h_name ; /* function name (borrowed reference), ends up in _name */
118118 /* h_code: held in bw_code */
119- duk_hobject * h_consts ; /* array */
120- duk_hobject * h_funcs ; /* array of function templates: [func1, offset1, line1, func2, offset2, line2]
121- * offset/line points to closing brace to allow skipping on pass 2
122- */
123- duk_hobject * h_decls ; /* array of declarations: [ name1, val1, name2, val2, ... ]
124- * valN = (typeN) | (fnum << 8), where fnum is inner func number (0 for vars)
125- * record function and variable declarations in pass 1
126- */
127- duk_hobject * h_labelnames ; /* array of active label names */
128- duk_hbuffer_dynamic * h_labelinfos ; /* C array of duk_labelinfo */
129- duk_hobject * h_argnames ; /* array of formal argument names (-> _Formals) */
130- duk_hobject * h_varmap ; /* variable map for pass 2 (identifier -> register number or null (unmapped)) */
119+ duk_hobject * h_consts ; /* array */
120+ duk_hobject * h_funcs ; /* array of function templates: [func1, offset1, line1, func2, offset2, line2]
121+ * offset/line points to closing brace to allow skipping on pass 2
122+ */
123+ duk_hobject * h_decls ; /* array of declarations: [ name1, val1, name2, val2, ... ]
124+ * valN = (typeN) | (fnum << 8), where fnum is inner func number (0 for vars)
125+ * record function and variable declarations in pass 1
126+ */
127+ duk_hobject * h_labelnames ; /* array of active label names */
128+ duk_hbuffer_dynamic * h_labelinfos ; /* C array of duk_labelinfo */
129+ duk_hobject * h_argnames ; /* array of formal argument names (-> _Formals) */
130+ duk_hobject * h_varmap ; /* variable map for pass 2 (identifier -> register number or null (unmapped)) */
131131
132132 /* Value stack indices for tracking objects. */
133133 /* code_idx: not needed */
@@ -140,9 +140,9 @@ struct duk_compiler_func {
140140 duk_idx_t varmap_idx ;
141141
142142 /* Temp reg handling. */
143- duk_regconst_t temp_first ; /* first register that is a temporary (below: variables) */
144- duk_regconst_t temp_next ; /* next temporary register to allocate */
145- duk_regconst_t temp_max ; /* highest value of temp_reg (temp_max - 1 is highest used reg) */
143+ duk_regconst_t temp_first ; /* first register that is a temporary (below: variables) */
144+ duk_regconst_t temp_next ; /* next temporary register to allocate */
145+ duk_regconst_t temp_max ; /* highest value of temp_reg (temp_max - 1 is highest used reg) */
146146
147147 /* Shuffle registers if large number of regs/consts. */
148148 duk_regconst_t shuffle1 ;
@@ -152,60 +152,62 @@ struct duk_compiler_func {
152152 /* Stats for current expression being parsed. */
153153 duk_int_t nud_count ;
154154 duk_int_t led_count ;
155- duk_int_t paren_level ; /* parenthesis count, 0 = top level */
156- duk_bool_t expr_lhs ; /* expression is left-hand-side compatible */
157- duk_bool_t allow_in ; /* current paren level allows 'in' token */
155+ duk_int_t paren_level ; /* parenthesis count, 0 = top level */
156+ duk_bool_t expr_lhs ; /* expression is left-hand-side compatible */
157+ duk_bool_t allow_in ; /* current paren level allows 'in' token */
158158
159159 /* Misc. */
160- duk_int_t stmt_next ; /* statement id allocation (running counter) */
161- duk_int_t label_next ; /* label id allocation (running counter) */
162- duk_int_t catch_depth ; /* catch stack depth */
163- duk_int_t with_depth ; /* with stack depth (affects identifier lookups) */
164- duk_int_t fnum_next ; /* inner function numbering */
165- duk_int_t num_formals ; /* number of formal arguments */
166- duk_regconst_t reg_stmt_value ; /* register for writing value of 'non-empty' statements (global or eval code), -1 is marker */
160+ duk_int_t stmt_next ; /* statement id allocation (running counter) */
161+ duk_int_t label_next ; /* label id allocation (running counter) */
162+ duk_int_t catch_depth ; /* catch stack depth */
163+ duk_int_t with_depth ; /* with stack depth (affects identifier lookups) */
164+ duk_int_t fnum_next ; /* inner function numbering */
165+ duk_int_t num_formals ; /* number of formal arguments */
166+ duk_regconst_t
167+ reg_stmt_value ; /* register for writing value of 'non-empty' statements (global or eval code), -1 is marker */
167168#if defined(DUK_USE_DEBUGGER_SUPPORT )
168- duk_int_t min_line ; /* XXX: typing (duk_hcompfunc has duk_uint32_t) */
169+ duk_int_t min_line ; /* XXX: typing (duk_hcompfunc has duk_uint32_t) */
169170 duk_int_t max_line ;
170171#endif
171172
172173 /* Status booleans. */
173- duk_uint8_t is_function ; /* is an actual function (not global/eval code) */
174- duk_uint8_t is_eval ; /* is eval code */
175- duk_uint8_t is_global ; /* is global code */
176- duk_uint8_t is_namebinding ; /* needs a name binding */
177- duk_uint8_t is_constructable ; /* result is constructable */
178- duk_uint8_t is_setget ; /* is a setter/getter */
179- duk_uint8_t is_strict ; /* function is strict */
180- duk_uint8_t is_notail ; /* function must not be tail called */
181- duk_uint8_t in_directive_prologue ; /* parsing in "directive prologue", recognize directives */
182- duk_uint8_t in_scanning ; /* parsing in "scanning" phase (first pass) */
183- duk_uint8_t may_direct_eval ; /* function may call direct eval */
184- duk_uint8_t id_access_arguments ; /* function refers to 'arguments' identifier */
185- duk_uint8_t id_access_slow ; /* function makes one or more slow path accesses that won't match own static variables */
186- duk_uint8_t id_access_slow_own ; /* function makes one or more slow path accesses that may match own static variables */
187- duk_uint8_t is_arguments_shadowed ; /* argument/function declaration shadows 'arguments' */
188- duk_uint8_t needs_shuffle ; /* function needs shuffle registers */
189- duk_uint8_t reject_regexp_in_adv ; /* reject RegExp literal on next advance() call; needed for handling IdentifierName productions */
190- duk_uint8_t allow_regexp_in_adv ; /* allow RegExp literal on next advance() call */
174+ duk_uint8_t is_function ; /* is an actual function (not global/eval code) */
175+ duk_uint8_t is_eval ; /* is eval code */
176+ duk_uint8_t is_global ; /* is global code */
177+ duk_uint8_t is_namebinding ; /* needs a name binding */
178+ duk_uint8_t is_constructable ; /* result is constructable */
179+ duk_uint8_t is_setget ; /* is a setter/getter */
180+ duk_uint8_t is_strict ; /* function is strict */
181+ duk_uint8_t is_notail ; /* function must not be tail called */
182+ duk_uint8_t in_directive_prologue ; /* parsing in "directive prologue", recognize directives */
183+ duk_uint8_t in_scanning ; /* parsing in "scanning" phase (first pass) */
184+ duk_uint8_t may_direct_eval ; /* function may call direct eval */
185+ duk_uint8_t id_access_arguments ; /* function refers to 'arguments' identifier */
186+ duk_uint8_t id_access_slow ; /* function makes one or more slow path accesses that won't match own static variables */
187+ duk_uint8_t id_access_slow_own ; /* function makes one or more slow path accesses that may match own static variables */
188+ duk_uint8_t is_arguments_shadowed ; /* argument/function declaration shadows 'arguments' */
189+ duk_uint8_t needs_shuffle ; /* function needs shuffle registers */
190+ duk_uint8_t
191+ reject_regexp_in_adv ; /* reject RegExp literal on next advance() call; needed for handling IdentifierName productions */
192+ duk_uint8_t allow_regexp_in_adv ; /* allow RegExp literal on next advance() call */
191193};
192194
193195struct duk_compiler_ctx {
194196 duk_hthread * thr ;
195197
196198 /* filename being compiled (ends up in functions' '_filename' property) */
197- duk_hstring * h_filename ; /* borrowed reference */
199+ duk_hstring * h_filename ; /* borrowed reference */
198200
199201 /* lexing (tokenization) state (contains two valstack slot indices) */
200202 duk_lexer_ctx lex ;
201203
202204 /* current and previous token for parsing */
203205 duk_token prev_token ;
204206 duk_token curr_token ;
205- duk_idx_t tok11_idx ; /* curr_token slot1 (matches 'lex' slot1_idx) */
206- duk_idx_t tok12_idx ; /* curr_token slot2 (matches 'lex' slot2_idx) */
207- duk_idx_t tok21_idx ; /* prev_token slot1 */
208- duk_idx_t tok22_idx ; /* prev_token slot2 */
207+ duk_idx_t tok11_idx ; /* curr_token slot1 (matches 'lex' slot1_idx) */
208+ duk_idx_t tok12_idx ; /* curr_token slot2 (matches 'lex' slot2_idx) */
209+ duk_idx_t tok21_idx ; /* prev_token slot1 */
210+ duk_idx_t tok22_idx ; /* prev_token slot2 */
209211
210212 /* recursion limit */
211213 duk_int_t recursion_depth ;
@@ -222,6 +224,9 @@ struct duk_compiler_ctx {
222224 * Prototypes
223225 */
224226
225- DUK_INTERNAL_DECL void duk_js_compile (duk_hthread * thr , const duk_uint8_t * src_buffer , duk_size_t src_length , duk_small_uint_t flags );
227+ DUK_INTERNAL_DECL void duk_js_compile (duk_hthread * thr ,
228+ const duk_uint8_t * src_buffer ,
229+ duk_size_t src_length ,
230+ duk_small_uint_t flags );
226231
227- #endif /* DUK_JS_COMPILER_H_INCLUDED */
232+ #endif /* DUK_JS_COMPILER_H_INCLUDED */
0 commit comments