mirror of
https://github.com/GTNewHorizons/CraftTweaker.git
synced 2026-11-18 03:15:14 +00:00
- Added interface to game, client and server - Added transformations - Made ingredient conditions more practical to use, no longer requires imports - Started implementation of event handling - Moved commands and logic to the common API code - Added common interface to MineTweaker recipes - Added string methods - Moved the logger from static value to static getter - Fixed crashes on dedicated servers - Fixed bracket resolution for <id:meta> values in 1.6.4 - Fixed scripts not being sent to multiplayer clients in 1.6.4
62 lines
2.0 KiB
Java
62 lines
2.0 KiB
Java
package stanhebben.zenscript.statements;
|
|
|
|
import org.objectweb.asm.Label;
|
|
import stanhebben.zenscript.compiler.EnvironmentScope;
|
|
import stanhebben.zenscript.compiler.IEnvironmentMethod;
|
|
import stanhebben.zenscript.expression.Expression;
|
|
import stanhebben.zenscript.parser.expression.ParsedExpression;
|
|
import stanhebben.zenscript.type.IZenIterator;
|
|
import stanhebben.zenscript.type.ZenType;
|
|
import stanhebben.zenscript.symbols.SymbolLocal;
|
|
import stanhebben.zenscript.util.MethodOutput;
|
|
import stanhebben.zenscript.util.ZenPosition;
|
|
|
|
public class StatementForeach extends Statement {
|
|
private final String[] varnames;
|
|
private final ParsedExpression list;
|
|
private final Statement body;
|
|
|
|
public StatementForeach(ZenPosition position, String[] varnames, ParsedExpression list, Statement body) {
|
|
super(position);
|
|
|
|
this.varnames = varnames;
|
|
this.list = list;
|
|
this.body = body;
|
|
}
|
|
|
|
@Override
|
|
public void compile(IEnvironmentMethod environment) {
|
|
Expression cList = list.compile(environment).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);
|
|
localVariables[i] = local.getLocal(localVar);
|
|
}
|
|
|
|
cList.compile(true, environment);
|
|
iterator.compileStart(localVariables);
|
|
|
|
Label repeat = new Label();
|
|
Label exit = new Label();
|
|
|
|
methodOutput.label(repeat);
|
|
iterator.compilePreIterate(localVariables, exit);
|
|
body.compile(local);
|
|
iterator.compilePostIterate(localVariables, exit, repeat);
|
|
methodOutput.label(exit);
|
|
}
|
|
}
|