diff options
author | bd-912 <bdunahu@colostate.edu> | 2024-04-09 21:51:27 -0600 |
---|---|---|
committer | bd-912 <bdunahu@colostate.edu> | 2024-04-09 21:51:27 -0600 |
commit | c1e124b957fa840f7bd8da9ffc6871140cfabf16 (patch) | |
tree | 46140a2cad0b9ff95ed0e5728b47bb1c46d1cca5 | |
parent | 0de1debf8b72c460d6974de8a8ab9cbbdeecb160 (diff) |
Finished Vaporize.MessageSend
-rw-r--r-- | st/SymTableTopDown.java | 2 | ||||
-rw-r--r-- | st/SymbolTable.java | 9 | ||||
-rw-r--r-- | st/TypeInstance.java | 10 | ||||
-rw-r--r-- | vaporize/library/TypeFactory.java | 2 | ||||
-rw-r--r-- | vaporize/library/VaporizeSimp.java | 26 |
5 files changed, 46 insertions, 3 deletions
diff --git a/st/SymTableTopDown.java b/st/SymTableTopDown.java index 7258211..a4c641c 100644 --- a/st/SymTableTopDown.java +++ b/st/SymTableTopDown.java @@ -116,8 +116,10 @@ public class SymTableTopDown<R> extends GJDepthFirst<R,SymbolTable> { * f2 -> ";" */ public R visit(VarDeclaration n, SymbolTable symt) { + String cls = ((Identifier) n.f0.f0.choice).f0.tokenImage; String id = n.f1.f0.tokenImage; symt.addLocal(id); + symt.addClassInstance(id, cls); n.f0.accept(this, symt); diff --git a/st/SymbolTable.java b/st/SymbolTable.java index d0ea221..1c0af09 100644 --- a/st/SymbolTable.java +++ b/st/SymbolTable.java @@ -80,6 +80,15 @@ public class SymbolTable { mtd.addArgument(para); // also adds to local vars } + public void addClassInstance(String t, String c) { + TypeInstance type = this.getType(t); + ClassInstance cls = (c != null) ? + this.getClass(c) : + null; + + type.addClassInstance(cls); + } + /** * Methods to safely retrieve differentiable types diff --git a/st/TypeInstance.java b/st/TypeInstance.java index 302f9f0..596f638 100644 --- a/st/TypeInstance.java +++ b/st/TypeInstance.java @@ -2,10 +2,20 @@ package st; public class TypeInstance extends AbstractInstance { + ClassInstance cls; + public TypeInstance(String name, TypeEnum type) { super(name, type); } + public void addClassInstance(ClassInstance cls) { + this.cls = cls; + } + + public ClassInstance getClassInstance() { + return this.cls; + } + public boolean sameType(TypeInstance other) { /** * Given a TypeInstance object other, diff --git a/vaporize/library/TypeFactory.java b/vaporize/library/TypeFactory.java index 0166e3c..b73862f 100644 --- a/vaporize/library/TypeFactory.java +++ b/vaporize/library/TypeFactory.java @@ -14,7 +14,7 @@ public class TypeFactory { } public String addNewAlias(TypeInstance t) { - String alias = String.format("t.%d", type_num); + String alias = String.format("t.%d", this.type_num++); this.map.put(t, alias); return alias; } diff --git a/vaporize/library/VaporizeSimp.java b/vaporize/library/VaporizeSimp.java index 44121a9..a77f579 100644 --- a/vaporize/library/VaporizeSimp.java +++ b/vaporize/library/VaporizeSimp.java @@ -570,9 +570,31 @@ public class VaporizeSimp extends GJDepthFirst<String,SymbolTable> { */ public String visit(MessageSend n, SymbolTable symt) { String mod = ""; - mod += n.f0.accept(this, symt); + String id = n.f0.accept(this, symt); mod += n.f1.accept(this, symt); - mod += n.f2.accept(this, symt); + String id2 = n.f2.accept(this, symt); + TypeInstance tp1 = new TypeInstance("tp1", TypeEnum.ERROR); // TypeFactory likes to know who it's renting to + TypeInstance tp2 = new TypeInstance("tp2", TypeEnum.ERROR); + + TypeInstance cur = symt.getType(id); + int mtdIndex = cur.getClassInstance() + .getMethods().indexOf(symt.getMethod(id2)) * 4; + + mod += String.format(" %s = [%s+%d]\n", + this.tf.addNewAlias(tp1), + this.tf.retrieveAlias(cur), + 0); + + mod += String.format(" %s = [%s+%d]\n", + this.tf.addNewAlias(tp2), + this.tf.retrieveAlias(tp1), + mtdIndex); + + mod += String.format(" call %s(%s)\n", + this.tf.retrieveAlias(tp2), + this.tf.retrieveAlias(cur)); + + mod += n.f3.accept(this, symt); mod += n.f4.accept(this, symt); mod += n.f5.accept(this, symt); |