- b.add(parserLine, JF, JS.N(2));
- b.add(parserLine, BREAK); // if we have, then BREAK
- b.add(parserLine, GET_PRESERVE); // get the key out of the keys array
- b.add(parserLine, LITERAL, varName);
- b.add(parserLine, PUT); // write it to this[varName]
- parseStatement(b, null); // do some stuff
- b.add(parserLine, CONTINUE); // continue if we fall out the bottom
-
- b.set(size - 1, JS.N(b.size - size + 1)); // BREAK to here
- b.add(parserLine, OLDSCOPE); // restore the scope
-
+ // Stack is now index<0, index, keys, obj, LoopMarker, ...
+
+ b.add(parserLine, JF, JS.N(5)); // if we're >= 0 jump 5 down (to NEWSCOPE)
+ // Move the LoopMarker back into place - this is sort of ugly
+ b.add(parserLine, SWAP, JS.N(3));
+ b.add(parserLine, SWAP, JS.N(3));
+ b.add(parserLine, SWAP, JS.N(3));
+ // Stack is now: LoopMarker, -1, keys, obj, ...
+ b.add(parserLine, BREAK);
+
+ b.add(parserLine, NEWSCOPE);
+ if(hadVar) {
+ b.add(parserLine, DECLARE, JSString.intern(varName));
+ b.add(parserLine, POP);
+ }
+
+ // Stack is now: index, keys, obj, LoopMarker, ...
+ b.add(parserLine, GET_PRESERVE); // key, index, keys, obj, LoopMarker, ...
+ b.add(parserLine, TOPSCOPE); // scope, key, index, keys, obj, LoopMarker, ...
+ b.add(parserLine, SWAP); // key, scope, index, keys, obj, LoopMarker, ...
+ b.add(parserLine, LITERAL, JSString.intern(varName)); // varName, key, scope, index, keys, obj, LoopMaker, ...
+ b.add(parserLine, SWAP); // key, varName, scope, index, keys, obj, LoopMarker, ...
+ b.add(parserLine, PUT); // key, scope, index, keys, obj, LoopMarker, ...
+ b.add(parserLine, POP); // scope, index, keys, obj, LoopMarker
+ b.add(parserLine, POP); // index, keys, obj, LoopMarker, ...
+ // Move the LoopMarker back into place - this is sort of ugly
+ b.add(parserLine, SWAP, JS.N(3));
+ b.add(parserLine, SWAP, JS.N(3));
+ b.add(parserLine, SWAP, JS.N(3));
+
+ parseStatement(b, null);
+
+ b.add(parserLine, OLDSCOPE);
+ b.add(parserLine, CONTINUE);
+ // jump here on break
+ b.set(size, JS.N(b.size - size));
+
+ b.add(parserLine, POP); // N
+ b.add(parserLine, POP); // KEYS
+ b.add(parserLine, POP); // OBJ
+