use of stanhebben.zenscript.expression.Expression in project ZenScript by CraftTweaker.
the class StatementIf method compile.
@Override
public void compile(IEnvironmentMethod environment) {
environment.getOutput().position(getPosition());
Expression cCondition = condition.compile(environment, ZenType.BOOL).eval(environment).cast(getPosition(), environment, ZenType.BOOL);
ZenType expressionType = cCondition.getType();
if (expressionType.canCastImplicit(ZenType.BOOL, environment)) {
Label labelEnd = new Label();
Label labelElse = onElse == null ? labelEnd : new Label();
cCondition.compileIf(labelElse, environment);
onThen.compile(environment);
MethodOutput methodOutput = environment.getOutput();
if (onElse != null) {
methodOutput.goTo(labelEnd);
methodOutput.label(labelElse);
onElse.compile(environment);
}
methodOutput.label(labelEnd);
} else {
environment.error(getPosition(), "condition is not a boolean");
}
}
Aggregations