use of stanhebben.zenscript.symbols.SymbolLocal in project ZenScript by CraftTweaker.
the class StatementForeach method compile.
@Override
public void compile(IEnvironmentMethod environment) {
Expression cList = list.compile(environment, ZenType.ANYARRAY).eval(environment);
ZenType listType = cList.getType();
IZenIterator iterator = listType.makeIterator(varnames.length, environment);
if (iterator == null) {
environment.error(getPosition(), "No iterator with " + varnames.length + " variables");
return;
}
MethodOutput methodOutput = environment.getOutput();
environment.getOutput().position(getPosition());
IEnvironmentMethod local = new EnvironmentScope(environment);
int[] localVariables = new int[varnames.length];
for (int i = 0; i < localVariables.length; i++) {
SymbolLocal localVar = new SymbolLocal(iterator.getType(i), true);
local.putValue(varnames[i], localVar, getPosition());
localVariables[i] = local.getLocal(localVar);
}
cList.compile(true, environment);
iterator.compileStart(localVariables);
Label repeat = new Label();
Label exit = new Label();
// Allows for break statements, sets the exit label!
for (Statement statement : body.getSubStatements()) {
if (statement instanceof StatementBreak)
((StatementBreak) statement).setExit(exit);
}
methodOutput.label(repeat);
iterator.compilePreIterate(localVariables, exit);
body.compile(local);
iterator.compilePostIterate(localVariables, exit, repeat);
methodOutput.label(exit);
iterator.compileEnd();
}
use of stanhebben.zenscript.symbols.SymbolLocal in project ZenScript by CraftTweaker.
the class StatementVar method compile.
@Override
public void compile(IEnvironmentMethod environment) {
environment.getOutput().position(getPosition());
Expression cInitializer = initializer == null ? null : initializer.compile(environment, type).eval(environment);
ZenType cType = type == null ? (cInitializer == null ? ZenTypeAny.INSTANCE : cInitializer.getType()) : type;
SymbolLocal symbol = new SymbolLocal(cType, isFinal);
environment.putValue(name, symbol, getPosition());
if (cInitializer != null) {
cInitializer.compile(true, environment);
environment.getOutput().store(symbol.getType().toASMType(), environment.getLocal(symbol));
}
}
Aggregations