Lines Matching full:for
8 * The parser uses a traditional top-down recursive parsing for the
10 * for the expression level. The attempt is to minimize the C stack
20 * See doc/compiler.rst for discussion on the design.
24 * - duk_regconst_t: unsigned, no marker value for "none"
34 /* for array and object literals */
228 * Parser control values for tokens. The token table is ordered by the
231 * The binding powers are for lbp() use (i.e. for use in led() context).
232 * Binding powers are positive for typing convenience, and bits at the
233 * top should be reserved for flags. Binding power step must be higher
234 * than 1 so that binding power "lbp - 1" can be used for right associative
235 * operators. Currently a step of 2 is used (which frees one more bit for
484 * Helpers for duk_compiler_func.
551 /* reset function state (prepare for pass 2) */
568 /* keep func->h_argnames; it is fixed for all passes */ in duk__reset_func_for_pass2()
596 for (i = 0; i < e_next; i++) { in duk__cleanup_varmap()
740 for (i = 0; i < consts_count; i++) {
753 for (i = 0; i < funcs_count; i++) {
774 for (i = 0; i < code_count; i++) {
787 * (Not very critical for function templates.)
823 * handling for 'length' in duk_js_push_closure(); it currently relies
853 * - Need tokenizer indices for start and end to substring
859 * For global or eval code this is straightforward. For functions
860 * created with the Function constructor we only get the source for
863 * For instance, for constructed functions (v8):
870 * Similarly for e.g. getters (v8):
905 * Source filename (or equivalent), for identifying thrown errors.
976 * for opcodes the emission helpers explicitly understand (like DUK_OP_CALL).
992 * For slots B and C the raw slot size is 9 bits but one bit is reserved for
993 * the reg/const indicator. To use the full 9-bit range for a raw value,
995 * Shuffling is only done for A, B, and C slots, not the larger BC or ABC slots.
1002 * fit into 16 bits for now, so use duk_small_uint.t.
1011 …JUMPSLOT (1 << 15) /* reserve a jumpslot after instr before target spilling, used for NEXTENUM */
1077 /* Limit checks for bytecode byte size and line number. */
1101 * function line range information for debugging, so that e.g. opening
1103 * for the line containing the brace.
1143 * Currently we check for the limits, which provides additional
1176 /* Special handling for call setup instructions. The target
1209 ins |= DUK_ENC_OP_A_B_C(0, 0, 0x100, 0); /* const flag for B */
1243 /* Special handling for CALL/NEW/MPUTOBJ/MPUTARR shuffling.
1244 * For each, slot B identifies the first register of a range
1277 ins |= DUK_ENC_OP_A_B_C(0, 0, 0, 0x100); /* const flag for C */
1310 /* Special shuffling for INITGET/INITSET, where slot C
1524 DUK_DDD(DUK_DDDPRINT("emit LDINT to reg %ld for %ld", (long) reg, (long) val));
1530 DUK_DDD(DUK_DDDPRINT("emit LDINT+LDINTX to reg %ld for %ld -> hi %ld, lo %ld",
1572 ret = duk__get_current_pc(comp_ctx); /* useful for patching jumps later */
1578 * currently needed for compiling for-in.
1658 * for functions with a lot of constants and a try-catch statement.
1702 * Peephole optimizer for finished bytecode.
1722 for (iter = 0; iter < DUK_COMPILER_PEEPHOLE_MAXITER; iter++) {
1725 for (i = 0; i < n; i++) {
1741 * This does not need to be checked for explicitly; the case
1781 /* Flags for intermediate value coercions. A flag for using a forced reg
1791 #if 0 /* enable manually for dumping */
1885 /* get const for value at valstack top */
1899 /* Explicit check for fastint downgrade. */
1903 /* Sanity workaround for handling functions with a large number of
1908 for (i = 0; i < n_check; i++) {
1912 * constant for e.g. +0 and -0.
1915 DUK_DDD(DUK_DDDPRINT("reused existing constant for %!T -> const index %ld",
1926 DUK_DDD(DUK_DDDPRINT("allocating new constant for %!T -> const index %ld",
2158 /* inline arithmetic check for constant values */
2473 * Currently, the varmap is modified for the duration of the catch
2498 * identifier is register-bound and if not, allocating a constant for the
2545 /* Duplicate (shadowing) labels are not allowed, except for the empty
2546 * labels (which are used as default labels for switch and iteration
2582 /* Labels can be used for iteration statements but also for other statements,
2583 * in particular a label can be used for a block statement. All cases of a
2620 DUK_DDD(DUK_DDDPRINT("updating (overwriting) label flags for li=%p, label_id=%ld, flags=%ld",
2676 /* currently all labels accept a break, so no explicit check for it now */
2689 * label, for which duplication is allowed, and thus there is hope of
2744 duk_reg_t temp_start; /* temp reg value for start of loop */
2781 for (;;) {
2789 for (;;) {
2842 * of registers, the emitter has special handling for this
2902 * below implement E5 Section 11.1.5, step 4 for production:
2952 duk_reg_t reg_key; /* temp reg for key literal */
2954 duk_reg_t temp_start; /* temp reg value for start of loop */
2971 /* temp object for tracking / detecting duplicate keys */
2982 for (;;) {
2990 for (;;) {
3011 * a string constant) even for numeric keys (e.g. "{1:'foo'}").
3060 /* same handling for identifiers and strings */
3081 * of registers, the emitter has special handling for this
3113 * emitter code has special handling for it (must not set the
3126 /* same handling for identifiers and strings */
3203 for (;;) {
3368 comp_ctx->curr_func.allow_in = 1; /* reset 'allow_in' for parenthesized expression */
3391 * See doc/compiler.rst for discussion on the parsing approach,
3392 * and testcases/test-dev-new.js for a bunch of documented tests.
3441 * O(depth^2) parse count for inner functions is handled by recording a
3555 DUK_DDD(DUK_DDDPRINT("typeof for an identifier name which could not be resolved "
3684 /* Specific assumptions for opcode numbering. */
3733 * for proper semantics (consider ToNumber() called for an object).
3740 reg_res); /* for side effects, result ignored */
3789 /* XXX: default priority for infix operators is duk__expr_lbp(tok) -> get it here? */
3796 /* Property access expressions are critical for correct LHS ordering,
3800 * for 'left'. However, allowing a reg-bound variable seems safe here
3833 /* Property access expressions are critical for correct LHS ordering,
3839 /* XXX: coerce to regs? it might be better for enumeration use, where the
3843 /* XXX: for simple cases like x['y'] an unnecessary LDREG is
3844 * emitted for the base value; could avoid it if we knew that
4128 * Right associativiness is reflected in the BP for recursion,
4131 * XXX: just use DUK__BP_COMMA (i.e. no need for 2-step bp levels)?
4214 /* XXX: shared handling for 'duk__expr_lhs'? */
4252 * Shared handling for logical AND and logical OR.
4257 * For logical AND truthval=1, for logical OR truthval=0.
4259 * See doc/compiler.rst for discussion on compiling logical
4267 * skip jumps to skip over the entire tail. Similarly for logical OR.
4316 * For example, it'd be generally incorrect for the expression value
4320 * avoid the extra temporary for some known-to-be-safe cases.
4322 * for example "x = y + z;", where the assignment expression value is
4338 /* A top-level assignment is e.g. "x = y;". For these it's safe
4345 * is relevant for e.g. eval code.
4364 /* E5 Section 11.13.1 (and others for other assignments), step 4. */
4385 /* For X <op>= Y we need to evaluate the pre-op
4403 * become the expression value for top level assignments
4417 /* Try to optimize X <op>= Y for reg-bound
4444 …DUK_DD(DUK_DDPRINT("rhs is side effect free, rewind and avoid unnecessary temp for reg-based <op>=…
4448 …DDPRINT("rhs evaluation emitted code, not sure if rhs is side effect free; use temp reg for LHS"));
4466 * temporary. No optimization for top level assignment.
4518 * for PUTVAR.
4521 * just use 9 bits for reg_res (and support constants) and 17
4522 * instead of 18 bits for the varname const index.
4534 /* E5 Section 11.13.1 (and others) step 4 never matches for prop writes -> no check */
4545 * (i.e., non-temp). Require temp regs for both key and base.
4547 * Don't allow a constant for the object (even for a number
4596 /* No support for lvalues returned from new or function call expressions.
4599 * evaluated before throwing a ReferenceError. For instance:
4645 /* Specific assumptions for opcode numbering. */
4694 * for proper semantics (consider ToNumber() called for an object).
4700 reg_res); /* for side effects, result ignored */
4727 /* XXX: integrate support for this into led() instead?
4760 #define DUK__EXPR_FLAG_REJECT_IN (1 << 8) /* reject 'in' token (used for for-in) */
4762 #define DUK__EXPR_FLAG_REQUIRE_INIT (1 << 10) /* require initializer for var/const */
4768 duk_ivalue tmp_alloc; /* 'res' is used for "left", and 'tmp' for "right" */
4794 /* XXX: increase ctx->expr_tokens here for every consumed token
4846 /* A bunch of helpers (for size optimization) that combine duk__expr()/duk__exprtop()
4962 * When called from 'for-in' statement parser, the initializer expression must
4972 * These allow the caller to use the variable for further assignment, e.g.
4973 * as is done in 'for-in' parsing.
5038 /* Used for minimal 'const': initializer required. */
5060 for (;;) {
5076 duk_reg_t reg_temps; /* preallocated temporaries (2) for variants 3 and 4 */
5078 DUK_DDD(DUK_DDDPRINT("start parsing a for/for-in statement"));
5080 /* Two temporaries are preallocated here for variants 3 and 4 which need
5082 * (concretely: for the enumerator object and the next enumerated value).
5091 * For/for-in main variants are:
5093 * 1. for (ExpressionNoIn_opt; Expression_opt; Expression_opt) Statement
5094 * 2. for (var VariableDeclarationNoIn; Expression_opt; Expression_opt) Statement
5095 * 3. for (LeftHandSideExpression in Expression) Statement
5096 * 4. for (var VariableDeclarationNoIn in Expression) Statement
5099 * tricky but we manage to do so for now.
5101 * See doc/compiler.rst for a detailed discussion of control flow
5105 duk__advance(comp_ctx); /* eat 'for' */
5108 …DUK_DDD(DUK_DDDPRINT("detecting for/for-in loop variant, pc=%ld", (long) duk__get_current_pc(comp_…
5131 …DUK_DDD(DUK_DDDPRINT("detected for variant 4: for (var VariableDeclarationNoIn in Expression) Stat…
5150 …DUK_DDD(DUK_DDDPRINT("detected for variant 2: for (var VariableDeclarationNoIn; Expression_opt; Ex…
5151 for (;;) {
5182 …DUK_DDD(DUK_DDDPRINT("detected for variant 3: for (LeftHandSideExpression in Expression) Statement…
5204 /* Don't allow a constant for the object (even for a number etc), as
5227 …DUK_DDD(DUK_DDDPRINT("detected for variant 1: for (ExpressionNoIn_opt; Expression_opt; Expression_…
5247 DUK_DDD(DUK_DDDPRINT("shared code for parsing variants 1 and 2"));
5317 * For variant 3 (e.g. "for (A in C) D;") the code for A (except the
5322 * For variant 4, if the variable declaration had an initializer
5323 * (e.g. "for (var A = B in C) D;") the code for the assignment
5337 …DUK_DDD(DUK_DDDPRINT("shared code for parsing variants 3 and 4, pc_v34_lhs=%ld", (long) pc_v34_lhs…
5344 * for discussion on the intricacies of control flow and side effects
5345 * for variants 3 and 4.
5352 /* The code for writing reg_temps + 0 to the left hand side has already
5360 /* Parse enumeration target and initialize enumerator. For 'null' and 'undefined',
5384 * after the jump slot (for NEXTENUM the shuffle opcodes are
5419 DUK_DDD(DUK_DDDPRINT("end parsing a for/for-in statement"));
5429 duk_regconst_t rc_switch; /* reg/const for switch value */
5430 duk_regconst_t rc_case; /* reg/const for case value */
5458 * See E5 Section 12.11. Also see doc/compiler.rst for compilation
5472 for (;;) {
5476 /* sufficient for keeping temp reg numbers in check */
5491 * Note: cannot use reg_case as a temp register (for SEQ target)
5495 duk__patch_jump_here(comp_ctx, pc_prevcase); /* chain jumps for case
5526 /* Fix for https://github.com/svaarala/duktape/issues/155:
5557 /* Note: this is correct even for default clause statements:
5561 duk__patch_jump_here(comp_ctx, pc_prevstmt); /* chain jumps for 'fall-through'
5565 for (;;) {
5737 …duk_int_t label_pc; /* points to LABEL; pc+1 = jump site for break; pc+2 = jump site for continue…
5761 * to an appropriate place (for break, going through ENDLABEL correctly).
5828 * test-bug-tailcall-thread-yield-resume.js for discussion.)
5832 * For instance, for the expression 'return 0, (function ()
5834 * bytecode is emitted for '2') but 'rc_val' indicates
5844 * be no way currently for 'rc_val' to be a temporary for an
5907 duk_reg_t reg_catch; /* reg_catch+0 and reg_catch+1 are reserved for TRYCATCH */
5918 * See the following documentation for discussion:
5938 /* The target for this LDCONST may need output shuffling, but we assume
5948 duk__emit_invalid(comp_ctx); /* jump for 'catch' case */
5949 duk__emit_invalid(comp_ctx); /* jump for 'finally' case or end (if no finally) */
5961 * register for the duration of the catch clause. We need to store
5962 * and restore the original value for the varmap entry (if any).
5966 * Note: currently register bindings must be fixed for the entire
5979 duk_int_t varmap_value; /* for storing/restoring the varmap binding for catch variable */
6016 DUK_DDD(DUK_DDDPRINT("varmap before modifying for catch clause: %!iT",
6034 * work for closures created inside the catch clause.
6076 * XXX: for now, indicate that an expensive catch binding
6108 * will replace the LDCONST with a NOP. For any actual constant (including
6186 DUK_DDD(DUK_DDDPRINT("allocated new label id for label site: %ld", (long) label_id));
6199 * Creates a label site (with an empty label) automatically for iteration
6200 * statements. Also "peels off" any label statements for explicit labels.
6231 * unset for any recursive statement parsing. It is only "revived"
6261 * Main switch for statement / source element type.
6273 * (E5 Section 12.4). Hence any non-error semantics for such
6275 * for function statements are modelled after V8, see
6291 * O(depth^2) parse count for inner functions is handled by recording a
6373 * handling for automatic semicolon handling (triggered by the
6378 * See doc/compiler.rst for details.
6401 * For/for-in statement is complicated to parse because
6402 * determining the statement type (three-part for vs. a
6403 * for-in) requires potential backtracking.
6405 * See the helper for the messy stuff.
6407 DUK_DDD(DUK_DDDPRINT("for/for-in statement"));
6443 * See the helper for details.
6505 * code for a single token expression. However, it will generate an
6508 * A similar approach is used for labels.
6535 DUK_DDD(DUK_DDDPRINT("explicit label site for label '%!O'",
6627 * for implicit return values. In other cases we need
6662 DUK_DDD(DUK_DDDPRINT("automatic semicolon terminates statement (allowed for compatibility "
6729 * intermediate values suffice for parsing of each function. Nesting is needed
6730 * for nested functions (which may occur inside expressions).
6743 for (;;) {
6776 * function; for us it essentially means that function prologue. The
6782 * to be tracked for detecting duplicates. Currently such identifiers
6798 * - The "name" binding for a named function expression. This is also
6802 /* XXX: add support for variables to not be register bound always, to
6835 * (there's no support for shuffling them now).
6842 for (i = 0; i < num_args; i++) {
6884 /* use temp_next for tracking register allocations */
6917 for (i = 0; i < num_decls; i += 2) {
6956 /* Function declaration for global/eval code is emitted even
6957 * for duplicates, because of E5 Section 10.5, step 5.e of
6958 * E5.1 (special behavior for variable bound to global object).
7019 for (i = 0; i < num_decls; i += 2) {
7045 "a no-op for variable declaration purposes"));
7116 * For instance, for Function constructor, the argument names are originally
7157 * Store lexer position for a later rewind
7192 * Gather variable/function declarations needed for second pass.
7232 * Generate actual code. In most cases the need for shuffle
7238 for (;;) {
7248 * curr_token line number info should be initialized for pass 2 before
7254 comp_ctx->curr_token.t = 0; /* this is needed for regexp mode */
7255 …comp_ctx->curr_token.start_line = 0; /* needed for line number tracking (becomes prev_token.start…
7260 * 'varmap' for second pass. Function prologue for variable declarations,
7263 * Strict mode restrictions for duplicate and invalid argument
7356 * case for iteration and conditional statements, for instance).
7408 * - the token after 'function' for function expression/declaration/statement
7409 * - the token after 'set' or 'get' for setter/getter
7419 for (;;) {
7477 * We don't check for prohibited names here, because we don't
7481 * For function expressions and declarations function name must
7482 * be an Identifer (excludes reserved words). For setter/getter
7526 * We don't check for prohibited names or for duplicate argument
7595 comp_ctx->curr_token.t = 0; /* this is needed for regexp mode */
7596 …comp_ctx->curr_token.start_line = 0; /* needed for line number tracking (becomes prev_token.start…
7764 …comp_ctx->curr_token.start_line = 0; /* needed for line number tracking (becomes prev_token.start…
7767 * Initialize function state for a zero-argument function
7856 thr->compile_ctx = &comp_stk.comp_ctx_alloc; /* for duk_error_augment.c */