1 package org.simantics.scl.compiler.internal.codegen.references;
3 import gnu.trove.map.hash.THashMap;
5 import org.cojen.classfile.TypeDesc;
6 import org.simantics.scl.compiler.internal.codegen.ssa.SSAFunction;
7 import org.simantics.scl.compiler.internal.codegen.ssa.binders.BoundVarBinder;
8 import org.simantics.scl.compiler.internal.codegen.ssa.statements.LetApply;
9 import org.simantics.scl.compiler.internal.codegen.utils.MethodBuilder;
10 import org.simantics.scl.compiler.internal.codegen.utils.TransientClassBuilder;
11 import org.simantics.scl.compiler.types.TVar;
12 import org.simantics.scl.compiler.types.Type;
14 public final class BoundVar extends Val {
15 public BoundVarBinder parent;
20 * This means that the bound var does not need a local variable
21 * but it can be generated into stack when needed.
23 public boolean generateOnFly;
25 public BoundVar(Type type) {
30 public Type getType() {
35 public void push(MethodBuilder mb) {
37 ((LetApply)parent).push(mb);
38 else if(!mb.getJavaTypeTranslator().toTypeDesc(type).equals(TypeDesc.VOID))
39 mb.loadLocal(mb.getLocalVariable(this));
42 public BoundVar copy(THashMap<TVar, TVar> tvarMap) {
43 return new BoundVar(type.replace(tvarMap));
46 public void replace(TVar[] vars, Type[] replacements) {
47 type = type.replace(vars, replacements);
50 public SSAFunction getFunctionParent() {
51 return parent.getParentFunction();
54 public static BoundVar[] concat(BoundVar[] a, BoundVar[] b) {
55 BoundVar[] result = new BoundVar[a.length + b.length];
59 for(int i=0;i<b.length;++i)
64 public BoundVarBinder getParent() {
69 public int getEffectiveArity() {
70 if(parent instanceof SSAFunction) {
71 SSAFunction function = (SSAFunction)parent;
72 int arity = function.getArity();
73 if(function.hasEffect())
82 public Object realizeValue(TransientClassBuilder classLoader) {
83 throw new UnsupportedOperationException();
86 public static BoundVar[] copy(BoundVar[] vars) {
87 BoundVar[] result = new BoundVar[vars.length];
88 for(int i=0;i<vars.length;++i)
89 result[i] = new BoundVar(vars[i].getType());
94 public void setLabel(String label) {
98 public String getLabel() {