summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbd-912 <bdunahu@colostate.edu>2024-04-11 11:51:19 -0600
committerbd-912 <bdunahu@colostate.edu>2024-04-11 11:51:19 -0600
commitb0ddefd7e9a05905668bcef7110c623883e05c86 (patch)
tree4b068852bc2a0ade0186d0826b97f65d34e7d40a
parent1080b37bbe40fe56b919d22804c159cccdca3c95 (diff)
Very simple argument passing Boil.MessageSend
-rw-r--r--boil/library/BoilSimp.java21
-rw-r--r--boil/tests/ex32.java9
-rw-r--r--st/SymTableTopDown.java3
3 files changed, 22 insertions, 11 deletions
diff --git a/boil/library/BoilSimp.java b/boil/library/BoilSimp.java
index b5ea518..991319f 100644
--- a/boil/library/BoilSimp.java
+++ b/boil/library/BoilSimp.java
@@ -510,8 +510,7 @@ public class BoilSimp extends GJDepthFirst<String,SymbolTable> {
String oper2 = n.f2.accept(this, symt);
TypeInstance tp1 = new TypeInstance("tp1", TypeEnum.ERROR);
- mod += String.format(" %s = AddS(%s %s)\n",
- this.tf.addNewAlias(tp1),
+ mod += String.format("Add(%s %s)",
oper1,
oper2);
@@ -588,6 +587,7 @@ public class BoilSimp extends GJDepthFirst<String,SymbolTable> {
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;
@@ -603,13 +603,26 @@ public class BoilSimp extends GJDepthFirst<String,SymbolTable> {
mtdIndex);
mod += n.f3.accept(this, symt);
- mod = n.f4.accept(this, symt);
+ String args = n.f4.accept(this, symt);
mod += n.f5.accept(this, symt);
- mod += String.format(" call %s(%s)\n",
+ TypeInstance tp3 = new TypeInstance("tp3", TypeEnum.ERROR);
+
+ if (!args.isEmpty())
+ mod += String.format(" %s = %s\n",
+ this.tf.addNewAlias(tp3),
+ args);
+
+ mod += String.format(" call %s(%s",
this.tf.retrieveAlias(tp2),
this.tf.retrieveAlias(cur));
+ if (!args.isEmpty())
+ mod += String.format(" %s",
+ this.tf.retrieveAlias(tp3));
+
+ mod += ")\n";
+
return mod;
}
diff --git a/boil/tests/ex32.java b/boil/tests/ex32.java
index 5e421c4..af4dcd7 100644
--- a/boil/tests/ex32.java
+++ b/boil/tests/ex32.java
@@ -1,16 +1,13 @@
-class ex31 {
+class ex32 {
public static void main(String[] a) {
A a ;
a = new A() ;
- System.out.println(a.bar()) ;
+ System.out.println(a.foo(12 + 13)) ;
}
}
class A {
- public int foo() {
+ public int foo(int a) {
return 22 ;
}
- public int bar() {
- return 42 ;
- }
}
diff --git a/st/SymTableTopDown.java b/st/SymTableTopDown.java
index 2f65919..df136aa 100644
--- a/st/SymTableTopDown.java
+++ b/st/SymTableTopDown.java
@@ -116,9 +116,10 @@ public class SymTableTopDown<R> extends GJDepthFirst<R,SymbolTable> {
* f2 -> ";"
*/
public R visit(VarDeclaration n, SymbolTable symt) {
- String cls = (n.f0.f0.which == 4) ?
+ String cls = (n.f0.f0.which == 3) ?
((Identifier) n.f0.f0.choice).f0.tokenImage :
null;
+
String id = n.f1.f0.tokenImage;
symt.addLocal(id);
symt.addClassInstance(id, cls);