X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.scl.compiler%2Fsrc%2Forg%2Fsimantics%2Fscl%2Fcompiler%2Finternal%2Fcodegen%2Fcontinuations%2FCont.java;fp=bundles%2Forg.simantics.scl.compiler%2Fsrc%2Forg%2Fsimantics%2Fscl%2Fcompiler%2Finternal%2Fcodegen%2Fcontinuations%2FCont.java;h=eb6d17d98d89469ad70c5f87a367b2ff0f2c0ac5;hb=969bd23cab98a79ca9101af33334000879fb60c5;hp=0000000000000000000000000000000000000000;hpb=866dba5cd5a3929bbeae85991796acb212338a08;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/codegen/continuations/Cont.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/codegen/continuations/Cont.java new file mode 100644 index 000000000..eb6d17d98 --- /dev/null +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/codegen/continuations/Cont.java @@ -0,0 +1,76 @@ +package org.simantics.scl.compiler.internal.codegen.continuations; + +import org.simantics.scl.compiler.internal.codegen.references.BoundVar; +import org.simantics.scl.compiler.internal.codegen.references.Val; +import org.simantics.scl.compiler.internal.codegen.references.ValRef; +import org.simantics.scl.compiler.internal.codegen.ssa.SSABlock; +import org.simantics.scl.compiler.internal.codegen.ssa.SSAFunction; +import org.simantics.scl.compiler.internal.codegen.ssa.exits.Jump; +import org.simantics.scl.compiler.internal.codegen.utils.CopyContext; +import org.simantics.scl.compiler.types.TVar; +import org.simantics.scl.compiler.types.Type; + +public abstract class Cont implements ICont { + + transient ContRef occurrence; + + @Override + public ContRef createOccurrence() { + return new ContRef(this); + } + + public void replaceWith(Cont other) { + ContRef cur = occurrence; + if(cur != null) { + while(true) { + cur.binding = other; + if(cur.next == null) + break; + else + cur = cur.next; + } + cur.next = other.occurrence; + if(other.occurrence != null) + other.occurrence.prev = cur; + other.occurrence = occurrence; + occurrence = null; + } + } + + public abstract int getArity(); + public abstract Type getParameterType(int parameterId); + + public int occurrenceCount() { + int count = 0; + for(ContRef ref = occurrence;ref != null;ref=ref.next) + ++count; + return count; + } + + public boolean hasMoreThanOneOccurences() { + return occurrence != null && occurrence.next != null; + } + + public boolean hasNoOccurences() { + return occurrence == null; + } + + public abstract Cont copy(CopyContext context); + public abstract void replace(TVar[] vars, Type[] replacements); + + public ContRef getOccurrence() { + return occurrence; + } + + public Cont createProxy(SSAFunction function, Val[] newParameters, Val[] oldParameters) { + BoundVar[] proxyParameters = new BoundVar[oldParameters.length]; + for(int i=0;i