- CompiledFunctionImpl block = new JS.CompiledFunction("stdin", 0, new InputStreamReader(System.in), null);
+ Function block = new Function("stdin", 0, new InputStreamReader(System.in), null);
* bytecodes for that expression to <tt>appendTo</tt>; the
* appended bytecodes MUST grow the stack by exactly one element.
*/
* bytecodes for that expression to <tt>appendTo</tt>; the
* appended bytecodes MUST grow the stack by exactly one element.
*/
int saveParserLine = parserLine;
_startExpr(appendTo, minPrecedence);
parserLine = saveParserLine;
}
int saveParserLine = parserLine;
_startExpr(appendTo, minPrecedence);
parserLine = saveParserLine;
}
b.add(parserLine, LITERAL, new Integer(i++)); // push the index in the array to place it into
if (peekToken() == COMMA || peekToken() == RB)
b.add(parserLine, LITERAL, null); // for stuff like [1,,2,]
b.add(parserLine, LITERAL, new Integer(i++)); // push the index in the array to place it into
if (peekToken() == COMMA || peekToken() == RB)
b.add(parserLine, LITERAL, null); // for stuff like [1,,2,]
}
case INC: case DEC: { // prefix (not postfix)
startExpr(b, precedence[tok]);
}
case INC: case DEC: { // prefix (not postfix)
startExpr(b, precedence[tok]);
if (b.get(prev) == GET && b.getArg(prev) != null)
b.set(prev, LITERAL, b.getArg(prev));
else if(b.get(prev) == GET)
if (b.get(prev) == GET && b.getArg(prev) != null)
b.set(prev, LITERAL, b.getArg(prev));
else if(b.get(prev) == GET)
- CompiledFunctionImpl b2 = new JS.CompiledFunction(sourceName, parserLine, null, null);
+ Function b2 = new Function(sourceName, parserLine, null, null);
b.add(parserLine, NEWFUNCTION, b2);
// function prelude; arguments array is already on the stack
b.add(parserLine, NEWFUNCTION, b2);
// function prelude; arguments array is already on the stack
if (peekToken() == NAME) {
consume(NAME); // a named argument
String varName = string;
b2.add(parserLine, DUP); // dup the args array
if (peekToken() == NAME) {
consume(NAME); // a named argument
String varName = string;
b2.add(parserLine, DUP); // dup the args array
b2.add(parserLine, TOPSCOPE);
b2.add(parserLine, SWAP);
b2.add(parserLine, DECLARE, varName); // declare the name
b2.add(parserLine, TOPSCOPE);
b2.add(parserLine, SWAP);
b2.add(parserLine, DECLARE, varName); // declare the name
b2.add(parserLine, POP); // pop off the arguments array
b2.add(parserLine, POP); // pop off TOPSCOPE
b2.add(parserLine, POP); // pop off the arguments array
b2.add(parserLine, POP); // pop off TOPSCOPE
- if(b2.get(b2.size()-1) != RETURN) {
- b2.add(parserLine, LITERAL, null); // in case we "fall out the bottom", return NULL
- b2.add(parserLine, RETURN);
- }
+ b2.add(parserLine, LITERAL, null); // in case we "fall out the bottom", return NULL
+ b2.add(parserLine, RETURN);
* expression that modifies the assignable. This method always
* decreases the stack depth by exactly one element.
*/
* expression that modifies the assignable. This method always
* decreases the stack depth by exactly one element.
*/
int saveParserLine = parserLine;
_continueExprAfterAssignable(b,minPrecedence);
parserLine = saveParserLine;
}
int saveParserLine = parserLine;
_continueExprAfterAssignable(b,minPrecedence);
parserLine = saveParserLine;
}
if (b == null) throw new Error("got null b; this should never happen");
int tok = getToken();
if (minPrecedence != -1 && (precedence[tok] < minPrecedence || (precedence[tok] == minPrecedence && !isRightAssociative[tok])))
if (b == null) throw new Error("got null b; this should never happen");
int tok = getToken();
if (minPrecedence != -1 && (precedence[tok] < minPrecedence || (precedence[tok] == minPrecedence && !isRightAssociative[tok])))
b.add(parserLine, GET_PRESERVE);
startExpr(b, precedence[tok]);
b.add(parserLine, GET_PRESERVE);
startExpr(b, precedence[tok]);
// tok-1 is always s/^ASSIGN_// (0 is BITOR, 1 is ASSIGN_BITOR, etc)
b.add(parserLine, tok - 1, tok-1==ADD ? new Integer(2) : null);
b.add(parserLine, PUT);
b.add(parserLine, SWAP);
b.add(parserLine, POP);
// tok-1 is always s/^ASSIGN_// (0 is BITOR, 1 is ASSIGN_BITOR, etc)
b.add(parserLine, tok - 1, tok-1==ADD ? new Integer(2) : null);
b.add(parserLine, PUT);
b.add(parserLine, SWAP);
b.add(parserLine, POP);
- if(b.get(b.size()-1) == LITERAL && b.getArg(b.size()-1) != null)
- b.set(b.size()-1,GET,b.getArg(b.size()-1));
+ if(b.get(b.size-1) == LITERAL && b.getArg(b.size-1) != null)
+ b.set(b.size-1,GET,b.getArg(b.size-1));
int saveParserLine = parserLine;
_continueExpr(b, minPrecedence);
parserLine = saveParserLine;
}
int saveParserLine = parserLine;
_continueExpr(b, minPrecedence);
parserLine = saveParserLine;
}
startExpr(b, precedence[tok]); // otherwise check the second value
b.add(parserLine, JMP, new Integer(2)); // leave the second value on the stack and jump to the end
b.add(parserLine, LITERAL, tok == AND ?
new Boolean(false) : new Boolean(true)); // target of the short-circuit jump is here
startExpr(b, precedence[tok]); // otherwise check the second value
b.add(parserLine, JMP, new Integer(2)); // leave the second value on the stack and jump to the end
b.add(parserLine, LITERAL, tok == AND ?
new Boolean(false) : new Boolean(true)); // target of the short-circuit jump is here
b.add(parserLine, LITERAL, string);
continueExprAfterAssignable(b,minPrecedence);
break;
b.add(parserLine, LITERAL, string);
continueExprAfterAssignable(b,minPrecedence);
break;
startExpr(b, minPrecedence); // write the if-true expression
b.add(parserLine, JMP, new Integer(0)); // if true, jump *over* the if-false expression
startExpr(b, minPrecedence); // write the if-true expression
b.add(parserLine, JMP, new Integer(0)); // if true, jump *over* the if-false expression
- void parseBlock(CompiledFunctionImpl b) throws IOException { parseBlock(b, null); }
- void parseBlock(CompiledFunctionImpl b, String label) throws IOException {
+ void parseBlock(Function b) throws IOException { parseBlock(b, null); }
+ void parseBlock(Function b, String label) throws IOException {
if (peekToken() == -1) return;
else if (peekToken() != LC) parseStatement(b, null);
else {
if (peekToken() == -1) return;
else if (peekToken() != LC) parseStatement(b, null);
else {
int saveParserLine = parserLine;
_parseStatement(b, label);
parserLine = saveParserLine;
}
int saveParserLine = parserLine;
_parseStatement(b, label);
parserLine = saveParserLine;
}
consume(RP);
b.add(parserLine, JF, new Integer(0)); // if false, jump to the else-block
consume(RP);
b.add(parserLine, JF, new Integer(0)); // if false, jump to the else-block
parseStatement(b, null);
if (peekToken() == ELSE) {
consume(ELSE);
b.add(parserLine, JMP, new Integer(0)); // if we took the true-block, jump over the else-block
parseStatement(b, null);
if (peekToken() == ELSE) {
consume(ELSE);
b.add(parserLine, JMP, new Integer(0)); // if we took the true-block, jump over the else-block
- b.set(size - 1, new Integer(b.size() - size + 1)); // regardless of which branch we took, b[size] needs to point here
+ b.set(size - 1, new Integer(b.size - size + 1)); // regardless of which branch we took, b[size] needs to point here
b.add(parserLine, POP); // discard the first-iteration indicator
startExpr(b, -1);
b.add(parserLine, JT, new Integer(2)); // if the while() clause is true, jump over the BREAK
b.add(parserLine, POP); // discard the first-iteration indicator
startExpr(b, -1);
b.add(parserLine, JT, new Integer(2)); // if the while() clause is true, jump over the BREAK
consume(COLON);
b.add(parserLine, EQ); // check if we should do this case-block
b.add(parserLine, JF, new Integer(0)); // if not, jump to the next one
consume(COLON);
b.add(parserLine, EQ); // check if we should do this case-block
b.add(parserLine, JF, new Integer(0)); // if not, jump to the next one
// parse the expression to be TRYed
parseStatement(b, null);
// pop the try marker. this is pushed when the TRY bytecode is executed
b.add(parserLine, POP);
// jump forward to the end of the catch block, start of the finally block
b.add(parserLine, JMP);
// parse the expression to be TRYed
parseStatement(b, null);
// pop the try marker. this is pushed when the TRY bytecode is executed
b.add(parserLine, POP);
// jump forward to the end of the catch block, start of the finally block
b.add(parserLine, JMP);
if (peekToken() != CATCH && peekToken() != FINALLY)
throw pe("try without catch or finally");
int catchJMPDistance = -1;
if (peekToken() == CATCH) {
if (peekToken() != CATCH && peekToken() != FINALLY)
throw pe("try without catch or finally");
int catchJMPDistance = -1;
if (peekToken() == CATCH) {
int finallyJMPDistance = -1;
if (peekToken() == FINALLY) {
b.add(parserLine, LITERAL, null); // null FinallyData
int finallyJMPDistance = -1;
if (peekToken() == FINALLY) {
b.add(parserLine, LITERAL, null); // null FinallyData
b.add(parserLine, LOOP); // we actually only add this to ensure that BREAK works
b.add(parserLine, POP); // discard the first-iteration indicator
b.add(parserLine, LOOP); // we actually only add this to ensure that BREAK works
b.add(parserLine, POP); // discard the first-iteration indicator
parseStatement(b, null); // do some stuff
b.add(parserLine, CONTINUE); // continue if we fall out the bottom
parseStatement(b, null); // do some stuff
b.add(parserLine, CONTINUE); // continue if we fall out the bottom
b.add(parserLine, NEWSCOPE); // grab a fresh scope
parseStatement(b, null); // initializer
b.add(parserLine, NEWSCOPE); // grab a fresh scope
parseStatement(b, null); // initializer
- CompiledFunctionImpl e2 = // we need to put the incrementor before the test
- new JS.CompiledFunction(sourceName, parserLine, null, null); // so we save the test here
+ Function e2 = // we need to put the incrementor before the test
+ new Function(sourceName, parserLine, null, null); // so we save the test here
b.add(parserLine, JT, new Integer(0)); // if we're on the first iteration, jump over the incrementor
b.add(parserLine, JT, new Integer(0)); // if we're on the first iteration, jump over the incrementor
b.add(parserLine, BREAK);
parseStatement(b, null);
b.add(parserLine, CONTINUE); // if we fall out the bottom, CONTINUE
b.add(parserLine, BREAK);
parseStatement(b, null);
b.add(parserLine, CONTINUE); // if we fall out the bottom, CONTINUE