1 package org.simantics.scl.compiler.internal.codegen.continuations;
\r
3 import org.simantics.scl.compiler.internal.codegen.references.BoundVar;
\r
4 import org.simantics.scl.compiler.internal.codegen.references.Val;
\r
5 import org.simantics.scl.compiler.internal.codegen.references.ValRef;
\r
6 import org.simantics.scl.compiler.internal.codegen.ssa.SSABlock;
\r
7 import org.simantics.scl.compiler.internal.codegen.ssa.SSAFunction;
\r
8 import org.simantics.scl.compiler.internal.codegen.ssa.exits.Jump;
\r
9 import org.simantics.scl.compiler.internal.codegen.utils.CopyContext;
\r
10 import org.simantics.scl.compiler.types.TVar;
\r
11 import org.simantics.scl.compiler.types.Type;
\r
13 public abstract class Cont implements ICont {
\r
15 transient ContRef occurrence;
\r
18 public ContRef createOccurrence() {
\r
19 return new ContRef(this);
\r
22 public void replaceWith(Cont other) {
\r
23 ContRef cur = occurrence;
\r
26 cur.binding = other;
\r
27 if(cur.next == null)
\r
32 cur.next = other.occurrence;
\r
33 if(other.occurrence != null)
\r
34 other.occurrence.prev = cur;
\r
35 other.occurrence = occurrence;
\r
40 public abstract int getArity();
\r
41 public abstract Type getParameterType(int parameterId);
\r
43 public int occurrenceCount() {
\r
45 for(ContRef ref = occurrence;ref != null;ref=ref.next)
\r
50 public boolean hasMoreThanOneOccurences() {
\r
51 return occurrence != null && occurrence.next != null;
\r
54 public boolean hasNoOccurences() {
\r
55 return occurrence == null;
\r
58 public abstract Cont copy(CopyContext context);
\r
59 public abstract void replace(TVar[] vars, Type[] replacements);
\r
61 public ContRef getOccurrence() {
\r
65 public Cont createProxy(SSAFunction function, Val[] newParameters, Val[] oldParameters) {
\r
66 BoundVar[] proxyParameters = new BoundVar[oldParameters.length];
\r
67 for(int i=0;i<oldParameters.length;++i)
\r
68 proxyParameters[i] = new BoundVar(oldParameters[i].getType());
\r
69 SSABlock block = new SSABlock(proxyParameters);
\r
70 function.addBlock(block);
\r
71 block.setExit(new Jump(createOccurrence(),
\r
72 ValRef.concat(ValRef.createOccurrences(newParameters),
\r
73 ValRef.createOccurrences(proxyParameters))));
\r