Skip to content

Instantly share code, notes, and snippets.

@dunst0
Last active December 11, 2015 06:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dunst0/4558536 to your computer and use it in GitHub Desktop.
Save dunst0/4558536 to your computer and use it in GitHub Desktop.
/**
* Defines how to process a GenFor-Statement.
*
* @param stmtGenFor GenFor-Statement that should be processed
* @throws Exception in case of procession error
*/
@Override
public void processStatement(StmtGenFor stmtGenFor) throws Exception {
final String F = String.format(INTERN_VARIABLE_FORMAT, "f");
final String S = String.format(INTERN_VARIABLE_FORMAT, "s");
final String VAR = String.format(INTERN_VARIABLE_FORMAT, "var");
LinkedList<String> outerNames = new LinkedList<String>();
outerNames.add(F);
outerNames.add(S);
outerNames.add(VAR);
Statement outerDef = new StmtLocalDef(outerNames, stmtGenFor.getExprList());
LinkedList<Expression> stepParams = new LinkedList<Expression>();
stepParams.add(new ExprVariable(S));
stepParams.add(new ExprVariable(VAR));
LinkedList<Expression> stepExpressions = new LinkedList<Expression>();
stepExpressions.add(new ExprCall(new ExprVariable(F), stepParams));
Statement stepDef = new StmtLocalDef(stmtGenFor.getNameList(), stepExpressions);
LinkedList<LValue> backLValue = new LinkedList<LValue>();
backLValue.add(new LValueVar(VAR));
LinkedList<Expression> backExpr = new LinkedList<Expression>();
backExpr.add(new ExprVariable(stmtGenFor.getNameList().get(0)));
Statement backupAssign = new StmtAssign(backLValue, backExpr);
LinkedList<Statement> thenStatements = new LinkedList<Statement>();
thenStatements.add(new StmtBreak());
Statement whileBreak = new StmtIf(
new ExprBinary(
new ExprVariable(VAR),
new ExprVariable(stmtGenFor.getNameList().get(0)),
BinaryOperator.Equal
),
new Block(thenStatements)
);
//while block statements
LinkedList<Statement> whileBlockStatements = new LinkedList<Statement>();
whileBlockStatements.add(stepDef);
whileBlockStatements.add(backupAssign);
whileBlockStatements.add(whileBreak);
whileBlockStatements.addAll(stmtGenFor.getCodeBlock().getStmtList());
StmtWhile stmtWhile = new StmtWhile(new ExprBool(true), new Block(whileBlockStatements));
LinkedList<Statement> doStatements = new LinkedList<Statement>();
doStatements.add(outerDef);
doStatements.add(stmtWhile);
//delegate to Do-Statement processing
processStatement(new StmtDo(new Block(doStatements)));
}
v.accept()
unTuple 1
dupl
loadString name
move 2
storeField
move 2
foreach arg = args do
arg.accept()
if arg not last then
untuple 1
end
tuple 1 + #args
call
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment