Search in sources :

Example 11 with Expression

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");
    }
}
Also used : Expression(stanhebben.zenscript.expression.Expression) ParsedExpression(stanhebben.zenscript.parser.expression.ParsedExpression) Label(org.objectweb.asm.Label) ZenType(stanhebben.zenscript.type.ZenType)

Aggregations

Expression (stanhebben.zenscript.expression.Expression)11 IPartialExpression (stanhebben.zenscript.expression.partial.IPartialExpression)6 ParsedExpression (stanhebben.zenscript.parser.expression.ParsedExpression)4 ZenType (stanhebben.zenscript.type.ZenType)4 Label (org.objectweb.asm.Label)2 SymbolLocal (stanhebben.zenscript.symbols.SymbolLocal)2 Annotation (java.lang.annotation.Annotation)1 Type (org.objectweb.asm.Type)1