summaryrefslogtreecommitdiff
path: root/boil/library
diff options
context:
space:
mode:
authorbd-912 <bdunahu@colostate.edu>2024-04-17 12:59:49 -0600
committerbd-912 <bdunahu@colostate.edu>2024-04-17 12:59:49 -0600
commit6d68e534aa53f3879ebc8a4f5803e468dc86a6bc (patch)
tree9da021b2a1dad2a635b9ecb3da066cb271dc082f /boil/library
parentdf976c9bac104d44c8e7b446235ad73e956b5415 (diff)
Uber-gross anonymous class functionality in Boil.MessageSend
Diffstat (limited to 'boil/library')
-rw-r--r--boil/library/BoilSimp.java126
1 files changed, 71 insertions, 55 deletions
diff --git a/boil/library/BoilSimp.java b/boil/library/BoilSimp.java
index 561bbcd..0d45485 100644
--- a/boil/library/BoilSimp.java
+++ b/boil/library/BoilSimp.java
@@ -6,7 +6,7 @@ import st.*;
import misc.*;
import java.util.*;
-public class BoilSimp extends GJDepthFirst<String,TypeInstance> {
+public class BoilSimp extends GJDepthFirst<String,String> {
private String vapor; // the collected vapor program
private TypeFactory tf; // the shared type generator
@@ -27,7 +27,7 @@ public class BoilSimp extends GJDepthFirst<String,TypeInstance> {
//
// Auto class visitors--probably don't need to be overridden.
//
- public String visit(NodeList n, TypeInstance args) {
+ public String visit(NodeList n, String args) {
String mod = "";
int _count=0;
for ( Enumeration<Node> e = n.elements(); e.hasMoreElements(); ) {
@@ -37,7 +37,7 @@ public class BoilSimp extends GJDepthFirst<String,TypeInstance> {
return mod;
}
- public String visit(NodeListOptional n, TypeInstance args) {
+ public String visit(NodeListOptional n, String args) {
String mod = "";
if ( n.present() ) {
int _count=0;
@@ -51,14 +51,14 @@ public class BoilSimp extends GJDepthFirst<String,TypeInstance> {
return "";
}
- public String visit(NodeOptional n, TypeInstance args) {
+ public String visit(NodeOptional n, String args) {
if ( n.present() )
return n.node.accept(this,args);
else
return "";
}
- public String visit(NodeSequence n, TypeInstance args) {
+ public String visit(NodeSequence n, String args) {
String mod = "";
int _count=0;
for ( Enumeration<Node> e = n.elements(); e.hasMoreElements(); ) {
@@ -68,7 +68,7 @@ public class BoilSimp extends GJDepthFirst<String,TypeInstance> {
return mod;
}
- public String visit(NodeToken n, TypeInstance args) { return ""; }
+ public String visit(NodeToken n, String args) { return ""; }
//
// User-generated visitor methods below
@@ -79,7 +79,7 @@ public class BoilSimp extends GJDepthFirst<String,TypeInstance> {
* f1 -> ( TypeDeclaration() )*
* f2 -> <EOF>
*/
- public String visit(Goal n, TypeInstance args) {
+ public String visit(Goal n, String args) {
String mod = "";
n.f0.accept(this, args);
n.f1.accept(this, args);
@@ -107,7 +107,7 @@ public class BoilSimp extends GJDepthFirst<String,TypeInstance> {
* f16 -> "}"
* f17 -> "}"
*/
- public String visit(MainClass n, TypeInstance args) {
+ public String visit(MainClass n, String args) {
String id = n.f1.f0.tokenImage;
this.symt.setActive(TypeEnum.classname, id);
@@ -147,7 +147,7 @@ public class BoilSimp extends GJDepthFirst<String,TypeInstance> {
* f0 -> ClassDeclaration()
* | ClassExtendsDeclaration()
*/
- public String visit(TypeDeclaration n, TypeInstance args) {
+ public String visit(TypeDeclaration n, String args) {
String mod = "";
n.f0.accept(this, args);
return mod;
@@ -161,7 +161,7 @@ public class BoilSimp extends GJDepthFirst<String,TypeInstance> {
* f4 -> ( MethodDeclaration() )*
* f5 -> "}"
*/
- public String visit(ClassDeclaration n, TypeInstance args) {
+ public String visit(ClassDeclaration n, String args) {
String id = n.f1.f0.tokenImage;
this.symt.setActive(TypeEnum.classname, id);
String mod = "";
@@ -191,7 +191,7 @@ public class BoilSimp extends GJDepthFirst<String,TypeInstance> {
* f6 -> ( MethodDeclaration() )*
* f7 -> "}"
*/
- public String visit(ClassExtendsDeclaration n, TypeInstance args) {
+ public String visit(ClassExtendsDeclaration n, String args) {
String id = n.f1.f0.tokenImage;
this.symt.setActive(TypeEnum.classname, id);
String mod = "";
@@ -212,7 +212,7 @@ public class BoilSimp extends GJDepthFirst<String,TypeInstance> {
* f1 -> Identifier()
* f2 -> ";"
*/
- public String visit(VarDeclaration n, TypeInstance args) {
+ public String visit(VarDeclaration n, String args) {
String mod = "";
String cls = n.f0.accept(this, args);
@@ -243,7 +243,7 @@ public class BoilSimp extends GJDepthFirst<String,TypeInstance> {
* f11 -> ";"
* f12 -> "}"
*/
- public String visit(MethodDeclaration n, TypeInstance args) {
+ public String visit(MethodDeclaration n, String args) {
String id = n.f2.f0.tokenImage;
this.symt.setActive(TypeEnum.method, id);
this.tf.reset();
@@ -287,7 +287,7 @@ public class BoilSimp extends GJDepthFirst<String,TypeInstance> {
* f0 -> FormalParameter()
* f1 -> ( FormalParameterRest() )*
*/
- public String visit(FormalParameterList n, TypeInstance args) {
+ public String visit(FormalParameterList n, String args) {
String mod = "";
String arg = n.f0.accept(this, args);
if (arg != null)
@@ -300,7 +300,7 @@ public class BoilSimp extends GJDepthFirst<String,TypeInstance> {
* f0 -> Type()
* f1 -> Identifier()
*/
- public String visit(FormalParameter n, TypeInstance args) {
+ public String visit(FormalParameter n, String args) {
String mod = "";
mod += n.f0.accept(this, args);
mod += n.f1.accept(this, args);
@@ -311,7 +311,7 @@ public class BoilSimp extends GJDepthFirst<String,TypeInstance> {
* f0 -> ","
* f1 -> FormalParameter()
*/
- public String visit(FormalParameterRest n, TypeInstance args) {
+ public String visit(FormalParameterRest n, String args) {
String mod = "";
n.f0.accept(this, args);
String arg = n.f1.accept(this, args);
@@ -326,7 +326,7 @@ public class BoilSimp extends GJDepthFirst<String,TypeInstance> {
* | IntegerType()
* | Identifier()
*/
- public String visit(Type n, TypeInstance args) {
+ public String visit(Type n, String args) {
String mod = "";
mod += n.f0.accept(this, args);
return mod;
@@ -337,7 +337,7 @@ public class BoilSimp extends GJDepthFirst<String,TypeInstance> {
* f1 -> "["
* f2 -> "]"
*/
- public String visit(ArrayType n, TypeInstance args) {
+ public String visit(ArrayType n, String args) {
String mod = "";
n.f0.accept(this, args);
n.f1.accept(this, args);
@@ -348,7 +348,7 @@ public class BoilSimp extends GJDepthFirst<String,TypeInstance> {
/**
* f0 -> "boolean"
*/
- public String visit(BooleanType n, TypeInstance args) {
+ public String visit(BooleanType n, String args) {
String mod = "";
n.f0.accept(this, args);
return mod;
@@ -357,7 +357,7 @@ public class BoilSimp extends GJDepthFirst<String,TypeInstance> {
/**
* f0 -> "int"
*/
- public String visit(IntegerType n, TypeInstance args) {
+ public String visit(IntegerType n, String args) {
String mod = "";
n.f0.accept(this, args);;
return mod;
@@ -371,7 +371,7 @@ public class BoilSimp extends GJDepthFirst<String,TypeInstance> {
* | WhileStatement()
* | PrintStatement()
*/
- public String visit(Statement n, TypeInstance args) {
+ public String visit(Statement n, String args) {
String mod = "";
n.f0.accept(this, args);
return mod;
@@ -382,7 +382,7 @@ public class BoilSimp extends GJDepthFirst<String,TypeInstance> {
* f1 -> ( Statement() )*
* f2 -> "}"
*/
- public String visit(Block n, TypeInstance args) {
+ public String visit(Block n, String args) {
String mod = "";
n.f0.accept(this, args);
n.f1.accept(this, args);
@@ -396,7 +396,7 @@ public class BoilSimp extends GJDepthFirst<String,TypeInstance> {
* f2 -> Expression()
* f3 -> ";"
*/
- public String visit(AssignmentStatement n, TypeInstance args) {
+ public String visit(AssignmentStatement n, String args) {
String mod = "";
String id = n.f0.accept(this, args);
@@ -437,7 +437,7 @@ public class BoilSimp extends GJDepthFirst<String,TypeInstance> {
* f5 -> Expression()
* f6 -> ";"
*/
- public String visit(ArrayAssignmentStatement n, TypeInstance args) {
+ public String visit(ArrayAssignmentStatement n, String args) {
String mod = "";
n.f0.accept(this, args);
n.f1.accept(this, args);
@@ -458,7 +458,7 @@ public class BoilSimp extends GJDepthFirst<String,TypeInstance> {
* f5 -> "else"
* f6 -> Statement()
*/
- public String visit(IfStatement n, TypeInstance args) {
+ public String visit(IfStatement n, String args) {
String mod = "";
n.f0.accept(this, args);
n.f1.accept(this, args);
@@ -477,7 +477,7 @@ public class BoilSimp extends GJDepthFirst<String,TypeInstance> {
* f3 -> ")"
* f4 -> Statement()
*/
- public String visit(WhileStatement n, TypeInstance args) {
+ public String visit(WhileStatement n, String args) {
String mod = "";
n.f0.accept(this, args);
n.f1.accept(this, args);
@@ -494,7 +494,7 @@ public class BoilSimp extends GJDepthFirst<String,TypeInstance> {
* f3 -> ")"
* f4 -> ";"
*/
- public String visit(PrintStatement n, TypeInstance args) {
+ public String visit(PrintStatement n, String args) {
String mod = "";
n.f0.accept(this, args);
n.f1.accept(this, args);
@@ -522,7 +522,7 @@ public class BoilSimp extends GJDepthFirst<String,TypeInstance> {
* | MessageSend()
* | PrimaryExpression()
*/
- public String visit(Expression n, TypeInstance args) {
+ public String visit(Expression n, String args) {
String mod = "";
mod += n.f0.accept(this, args);
return mod;
@@ -533,7 +533,7 @@ public class BoilSimp extends GJDepthFirst<String,TypeInstance> {
* f1 -> "&&"
* f2 -> PrimaryExpression()
*/
- public String visit(AndExpression n, TypeInstance args) {
+ public String visit(AndExpression n, String args) {
String mod = "";
n.f0.accept(this, args);
n.f1.accept(this, args);
@@ -546,7 +546,7 @@ public class BoilSimp extends GJDepthFirst<String,TypeInstance> {
* f1 -> "<"
* f2 -> PrimaryExpression()
*/
- public String visit(CompareExpression n, TypeInstance args) {
+ public String visit(CompareExpression n, String args) {
String mod = "";
n.f0.accept(this, args);
n.f1.accept(this, args);
@@ -559,7 +559,7 @@ public class BoilSimp extends GJDepthFirst<String,TypeInstance> {
* f1 -> "+"
* f2 -> PrimaryExpression()
*/
- public String visit(PlusExpression n, TypeInstance args) {
+ public String visit(PlusExpression n, String args) {
String mod = "";
String oper1 = n.f0.accept(this, args);
n.f1.accept(this, args);
@@ -577,7 +577,7 @@ public class BoilSimp extends GJDepthFirst<String,TypeInstance> {
* f1 -> "-"
* f2 -> PrimaryExpression()
*/
- public String visit(MinusExpression n, TypeInstance args) {
+ public String visit(MinusExpression n, String args) {
String mod = "";
String oper1 = n.f0.accept(this, args);
n.f1.accept(this, args);
@@ -596,7 +596,7 @@ public class BoilSimp extends GJDepthFirst<String,TypeInstance> {
* f1 -> "*"
* f2 -> PrimaryExpression()
*/
- public String visit(TimesExpression n, TypeInstance args) {
+ public String visit(TimesExpression n, String args) {
String mod = "";
String oper1 = n.f0.accept(this, args);
n.f1.accept(this, args);
@@ -616,7 +616,7 @@ public class BoilSimp extends GJDepthFirst<String,TypeInstance> {
* f2 -> PrimaryExpression()
* f3 -> "]"
*/
- public String visit(ArrayLookup n, TypeInstance args) {
+ public String visit(ArrayLookup n, String args) {
String mod = "";
n.f0.accept(this, args);
n.f1.accept(this, args);
@@ -630,7 +630,7 @@ public class BoilSimp extends GJDepthFirst<String,TypeInstance> {
* f1 -> "."
* f2 -> "length"
*/
- public String visit(ArrayLength n, TypeInstance args) {
+ public String visit(ArrayLength n, String args) {
String mod = "";
n.f0.accept(this, args);
n.f1.accept(this, args);
@@ -646,21 +646,37 @@ public class BoilSimp extends GJDepthFirst<String,TypeInstance> {
* f4 -> ( ExpressionList() )?
* f5 -> ")"
*/
- public String visit(MessageSend n, TypeInstance args) {
+ public String visit(MessageSend n, String args) {
String mod = "";
String id = n.f0.accept(this, args);
+
+ // gross code was required to create proper types + classes for anonymous classes...
+ TypeInstance cur;
+ ClassInstance cls;
+ if (this.symt.getType(id) != null) {
+ cur = this.symt.getType(id);
+ } else {
+ cur = new TypeInstance(Integer.toString(this.id++), TypeEnum.ERROR);
+ cur.addClassInstance(this.symt.getClass(id.substring(id.indexOf('_')+1)));
+
+ this.vapor += String.format(" %s = HeapAllocZ(%d)\n",
+ this.tf.alias(cur.getName()),
+ cur.getSize());
+ this.vapor += String.format(" if0 %s goto :error\n",
+ this.tf.alias(cur.getName()));
+
+ this.vapor += String.format(" [%s+%d] = %s\n",
+ this.tf.alias(cur.getName()),
+ 0,
+ id);
+ }
n.f1.accept(this, args);
String id2 = n.f2.accept(this, args);
String tp1 = Integer.toString(this.id++); // TypeFactory likes to know who it's renting to
String tp2 = "tp2";
-
- TypeInstance cur = this.symt.getType(id);
- // System.out.println("id: " + id);
- // System.out.println("id2: " + id2);
- // System.out.println("cur: " + this.symt.getType(id));
- int mtdIndex = cur.getClassInstance()
- .getMethods().indexOf(this.symt.getMethod(id2)) * 4;
+ int mtdIndex = cur.getClassInstance().getMethods()
+ .indexOf(this.symt.getMethod(id2)) * 4;
this.vapor += String.format(" %s = [%s+%d]\n",
this.tf.alias(tp1),
@@ -692,7 +708,7 @@ public class BoilSimp extends GJDepthFirst<String,TypeInstance> {
* f0 -> Expression()
* f1 -> ( ExpressionRest() )*
*/
- public String visit(ExpressionList n, TypeInstance args) {
+ public String visit(ExpressionList n, String args) {
String mod = "";
String rhs = n.f0.accept(this, args);
@@ -709,7 +725,7 @@ public class BoilSimp extends GJDepthFirst<String,TypeInstance> {
* f0 -> ","
* f1 -> Expression()
*/
- public String visit(ExpressionRest n, TypeInstance args) {
+ public String visit(ExpressionRest n, String args) {
String mod = "";
n.f0.accept(this, args);
String rhs = n.f1.accept(this, args);
@@ -732,7 +748,7 @@ public class BoilSimp extends GJDepthFirst<String,TypeInstance> {
* | NotExpression()
* | BracketExpression()
*/
- public String visit(PrimaryExpression n, TypeInstance args) {
+ public String visit(PrimaryExpression n, String args) {
String mod = "";
mod += n.f0.accept(this, args);
return mod;
@@ -741,7 +757,7 @@ public class BoilSimp extends GJDepthFirst<String,TypeInstance> {
/**
* f0 -> <INTEGER_LITERAL>
*/
- public String visit(IntegerLiteral n, TypeInstance args) {
+ public String visit(IntegerLiteral n, String args) {
String mod = "";
mod += n.f0.tokenImage;
return mod;
@@ -750,7 +766,7 @@ public class BoilSimp extends GJDepthFirst<String,TypeInstance> {
/**
* f0 -> "true"
*/
- public String visit(TrueLiteral n, TypeInstance args) {
+ public String visit(TrueLiteral n, String args) {
String mod = "";
n.f0.accept(this, args);
return mod;
@@ -759,7 +775,7 @@ public class BoilSimp extends GJDepthFirst<String,TypeInstance> {
/**
* f0 -> "false"
*/
- public String visit(FalseLiteral n, TypeInstance args) {
+ public String visit(FalseLiteral n, String args) {
String mod = "";
n.f0.accept(this, args);
return mod;
@@ -768,7 +784,7 @@ public class BoilSimp extends GJDepthFirst<String,TypeInstance> {
/**
* f0 -> <IDENTIFIER>
*/
- public String visit(Identifier n, TypeInstance args) {
+ public String visit(Identifier n, String args) {
String mod = "";
mod += n.f0.tokenImage;
return mod;
@@ -777,7 +793,7 @@ public class BoilSimp extends GJDepthFirst<String,TypeInstance> {
/**
* f0 -> "this"
*/
- public String visit(ThisExpression n, TypeInstance args) {
+ public String visit(ThisExpression n, String args) {
String mod = "";
n.f0.accept(this, args);
return mod;
@@ -790,7 +806,7 @@ public class BoilSimp extends GJDepthFirst<String,TypeInstance> {
* f3 -> Expression()
* f4 -> "]"
*/
- public String visit(ArrayAllocationExpression n, TypeInstance args) {
+ public String visit(ArrayAllocationExpression n, String args) {
String mod = "";
n.f0.accept(this, args);
n.f1.accept(this, args);
@@ -806,7 +822,7 @@ public class BoilSimp extends GJDepthFirst<String,TypeInstance> {
* f2 -> "("
* f3 -> ")"
*/
- public String visit(AllocationExpression n, TypeInstance args) {
+ public String visit(AllocationExpression n, String args) {
String mod = "";
n.f0.accept(this, args);
String cls = n.f1.accept(this, args);
@@ -823,7 +839,7 @@ public class BoilSimp extends GJDepthFirst<String,TypeInstance> {
* f0 -> "!"
* f1 -> Expression()
*/
- public String visit(NotExpression n, TypeInstance args) {
+ public String visit(NotExpression n, String args) {
String mod = "";
n.f0.accept(this, args);
n.f1.accept(this, args);
@@ -835,7 +851,7 @@ public class BoilSimp extends GJDepthFirst<String,TypeInstance> {
* f1 -> Expression()
* f2 -> ")"
*/
- public String visit(BracketExpression n, TypeInstance args) {
+ public String visit(BracketExpression n, String args) {
String mod = "";
n.f0.accept(this, args);
n.f1.accept(this, args);