use of stanhebben.zenscript.expression.Expression 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.expression.Expression 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));
}
}
use of stanhebben.zenscript.expression.Expression in project ZenScript by CraftTweaker.
the class ParsedExpressionCompare method compile.
@Override
public IPartialExpression compile(IEnvironmentMethod environment, ZenType predictedType) {
Expression cLeft = left.compile(environment, null).eval(environment);
Expression cRight = right.compile(environment, null).eval(environment);
return cLeft.getType().compare(getPosition(), environment, cLeft, cRight, type);
}
use of stanhebben.zenscript.expression.Expression in project ZenScript by CraftTweaker.
the class ParsedExpressionIndexSet method compile.
@Override
public IPartialExpression compile(IEnvironmentMethod environment, ZenType predictedType) {
// TODO: improve prediction in this expression
Expression cValue = value.compile(environment, null).eval(environment);
Expression cIndex = index.compile(environment, null).eval(environment);
Expression cSetValue = setValue.compile(environment, null).eval(environment);
return cValue.getType().trinary(getPosition(), environment, cValue, cIndex, cSetValue, OperatorType.INDEXSET);
}
use of stanhebben.zenscript.expression.Expression in project ZenScript by CraftTweaker.
the class StatementReturn method compile.
@Override
public void compile(IEnvironmentMethod environment) {
environment.getOutput().position(getPosition());
if (expression == null) {
environment.getOutput().ret();
} else {
Expression cExpression = expression.compile(environment, returnType).eval(environment);
cExpression.compile(true, environment);
Type returnType = cExpression.getType().toASMType();
environment.getOutput().returnType(returnType);
}
}
Aggregations