summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbd-912 <bdunahu@colostate.edu>2024-04-09 23:48:26 -0600
committerbd-912 <bdunahu@colostate.edu>2024-04-09 23:48:26 -0600
commit61a28b7f8e709d1884ccab15f0dc38ed19dfde70 (patch)
tree4a08bf487d7a18cc8cd328876067e57d261920f6
parentc1e124b957fa840f7bd8da9ffc6871140cfabf16 (diff)
Partial arguments in Vaporize.MessageSend, Typecheck for milestone
-rw-r--r--Typecheck.java22
-rw-r--r--st/SymTableTopDown.java4
-rw-r--r--st/SymbolTable.java4
-rw-r--r--typecheck/library/TypeCheckSimp.java2
-rw-r--r--typecheck/tests/IsPositive.java6
-rw-r--r--vaporize/library/VaporizeSimp.java40
-rw-r--r--vaporize/tests_easy/ex31.java4
7 files changed, 50 insertions, 32 deletions
diff --git a/Typecheck.java b/Typecheck.java
index b4149d9..4c43709 100644
--- a/Typecheck.java
+++ b/Typecheck.java
@@ -26,18 +26,18 @@ public class Typecheck {
root.accept(new SymTableTopDown<Void>(), symt);
PrintFilter.print("===================================================", true);
- // TypeCheckSimp ts = new TypeCheckSimp();
- // TypeInstance res = root.accept(ts, symt);
+ TypeCheckSimp ts = new TypeCheckSimp();
+ TypeInstance res = root.accept(ts, symt);
- // // Ugly code not to be inspired from: "my" way of storing
- // // type info / typecheck property: if some of my internal
- // // structure is empty, then things don't typecheck for
- // // me. This is specific to my own implementation.
- // // if (res != null && res.type_array.size() > 0)
- // if (res.getType() != TypeEnum.ERROR)
- // System.out.println("Program type checked successfully");
- // else
- // System.out.println("Type error");
+ // Ugly code not to be inspired from: "my" way of storing
+ // type info / typecheck property: if some of my internal
+ // structure is empty, then things don't typecheck for
+ // me. This is specific to my own implementation.
+ // if (res != null && res.type_array.size() > 0)
+ if (res.getType() != TypeEnum.ERROR)
+ System.out.println("Program type checked successfully");
+ else
+ System.out.println("Type error");
}
catch (ParseException e) {
System.out.println(e.toString());
diff --git a/st/SymTableTopDown.java b/st/SymTableTopDown.java
index a4c641c..2f65919 100644
--- a/st/SymTableTopDown.java
+++ b/st/SymTableTopDown.java
@@ -116,7 +116,9 @@ 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 cls = (n.f0.f0.which == 4) ?
+ ((Identifier) n.f0.f0.choice).f0.tokenImage :
+ null;
String id = n.f1.f0.tokenImage;
symt.addLocal(id);
symt.addClassInstance(id, cls);
diff --git a/st/SymbolTable.java b/st/SymbolTable.java
index 1c0af09..93d3af9 100644
--- a/st/SymbolTable.java
+++ b/st/SymbolTable.java
@@ -8,8 +8,8 @@ import java.util.*;
* of each symbol consistent.
*/
public class SymbolTable {
- private HashMap<String,AbstractInstance> symt; // the mapping of ids to Instances
- private HashMap<TypeEnum,String> active; // the current scope of the visitor (class, method)
+ private HashMap<String,AbstractInstance> symt; // the mapping of ids to Instances
+ private HashMap<TypeEnum,String> active; // the current scope of the visitor (class, method)
public SymbolTable() {
this.symt = new HashMap<>();
diff --git a/typecheck/library/TypeCheckSimp.java b/typecheck/library/TypeCheckSimp.java
index b3a9ca3..1a77477 100644
--- a/typecheck/library/TypeCheckSimp.java
+++ b/typecheck/library/TypeCheckSimp.java
@@ -434,7 +434,7 @@ public class TypeCheckSimp extends GJDepthFirst<TypeInstance,SymbolTable> {
++this.offset;
this.printNode(n, symt, true, null);
- TypeInstance ret = new TypeInstance(null, TypeEnum.integer);
+ TypeInstance ret = new TypeInstance(null, TypeEnum.integer);
this.printNode(n, symt, false, ret.getType());
--this.offset;
diff --git a/typecheck/tests/IsPositive.java b/typecheck/tests/IsPositive.java
index 6adc30f..087cd3f 100644
--- a/typecheck/tests/IsPositive.java
+++ b/typecheck/tests/IsPositive.java
@@ -1,13 +1,13 @@
class IsPositive{
public static void main(String[] a){
- System.out.println(new Positive().isPositive(10));
+ System.out.println(new Positive().isPos(10));
}
}
class Positive {
- public bool IsPositive(int num){
+ public bool isPos(int num){
bool positive ;
-
+
if (0 < num)
positive = true ;
else
diff --git a/vaporize/library/VaporizeSimp.java b/vaporize/library/VaporizeSimp.java
index a77f579..a7faf88 100644
--- a/vaporize/library/VaporizeSimp.java
+++ b/vaporize/library/VaporizeSimp.java
@@ -233,17 +233,18 @@ public class VaporizeSimp extends GJDepthFirst<String,SymbolTable> {
String mod = "";
mod += n.f0.accept(this, symt);
- mod += n.f1.accept(this, symt);
+ n.f1.accept(this, symt);
n.f2.accept(this, symt);
- mod += "func " + symt.getActive(TypeEnum.classname) + "_" + id + "(this)\n";
+ mod += "func " + symt.getActive(TypeEnum.classname) + "_" + id + "(this";
mod += n.f3.accept(this, symt);
- mod += n.f4.accept(this, symt);
+ String args = n.f4.accept(this, symt);
+ mod += String.format("%s)\n", args);
mod += n.f5.accept(this, symt);
mod += n.f6.accept(this, symt);
mod += n.f7.accept(this, symt);
mod += n.f8.accept(this, symt);
mod += n.f9.accept(this, symt);
- mod += n.f10.accept(this, symt);
+ n.f10.accept(this, symt); // FIXME
mod += n.f11.accept(this, symt);
mod += n.f12.accept(this, symt);
@@ -260,7 +261,9 @@ public class VaporizeSimp extends GJDepthFirst<String,SymbolTable> {
*/
public String visit(FormalParameterList n, SymbolTable symt) {
String mod = "";
- mod += n.f0.accept(this, symt);
+ String arg = n.f0.accept(this, symt);
+ if (arg != null)
+ mod += " " + arg;
mod += n.f1.accept(this, symt);
return mod;
}
@@ -283,7 +286,9 @@ public class VaporizeSimp extends GJDepthFirst<String,SymbolTable> {
public String visit(FormalParameterRest n, SymbolTable symt) {
String mod = "";
mod += n.f0.accept(this, symt);
- mod += n.f1.accept(this, symt);
+ String arg = n.f1.accept(this, symt);
+ if (arg != null)
+ mod += " " + arg;
return mod;
}
@@ -326,7 +331,7 @@ public class VaporizeSimp extends GJDepthFirst<String,SymbolTable> {
*/
public String visit(IntegerType n, SymbolTable symt) {
String mod = "";
- mod += n.f0.accept(this, symt);
+ mod += n.f0.accept(this, symt);;
return mod;
}
@@ -500,9 +505,16 @@ public class VaporizeSimp extends GJDepthFirst<String,SymbolTable> {
*/
public String visit(PlusExpression n, SymbolTable symt) {
String mod = "";
- mod += n.f0.accept(this, symt);
+ String oper1 = n.f0.accept(this, symt);
mod += n.f1.accept(this, symt);
- mod += n.f2.accept(this, symt);
+ 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),
+ oper1,
+ oper2);
+
return mod;
}
@@ -590,14 +602,14 @@ public class VaporizeSimp extends GJDepthFirst<String,SymbolTable> {
this.tf.retrieveAlias(tp1),
mtdIndex);
+ mod += n.f3.accept(this, symt);
+ mod = n.f4.accept(this, symt);
+ mod += n.f5.accept(this, symt);
+
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);
return mod;
}
@@ -645,7 +657,7 @@ public class VaporizeSimp extends GJDepthFirst<String,SymbolTable> {
*/
public String visit(IntegerLiteral n, SymbolTable symt) {
String mod = "";
- mod += n.f0.accept(this, symt);
+ mod += n.f0.tokenImage;
return mod;
}
diff --git a/vaporize/tests_easy/ex31.java b/vaporize/tests_easy/ex31.java
index 6527b8b..d5a6980 100644
--- a/vaporize/tests_easy/ex31.java
+++ b/vaporize/tests_easy/ex31.java
@@ -9,4 +9,8 @@ class A {
public int foo() {
return 22 ;
}
+
+ public int bar() {
+ return 42 ;
+ }
}