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