X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.scl.compiler%2Fsrc%2Forg%2Fsimantics%2Fscl%2Fcompiler%2Felaboration%2Fjava%2FEmptyListConstructor.java;fp=bundles%2Forg.simantics.scl.compiler%2Fsrc%2Forg%2Fsimantics%2Fscl%2Fcompiler%2Felaboration%2Fjava%2FEmptyListConstructor.java;h=24ea0fbe83d80b779002771aa919d8e459e52dc7;hb=969bd23cab98a79ca9101af33334000879fb60c5;hp=0000000000000000000000000000000000000000;hpb=866dba5cd5a3929bbeae85991796acb212338a08;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/java/EmptyListConstructor.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/java/EmptyListConstructor.java new file mode 100644 index 000000000..24ea0fbe8 --- /dev/null +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/java/EmptyListConstructor.java @@ -0,0 +1,46 @@ +package org.simantics.scl.compiler.elaboration.java; + +import org.cojen.classfile.TypeDesc; +import org.objectweb.asm.Label; +import org.simantics.scl.compiler.common.exceptions.InternalCompilerError; +import org.simantics.scl.compiler.constants.Constant; +import org.simantics.scl.compiler.internal.codegen.continuations.Cont; +import org.simantics.scl.compiler.internal.codegen.references.IVal; +import org.simantics.scl.compiler.internal.codegen.utils.Constants; +import org.simantics.scl.compiler.internal.codegen.utils.MethodBuilder; +import org.simantics.scl.compiler.types.TVar; +import org.simantics.scl.compiler.types.Types; +import org.simantics.scl.compiler.types.kinds.Kinds; + + +public class EmptyListConstructor extends Constant { + + private static final TVar A = Types.var(Kinds.STAR); + + public EmptyListConstructor() { + super(Types.forAll(A, Types.list(A))); + } + + @Override + public void push(MethodBuilder mb) { + mb.loadStaticField("java/util/Collections", "EMPTY_LIST", Constants.LIST); + } + + @Override + public void deconstruct(MethodBuilder mb, IVal parameter, Cont success, + Label failure) { + if(failure == null) + throw new InternalCompilerError("List deconstruction may always fail"); + + parameter.push(mb); + mb.invokeInterface(Constants.LIST, "size", TypeDesc.INT, Constants.EMPTY_TYPEDESC_ARRAY); + mb.ifZeroComparisonBranch(failure, "!="); + mb.jump(success); + } + + @Override + public int constructorTag() { + return 0; + } + +}