From 1851f5e76018ec1df3b55dce6cc9a64c9497bf7a Mon Sep 17 00:00:00 2001 From: bd-912 Date: Fri, 26 Apr 2024 15:50:38 -0600 Subject: Rearrange directory structure --- boil/BoilVisitor.java | 1294 +++++++++++++++++++++++++++++++++++++++++ boil/TypeFactory.java | 51 ++ boil/library/BoilVisitor.java | 1294 ----------------------------------------- boil/library/TypeFactory.java | 51 -- boil/tests/BinaryTree.java | 334 ----------- boil/tests/BubbleSort.java | 93 --- boil/tests/Factorial.java | 16 - boil/tests/LinearSearch.java | 99 ---- boil/tests/LinkedList.java | 278 --------- boil/tests/MoreThan4.java | 29 - boil/tests/QuickSort.java | 112 ---- boil/tests/TreeVisitor.java | 374 ------------ boil/tests/ex29.java | 5 - boil/tests/ex30.java | 11 - boil/tests/ex31.java | 16 - boil/tests/ex32.java | 14 - boil/tests/ex33.java | 23 - boil/tests/ex34.java | 20 - boil/tests/ex35.java | 11 - boil/tests/ex36.java | 15 - boil/tests/ex37.java | 20 - boil/tests/ex38.java | 20 - boil/tests/ex39.java | 12 - boil/tests/ex40.java | 19 - boil/tests/ex41.java | 25 - boil/tests/ex42.java | 26 - boil/tests/ex43.java | 22 - boil/tests/ex44.java | 16 - boil/tests/ex45.java | 19 - boil/tests/ex46.java | 32 - boil/tests/ex47.java | 24 - boil/tests/ex48.java | 23 - boil/tests/ex49.java | 26 - boil/tests/ex50.java | 35 -- 34 files changed, 1345 insertions(+), 3114 deletions(-) create mode 100644 boil/BoilVisitor.java create mode 100644 boil/TypeFactory.java delete mode 100644 boil/library/BoilVisitor.java delete mode 100644 boil/library/TypeFactory.java delete mode 100644 boil/tests/BinaryTree.java delete mode 100644 boil/tests/BubbleSort.java delete mode 100644 boil/tests/Factorial.java delete mode 100644 boil/tests/LinearSearch.java delete mode 100644 boil/tests/LinkedList.java delete mode 100644 boil/tests/MoreThan4.java delete mode 100644 boil/tests/QuickSort.java delete mode 100644 boil/tests/TreeVisitor.java delete mode 100644 boil/tests/ex29.java delete mode 100644 boil/tests/ex30.java delete mode 100644 boil/tests/ex31.java delete mode 100644 boil/tests/ex32.java delete mode 100644 boil/tests/ex33.java delete mode 100644 boil/tests/ex34.java delete mode 100644 boil/tests/ex35.java delete mode 100644 boil/tests/ex36.java delete mode 100644 boil/tests/ex37.java delete mode 100644 boil/tests/ex38.java delete mode 100644 boil/tests/ex39.java delete mode 100644 boil/tests/ex40.java delete mode 100644 boil/tests/ex41.java delete mode 100644 boil/tests/ex42.java delete mode 100644 boil/tests/ex43.java delete mode 100644 boil/tests/ex44.java delete mode 100644 boil/tests/ex45.java delete mode 100644 boil/tests/ex46.java delete mode 100644 boil/tests/ex47.java delete mode 100644 boil/tests/ex48.java delete mode 100644 boil/tests/ex49.java delete mode 100644 boil/tests/ex50.java (limited to 'boil') diff --git a/boil/BoilVisitor.java b/boil/BoilVisitor.java new file mode 100644 index 0000000..e8bafe3 --- /dev/null +++ b/boil/BoilVisitor.java @@ -0,0 +1,1294 @@ +package boil; + +import syntaxtree.*; +import visitor.*; +import st.*; +import misc.*; +import java.util.*; + +public class BoilVisitor extends GJDepthFirst { + + private String vapor; + private TypeFactory tf; // the shared type generator + private int id; + private SymbolTable symt; + + private MethodInstance recentMethod = null; // the most recent method called + private ClassInstance recentClass = null; + + public BoilVisitor(SymbolTable symt) { + this.symt = symt; + this.vapor = ""; + this.tf = new TypeFactory(); + this.id = 0; + } + + public String getVapor() { + return this.vapor; + } + + public int getVarIndex(ClassInstance cls, TypeInstance type) { + /** + * Returns the index of the attribute in the class, or a negative number + * if it is not included. + */ + int attr_index = -1; + if (cls != null && + ((attr_index = cls.getLocals().indexOf(type)*4) >= 0)) { + attr_index += cls.getMethods().size() * 4; + } + return attr_index; + } + + public String memoryRead(String rhs) { + String lhs = this.tf.alias(this.getUniqueID()); + this.addVapor(String.format(" %s = %s\n", + lhs, + rhs)); + + return lhs; + } + + private void addVapor(String str) { + MinimalLogger.info(String.format("Adding \"%s\"", + str)); + this.vapor += str; + } + + private String getUniqueID() { + return Integer.toString(this.id++); + } + + private void resetIDs() { + MinimalLogger.info(String.format("Clearing tf for new function...")); + this.tf.reset(); + this.id = 0; + } + + // + // Auto class visitors--probably don't need to be overridden. + // + public String visit(NodeList n, String argu) { + String _ret=""; + int _count=0; + for ( Enumeration e = n.elements(); e.hasMoreElements(); ) { + _ret += e.nextElement().accept(this,argu); + _count++; + } + return _ret; + } + + public String visit(NodeListOptional n, String argu) { + if ( n.present() ) { + String _ret=""; + int _count=0; + for ( Enumeration e = n.elements(); e.hasMoreElements(); ) { + _ret += e.nextElement().accept(this,argu); + _count++; + } + return _ret; + } + else + return ""; + } + + public String visit(NodeOptional n, String argu) { + if ( n.present() ) + return n.node.accept(this,argu); + else + return ""; + } + + public String visit(NodeSequence n, String argu) { + String _ret=null; + int _count=0; + for ( Enumeration e = n.elements(); e.hasMoreElements(); ) { + e.nextElement().accept(this,argu); + _count++; + } + return _ret; + } + + public String visit(NodeToken n, String argu) { + return null; + } + + // + // User-generated visitor methods below + // + + /** + * f0 -> MainClass() + * f1 -> ( TypeDeclaration() )* + * f2 -> + */ + public String visit(Goal n, String argu) { + String _ret=null; + MinimalLogger.info(String.format("-> %s", + n.getClass().getSimpleName())); + /////////////////////////////////////////////////////////////// + n.f0.accept(this, argu); + n.f1.accept(this, argu); + n.f2.accept(this, argu); + + this.addVapor(String.format("func AllocArray(size)\n bytes = MulS(size 4)\n bytes = Add(bytes 4)\n v = HeapAllocZ(bytes)\n [v] = size\n ret v\n")); + /////////////////////////////////////////////////////////////// + MinimalLogger.info(String.format("<- %s with %s", + n.getClass().getSimpleName(), + _ret)); + return _ret; + } + + /** + * f0 -> "class" + * f1 -> Identifier() + * f2 -> "{" + * f3 -> "public" + * f4 -> "static" + * f5 -> "void" + * f6 -> "main" + * f7 -> "(" + * f8 -> "String" + * f9 -> "[" + * f10 -> "]" + * f11 -> Identifier() + * f12 -> ")" + * f13 -> "{" + * f14 -> ( VarDeclaration() )* + * f15 -> ( Statement() )* + * f16 -> "}" + * f17 -> "}" + */ + public String visit(MainClass n, String argu) { + String _ret=null; + this.tf.reset(); + String id = n.f1.f0.tokenImage; + MinimalLogger.info(String.format("-> %s (%s)", + n.getClass().getSimpleName(), + id)); + this.symt.setActive(TypeEnum.classname, symt.getClass(id)); + this.symt.setActive(TypeEnum.method, symt.getMethod(n.f6.tokenImage)); + /////////////////////////////////////////////////////////////// + this.addVapor("func Main()\n"); + n.f1.accept(this, argu); + n.f11.accept(this, argu); + n.f14.accept(this, argu); + n.f15.accept(this, argu); + this.addVapor(" ret\n\n"); + /////////////////////////////////////////////////////////////// + this.symt.removeActive(TypeEnum.method); + symt.removeActive(TypeEnum.classname); + MinimalLogger.info(String.format("<- %s (%s)", + n.getClass().getSimpleName(), + id)); + return _ret; + } + + /** + * f0 -> ClassDeclaration() + * | ClassExtendsDeclaration() + */ + public String visit(TypeDeclaration n, String argu) { + String _ret=null; + MinimalLogger.info(String.format("-> %s", + n.getClass().getSimpleName())); + /////////////////////////////////////////////////////////////// + n.f0.accept(this, argu); + MinimalLogger.info(String.format("<- %s with %s", + n.getClass().getSimpleName(), + _ret)); + /////////////////////////////////////////////////////////////// + return _ret; + } + + /** + * f0 -> "class" + * f1 -> Identifier() + * f2 -> "{" + * f3 -> ( VarDeclaration() )* + * f4 -> ( MethodDeclaration() )* + * f5 -> "}" + */ + public String visit(ClassDeclaration n, String argu) { + String _ret=null; + String id = n.f1.f0.tokenImage; + MinimalLogger.info(String.format("-> %s (%s)", + n.getClass().getSimpleName(), + id)); + this.symt.setActive(TypeEnum.classname, symt.getClass(id)); + /////////////////////////////////////////////////////////////// + this.addVapor(String.format("const functable_%s\n", id)); + for (MethodInstance mtd : this.symt.getClass(id).getMethods()) { + this.addVapor(String.format(" :%s_%s\n", mtd.getParentClass().getName(), mtd)); + } + this.addVapor("\n"); + // n.f3.accept(this, argu); + n.f4.accept(this, argu); + /////////////////////////////////////////////////////////////// + this.symt.removeActive(TypeEnum.classname); + MinimalLogger.info(String.format("<- %s (%s)", + n.getClass().getSimpleName(), + id)); + return _ret; + } + + /** + * f0 -> "class" + * f1 -> Identifier() + * f2 -> "extends" + * f3 -> Identifier() + * f4 -> "{" + * f5 -> ( VarDeclaration() )* + * f6 -> ( MethodDeclaration() )* + * f7 -> "}" + */ + public String visit(ClassExtendsDeclaration n, String argu) { + String _ret=null; + String id = n.f1.f0.tokenImage; + MinimalLogger.info(String.format("-> %s (%s)", + n.getClass().getSimpleName(), + id)); + this.symt.setActive(TypeEnum.classname, symt.getClass(id)); + /////////////////////////////////////////////////////////////// + this.addVapor(String.format("const functable_%s\n", id)); + for (MethodInstance mtd : this.symt.getClass(id).getMethods()) { + this.addVapor(String.format(" :%s_%s\n", mtd.getParentClass().getName(), mtd)); + } + this.addVapor("\n"); + // n.f3.accept(this, argu); + // n.f5.accept(this, argu); + n.f6.accept(this, argu); + /////////////////////////////////////////////////////////////// + this.symt.removeActive(TypeEnum.classname); + MinimalLogger.info(String.format("<- %s (%s)", + n.getClass().getSimpleName(), + id)); + return _ret; + } + + /** + * f0 -> Type() + * f1 -> Identifier() + * f2 -> ";" + */ + public String visit(VarDeclaration n, String argu) { + String _ret=null; + String id = n.f1.f0.tokenImage; + MinimalLogger.info(String.format("-> %s (%s)", + n.getClass().getSimpleName(), + id)); + /////////////////////////////////////////////////////////////// + // if (t.getClassInstance() != null) + // this.addVapor(String.format(" %s = HeapAllocZ(%d)\n", + // this.tf.alias(t.getName()), + // t.getSize())); + n.f0.accept(this, argu); + /////////////////////////////////////////////////////////////// + MinimalLogger.info(String.format("<- %s (%s)", + n.getClass().getSimpleName(), + id)); + return _ret; + } + + /** + * f0 -> "public" + * f1 -> Type() + * f2 -> Identifier() + * f3 -> "(" + * f4 -> ( FormalParameterList() )? + * f5 -> ")" + * f6 -> "{" + * f7 -> ( VarDeclaration() )* + * f8 -> ( Statement() )* + * f9 -> "return" + * f10 -> Expression() + * f11 -> ";" + * f12 -> "}" + */ + public String visit(MethodDeclaration n, String argu) { + String _ret=null; + this.tf.reset(); + String id = n.f2.f0.tokenImage; + MinimalLogger.info(String.format("-> %s (%s)", + n.getClass().getSimpleName(), + id)); + this.symt.setActive(TypeEnum.method, symt.getMethod(id)); + /////////////////////////////////////////////////////////////// + // n.f1.accept(this, argu); + this.addVapor(String.format("func %s_%s(this ", + this.symt.getActive(TypeEnum.classname), + id)); + String para = n.f4.accept(this, argu); + this.addVapor(String.format("%s)\n", para)); + + n.f7.accept(this, argu); + n.f8.accept(this, argu); + String ret = n.f10.accept(this, argu); + String retID = this.getUniqueID(); + this.addVapor(String.format(" %s = %s\n ret %s\n\n", + this.tf.alias(retID), + ret, + this.tf.alias(retID))); + /////////////////////////////////////////////////////////////// + this.symt.removeActive(TypeEnum.method); + MinimalLogger.info(String.format("<- %s (%s)", + n.getClass().getSimpleName(), + id)); + return _ret; + } + + /** + * f0 -> FormalParameter() + * f1 -> ( FormalParameterRest() )* + */ + public String visit(FormalParameterList n, String argu) { + String _ret=""; + MinimalLogger.info(String.format("-> %s", + n.getClass().getSimpleName())); + /////////////////////////////////////////////////////////////// + _ret += n.f0.accept(this, argu); + _ret += n.f1.accept(this, argu); + /////////////////////////////////////////////////////////////// + MinimalLogger.info(String.format("<- %s with %s", + n.getClass().getSimpleName(), + _ret)); + return _ret; + } + + /** + * f0 -> Type() + * f1 -> Identifier() + */ + public String visit(FormalParameter n, String argu) { + String _ret=""; + String id = n.f1.f0.tokenImage; + MinimalLogger.info(String.format("-> %s (%s)", + n.getClass().getSimpleName(), + id)); + /////////////////////////////////////////////////////////////// + // n.f0.accept(this, argu); + _ret += n.f1.accept(this,argu) + " "; + /////////////////////////////////////////////////////////////// + MinimalLogger.info(String.format("<- %s (%s)", + n.getClass().getSimpleName(), + id)); + return _ret; + } + + /** + * f0 -> "," + * f1 -> FormalParameter() + */ + public String visit(FormalParameterRest n, String argu) { + String _ret=""; + MinimalLogger.info(String.format("-> %s", + n.getClass().getSimpleName())); + /////////////////////////////////////////////////////////////// + _ret += n.f1.accept(this, argu); + /////////////////////////////////////////////////////////////// + MinimalLogger.info(String.format("<- %s with %s", + n.getClass().getSimpleName(), + _ret)); + return _ret; + } + + /** + * f0 -> ArrayType() + * | BooleanType() + * | IntegerType() + * | Identifier() + */ + public String visit(Type n, String argu) { + String _ret=null; + MinimalLogger.info(String.format("-> %s", + n.getClass().getSimpleName())); + /////////////////////////////////////////////////////////////// + n.f0.accept(this, argu); + /////////////////////////////////////////////////////////////// + MinimalLogger.info(String.format("<- %s with %s", + n.getClass().getSimpleName(), + _ret)); + return _ret; + } + + /** + * f0 -> "int" + * f1 -> "[" + * f2 -> "]" + */ + public String visit(ArrayType n, String argu) { + String _ret=null; + MinimalLogger.info(String.format("-> %s", + n.getClass().getSimpleName())); + /////////////////////////////////////////////////////////////// + /////////////////////////////////////////////////////////////// + MinimalLogger.info(String.format("<- %s with %s", + n.getClass().getSimpleName(), + _ret)); + return _ret; + } + + /** + * f0 -> "boolean" + */ + public String visit(BooleanType n, String argu) { + String _ret=null; + MinimalLogger.info(String.format("-> %s", + n.getClass().getSimpleName())); + /////////////////////////////////////////////////////////////// + /////////////////////////////////////////////////////////////// + MinimalLogger.info(String.format("<- %s with %s", + n.getClass().getSimpleName(), + _ret)); + return _ret; + } + + /** + * f0 -> "int" + */ + public String visit(IntegerType n, String argu) { + String _ret=null; + MinimalLogger.info(String.format("-> %s", + n.getClass().getSimpleName())); + /////////////////////////////////////////////////////////////// + /////////////////////////////////////////////////////////////// + MinimalLogger.info(String.format("<- %s with %s", + n.getClass().getSimpleName(), + _ret)); + return _ret; + } + + /** + * f0 -> Block() + * | AssignmentStatement() + * | ArrayAssignmentStatement() + * | IfStatement() + * | WhileStatement() + * | PrintStatement() + */ + public String visit(Statement n, String argu) { + String _ret=""; + MinimalLogger.info(String.format("-> %s", + n.getClass().getSimpleName())); + /////////////////////////////////////////////////////////////// + _ret += n.f0.accept(this, argu); + /////////////////////////////////////////////////////////////// + MinimalLogger.info(String.format("<- %s with %s", + n.getClass().getSimpleName(), + _ret)); + return _ret; + } + + /** + * f0 -> "{" + * f1 -> ( Statement() )* + * f2 -> "}" + */ + public String visit(Block n, String argu) { + String _ret=null; + MinimalLogger.info(String.format("-> %s", + n.getClass().getSimpleName())); + /////////////////////////////////////////////////////////////// + n.f1.accept(this, argu); + /////////////////////////////////////////////////////////////// + MinimalLogger.info(String.format("<- %s with %s", + n.getClass().getSimpleName(), + _ret)); + return _ret; + } + + /** + * f0 -> Identifier() + * f1 -> "=" + * f2 -> Expression() + * f3 -> ";" + */ + public String visit(AssignmentStatement n, String argu) { + String _ret=null; + String id = n.f0.f0.tokenImage; + MinimalLogger.info(String.format("-> %s", + n.getClass().getSimpleName())); + /////////////////////////////////////////////////////////////// + String lhs = n.f0.accept(this, argu); + String expr = n.f2.accept(this, argu); + + int attr_index = 0; + TypeInstance t; + if ((t = this.symt.getType(lhs)) != null) { + // memory store + ClassInstance cur = (ClassInstance) this.symt.getActive(TypeEnum.classname); + attr_index = getVarIndex(cur, t); + lhs = String.format("[this+%d]", attr_index); + } + + + this.addVapor(String.format(" %s = %s\n", + lhs, + expr)); + /////////////////////////////////////////////////////////////// + MinimalLogger.info(String.format("<- %s", + n.getClass().getSimpleName())); + return _ret; + } + + /** + * f0 -> Identifier() + * f1 -> "[" + * f2 -> Expression() + * f3 -> "]" + * f4 -> "=" + * f5 -> Expression() + * f6 -> ";" + */ + public String visit(ArrayAssignmentStatement n, String argu) { + String _ret=null; + MinimalLogger.info(String.format("-> %s", + n.getClass().getSimpleName())); + /////////////////////////////////////////////////////////////// + String arrID = this.tf.alias(this.getUniqueID()); + String arr = n.f0.accept(this, argu); + this.addVapor(String.format(" %s = %s\n", + arrID, + arr)); + + String indexID = this.tf.alias(this.getUniqueID()); + this.addVapor(String.format(" %s = MulS(%s %s)\n", + indexID, + n.f2.accept(this, argu), + 4)); + this.addVapor(String.format(" %s = Add(%s %s)\n", + indexID, + indexID, + 4)); + this.addVapor(String.format(" %s = Add(%s %s)\n", + indexID, + arrID, + indexID)); + + String expr = n.f5.accept(this, argu); + + this.addVapor(String.format(" [%s] = %s\n", + indexID, + expr)); + /////////////////////////////////////////////////////////////// + MinimalLogger.info(String.format("<- %s with %s", + n.getClass().getSimpleName(), + _ret)); + return _ret; + } + + /** + * f0 -> "if" + * f1 -> "(" + * f2 -> Expression() + * f3 -> ")" + * f4 -> Statement() + * f5 -> "else" + * f6 -> Statement() + */ + public String visit(IfStatement n, String argu) { + String _ret=null; + MinimalLogger.info(String.format("-> %s", + n.getClass().getSimpleName())); + /////////////////////////////////////////////////////////////// + String ifID = this.getUniqueID(); + String cond = n.f2.accept(this, argu); + + this.addVapor(String.format(" %s = %s\n", + this.tf.alias(ifID), + cond)); + this.addVapor(String.format(" if0 %s goto :if%s_else\nif%s_body:\n", + this.tf.alias(ifID), + ifID, + ifID)); + + n.f4.accept(this, argu); + + this.addVapor(String.format(" goto :if%s_end\nif%s_else:\n", + ifID, + ifID)); + + n.f6.accept(this, argu); + + this.addVapor(String.format("if%s_end:\n", + ifID)); + /////////////////////////////////////////////////////////////// + MinimalLogger.info(String.format("<- %s with %s", + n.getClass().getSimpleName(), + _ret)); + return _ret; + } + + /** + * f0 -> "while" + * f1 -> "(" + * f2 -> Expression() + * f3 -> ")" + * f4 -> Statement() + */ + public String visit(WhileStatement n, String argu) { + String _ret=null; + MinimalLogger.info(String.format("-> %s", + n.getClass().getSimpleName())); + /////////////////////////////////////////////////////////////// + String whileID = this.getUniqueID(); + + this.addVapor(String.format("while%s_test:\n", + whileID)); + String cond = n.f2.accept(this, argu); + + String condID = this.getUniqueID(); + this.addVapor(String.format(" %s = %s\n", + this.tf.alias(condID), + cond)); + this.addVapor(String.format(" if0 %s goto :while%s_end\nwhile%s_body:\n", + this.tf.alias(condID), + whileID, + whileID)); + + n.f4.accept(this, argu); + + this.addVapor(String.format(" goto :while%s_test\nwhile%s_end:\n", + whileID, + whileID)); + /////////////////////////////////////////////////////////////// + MinimalLogger.info(String.format("<- %s with %s", + n.getClass().getSimpleName(), + _ret)); + return _ret; + } + + /** + * f0 -> "System.out.println" + * f1 -> "(" + * f2 -> Expression() + * f3 -> ")" + * f4 -> ";" + */ + public String visit(PrintStatement n, String argu) { + String _ret=null; + MinimalLogger.info(String.format("-> %s", + n.getClass().getSimpleName())); + /////////////////////////////////////////////////////////////// + String printTemp = this.getUniqueID(); + String expr = n.f2.accept(this, argu); + + this.addVapor(String.format(" %s = %s\n", + this.tf.alias(printTemp), + expr)); + + this.addVapor(String.format(" PrintIntS(%s)\n", + this.tf.alias(printTemp))); + + /////////////////////////////////////////////////////////////// + MinimalLogger.info(String.format("<- %s with %s", + n.getClass().getSimpleName(), + _ret)); + return _ret; + } + + /** + * f0 -> AndExpression() + * | CompareExpression() + * | PlusExpression() + * | MinusExpression() + * | TimesExpression() + * | ArrayLookup() + * | ArrayLength() + * | MessageSend() + * | PrimaryExpression() + */ + // Expressions return a TYPE alias which is equal to the expression! + public String visit(Expression n, String argu) { + String _ret=""; + MinimalLogger.info(String.format("-> %s", + n.getClass().getSimpleName())); + /////////////////////////////////////////////////////////////// + _ret += n.f0.accept(this, argu); + /////////////////////////////////////////////////////////////// + MinimalLogger.info(String.format("<- %s with %s", + n.getClass().getSimpleName(), + _ret)); + return _ret; + } + + /** + * f0 -> PrimaryExpression() + * f1 -> "&&" + * f2 -> PrimaryExpression() + */ + // Expressions return a TYPE alias which is equal to the expression! + public String visit(AndExpression n, String argu) { + String _ret=""; + MinimalLogger.info(String.format("-> %s", + n.getClass().getSimpleName())); + _ret += this.tf.alias(this.getUniqueID()); + /////////////////////////////////////////////////////////////// + String oper1 = this.memoryRead(n.f0.accept(this, argu)); + String oper2 = this.memoryRead(n.f2.accept(this, argu)); + String one = this.tf.alias(this.getUniqueID()); + this.addVapor(String.format(" %s = Eq(1 %s)\n", + one, + oper1)); + String two = this.tf.alias(this.getUniqueID()); + this.addVapor(String.format(" %s = Eq(1 %s)\n", + two, + oper2)); + this.addVapor(String.format(" %s = Eq(%s %s)\n", + _ret, + one, + two)); + /////////////////////////////////////////////////////////////// + MinimalLogger.info(String.format("<- %s with %s", + n.getClass().getSimpleName(), + _ret)); + return _ret; + } + + /** + * f0 -> PrimaryExpression() + * f1 -> "<" + * f2 -> PrimaryExpression() + */ + // Expressions return a TYPE alias which is equal to the expression! + public String visit(CompareExpression n, String argu) { + String _ret=""; + MinimalLogger.info(String.format("-> %s", + n.getClass().getSimpleName())); + _ret += this.tf.alias(this.getUniqueID()); + /////////////////////////////////////////////////////////////// + String oper1 = this.memoryRead(n.f0.accept(this, argu)); + String oper2 = this.memoryRead(n.f2.accept(this, argu)); + this.addVapor(String.format(" %s = LtS(%s %s)\n", + _ret, + oper1, + oper2)); + /////////////////////////////////////////////////////////////// + MinimalLogger.info(String.format("<- %s with %s", + n.getClass().getSimpleName(), + _ret)); + return _ret; + } + + /** + * f0 -> PrimaryExpression() + * f1 -> "+" + * f2 -> PrimaryExpression() + */ + // Expressions return a TYPE alias which is equal to the expression! + public String visit(PlusExpression n, String argu) { + String _ret=""; + MinimalLogger.info(String.format("-> %s", + n.getClass().getSimpleName())); + _ret += this.tf.alias(this.getUniqueID()); + /////////////////////////////////////////////////////////////// + String oper1 = this.memoryRead(n.f0.accept(this, argu)); + String oper2 = this.memoryRead(n.f2.accept(this, argu)); + this.addVapor(String.format(" %s = Add(%s %s)\n", + _ret, + oper1, + oper2)); + /////////////////////////////////////////////////////////////// + MinimalLogger.info(String.format("<- %s with %s", + n.getClass().getSimpleName(), + _ret)); + return _ret; + } + + /** + * f0 -> PrimaryExpression() + * f1 -> "-" + * f2 -> PrimaryExpression() + */ + // Expressions return a TYPE alias which is equal to the expression! + public String visit(MinusExpression n, String argu) { + String _ret=""; + MinimalLogger.info(String.format("-> %s", + n.getClass().getSimpleName())); + _ret += this.tf.alias(this.getUniqueID()); + /////////////////////////////////////////////////////////////// + String oper1 = this.memoryRead(n.f0.accept(this, argu)); + String oper2 = this.memoryRead(n.f2.accept(this, argu)); + this.addVapor(String.format(" %s = Sub(%s %s)\n", + _ret, + oper1, + oper2)); + /////////////////////////////////////////////////////////////// + MinimalLogger.info(String.format("<- %s with %s", + n.getClass().getSimpleName(), + _ret)); + return _ret; + } + + /** + * f0 -> PrimaryExpression() + * f1 -> "*" + * f2 -> PrimaryExpression() + */ + // Expressions return a TYPE alias which is equal to the expression! + public String visit(TimesExpression n, String argu) { + String _ret=""; + MinimalLogger.info(String.format("-> %s", + n.getClass().getSimpleName())); + _ret += this.tf.alias(this.getUniqueID()); + /////////////////////////////////////////////////////////////// + String oper1 = this.memoryRead(n.f0.accept(this, argu)); + String oper2 = this.memoryRead(n.f2.accept(this, argu)); + this.addVapor(String.format(" %s = MulS(%s %s)\n", + _ret, + oper1, + oper2)); + /////////////////////////////////////////////////////////////// + MinimalLogger.info(String.format("<- %s with %s", + n.getClass().getSimpleName(), + _ret)); + return _ret; + } + + /** + * f0 -> PrimaryExpression() + * f1 -> "[" + * f2 -> PrimaryExpression() + * f3 -> "]" + */ + // Expressions return a TYPE alias which is equal to the expression! + public String visit(ArrayLookup n, String argu) { + String _ret=""; + MinimalLogger.info(String.format("-> %s", + n.getClass().getSimpleName())); + _ret += this.tf.alias(this.getUniqueID()); + /////////////////////////////////////////////////////////////// + String arrID = this.tf.alias(this.getUniqueID()); + String arr = n.f0.accept(this, argu); + String indexID = this.tf.alias(this.getUniqueID()); + this.addVapor(String.format(" %s = %s\n", + arrID, + arr)); + this.addVapor(String.format(" %s = MulS(%s %s)\n", + indexID, + n.f2.accept(this, argu), + 4)); + this.addVapor(String.format(" %s = Add(%s %s)\n", + indexID, + indexID, + 4)); + this.addVapor(String.format(" %s = Add(%s %s)\n", + indexID, + arrID, + indexID)); + this.addVapor(String.format(" %s = [%s]\n", + _ret, + indexID)); + /////////////////////////////////////////////////////////////// + MinimalLogger.info(String.format("<- %s with %s", + n.getClass().getSimpleName(), + _ret)); + return _ret; + } + + /** + * f0 -> PrimaryExpression() + * f1 -> "." + * f2 -> "length" + */ + // Expressions return a TYPE alias which is equal to the expression! + public String visit(ArrayLength n, String argu) { + String _ret=""; + MinimalLogger.info(String.format("-> %s", + n.getClass().getSimpleName())); + _ret += this.tf.alias(this.getUniqueID()); + /////////////////////////////////////////////////////////////// + String arrID = this.tf.alias(this.getUniqueID()); + String arr = n.f0.accept(this, argu); + this.addVapor(String.format(" %s = %s\n", + arrID, + arr)); + this.addVapor(String.format(" %s = [%s+0]\n", + _ret, + arrID)); + /////////////////////////////////////////////////////////////// + MinimalLogger.info(String.format("<- %s with %s", + n.getClass().getSimpleName(), + _ret)); + return _ret; + } + + /** + * f0 -> PrimaryExpression() + * f1 -> "." + * f2 -> Identifier() + * f3 -> "(" + * f4 -> ( ExpressionList() )? + * f5 -> ")" + */ + // Expressions return a TYPE alias which is equal to the expression! + public String visit(MessageSend n, String argu) { + String _ret=""; + MinimalLogger.info(String.format("-> %s", + n.getClass().getSimpleName())); + /////////////////////////////////////////////////////////////// + _ret += this.tf.alias(this.getUniqueID()); + String mtd = n.f2.f0.tokenImage; + String rhs; + TypeInstance t; + switch (n.f0.f0.which) { + case 3: + MinimalLogger.info("Message send found an IDENTIFIER"); + rhs = ((Identifier) n.f0.f0.choice).f0.tokenImage; + t = this.symt.getType(rhs); + if (t == null) + t = this.symt.getTypeAttr(rhs); + rhs = n.f0.accept(this, argu); + this.addVapor(String.format(" %s = %s\n", + this.tf.alias(t.getName()), + rhs)); + break; + case 4: + // we'll do everything here and exit the function + MinimalLogger.info("Message send found THIS"); + rhs = n.f0.accept(this, argu); + rhs = this.tf.alias(this.getUniqueID()); + this.addVapor(String.format(" %s = [this]\n", + rhs)); + ClassInstance cur = (ClassInstance) this.symt.getActive(TypeEnum.classname); + MinimalLogger.info("Calculating method index to call..."); + int mtdIndex = cur.getMethods() + .indexOf(this.symt.getMethod(mtd, cur)) * 4; + + this.addVapor(n.f4.accept(this, argu)); + this.addVapor(String.format(" %s = [%s+%d]\n", + rhs, + rhs, + mtdIndex)); + this.addVapor(String.format(" %s = call %s(this", + _ret, + rhs)); + this.addVapor(String.format(" %s)\n", + this.tf.retrieveRecentList(this.symt.getMethod(mtd, cur) + .getArguments() + .size()))); + this.recentMethod = this.symt.getMethod(mtd, cur); + return _ret; + case 6: + MinimalLogger.info("Message send found ANONYMOUS"); + // expand the entire object out! + rhs = n.f0.accept(this, argu); + t = new TypeInstance(rhs, TypeEnum.ERROR, + (MethodInstance) this.symt.getActive(TypeEnum.method), + (ClassInstance) this.symt.getActive(TypeEnum.classname)); + t.addClassInstance(this.recentClass); + this.addVapor(String.format(" %s = %s\n", + this.tf.alias(t.getName()), + rhs)); + break; + case 8: + MinimalLogger.info("Message send found BRACKET"); + rhs = n.f0.accept(this, argu); + ClassInstance cls = this.recentMethod.getReturn(); + t = new TypeInstance(this.getUniqueID(), TypeEnum.ERROR, + (MethodInstance) this.symt.getActive(TypeEnum.method), + (ClassInstance) this.symt.getActive(TypeEnum.classname)); + this.addVapor(String.format(" %s = %s\n", + this.tf.alias(t.getName()), + rhs)); + t.addClassInstance(cls); + break; + default: + MinimalLogger.severe(String.format("Message send found UNKNOWN %s", + n.f0.f0.choice.toString())); + rhs = null; + t = null; + } + + String tp1 = this.tf.alias(this.getUniqueID()); + String tp2 = this.tf.alias(this.getUniqueID()); + + this.addVapor(String.format(" %s = [%s+%d]\n", + tp1, + this.tf.alias(t.getName()), + 0)); + + MinimalLogger.info("Calculating method index to call..."); + MinimalLogger.severe("t: " + t); + MinimalLogger.severe("mtd: " + mtd); + MinimalLogger.severe("t.getClassInstance() " + t.getClassInstance()); + MinimalLogger.severe("t.getClassInstance().getMethods() " + t.getClassInstance().getMethods().toString()); + this.recentMethod = this.symt.getMethod(mtd, t.getClassInstance()); + int mtdIndex = t.getClassInstance().getMethods() + .indexOf(this.symt.getMethod(mtd, t.getClassInstance())) * 4; + + this.addVapor(String.format(" %s = [%s+%d]\n", + tp2, + tp1, + mtdIndex)); + + this.addVapor(n.f4.accept(this, argu)); + + this.addVapor(String.format(" %s = call %s(%s", + _ret, + tp2, + this.tf.alias(t.getName()))); + + this.addVapor(String.format(" %s)\n", + this.tf.retrieveRecentList(this.symt.getMethod(mtd, t.getClassInstance()) + .getArguments() + .size()))); + /////////////////////////////////////////////////////////////// + MinimalLogger.info(String.format("<- %s with %s", + n.getClass().getSimpleName(), + _ret)); + return _ret; + } + + /** + * f0 -> Expression() + * f1 -> ( ExpressionRest() )* + */ + public String visit(ExpressionList n, String argu) { + String _ret=""; + MinimalLogger.info(String.format("-> %s", + n.getClass().getSimpleName())); + /////////////////////////////////////////////////////////////// + String rhs = n.f0.accept(this, argu); + _ret += String.format(" %s = %s\n", + this.tf.alias(this.getUniqueID()), + rhs); + _ret += n.f1.accept(this, argu); + /////////////////////////////////////////////////////////////// + MinimalLogger.info(String.format("<- %s with %s", + n.getClass().getSimpleName(), + _ret)); + return _ret; + } + + /** + * f0 -> "," + * f1 -> Expression() + */ + public String visit(ExpressionRest n, String argu) { + String _ret=""; + MinimalLogger.info(String.format("-> %s", + n.getClass().getSimpleName())); + /////////////////////////////////////////////////////////////// + String rhs = n.f1.accept(this, argu); + _ret += String.format(" %s = %s\n", + this.tf.alias(this.getUniqueID()), + rhs); + /////////////////////////////////////////////////////////////// + MinimalLogger.info(String.format("<- %s with %s", + n.getClass().getSimpleName(), + _ret)); + return _ret; + } + + /** + * f0 -> IntegerLiteral() + * | TrueLiteral() + * | FalseLiteral() + * | Identifier() + * | ThisExpression() + * | ArrayAllocationExpression() + * | AllocationExpression() + * | NotExpression() + * | BracketExpression() + */ + public String visit(PrimaryExpression n, String argu) { + String _ret=""; + MinimalLogger.info(String.format("-> %s", + n.getClass().getSimpleName())); + /////////////////////////////////////////////////////////////// + _ret += n.f0.accept(this, argu); + /////////////////////////////////////////////////////////////// + MinimalLogger.info(String.format("<- %s with %s", + n.getClass().getSimpleName(), + _ret)); + return _ret; + } + + /** + * f0 -> + */ + public String visit(IntegerLiteral n, String argu) { + String _ret=""; + MinimalLogger.info(String.format("-> %s", + n.getClass().getSimpleName())); + /////////////////////////////////////////////////////////////// + _ret += n.f0.tokenImage; + /////////////////////////////////////////////////////////////// + MinimalLogger.info(String.format("<- %s with %s", + n.getClass().getSimpleName(), + _ret)); + return _ret; + } + + /** + * f0 -> "true" + */ + public String visit(TrueLiteral n, String argu) { + String _ret=""; + MinimalLogger.info(String.format("-> %s", + n.getClass().getSimpleName())); + /////////////////////////////////////////////////////////////// + _ret += "1"; + /////////////////////////////////////////////////////////////// + MinimalLogger.info(String.format("<- %s with %s", + n.getClass().getSimpleName(), + _ret)); + return _ret; + } + + /** + * f0 -> "false" + */ + public String visit(FalseLiteral n, String argu) { + String _ret=""; + MinimalLogger.info(String.format("-> %s", + n.getClass().getSimpleName())); + /////////////////////////////////////////////////////////////// + _ret += "0"; + /////////////////////////////////////////////////////////////// + MinimalLogger.info(String.format("<- %s with %s", + n.getClass().getSimpleName(), + _ret)); + return _ret; + } + + /** + * f0 -> + */ + public String visit(Identifier n, String argu) { + String _ret=""; + String id = n.f0.tokenImage; + MinimalLogger.info(String.format("-> %s (%s)", + n.getClass().getSimpleName(), + id)); + /////////////////////////////////////////////////////////////// + ClassInstance cur = (ClassInstance) this.symt.getActive(TypeEnum.classname); + // TypeInstance localt = this.symt.getType(id); + TypeInstance t = this.symt.getTypeAttr(id); + if (cur.getLocals().contains(t)) { + MinimalLogger.info(String.format("Identifier found a class variable %s", + id)); + int attr_index = getVarIndex(cur, t); + _ret += String.format("[this+%d]", attr_index); + } else { + _ret += this.tf.alias(id); + } + /////////////////////////////////////////////////////////////// + MinimalLogger.info(String.format("<- %s (%s) with %s", + n.getClass().getSimpleName(), + id, + _ret)); + return _ret; + } + + /** + * f0 -> "this" + */ + public String visit(ThisExpression n, String argu) { + String _ret=""; + MinimalLogger.info(String.format("-> %s", + n.getClass().getSimpleName())); + /////////////////////////////////////////////////////////////// + _ret += "this"; + /////////////////////////////////////////////////////////////// + MinimalLogger.info(String.format("<- %s with %s", + n.getClass().getSimpleName(), + _ret)); + return _ret; + } + + /** + * f0 -> "new" + * f1 -> "int" + * f2 -> "[" + * f3 -> Expression() + * f4 -> "]" + */ + public String visit(ArrayAllocationExpression n, String argu) { + String _ret=""; + MinimalLogger.info(String.format("-> %s", + n.getClass().getSimpleName())); + /////////////////////////////////////////////////////////////// + String len = n.f3.accept(this, argu); + String aAllocID = this.tf.alias(this.getUniqueID()); + this.addVapor(String.format(" %s = call :AllocArray(%s)\n", + aAllocID, + len)); + + _ret += aAllocID; + /////////////////////////////////////////////////////////////// + MinimalLogger.info(String.format("<- %s with %s", + n.getClass().getSimpleName(), + _ret)); + return _ret; + } + + /** + * f0 -> "new" + * f1 -> Identifier() + * f2 -> "(" + * f3 -> ")" + */ + public String visit(AllocationExpression n, String argu) { + String _ret=""; + String id = n.f1.f0.tokenImage; + MinimalLogger.info(String.format("-> %s", + n.getClass().getSimpleName())); + _ret += this.tf.alias(this.getUniqueID()); + /////////////////////////////////////////////////////////////// + ClassInstance cls = this.symt.getClass(id); + this.recentClass = cls; + this.addVapor(String.format(" %s = HeapAllocZ(%d)\n", + _ret, + cls.getSize())); + + this.addVapor(String.format(" [%s+0] = :functable_%s\n", + _ret, + id)); + /////////////////////////////////////////////////////////////// + MinimalLogger.info(String.format("<- %s with %s", + n.getClass().getSimpleName(), + _ret)); + return _ret; + } + + /** + * f0 -> "!" + * f1 -> Expression() + */ + public String visit(NotExpression n, String argu) { + String _ret=""; + MinimalLogger.info(String.format("-> %s", + n.getClass().getSimpleName())); + _ret += this.tf.alias(this.getUniqueID()); + /////////////////////////////////////////////////////////////// + this.addVapor(String.format(" %s = Eq(%s 0)\n", + _ret, + n.f1.accept(this, argu))); + /////////////////////////////////////////////////////////////// + MinimalLogger.info(String.format("<- %s with %s", + n.getClass().getSimpleName(), + _ret)); + return _ret; + } + + /** + * f0 -> "(" + * f1 -> Expression() + * f2 -> ")" + */ + public String visit(BracketExpression n, String argu) { + String _ret=""; + MinimalLogger.info(String.format("-> %s", + n.getClass().getSimpleName())); + /////////////////////////////////////////////////////////////// + _ret += n.f1.accept(this, argu); + /////////////////////////////////////////////////////////////// + MinimalLogger.info(String.format("<- %s with %s", + n.getClass().getSimpleName(), + _ret)); + return _ret; + } + +} diff --git a/boil/TypeFactory.java b/boil/TypeFactory.java new file mode 100644 index 0000000..d5b61f3 --- /dev/null +++ b/boil/TypeFactory.java @@ -0,0 +1,51 @@ +package boil; + +import misc.*; +import java.util.HashMap; + +public class TypeFactory { + + private int type_num; + private HashMap map; + + public void reset() { + this.type_num = 0; + this.map = new HashMap<>(); + } + + public String alias(String t) { + /** + * Given a TypeInstance, return the designated + * vapor alias. If the alias does not exist, create it. + */ + String alias; + if ((alias = this.map.get(t)) == null) { + alias = String.format("t.%d", this.type_num++); + MinimalLogger.info(String.format("Created alias %s for %s...", + alias, + t)); + + this.map.put(t, alias); + } + + return alias; + } + + public String retrieveRecentList(int x) { + /** + * Given int x, retrieve a space-delimited + * list of the x most recent entries. + */ + String rtn = ""; + if (x > 0) { + rtn += String.format("t.%d", + type_num-x); + for (int i = type_num-(x-1); i < type_num; ++i) { + rtn += String.format(" t.%d", + i); + } + } + + return rtn; + } +} diff --git a/boil/library/BoilVisitor.java b/boil/library/BoilVisitor.java deleted file mode 100644 index 001b6e6..0000000 --- a/boil/library/BoilVisitor.java +++ /dev/null @@ -1,1294 +0,0 @@ -package boil.library; - -import syntaxtree.*; -import visitor.*; -import st.*; -import misc.*; -import java.util.*; - -public class BoilVisitor extends GJDepthFirst { - - private String vapor; - private TypeFactory tf; // the shared type generator - private int id; - private SymbolTable symt; - - private MethodInstance recentMethod = null; // the most recent method called - private ClassInstance recentClass = null; - - public BoilVisitor(SymbolTable symt) { - this.symt = symt; - this.vapor = ""; - this.tf = new TypeFactory(); - this.id = 0; - } - - public String getVapor() { - return this.vapor; - } - - public int getVarIndex(ClassInstance cls, TypeInstance type) { - /** - * Returns the index of the attribute in the class, or a negative number - * if it is not included. - */ - int attr_index = -1; - if (cls != null && - ((attr_index = cls.getLocals().indexOf(type)*4) >= 0)) { - attr_index += cls.getMethods().size() * 4; - } - return attr_index; - } - - public String memoryRead(String rhs) { - String lhs = this.tf.alias(this.getUniqueID()); - this.addVapor(String.format(" %s = %s\n", - lhs, - rhs)); - - return lhs; - } - - private void addVapor(String str) { - MinimalLogger.info(String.format("Adding \"%s\"", - str)); - this.vapor += str; - } - - private String getUniqueID() { - return Integer.toString(this.id++); - } - - private void resetIDs() { - MinimalLogger.info(String.format("Clearing tf for new function...")); - this.tf.reset(); - this.id = 0; - } - - // - // Auto class visitors--probably don't need to be overridden. - // - public String visit(NodeList n, String argu) { - String _ret=""; - int _count=0; - for ( Enumeration e = n.elements(); e.hasMoreElements(); ) { - _ret += e.nextElement().accept(this,argu); - _count++; - } - return _ret; - } - - public String visit(NodeListOptional n, String argu) { - if ( n.present() ) { - String _ret=""; - int _count=0; - for ( Enumeration e = n.elements(); e.hasMoreElements(); ) { - _ret += e.nextElement().accept(this,argu); - _count++; - } - return _ret; - } - else - return ""; - } - - public String visit(NodeOptional n, String argu) { - if ( n.present() ) - return n.node.accept(this,argu); - else - return ""; - } - - public String visit(NodeSequence n, String argu) { - String _ret=null; - int _count=0; - for ( Enumeration e = n.elements(); e.hasMoreElements(); ) { - e.nextElement().accept(this,argu); - _count++; - } - return _ret; - } - - public String visit(NodeToken n, String argu) { - return null; - } - - // - // User-generated visitor methods below - // - - /** - * f0 -> MainClass() - * f1 -> ( TypeDeclaration() )* - * f2 -> - */ - public String visit(Goal n, String argu) { - String _ret=null; - MinimalLogger.info(String.format("-> %s", - n.getClass().getSimpleName())); - /////////////////////////////////////////////////////////////// - n.f0.accept(this, argu); - n.f1.accept(this, argu); - n.f2.accept(this, argu); - - this.addVapor(String.format("func AllocArray(size)\n bytes = MulS(size 4)\n bytes = Add(bytes 4)\n v = HeapAllocZ(bytes)\n [v] = size\n ret v\n")); - /////////////////////////////////////////////////////////////// - MinimalLogger.info(String.format("<- %s with %s", - n.getClass().getSimpleName(), - _ret)); - return _ret; - } - - /** - * f0 -> "class" - * f1 -> Identifier() - * f2 -> "{" - * f3 -> "public" - * f4 -> "static" - * f5 -> "void" - * f6 -> "main" - * f7 -> "(" - * f8 -> "String" - * f9 -> "[" - * f10 -> "]" - * f11 -> Identifier() - * f12 -> ")" - * f13 -> "{" - * f14 -> ( VarDeclaration() )* - * f15 -> ( Statement() )* - * f16 -> "}" - * f17 -> "}" - */ - public String visit(MainClass n, String argu) { - String _ret=null; - this.tf.reset(); - String id = n.f1.f0.tokenImage; - MinimalLogger.info(String.format("-> %s (%s)", - n.getClass().getSimpleName(), - id)); - this.symt.setActive(TypeEnum.classname, symt.getClass(id)); - this.symt.setActive(TypeEnum.method, symt.getMethod(n.f6.tokenImage)); - /////////////////////////////////////////////////////////////// - this.addVapor("func Main()\n"); - n.f1.accept(this, argu); - n.f11.accept(this, argu); - n.f14.accept(this, argu); - n.f15.accept(this, argu); - this.addVapor(" ret\n\n"); - /////////////////////////////////////////////////////////////// - this.symt.removeActive(TypeEnum.method); - symt.removeActive(TypeEnum.classname); - MinimalLogger.info(String.format("<- %s (%s)", - n.getClass().getSimpleName(), - id)); - return _ret; - } - - /** - * f0 -> ClassDeclaration() - * | ClassExtendsDeclaration() - */ - public String visit(TypeDeclaration n, String argu) { - String _ret=null; - MinimalLogger.info(String.format("-> %s", - n.getClass().getSimpleName())); - /////////////////////////////////////////////////////////////// - n.f0.accept(this, argu); - MinimalLogger.info(String.format("<- %s with %s", - n.getClass().getSimpleName(), - _ret)); - /////////////////////////////////////////////////////////////// - return _ret; - } - - /** - * f0 -> "class" - * f1 -> Identifier() - * f2 -> "{" - * f3 -> ( VarDeclaration() )* - * f4 -> ( MethodDeclaration() )* - * f5 -> "}" - */ - public String visit(ClassDeclaration n, String argu) { - String _ret=null; - String id = n.f1.f0.tokenImage; - MinimalLogger.info(String.format("-> %s (%s)", - n.getClass().getSimpleName(), - id)); - this.symt.setActive(TypeEnum.classname, symt.getClass(id)); - /////////////////////////////////////////////////////////////// - this.addVapor(String.format("const functable_%s\n", id)); - for (MethodInstance mtd : this.symt.getClass(id).getMethods()) { - this.addVapor(String.format(" :%s_%s\n", mtd.getParentClass().getName(), mtd)); - } - this.addVapor("\n"); - // n.f3.accept(this, argu); - n.f4.accept(this, argu); - /////////////////////////////////////////////////////////////// - this.symt.removeActive(TypeEnum.classname); - MinimalLogger.info(String.format("<- %s (%s)", - n.getClass().getSimpleName(), - id)); - return _ret; - } - - /** - * f0 -> "class" - * f1 -> Identifier() - * f2 -> "extends" - * f3 -> Identifier() - * f4 -> "{" - * f5 -> ( VarDeclaration() )* - * f6 -> ( MethodDeclaration() )* - * f7 -> "}" - */ - public String visit(ClassExtendsDeclaration n, String argu) { - String _ret=null; - String id = n.f1.f0.tokenImage; - MinimalLogger.info(String.format("-> %s (%s)", - n.getClass().getSimpleName(), - id)); - this.symt.setActive(TypeEnum.classname, symt.getClass(id)); - /////////////////////////////////////////////////////////////// - this.addVapor(String.format("const functable_%s\n", id)); - for (MethodInstance mtd : this.symt.getClass(id).getMethods()) { - this.addVapor(String.format(" :%s_%s\n", mtd.getParentClass().getName(), mtd)); - } - this.addVapor("\n"); - // n.f3.accept(this, argu); - // n.f5.accept(this, argu); - n.f6.accept(this, argu); - /////////////////////////////////////////////////////////////// - this.symt.removeActive(TypeEnum.classname); - MinimalLogger.info(String.format("<- %s (%s)", - n.getClass().getSimpleName(), - id)); - return _ret; - } - - /** - * f0 -> Type() - * f1 -> Identifier() - * f2 -> ";" - */ - public String visit(VarDeclaration n, String argu) { - String _ret=null; - String id = n.f1.f0.tokenImage; - MinimalLogger.info(String.format("-> %s (%s)", - n.getClass().getSimpleName(), - id)); - /////////////////////////////////////////////////////////////// - // if (t.getClassInstance() != null) - // this.addVapor(String.format(" %s = HeapAllocZ(%d)\n", - // this.tf.alias(t.getName()), - // t.getSize())); - n.f0.accept(this, argu); - /////////////////////////////////////////////////////////////// - MinimalLogger.info(String.format("<- %s (%s)", - n.getClass().getSimpleName(), - id)); - return _ret; - } - - /** - * f0 -> "public" - * f1 -> Type() - * f2 -> Identifier() - * f3 -> "(" - * f4 -> ( FormalParameterList() )? - * f5 -> ")" - * f6 -> "{" - * f7 -> ( VarDeclaration() )* - * f8 -> ( Statement() )* - * f9 -> "return" - * f10 -> Expression() - * f11 -> ";" - * f12 -> "}" - */ - public String visit(MethodDeclaration n, String argu) { - String _ret=null; - this.tf.reset(); - String id = n.f2.f0.tokenImage; - MinimalLogger.info(String.format("-> %s (%s)", - n.getClass().getSimpleName(), - id)); - this.symt.setActive(TypeEnum.method, symt.getMethod(id)); - /////////////////////////////////////////////////////////////// - // n.f1.accept(this, argu); - this.addVapor(String.format("func %s_%s(this ", - this.symt.getActive(TypeEnum.classname), - id)); - String para = n.f4.accept(this, argu); - this.addVapor(String.format("%s)\n", para)); - - n.f7.accept(this, argu); - n.f8.accept(this, argu); - String ret = n.f10.accept(this, argu); - String retID = this.getUniqueID(); - this.addVapor(String.format(" %s = %s\n ret %s\n\n", - this.tf.alias(retID), - ret, - this.tf.alias(retID))); - /////////////////////////////////////////////////////////////// - this.symt.removeActive(TypeEnum.method); - MinimalLogger.info(String.format("<- %s (%s)", - n.getClass().getSimpleName(), - id)); - return _ret; - } - - /** - * f0 -> FormalParameter() - * f1 -> ( FormalParameterRest() )* - */ - public String visit(FormalParameterList n, String argu) { - String _ret=""; - MinimalLogger.info(String.format("-> %s", - n.getClass().getSimpleName())); - /////////////////////////////////////////////////////////////// - _ret += n.f0.accept(this, argu); - _ret += n.f1.accept(this, argu); - /////////////////////////////////////////////////////////////// - MinimalLogger.info(String.format("<- %s with %s", - n.getClass().getSimpleName(), - _ret)); - return _ret; - } - - /** - * f0 -> Type() - * f1 -> Identifier() - */ - public String visit(FormalParameter n, String argu) { - String _ret=""; - String id = n.f1.f0.tokenImage; - MinimalLogger.info(String.format("-> %s (%s)", - n.getClass().getSimpleName(), - id)); - /////////////////////////////////////////////////////////////// - // n.f0.accept(this, argu); - _ret += n.f1.accept(this,argu) + " "; - /////////////////////////////////////////////////////////////// - MinimalLogger.info(String.format("<- %s (%s)", - n.getClass().getSimpleName(), - id)); - return _ret; - } - - /** - * f0 -> "," - * f1 -> FormalParameter() - */ - public String visit(FormalParameterRest n, String argu) { - String _ret=""; - MinimalLogger.info(String.format("-> %s", - n.getClass().getSimpleName())); - /////////////////////////////////////////////////////////////// - _ret += n.f1.accept(this, argu); - /////////////////////////////////////////////////////////////// - MinimalLogger.info(String.format("<- %s with %s", - n.getClass().getSimpleName(), - _ret)); - return _ret; - } - - /** - * f0 -> ArrayType() - * | BooleanType() - * | IntegerType() - * | Identifier() - */ - public String visit(Type n, String argu) { - String _ret=null; - MinimalLogger.info(String.format("-> %s", - n.getClass().getSimpleName())); - /////////////////////////////////////////////////////////////// - n.f0.accept(this, argu); - /////////////////////////////////////////////////////////////// - MinimalLogger.info(String.format("<- %s with %s", - n.getClass().getSimpleName(), - _ret)); - return _ret; - } - - /** - * f0 -> "int" - * f1 -> "[" - * f2 -> "]" - */ - public String visit(ArrayType n, String argu) { - String _ret=null; - MinimalLogger.info(String.format("-> %s", - n.getClass().getSimpleName())); - /////////////////////////////////////////////////////////////// - /////////////////////////////////////////////////////////////// - MinimalLogger.info(String.format("<- %s with %s", - n.getClass().getSimpleName(), - _ret)); - return _ret; - } - - /** - * f0 -> "boolean" - */ - public String visit(BooleanType n, String argu) { - String _ret=null; - MinimalLogger.info(String.format("-> %s", - n.getClass().getSimpleName())); - /////////////////////////////////////////////////////////////// - /////////////////////////////////////////////////////////////// - MinimalLogger.info(String.format("<- %s with %s", - n.getClass().getSimpleName(), - _ret)); - return _ret; - } - - /** - * f0 -> "int" - */ - public String visit(IntegerType n, String argu) { - String _ret=null; - MinimalLogger.info(String.format("-> %s", - n.getClass().getSimpleName())); - /////////////////////////////////////////////////////////////// - /////////////////////////////////////////////////////////////// - MinimalLogger.info(String.format("<- %s with %s", - n.getClass().getSimpleName(), - _ret)); - return _ret; - } - - /** - * f0 -> Block() - * | AssignmentStatement() - * | ArrayAssignmentStatement() - * | IfStatement() - * | WhileStatement() - * | PrintStatement() - */ - public String visit(Statement n, String argu) { - String _ret=""; - MinimalLogger.info(String.format("-> %s", - n.getClass().getSimpleName())); - /////////////////////////////////////////////////////////////// - _ret += n.f0.accept(this, argu); - /////////////////////////////////////////////////////////////// - MinimalLogger.info(String.format("<- %s with %s", - n.getClass().getSimpleName(), - _ret)); - return _ret; - } - - /** - * f0 -> "{" - * f1 -> ( Statement() )* - * f2 -> "}" - */ - public String visit(Block n, String argu) { - String _ret=null; - MinimalLogger.info(String.format("-> %s", - n.getClass().getSimpleName())); - /////////////////////////////////////////////////////////////// - n.f1.accept(this, argu); - /////////////////////////////////////////////////////////////// - MinimalLogger.info(String.format("<- %s with %s", - n.getClass().getSimpleName(), - _ret)); - return _ret; - } - - /** - * f0 -> Identifier() - * f1 -> "=" - * f2 -> Expression() - * f3 -> ";" - */ - public String visit(AssignmentStatement n, String argu) { - String _ret=null; - String id = n.f0.f0.tokenImage; - MinimalLogger.info(String.format("-> %s", - n.getClass().getSimpleName())); - /////////////////////////////////////////////////////////////// - String lhs = n.f0.accept(this, argu); - String expr = n.f2.accept(this, argu); - - int attr_index = 0; - TypeInstance t; - if ((t = this.symt.getType(lhs)) != null) { - // memory store - ClassInstance cur = (ClassInstance) this.symt.getActive(TypeEnum.classname); - attr_index = getVarIndex(cur, t); - lhs = String.format("[this+%d]", attr_index); - } - - - this.addVapor(String.format(" %s = %s\n", - lhs, - expr)); - /////////////////////////////////////////////////////////////// - MinimalLogger.info(String.format("<- %s", - n.getClass().getSimpleName())); - return _ret; - } - - /** - * f0 -> Identifier() - * f1 -> "[" - * f2 -> Expression() - * f3 -> "]" - * f4 -> "=" - * f5 -> Expression() - * f6 -> ";" - */ - public String visit(ArrayAssignmentStatement n, String argu) { - String _ret=null; - MinimalLogger.info(String.format("-> %s", - n.getClass().getSimpleName())); - /////////////////////////////////////////////////////////////// - String arrID = this.tf.alias(this.getUniqueID()); - String arr = n.f0.accept(this, argu); - this.addVapor(String.format(" %s = %s\n", - arrID, - arr)); - - String indexID = this.tf.alias(this.getUniqueID()); - this.addVapor(String.format(" %s = MulS(%s %s)\n", - indexID, - n.f2.accept(this, argu), - 4)); - this.addVapor(String.format(" %s = Add(%s %s)\n", - indexID, - indexID, - 4)); - this.addVapor(String.format(" %s = Add(%s %s)\n", - indexID, - arrID, - indexID)); - - String expr = n.f5.accept(this, argu); - - this.addVapor(String.format(" [%s] = %s\n", - indexID, - expr)); - /////////////////////////////////////////////////////////////// - MinimalLogger.info(String.format("<- %s with %s", - n.getClass().getSimpleName(), - _ret)); - return _ret; - } - - /** - * f0 -> "if" - * f1 -> "(" - * f2 -> Expression() - * f3 -> ")" - * f4 -> Statement() - * f5 -> "else" - * f6 -> Statement() - */ - public String visit(IfStatement n, String argu) { - String _ret=null; - MinimalLogger.info(String.format("-> %s", - n.getClass().getSimpleName())); - /////////////////////////////////////////////////////////////// - String ifID = this.getUniqueID(); - String cond = n.f2.accept(this, argu); - - this.addVapor(String.format(" %s = %s\n", - this.tf.alias(ifID), - cond)); - this.addVapor(String.format(" if0 %s goto :if%s_else\nif%s_body:\n", - this.tf.alias(ifID), - ifID, - ifID)); - - n.f4.accept(this, argu); - - this.addVapor(String.format(" goto :if%s_end\nif%s_else:\n", - ifID, - ifID)); - - n.f6.accept(this, argu); - - this.addVapor(String.format("if%s_end:\n", - ifID)); - /////////////////////////////////////////////////////////////// - MinimalLogger.info(String.format("<- %s with %s", - n.getClass().getSimpleName(), - _ret)); - return _ret; - } - - /** - * f0 -> "while" - * f1 -> "(" - * f2 -> Expression() - * f3 -> ")" - * f4 -> Statement() - */ - public String visit(WhileStatement n, String argu) { - String _ret=null; - MinimalLogger.info(String.format("-> %s", - n.getClass().getSimpleName())); - /////////////////////////////////////////////////////////////// - String whileID = this.getUniqueID(); - - this.addVapor(String.format("while%s_test:\n", - whileID)); - String cond = n.f2.accept(this, argu); - - String condID = this.getUniqueID(); - this.addVapor(String.format(" %s = %s\n", - this.tf.alias(condID), - cond)); - this.addVapor(String.format(" if0 %s goto :while%s_end\nwhile%s_body:\n", - this.tf.alias(condID), - whileID, - whileID)); - - n.f4.accept(this, argu); - - this.addVapor(String.format(" goto :while%s_test\nwhile%s_end:\n", - whileID, - whileID)); - /////////////////////////////////////////////////////////////// - MinimalLogger.info(String.format("<- %s with %s", - n.getClass().getSimpleName(), - _ret)); - return _ret; - } - - /** - * f0 -> "System.out.println" - * f1 -> "(" - * f2 -> Expression() - * f3 -> ")" - * f4 -> ";" - */ - public String visit(PrintStatement n, String argu) { - String _ret=null; - MinimalLogger.info(String.format("-> %s", - n.getClass().getSimpleName())); - /////////////////////////////////////////////////////////////// - String printTemp = this.getUniqueID(); - String expr = n.f2.accept(this, argu); - - this.addVapor(String.format(" %s = %s\n", - this.tf.alias(printTemp), - expr)); - - this.addVapor(String.format(" PrintIntS(%s)\n", - this.tf.alias(printTemp))); - - /////////////////////////////////////////////////////////////// - MinimalLogger.info(String.format("<- %s with %s", - n.getClass().getSimpleName(), - _ret)); - return _ret; - } - - /** - * f0 -> AndExpression() - * | CompareExpression() - * | PlusExpression() - * | MinusExpression() - * | TimesExpression() - * | ArrayLookup() - * | ArrayLength() - * | MessageSend() - * | PrimaryExpression() - */ - // Expressions return a TYPE alias which is equal to the expression! - public String visit(Expression n, String argu) { - String _ret=""; - MinimalLogger.info(String.format("-> %s", - n.getClass().getSimpleName())); - /////////////////////////////////////////////////////////////// - _ret += n.f0.accept(this, argu); - /////////////////////////////////////////////////////////////// - MinimalLogger.info(String.format("<- %s with %s", - n.getClass().getSimpleName(), - _ret)); - return _ret; - } - - /** - * f0 -> PrimaryExpression() - * f1 -> "&&" - * f2 -> PrimaryExpression() - */ - // Expressions return a TYPE alias which is equal to the expression! - public String visit(AndExpression n, String argu) { - String _ret=""; - MinimalLogger.info(String.format("-> %s", - n.getClass().getSimpleName())); - _ret += this.tf.alias(this.getUniqueID()); - /////////////////////////////////////////////////////////////// - String oper1 = this.memoryRead(n.f0.accept(this, argu)); - String oper2 = this.memoryRead(n.f2.accept(this, argu)); - String one = this.tf.alias(this.getUniqueID()); - this.addVapor(String.format(" %s = Eq(1 %s)\n", - one, - oper1)); - String two = this.tf.alias(this.getUniqueID()); - this.addVapor(String.format(" %s = Eq(1 %s)\n", - two, - oper2)); - this.addVapor(String.format(" %s = Eq(%s %s)\n", - _ret, - one, - two)); - /////////////////////////////////////////////////////////////// - MinimalLogger.info(String.format("<- %s with %s", - n.getClass().getSimpleName(), - _ret)); - return _ret; - } - - /** - * f0 -> PrimaryExpression() - * f1 -> "<" - * f2 -> PrimaryExpression() - */ - // Expressions return a TYPE alias which is equal to the expression! - public String visit(CompareExpression n, String argu) { - String _ret=""; - MinimalLogger.info(String.format("-> %s", - n.getClass().getSimpleName())); - _ret += this.tf.alias(this.getUniqueID()); - /////////////////////////////////////////////////////////////// - String oper1 = this.memoryRead(n.f0.accept(this, argu)); - String oper2 = this.memoryRead(n.f2.accept(this, argu)); - this.addVapor(String.format(" %s = LtS(%s %s)\n", - _ret, - oper1, - oper2)); - /////////////////////////////////////////////////////////////// - MinimalLogger.info(String.format("<- %s with %s", - n.getClass().getSimpleName(), - _ret)); - return _ret; - } - - /** - * f0 -> PrimaryExpression() - * f1 -> "+" - * f2 -> PrimaryExpression() - */ - // Expressions return a TYPE alias which is equal to the expression! - public String visit(PlusExpression n, String argu) { - String _ret=""; - MinimalLogger.info(String.format("-> %s", - n.getClass().getSimpleName())); - _ret += this.tf.alias(this.getUniqueID()); - /////////////////////////////////////////////////////////////// - String oper1 = this.memoryRead(n.f0.accept(this, argu)); - String oper2 = this.memoryRead(n.f2.accept(this, argu)); - this.addVapor(String.format(" %s = Add(%s %s)\n", - _ret, - oper1, - oper2)); - /////////////////////////////////////////////////////////////// - MinimalLogger.info(String.format("<- %s with %s", - n.getClass().getSimpleName(), - _ret)); - return _ret; - } - - /** - * f0 -> PrimaryExpression() - * f1 -> "-" - * f2 -> PrimaryExpression() - */ - // Expressions return a TYPE alias which is equal to the expression! - public String visit(MinusExpression n, String argu) { - String _ret=""; - MinimalLogger.info(String.format("-> %s", - n.getClass().getSimpleName())); - _ret += this.tf.alias(this.getUniqueID()); - /////////////////////////////////////////////////////////////// - String oper1 = this.memoryRead(n.f0.accept(this, argu)); - String oper2 = this.memoryRead(n.f2.accept(this, argu)); - this.addVapor(String.format(" %s = Sub(%s %s)\n", - _ret, - oper1, - oper2)); - /////////////////////////////////////////////////////////////// - MinimalLogger.info(String.format("<- %s with %s", - n.getClass().getSimpleName(), - _ret)); - return _ret; - } - - /** - * f0 -> PrimaryExpression() - * f1 -> "*" - * f2 -> PrimaryExpression() - */ - // Expressions return a TYPE alias which is equal to the expression! - public String visit(TimesExpression n, String argu) { - String _ret=""; - MinimalLogger.info(String.format("-> %s", - n.getClass().getSimpleName())); - _ret += this.tf.alias(this.getUniqueID()); - /////////////////////////////////////////////////////////////// - String oper1 = this.memoryRead(n.f0.accept(this, argu)); - String oper2 = this.memoryRead(n.f2.accept(this, argu)); - this.addVapor(String.format(" %s = MulS(%s %s)\n", - _ret, - oper1, - oper2)); - /////////////////////////////////////////////////////////////// - MinimalLogger.info(String.format("<- %s with %s", - n.getClass().getSimpleName(), - _ret)); - return _ret; - } - - /** - * f0 -> PrimaryExpression() - * f1 -> "[" - * f2 -> PrimaryExpression() - * f3 -> "]" - */ - // Expressions return a TYPE alias which is equal to the expression! - public String visit(ArrayLookup n, String argu) { - String _ret=""; - MinimalLogger.info(String.format("-> %s", - n.getClass().getSimpleName())); - _ret += this.tf.alias(this.getUniqueID()); - /////////////////////////////////////////////////////////////// - String arrID = this.tf.alias(this.getUniqueID()); - String arr = n.f0.accept(this, argu); - String indexID = this.tf.alias(this.getUniqueID()); - this.addVapor(String.format(" %s = %s\n", - arrID, - arr)); - this.addVapor(String.format(" %s = MulS(%s %s)\n", - indexID, - n.f2.accept(this, argu), - 4)); - this.addVapor(String.format(" %s = Add(%s %s)\n", - indexID, - indexID, - 4)); - this.addVapor(String.format(" %s = Add(%s %s)\n", - indexID, - arrID, - indexID)); - this.addVapor(String.format(" %s = [%s]\n", - _ret, - indexID)); - /////////////////////////////////////////////////////////////// - MinimalLogger.info(String.format("<- %s with %s", - n.getClass().getSimpleName(), - _ret)); - return _ret; - } - - /** - * f0 -> PrimaryExpression() - * f1 -> "." - * f2 -> "length" - */ - // Expressions return a TYPE alias which is equal to the expression! - public String visit(ArrayLength n, String argu) { - String _ret=""; - MinimalLogger.info(String.format("-> %s", - n.getClass().getSimpleName())); - _ret += this.tf.alias(this.getUniqueID()); - /////////////////////////////////////////////////////////////// - String arrID = this.tf.alias(this.getUniqueID()); - String arr = n.f0.accept(this, argu); - this.addVapor(String.format(" %s = %s\n", - arrID, - arr)); - this.addVapor(String.format(" %s = [%s+0]\n", - _ret, - arrID)); - /////////////////////////////////////////////////////////////// - MinimalLogger.info(String.format("<- %s with %s", - n.getClass().getSimpleName(), - _ret)); - return _ret; - } - - /** - * f0 -> PrimaryExpression() - * f1 -> "." - * f2 -> Identifier() - * f3 -> "(" - * f4 -> ( ExpressionList() )? - * f5 -> ")" - */ - // Expressions return a TYPE alias which is equal to the expression! - public String visit(MessageSend n, String argu) { - String _ret=""; - MinimalLogger.info(String.format("-> %s", - n.getClass().getSimpleName())); - /////////////////////////////////////////////////////////////// - _ret += this.tf.alias(this.getUniqueID()); - String mtd = n.f2.f0.tokenImage; - String rhs; - TypeInstance t; - switch (n.f0.f0.which) { - case 3: - MinimalLogger.info("Message send found an IDENTIFIER"); - rhs = ((Identifier) n.f0.f0.choice).f0.tokenImage; - t = this.symt.getType(rhs); - if (t == null) - t = this.symt.getTypeAttr(rhs); - rhs = n.f0.accept(this, argu); - this.addVapor(String.format(" %s = %s\n", - this.tf.alias(t.getName()), - rhs)); - break; - case 4: - // we'll do everything here and exit the function - MinimalLogger.info("Message send found THIS"); - rhs = n.f0.accept(this, argu); - rhs = this.tf.alias(this.getUniqueID()); - this.addVapor(String.format(" %s = [this]\n", - rhs)); - ClassInstance cur = (ClassInstance) this.symt.getActive(TypeEnum.classname); - MinimalLogger.info("Calculating method index to call..."); - int mtdIndex = cur.getMethods() - .indexOf(this.symt.getMethod(mtd, cur)) * 4; - - this.addVapor(n.f4.accept(this, argu)); - this.addVapor(String.format(" %s = [%s+%d]\n", - rhs, - rhs, - mtdIndex)); - this.addVapor(String.format(" %s = call %s(this", - _ret, - rhs)); - this.addVapor(String.format(" %s)\n", - this.tf.retrieveRecentList(this.symt.getMethod(mtd, cur) - .getArguments() - .size()))); - this.recentMethod = this.symt.getMethod(mtd, cur); - return _ret; - case 6: - MinimalLogger.info("Message send found ANONYMOUS"); - // expand the entire object out! - rhs = n.f0.accept(this, argu); - t = new TypeInstance(rhs, TypeEnum.ERROR, - (MethodInstance) this.symt.getActive(TypeEnum.method), - (ClassInstance) this.symt.getActive(TypeEnum.classname)); - t.addClassInstance(this.recentClass); - this.addVapor(String.format(" %s = %s\n", - this.tf.alias(t.getName()), - rhs)); - break; - case 8: - MinimalLogger.info("Message send found BRACKET"); - rhs = n.f0.accept(this, argu); - ClassInstance cls = this.recentMethod.getReturn(); - t = new TypeInstance(this.getUniqueID(), TypeEnum.ERROR, - (MethodInstance) this.symt.getActive(TypeEnum.method), - (ClassInstance) this.symt.getActive(TypeEnum.classname)); - this.addVapor(String.format(" %s = %s\n", - this.tf.alias(t.getName()), - rhs)); - t.addClassInstance(cls); - break; - default: - MinimalLogger.severe(String.format("Message send found UNKNOWN %s", - n.f0.f0.choice.toString())); - rhs = null; - t = null; - } - - String tp1 = this.tf.alias(this.getUniqueID()); - String tp2 = this.tf.alias(this.getUniqueID()); - - this.addVapor(String.format(" %s = [%s+%d]\n", - tp1, - this.tf.alias(t.getName()), - 0)); - - MinimalLogger.info("Calculating method index to call..."); - MinimalLogger.severe("t: " + t); - MinimalLogger.severe("mtd: " + mtd); - MinimalLogger.severe("t.getClassInstance() " + t.getClassInstance()); - MinimalLogger.severe("t.getClassInstance().getMethods() " + t.getClassInstance().getMethods().toString()); - this.recentMethod = this.symt.getMethod(mtd, t.getClassInstance()); - int mtdIndex = t.getClassInstance().getMethods() - .indexOf(this.symt.getMethod(mtd, t.getClassInstance())) * 4; - - this.addVapor(String.format(" %s = [%s+%d]\n", - tp2, - tp1, - mtdIndex)); - - this.addVapor(n.f4.accept(this, argu)); - - this.addVapor(String.format(" %s = call %s(%s", - _ret, - tp2, - this.tf.alias(t.getName()))); - - this.addVapor(String.format(" %s)\n", - this.tf.retrieveRecentList(this.symt.getMethod(mtd, t.getClassInstance()) - .getArguments() - .size()))); - /////////////////////////////////////////////////////////////// - MinimalLogger.info(String.format("<- %s with %s", - n.getClass().getSimpleName(), - _ret)); - return _ret; - } - - /** - * f0 -> Expression() - * f1 -> ( ExpressionRest() )* - */ - public String visit(ExpressionList n, String argu) { - String _ret=""; - MinimalLogger.info(String.format("-> %s", - n.getClass().getSimpleName())); - /////////////////////////////////////////////////////////////// - String rhs = n.f0.accept(this, argu); - _ret += String.format(" %s = %s\n", - this.tf.alias(this.getUniqueID()), - rhs); - _ret += n.f1.accept(this, argu); - /////////////////////////////////////////////////////////////// - MinimalLogger.info(String.format("<- %s with %s", - n.getClass().getSimpleName(), - _ret)); - return _ret; - } - - /** - * f0 -> "," - * f1 -> Expression() - */ - public String visit(ExpressionRest n, String argu) { - String _ret=""; - MinimalLogger.info(String.format("-> %s", - n.getClass().getSimpleName())); - /////////////////////////////////////////////////////////////// - String rhs = n.f1.accept(this, argu); - _ret += String.format(" %s = %s\n", - this.tf.alias(this.getUniqueID()), - rhs); - /////////////////////////////////////////////////////////////// - MinimalLogger.info(String.format("<- %s with %s", - n.getClass().getSimpleName(), - _ret)); - return _ret; - } - - /** - * f0 -> IntegerLiteral() - * | TrueLiteral() - * | FalseLiteral() - * | Identifier() - * | ThisExpression() - * | ArrayAllocationExpression() - * | AllocationExpression() - * | NotExpression() - * | BracketExpression() - */ - public String visit(PrimaryExpression n, String argu) { - String _ret=""; - MinimalLogger.info(String.format("-> %s", - n.getClass().getSimpleName())); - /////////////////////////////////////////////////////////////// - _ret += n.f0.accept(this, argu); - /////////////////////////////////////////////////////////////// - MinimalLogger.info(String.format("<- %s with %s", - n.getClass().getSimpleName(), - _ret)); - return _ret; - } - - /** - * f0 -> - */ - public String visit(IntegerLiteral n, String argu) { - String _ret=""; - MinimalLogger.info(String.format("-> %s", - n.getClass().getSimpleName())); - /////////////////////////////////////////////////////////////// - _ret += n.f0.tokenImage; - /////////////////////////////////////////////////////////////// - MinimalLogger.info(String.format("<- %s with %s", - n.getClass().getSimpleName(), - _ret)); - return _ret; - } - - /** - * f0 -> "true" - */ - public String visit(TrueLiteral n, String argu) { - String _ret=""; - MinimalLogger.info(String.format("-> %s", - n.getClass().getSimpleName())); - /////////////////////////////////////////////////////////////// - _ret += "1"; - /////////////////////////////////////////////////////////////// - MinimalLogger.info(String.format("<- %s with %s", - n.getClass().getSimpleName(), - _ret)); - return _ret; - } - - /** - * f0 -> "false" - */ - public String visit(FalseLiteral n, String argu) { - String _ret=""; - MinimalLogger.info(String.format("-> %s", - n.getClass().getSimpleName())); - /////////////////////////////////////////////////////////////// - _ret += "0"; - /////////////////////////////////////////////////////////////// - MinimalLogger.info(String.format("<- %s with %s", - n.getClass().getSimpleName(), - _ret)); - return _ret; - } - - /** - * f0 -> - */ - public String visit(Identifier n, String argu) { - String _ret=""; - String id = n.f0.tokenImage; - MinimalLogger.info(String.format("-> %s (%s)", - n.getClass().getSimpleName(), - id)); - /////////////////////////////////////////////////////////////// - ClassInstance cur = (ClassInstance) this.symt.getActive(TypeEnum.classname); - // TypeInstance localt = this.symt.getType(id); - TypeInstance t = this.symt.getTypeAttr(id); - if (cur.getLocals().contains(t)) { - MinimalLogger.info(String.format("Identifier found a class variable %s", - id)); - int attr_index = getVarIndex(cur, t); - _ret += String.format("[this+%d]", attr_index); - } else { - _ret += this.tf.alias(id); - } - /////////////////////////////////////////////////////////////// - MinimalLogger.info(String.format("<- %s (%s) with %s", - n.getClass().getSimpleName(), - id, - _ret)); - return _ret; - } - - /** - * f0 -> "this" - */ - public String visit(ThisExpression n, String argu) { - String _ret=""; - MinimalLogger.info(String.format("-> %s", - n.getClass().getSimpleName())); - /////////////////////////////////////////////////////////////// - _ret += "this"; - /////////////////////////////////////////////////////////////// - MinimalLogger.info(String.format("<- %s with %s", - n.getClass().getSimpleName(), - _ret)); - return _ret; - } - - /** - * f0 -> "new" - * f1 -> "int" - * f2 -> "[" - * f3 -> Expression() - * f4 -> "]" - */ - public String visit(ArrayAllocationExpression n, String argu) { - String _ret=""; - MinimalLogger.info(String.format("-> %s", - n.getClass().getSimpleName())); - /////////////////////////////////////////////////////////////// - String len = n.f3.accept(this, argu); - String aAllocID = this.tf.alias(this.getUniqueID()); - this.addVapor(String.format(" %s = call :AllocArray(%s)\n", - aAllocID, - len)); - - _ret += aAllocID; - /////////////////////////////////////////////////////////////// - MinimalLogger.info(String.format("<- %s with %s", - n.getClass().getSimpleName(), - _ret)); - return _ret; - } - - /** - * f0 -> "new" - * f1 -> Identifier() - * f2 -> "(" - * f3 -> ")" - */ - public String visit(AllocationExpression n, String argu) { - String _ret=""; - String id = n.f1.f0.tokenImage; - MinimalLogger.info(String.format("-> %s", - n.getClass().getSimpleName())); - _ret += this.tf.alias(this.getUniqueID()); - /////////////////////////////////////////////////////////////// - ClassInstance cls = this.symt.getClass(id); - this.recentClass = cls; - this.addVapor(String.format(" %s = HeapAllocZ(%d)\n", - _ret, - cls.getSize())); - - this.addVapor(String.format(" [%s+0] = :functable_%s\n", - _ret, - id)); - /////////////////////////////////////////////////////////////// - MinimalLogger.info(String.format("<- %s with %s", - n.getClass().getSimpleName(), - _ret)); - return _ret; - } - - /** - * f0 -> "!" - * f1 -> Expression() - */ - public String visit(NotExpression n, String argu) { - String _ret=""; - MinimalLogger.info(String.format("-> %s", - n.getClass().getSimpleName())); - _ret += this.tf.alias(this.getUniqueID()); - /////////////////////////////////////////////////////////////// - this.addVapor(String.format(" %s = Eq(%s 0)\n", - _ret, - n.f1.accept(this, argu))); - /////////////////////////////////////////////////////////////// - MinimalLogger.info(String.format("<- %s with %s", - n.getClass().getSimpleName(), - _ret)); - return _ret; - } - - /** - * f0 -> "(" - * f1 -> Expression() - * f2 -> ")" - */ - public String visit(BracketExpression n, String argu) { - String _ret=""; - MinimalLogger.info(String.format("-> %s", - n.getClass().getSimpleName())); - /////////////////////////////////////////////////////////////// - _ret += n.f1.accept(this, argu); - /////////////////////////////////////////////////////////////// - MinimalLogger.info(String.format("<- %s with %s", - n.getClass().getSimpleName(), - _ret)); - return _ret; - } - -} diff --git a/boil/library/TypeFactory.java b/boil/library/TypeFactory.java deleted file mode 100644 index ddf54c8..0000000 --- a/boil/library/TypeFactory.java +++ /dev/null @@ -1,51 +0,0 @@ -package boil.library; - -import misc.*; -import java.util.HashMap; - -public class TypeFactory { - - private int type_num; - private HashMap map; - - public void reset() { - this.type_num = 0; - this.map = new HashMap<>(); - } - - public String alias(String t) { - /** - * Given a TypeInstance, return the designated - * vapor alias. If the alias does not exist, create it. - */ - String alias; - if ((alias = this.map.get(t)) == null) { - alias = String.format("t.%d", this.type_num++); - MinimalLogger.info(String.format("Created alias %s for %s...", - alias, - t)); - - this.map.put(t, alias); - } - - return alias; - } - - public String retrieveRecentList(int x) { - /** - * Given int x, retrieve a space-delimited - * list of the x most recent entries. - */ - String rtn = ""; - if (x > 0) { - rtn += String.format("t.%d", - type_num-x); - for (int i = type_num-(x-1); i < type_num; ++i) { - rtn += String.format(" t.%d", - i); - } - } - - return rtn; - } -} diff --git a/boil/tests/BinaryTree.java b/boil/tests/BinaryTree.java deleted file mode 100644 index 18d1464..0000000 --- a/boil/tests/BinaryTree.java +++ /dev/null @@ -1,334 +0,0 @@ -class BinaryTree{ - public static void main(String[] a){ - System.out.println(new BT().Start()); - } -} - - -// This class invokes the methods to create a tree, -// insert, delete and serach for elements on it -class BT { - - public int Start(){ - Tree root ; - boolean ntb ; - int nti ; - - root = new Tree(); - ntb = root.Init(16); - ntb = root.Print(); - System.out.println(100000000); - ntb = root.Insert(8) ; - ntb = root.Print(); - ntb = root.Insert(24) ; - ntb = root.Insert(4) ; - ntb = root.Insert(12) ; - ntb = root.Insert(20) ; - ntb = root.Insert(28) ; - ntb = root.Insert(14) ; - ntb = root.Print(); - System.out.println(root.Search(24)); - System.out.println(root.Search(12)); - System.out.println(root.Search(16)); - System.out.println(root.Search(50)); - System.out.println(root.Search(12)); - ntb = root.Delete(12); - ntb = root.Print(); - System.out.println(root.Search(12)); - - return 0 ; - } - -} - -class Tree{ - Tree left ; - Tree right; - int key ; - boolean has_left ; - boolean has_right ; - Tree my_null ; - - // Initialize a node with a key value and no children - public boolean Init(int v_key){ - key = v_key ; - has_left = false ; - has_right = false ; - return true ; - } - - // Update the right child with rn - public boolean SetRight(Tree rn){ - right = rn ; - return true ; - } - - // Update the left child with ln - public boolean SetLeft(Tree ln){ - left = ln ; - return true ; - } - - public Tree GetRight(){ - return right ; - } - - public Tree GetLeft(){ - return left; - } - - public int GetKey(){ - return key ; - } - - public boolean SetKey(int v_key){ - key = v_key ; - return true ; - } - - public boolean GetHas_Right(){ - return has_right ; - } - - public boolean GetHas_Left(){ - return has_left ; - } - - public boolean SetHas_Left(boolean val){ - has_left = val ; - return true ; - } - - public boolean SetHas_Right(boolean val){ - has_right = val ; - return true ; - } - - // This method compares two integers and - // returns true if they are equal and false - // otherwise - public boolean Compare(int num1 , int num2){ - boolean ntb ; - int nti ; - - ntb = false ; - nti = num2 + 1 ; - if (num1 < num2) ntb = false ; - else if (!(num1 < nti)) ntb = false ; - else ntb = true ; - return ntb ; - } - - - // Insert a new element in the tree - public boolean Insert(int v_key){ - Tree new_node ; - boolean ntb ; - boolean cont ; - int key_aux ; - Tree current_node ; - - new_node = new Tree(); - ntb = new_node.Init(v_key) ; - current_node = this ; - cont = true ; - while (cont){ - key_aux = current_node.GetKey(); - if (v_key < key_aux){ - if (current_node.GetHas_Left()) - current_node = current_node.GetLeft() ; - else { - cont = false ; - ntb = current_node.SetHas_Left(true); - ntb = current_node.SetLeft(new_node); - } - } - else{ - if (current_node.GetHas_Right()) - current_node = current_node.GetRight() ; - else { - cont = false ; - ntb = current_node.SetHas_Right(true); - ntb = current_node.SetRight(new_node); - } - } - } - return true ; - } - - - // Delete an element from the tree - public boolean Delete(int v_key){ - Tree current_node ; - Tree parent_node ; - boolean cont ; - boolean found ; - boolean is_root ; - int key_aux ; - boolean ntb ; - - current_node = this ; - parent_node = this ; - cont = true ; - found = false ; - is_root = true ; - while (cont){ - key_aux = current_node.GetKey(); - if (v_key < key_aux) - if (current_node.GetHas_Left()){ - parent_node = current_node ; - current_node = current_node.GetLeft() ; - } - else cont = false ; - else - if (key_aux < v_key) - if (current_node.GetHas_Right()){ - parent_node = current_node ; - current_node = current_node.GetRight() ; - } - else cont = false ; - else { - if (is_root) - if ((!current_node.GetHas_Right()) && - (!current_node.GetHas_Left()) ) - ntb = true ; - else - ntb = this.Remove(parent_node,current_node); - else ntb = this.Remove(parent_node,current_node); - found = true ; - cont = false ; - } - is_root = false ; - } - return found ; - } - - - // Check if the element to be removed will use the - // righ or left subtree if one exists - public boolean Remove(Tree p_node, Tree c_node){ - boolean ntb ; - int auxkey1 ; - int auxkey2 ; - - if (c_node.GetHas_Left()) - ntb = this.RemoveLeft(p_node,c_node) ; - else - if (c_node.GetHas_Right()) - ntb = this.RemoveRight(p_node,c_node) ; - else { - auxkey1 = c_node.GetKey(); - //auxtree01 = p_node.GetLeft() ; - //auxkey2 = auxtree01.GetKey() ; - auxkey2 = (p_node.GetLeft()).GetKey() ; - if (this.Compare(auxkey1,auxkey2)) { - ntb = p_node.SetLeft(my_null); - ntb = p_node.SetHas_Left(false); - } - else { - ntb = p_node.SetRight(my_null); - ntb = p_node.SetHas_Right(false); - } - } - return true ; - } - - - // Copy the child key to the parent until a leaf is - // found and remove the leaf. This is done with the - // right subtree - public boolean RemoveRight(Tree p_node, Tree c_node){ - boolean ntb ; - - while (c_node.GetHas_Right()){ - //auxtree01 = c_node.GetRight() ; - //auxint02 = auxtree01.GetKey(); - //ntb = c_node.SetKey(auxint02); - ntb = c_node.SetKey((c_node.GetRight()).GetKey()); - p_node = c_node ; - c_node = c_node.GetRight() ; - } - ntb = p_node.SetRight(my_null); - ntb = p_node.SetHas_Right(false); - return true ; - } - - - // Copy the child key to the parent until a leaf is - // found and remove the leaf. This is done with the - // left subtree - public boolean RemoveLeft(Tree p_node, Tree c_node){ - boolean ntb ; - - while (c_node.GetHas_Left()){ - //auxtree01 = c_node.GetLeft() ; - //auxint02 = auxtree01.GetKey(); - //ntb = c_node.SetKey(auxint02); - ntb = c_node.SetKey((c_node.GetLeft()).GetKey()); - p_node = c_node ; - c_node = c_node.GetLeft() ; - } - ntb = p_node.SetLeft(my_null); - ntb = p_node.SetHas_Left(false); - return true ; - } - - // Search for an elemnt in the tree - public int Search(int v_key){ - boolean cont ; - int ifound ; - Tree current_node; - int key_aux ; - - current_node = this ; - cont = true ; - ifound = 0 ; - while (cont){ - key_aux = current_node.GetKey(); - if (v_key < key_aux) - if (current_node.GetHas_Left()) - current_node = current_node.GetLeft() ; - else cont = false ; - else - if (key_aux < v_key) - if (current_node.GetHas_Right()) - current_node = current_node.GetRight() ; - else cont = false ; - else { - ifound = 1 ; - cont = false ; - } - } - return ifound ; - } - - // Invoke the method to really print the tree elements - public boolean Print(){ - Tree current_node; - boolean ntb ; - - current_node = this ; - ntb = this.RecPrint(current_node); - return true ; - } - - // Print the elements of the tree - public boolean RecPrint(Tree node){ - boolean ntb ; - - if (node.GetHas_Left()){ - //auxtree01 = node.GetLeft() ; - //ntb = this.RecPrint(auxtree01); - ntb = this.RecPrint(node.GetLeft()); - } else ntb = true ; - System.out.println(node.GetKey()); - if (node.GetHas_Right()){ - //auxtree01 = node.GetRight() ; - //ntb = this.RecPrint(auxtree01); - ntb = this.RecPrint(node.GetRight()); - } else ntb = true ; - return true ; - } - -} - diff --git a/boil/tests/BubbleSort.java b/boil/tests/BubbleSort.java deleted file mode 100644 index e5645a9..0000000 --- a/boil/tests/BubbleSort.java +++ /dev/null @@ -1,93 +0,0 @@ -class BubbleSort{ - public static void main(String[] a){ - System.out.println(new BBS().Start(10)); - } -} - - -// This class contains the array of integers and -// methods to initialize, print and sort the array -// using Bublesort -class BBS{ - - int[] number ; - int size ; - - // Invoke the Initialization, Sort and Printing - // Methods - public int Start(int sz){ - int aux01 ; - aux01 = this.Init(sz); - aux01 = this.Print(); - System.out.println(99999); - aux01 = this.Sort(); - aux01 = this.Print(); - return 0 ; - } - - - // Sort array of integers using Bublesort method - public int Sort(){ - int nt ; - int i ; - int aux02 ; - int aux04 ; - int aux05 ; - int aux06 ; - int aux07 ; - int j ; - int t ; - i = size - 1 ; - aux02 = 0 - 1 ; - while (aux02 < i) { - j = 1 ; - //aux03 = i+1 ; - while (j < (i+1)){ - aux07 = j - 1 ; - aux04 = number[aux07] ; - aux05 = number[j] ; - if (aux05 < aux04) { - aux06 = j - 1 ; - t = number[aux06] ; - number[aux06] = number[j] ; - number[j] = t; - } - else nt = 0 ; - j = j + 1 ; - } - i = i - 1 ; - } - return 0 ; - } - - // Printing method - public int Print(){ - int j ; - j = 0 ; - while (j < (size)) { - System.out.println(number[j]); - j = j + 1 ; - } - return 0 ; - } - - // Initialize array of integers - public int Init(int sz){ - size = sz ; - number = new int[sz] ; - - number[0] = 20 ; - number[1] = 7 ; - number[2] = 12 ; - number[3] = 18 ; - number[4] = 2 ; - number[5] = 11 ; - number[6] = 6 ; - number[7] = 9 ; - number[8] = 19 ; - number[9] = 5 ; - - return 0 ; - } - -} diff --git a/boil/tests/Factorial.java b/boil/tests/Factorial.java deleted file mode 100644 index d938bb6..0000000 --- a/boil/tests/Factorial.java +++ /dev/null @@ -1,16 +0,0 @@ -class Factorial{ - public static void main(String[] a){ - System.out.println(new Fac().ComputeFac(10)); - } -} - -class Fac { - public int ComputeFac(int num){ - int num_aux ; - if (num < 1) - num_aux = 1 ; - else - num_aux = num * (this.ComputeFac(num-1)) ; - return num_aux ; - } -} diff --git a/boil/tests/LinearSearch.java b/boil/tests/LinearSearch.java deleted file mode 100644 index daddd94..0000000 --- a/boil/tests/LinearSearch.java +++ /dev/null @@ -1,99 +0,0 @@ -class LinearSearch{ - public static void main(String[] a){ - System.out.println(new LS().Start(10)); - } -} - - -// This class contains an array of integers and -// methods to initialize, print and search the array -// using Linear Search -class LS { - int[] number ; - int size ; - - // Invoke methods to initialize, print and search - // for elements on the array - public int Start(int sz){ - int aux01 ; - int aux02 ; - - aux01 = this.Init(sz); - aux02 = this.Print(); - System.out.println(9999); - System.out.println(this.Search(8)); - System.out.println(this.Search(12)) ; - System.out.println(this.Search(17)) ; - System.out.println(this.Search(50)) ; - return 55 ; - } - - // Print array of integers - public int Print(){ - int j ; - - j = 1 ; - while (j < (size)) { - System.out.println(number[j]); - j = j + 1 ; - } - return 0 ; - } - - // Search for a specific value (num) using - // linear search - public int Search(int num){ - int j ; - boolean ls01 ; - int ifound ; - int aux01 ; - int aux02 ; - int nt ; - - j = 1 ; - ls01 = false ; - ifound = 0 ; - - //System.out.println(num); - while (j < (size)) { - aux01 = number[j] ; - aux02 = num + 1 ; - if (aux01 < num) nt = 0 ; - else if (!(aux01 < aux02)) nt = 0 ; - else { - ls01 = true ; - ifound = 1 ; - j = size ; - } - j = j + 1 ; - } - - return ifound ; - } - - - - // initialize array of integers with some - // some sequence - public int Init(int sz){ - int j ; - int k ; - int aux01 ; - int aux02 ; - - size = sz ; - number = new int[sz] ; - - j = 1 ; - k = size + 1 ; - while (j < (size)) { - aux01 = 2 * j ; - aux02 = k - 3 ; - number[j] = aux01 + aux02 ; - j = j + 1 ; - k = k - 1 ; - } - return 0 ; - } - -} diff --git a/boil/tests/LinkedList.java b/boil/tests/LinkedList.java deleted file mode 100644 index 69adc33..0000000 --- a/boil/tests/LinkedList.java +++ /dev/null @@ -1,278 +0,0 @@ -class LinkedList{ - public static void main(String[] a){ - System.out.println(new LL().Start()); - } -} - -class Element { - int Age ; - int Salary ; - boolean Married ; - - // Initialize some class variables - public boolean Init(int v_Age, int v_Salary, boolean v_Married){ - Age = v_Age ; - Salary = v_Salary ; - Married = v_Married ; - return true ; - } - - public int GetAge(){ - return Age ; - } - - public int GetSalary(){ - return Salary ; - } - - public boolean GetMarried(){ - return Married ; - } - - // This method returns true if the object "other" - // has the same values for age, salary and - public boolean Equal(Element other){ - boolean ret_val ; - int aux01 ; - int aux02 ; - int nt ; - ret_val = true ; - - aux01 = other.GetAge(); - if (!this.Compare(aux01,Age)) ret_val = false ; - else { - aux02 = other.GetSalary(); - if (!this.Compare(aux02,Salary)) ret_val = false ; - else - if (Married) - if (!other.GetMarried()) ret_val = false; - else nt = 0 ; - else - if (other.GetMarried()) ret_val = false; - else nt = 0 ; - } - - return ret_val ; - } - - // This method compares two integers and - // returns true if they are equal and false - // otherwise - public boolean Compare(int num1 , int num2){ - boolean retval ; - int aux02 ; - retval = false ; - aux02 = num2 + 1 ; - if (num1 < num2) retval = false ; - else if (!(num1 < aux02)) retval = false ; - else retval = true ; - return retval ; - } - -} - -class List{ - Element elem ; - List next ; - boolean end ; - - // Initialize the node list as the last node - public boolean Init(){ - end = true ; - return true ; - } - - // Initialize the values of a new node - public boolean InitNew(Element v_elem, List v_next, boolean v_end){ - end = v_end ; - elem = v_elem ; - next = v_next ; - return true ; - } - - // Insert a new node at the beginning of the list - public List Insert(Element new_elem){ - boolean ret_val ; - List aux03 ; - List aux02 ; - aux03 = this ; - aux02 = new List(); - ret_val = aux02.InitNew(new_elem,aux03,false); - return aux02 ; - } - - - // Update the the pointer to the next node - public boolean SetNext(List v_next){ - next = v_next ; - return true ; - } - - // Delete an element e from the list - public List Delete(Element e){ - List my_head ; - boolean ret_val ; - boolean aux05; - List aux01 ; - List prev ; - boolean var_end ; - Element var_elem ; - int aux04 ; - int nt ; - - - my_head = this ; - ret_val = false ; - aux04 = 0 - 1 ; - aux01 = this ; - prev = this ; - var_end = end; - var_elem = elem ; - while ((!var_end) && (!ret_val)){ - if (e.Equal(var_elem)){ - ret_val = true ; - if (aux04 < 0) { - // delete first element - my_head = aux01.GetNext() ; - } - else{ // delete a non first element - System.out.println(0-555); - aux05 = prev.SetNext(aux01.GetNext()); - System.out.println(0-555); - - } - } else nt = 0 ; - if (!ret_val){ - prev = aux01 ; - aux01 = aux01.GetNext() ; - var_end = aux01.GetEnd(); - var_elem = aux01.GetElem(); - aux04 = 1 ; - } else nt = 0 ; - } - return my_head ; - } - - - // Search for an element e on the list - public int Search(Element e){ - int int_ret_val ; - List aux01 ; - Element var_elem ; - boolean var_end ; - int nt ; - - int_ret_val = 0 ; - aux01 = this ; - var_end = end; - var_elem = elem ; - while (!var_end){ - if (e.Equal(var_elem)){ - int_ret_val = 1 ; - } - else nt = 0 ; - aux01 = aux01.GetNext() ; - var_end = aux01.GetEnd(); - var_elem = aux01.GetElem(); - } - return int_ret_val ; - } - - public boolean GetEnd(){ - return end ; - } - - public Element GetElem(){ - return elem ; - } - - public List GetNext(){ - return next ; - } - - - // Print the linked list - public boolean Print(){ - List aux01 ; - boolean var_end ; - Element var_elem ; - - aux01 = this ; - var_end = end ; - var_elem = elem ; - while (!var_end){ - System.out.println(var_elem.GetAge()); - aux01 = aux01.GetNext() ; - var_end = aux01.GetEnd(); - var_elem = aux01.GetElem(); - } - - return true ; - } -} - - -// this class invokes the methods to insert, delete, -// search and print the linked list -class LL{ - - public int Start(){ - - List head ; - List last_elem ; - boolean aux01 ; - Element el01 ; - Element el02 ; - Element el03 ; - - last_elem = new List(); - aux01 = last_elem.Init(); - head = last_elem ; - aux01 = head.Init(); - aux01 = head.Print(); - - // inserting first element - el01 = new Element(); - aux01 = el01.Init(25,37000,false); - head = head.Insert(el01); - aux01 = head.Print(); - System.out.println(10000000); - // inserting second element - el01 = new Element(); - aux01 = el01.Init(39,42000,true); - el02 = el01 ; - head = head.Insert(el01); - aux01 = head.Print(); - System.out.println(10000000); - // inserting third element - el01 = new Element(); - aux01 = el01.Init(22,34000,false); - head = head.Insert(el01); - aux01 = head.Print(); - el03 = new Element(); - aux01 = el03.Init(27,34000,false); - System.out.println(head.Search(el02)); - System.out.println(head.Search(el03)); - System.out.println(10000000); - // inserting fourth element - el01 = new Element(); - aux01 = el01.Init(28,35000,false); - head = head.Insert(el01); - aux01 = head.Print(); - System.out.println(2220000); - - head = head.Delete(el02); - aux01 = head.Print(); - System.out.println(33300000); - - - head = head.Delete(el01); - aux01 = head.Print(); - System.out.println(44440000); - - return 0 ; - - - } - -} diff --git a/boil/tests/MoreThan4.java b/boil/tests/MoreThan4.java deleted file mode 100644 index 4960f01..0000000 --- a/boil/tests/MoreThan4.java +++ /dev/null @@ -1,29 +0,0 @@ -class MoreThan4{ - public static void main(String[] a){ - System.out.println(new MT4().Start(1,2,3,4,5,6)); - } -} - -class MT4 { - public int Start(int p1, int p2, int p3 , int p4, int p5, int p6){ - int aux ; - System.out.println(p1); - System.out.println(p2); - System.out.println(p3); - System.out.println(p4); - System.out.println(p5); - System.out.println(p6); - aux = this.Change(p6,p5,p4,p3,p2,p1); - return aux ; - } - - public int Change(int p1, int p2, int p3 , int p4, int p5, int p6){ - System.out.println(p1); - System.out.println(p2); - System.out.println(p3); - System.out.println(p4); - System.out.println(p5); - System.out.println(p6); - return 0 ; - } -} diff --git a/boil/tests/QuickSort.java b/boil/tests/QuickSort.java deleted file mode 100644 index 5893390..0000000 --- a/boil/tests/QuickSort.java +++ /dev/null @@ -1,112 +0,0 @@ -class QuickSort{ - public static void main(String[] a){ - System.out.println(new QS().Start(10)); - } -} - - -// This class contains the array of integers and -// methods to initialize, print and sort the array -// using Quicksort -class QS{ - - int[] number ; - int size ; - - // Invoke the Initialization, Sort and Printing - // Methods - public int Start(int sz){ - int aux01 ; - aux01 = this.Init(sz); - aux01 = this.Print(); - System.out.println(9999); - aux01 = size - 1 ; - aux01 = this.Sort(0,aux01); - aux01 = this.Print(); - return 0 ; - } - - - // Sort array of integers using Quicksort method - public int Sort(int left, int right){ - int v ; - int i ; - int j ; - int nt; - int t ; - boolean cont01; - boolean cont02; - int aux03 ; - t = 0 ; - if (left < right){ - v = number[right] ; - i = left - 1 ; - j = right ; - cont01 = true ; - while (cont01){ - cont02 = true ; - while (cont02){ - i = i + 1 ; - aux03 = number[i] ; - if (!(aux03