Search in sources :

Example 1 with MethodOutput

use of stanhebben.zenscript.util.MethodOutput in project ZenScript by CraftTweaker.

the class CastingRuleArrayArray method compile.

@Override
public void compile(IEnvironmentMethod method) {
    MethodOutput output = method.getOutput();
    Type fromType = from.getBaseType().toASMType();
    Type toType = to.getBaseType().toASMType();
    int result = output.local(to.toASMType());
    output.dup();
    output.arrayLength();
    output.newArray(toType);
    output.storeObject(result);
    output.iConst0();
    Label lbl = new Label();
    output.label(lbl);
    // stack: original index
    output.dupX1();
    output.dupX1();
    output.arrayLoad(fromType);
    // stack: original index value
    if (base != null)
        base.compile(method);
    output.loadObject(result);
    output.dupX2();
    output.dupX2();
    output.arrayStore(toType);
    output.pop();
    // stack: original index
    output.iConst1();
    output.iAdd();
    output.dupX1();
    output.arrayLength();
    output.ifICmpGE(lbl);
    output.pop();
    output.pop();
    output.loadObject(result);
}
Also used : MethodOutput(stanhebben.zenscript.util.MethodOutput)

Example 2 with MethodOutput

use of stanhebben.zenscript.util.MethodOutput in project ZenScript by CraftTweaker.

the class CastingRuleNullableVirtualMethod method compile.

@Override
public void compile(IEnvironmentMethod method) {
    MethodOutput output = method.getOutput();
    Label lblNotNull = new Label();
    Label lblAfter = new Label();
    output.dup();
    output.ifNonNull(lblNotNull);
    output.pop();
    output.aConstNull();
    output.goTo(lblAfter);
    output.label(lblNotNull);
    this.method.invokeVirtual(method.getOutput());
    output.label(lblAfter);
}
Also used : MethodOutput(stanhebben.zenscript.util.MethodOutput) Label(org.objectweb.asm.Label)

Example 3 with MethodOutput

use of stanhebben.zenscript.util.MethodOutput in project ZenScript by CraftTweaker.

the class CastingAnyString method compile.

@Override
public void compile(IEnvironmentMethod method) {
    MethodOutput output = method.getOutput();
    Label lblNonNull = new Label();
    Label lblAfter = new Label();
    output.dup();
    output.ifNonNull(lblNonNull);
    output.pop();
    output.aConstNull();
    output.goTo(lblAfter);
    output.label(lblNonNull);
    output.invokeInterface(IAny.class, "asString", String.class);
    output.label(lblAfter);
}
Also used : MethodOutput(stanhebben.zenscript.util.MethodOutput) Label(org.objectweb.asm.Label)

Example 4 with MethodOutput

use of stanhebben.zenscript.util.MethodOutput in project ZenScript by CraftTweaker.

the class CastingNotNull method compile.

@Override
public void compile(IEnvironmentMethod method) {
    MethodOutput output = method.getOutput();
    Label labelElse = new Label();
    Label labelAfter = new Label();
    output.ifNull(labelElse);
    output.iConst1();
    output.goTo(labelAfter);
    output.label(labelElse);
    output.iConst0();
    output.label(labelAfter);
}
Also used : MethodOutput(stanhebben.zenscript.util.MethodOutput) Label(org.objectweb.asm.Label)

Example 5 with MethodOutput

use of stanhebben.zenscript.util.MethodOutput in project ZenScript by CraftTweaker.

the class CastingRuleNullableStaticMethod method compile.

@Override
public void compile(IEnvironmentMethod method) {
    MethodOutput output = method.getOutput();
    Label lblNotNull = new Label();
    Label lblAfter = new Label();
    output.dup();
    output.ifNonNull(lblNotNull);
    output.pop();
    output.aConstNull();
    output.goTo(lblAfter);
    output.label(lblNotNull);
    if (base != null) {
        base.compile(method);
    }
    this.method.invokeStatic(method.getOutput());
    output.label(lblAfter);
}
Also used : MethodOutput(stanhebben.zenscript.util.MethodOutput) Label(org.objectweb.asm.Label)

Aggregations

MethodOutput (stanhebben.zenscript.util.MethodOutput)9 Label (org.objectweb.asm.Label)4 Method (java.lang.reflect.Method)1 ClassWriter (org.objectweb.asm.ClassWriter)1 Statement (stanhebben.zenscript.statements.Statement)1 SymbolArgument (stanhebben.zenscript.symbols.SymbolArgument)1 ZenType (stanhebben.zenscript.type.ZenType)1