From 1080b37bbe40fe56b919d22804c159cccdca3c95 Mon Sep 17 00:00:00 2001 From: bd-912 Date: Wed, 10 Apr 2024 23:40:25 -0600 Subject: Library rename, created A4 directories --- J2V.java | 4 +- boil/library/BoilSimp.java | 758 ++++++++++++++++++++++++++++++ boil/library/TypeFactory.java | 25 + boil/tests/BinaryTree.java | 334 +++++++++++++ boil/tests/BinaryTree.opt.vapor | 526 +++++++++++++++++++++ boil/tests/BinaryTree.vapor | 719 ++++++++++++++++++++++++++++ boil/tests/BubbleSort.java | 93 ++++ boil/tests/BubbleSort.opt.vapor | 277 +++++++++++ boil/tests/BubbleSort.vapor | 292 ++++++++++++ boil/tests/Factorial.java | 16 + boil/tests/Factorial.opt.vapor | 20 + boil/tests/Factorial.vapor | 30 ++ boil/tests/LinearSearch.java | 99 ++++ boil/tests/LinearSearch.opt.vapor | 130 ++++++ boil/tests/LinearSearch.vapor | 150 ++++++ boil/tests/LinkedList.java | 278 +++++++++++ boil/tests/LinkedList.opt.vapor | 373 +++++++++++++++ boil/tests/LinkedList.vapor | 505 ++++++++++++++++++++ boil/tests/MoreThan4.java | 29 ++ boil/tests/MoreThan4.opt.vapor | 27 ++ boil/tests/MoreThan4.vapor | 38 ++ boil/tests/QuickSort.java | 112 +++++ boil/tests/QuickSort.opt.vapor | 378 +++++++++++++++ boil/tests/QuickSort.vapor | 399 ++++++++++++++++ boil/tests/ShortCircuit.opt.vapor | 215 +++++++++ boil/tests/ShortCircuit.vapor | 128 +++++ boil/tests/TreeVisitor.java | 374 +++++++++++++++ boil/tests/TreeVisitor.opt.vapor | 635 +++++++++++++++++++++++++ boil/tests/TreeVisitor.vapor | 855 ++++++++++++++++++++++++++++++++++ boil/tests/ex1.java | 11 + boil/tests/ex1.vapor | 5 + boil/tests/ex2.java | 7 + boil/tests/ex2.vapor | 11 + boil/tests/ex29.java | 5 + boil/tests/ex30.java | 11 + boil/tests/ex30.vapor | 3 + boil/tests/ex31.java | 16 + boil/tests/ex32.java | 16 + boil/tests/ex33.java | 13 + typecheck/library/TypeCheckSimp.java | 2 +- typecheck/tests/IsPositive.java | 18 +- vaporize/library/TypeFactory.java | 25 - vaporize/library/VaporizeSimp.java | 668 ++++++++++++-------------- vaporize/tests/BinaryTree.java | 334 ------------- vaporize/tests/BinaryTree.opt.vapor | 526 --------------------- vaporize/tests/BinaryTree.vapor | 719 ---------------------------- vaporize/tests/BubbleSort.java | 93 ---- vaporize/tests/BubbleSort.opt.vapor | 277 ----------- vaporize/tests/BubbleSort.vapor | 292 ------------ vaporize/tests/Factorial.java | 16 - vaporize/tests/Factorial.opt.vapor | 20 - vaporize/tests/Factorial.vapor | 30 -- vaporize/tests/LinearSearch.java | 99 ---- vaporize/tests/LinearSearch.opt.vapor | 130 ------ vaporize/tests/LinearSearch.vapor | 150 ------ vaporize/tests/LinkedList.java | 278 ----------- vaporize/tests/LinkedList.opt.vapor | 373 --------------- vaporize/tests/LinkedList.vapor | 505 -------------------- vaporize/tests/MoreThan4.java | 29 -- vaporize/tests/MoreThan4.opt.vapor | 27 -- vaporize/tests/MoreThan4.vapor | 38 -- vaporize/tests/QuickSort.java | 112 ----- vaporize/tests/QuickSort.opt.vapor | 378 --------------- vaporize/tests/QuickSort.vapor | 399 ---------------- vaporize/tests/ShortCircuit.opt.vapor | 215 --------- vaporize/tests/ShortCircuit.vapor | 128 ----- vaporize/tests/TreeVisitor.java | 374 --------------- vaporize/tests/TreeVisitor.opt.vapor | 635 ------------------------- vaporize/tests/TreeVisitor.vapor | 855 ---------------------------------- vaporize/tests_easy/ex1.java | 11 - vaporize/tests_easy/ex1.vapor | 5 - vaporize/tests_easy/ex2.java | 7 - vaporize/tests_easy/ex2.vapor | 11 - vaporize/tests_easy/ex29.java | 5 - vaporize/tests_easy/ex30.java | 11 - vaporize/tests_easy/ex31.java | 16 - 76 files changed, 8225 insertions(+), 7503 deletions(-) create mode 100644 boil/library/BoilSimp.java create mode 100644 boil/library/TypeFactory.java create mode 100644 boil/tests/BinaryTree.java create mode 100644 boil/tests/BinaryTree.opt.vapor create mode 100644 boil/tests/BinaryTree.vapor create mode 100644 boil/tests/BubbleSort.java create mode 100644 boil/tests/BubbleSort.opt.vapor create mode 100644 boil/tests/BubbleSort.vapor create mode 100644 boil/tests/Factorial.java create mode 100644 boil/tests/Factorial.opt.vapor create mode 100644 boil/tests/Factorial.vapor create mode 100644 boil/tests/LinearSearch.java create mode 100644 boil/tests/LinearSearch.opt.vapor create mode 100644 boil/tests/LinearSearch.vapor create mode 100644 boil/tests/LinkedList.java create mode 100644 boil/tests/LinkedList.opt.vapor create mode 100644 boil/tests/LinkedList.vapor create mode 100644 boil/tests/MoreThan4.java create mode 100644 boil/tests/MoreThan4.opt.vapor create mode 100644 boil/tests/MoreThan4.vapor create mode 100644 boil/tests/QuickSort.java create mode 100644 boil/tests/QuickSort.opt.vapor create mode 100644 boil/tests/QuickSort.vapor create mode 100644 boil/tests/ShortCircuit.opt.vapor create mode 100644 boil/tests/ShortCircuit.vapor create mode 100644 boil/tests/TreeVisitor.java create mode 100644 boil/tests/TreeVisitor.opt.vapor create mode 100644 boil/tests/TreeVisitor.vapor create mode 100644 boil/tests/ex1.java create mode 100644 boil/tests/ex1.vapor create mode 100644 boil/tests/ex2.java create mode 100644 boil/tests/ex2.vapor create mode 100644 boil/tests/ex29.java create mode 100644 boil/tests/ex30.java create mode 100644 boil/tests/ex30.vapor create mode 100644 boil/tests/ex31.java create mode 100644 boil/tests/ex32.java create mode 100644 boil/tests/ex33.java delete mode 100644 vaporize/library/TypeFactory.java delete mode 100644 vaporize/tests/BinaryTree.java delete mode 100644 vaporize/tests/BinaryTree.opt.vapor delete mode 100644 vaporize/tests/BinaryTree.vapor delete mode 100644 vaporize/tests/BubbleSort.java delete mode 100644 vaporize/tests/BubbleSort.opt.vapor delete mode 100644 vaporize/tests/BubbleSort.vapor delete mode 100644 vaporize/tests/Factorial.java delete mode 100644 vaporize/tests/Factorial.opt.vapor delete mode 100644 vaporize/tests/Factorial.vapor delete mode 100644 vaporize/tests/LinearSearch.java delete mode 100644 vaporize/tests/LinearSearch.opt.vapor delete mode 100644 vaporize/tests/LinearSearch.vapor delete mode 100644 vaporize/tests/LinkedList.java delete mode 100644 vaporize/tests/LinkedList.opt.vapor delete mode 100644 vaporize/tests/LinkedList.vapor delete mode 100644 vaporize/tests/MoreThan4.java delete mode 100644 vaporize/tests/MoreThan4.opt.vapor delete mode 100644 vaporize/tests/MoreThan4.vapor delete mode 100644 vaporize/tests/QuickSort.java delete mode 100644 vaporize/tests/QuickSort.opt.vapor delete mode 100644 vaporize/tests/QuickSort.vapor delete mode 100644 vaporize/tests/ShortCircuit.opt.vapor delete mode 100644 vaporize/tests/ShortCircuit.vapor delete mode 100644 vaporize/tests/TreeVisitor.java delete mode 100644 vaporize/tests/TreeVisitor.opt.vapor delete mode 100644 vaporize/tests/TreeVisitor.vapor delete mode 100644 vaporize/tests_easy/ex1.java delete mode 100644 vaporize/tests_easy/ex1.vapor delete mode 100644 vaporize/tests_easy/ex2.java delete mode 100644 vaporize/tests_easy/ex2.vapor delete mode 100644 vaporize/tests_easy/ex29.java delete mode 100644 vaporize/tests_easy/ex30.java delete mode 100644 vaporize/tests_easy/ex31.java diff --git a/J2V.java b/J2V.java index 6038ffa..70c715f 100644 --- a/J2V.java +++ b/J2V.java @@ -5,7 +5,7 @@ import syntaxtree.*; import java.util.*; import st.*; import misc.*; -import vaporize.library.*; +import boil.library.*; public class J2V { public static void main(String[] args) { @@ -24,7 +24,7 @@ public class J2V { root.accept(new SymTableBottomUp(), symt); root.accept(new SymTableTopDown(), symt); - VaporizeSimp vp = new VaporizeSimp(); + BoilSimp vp = new BoilSimp(); String program = root.accept(vp, symt); PrintFilter.print("===================================================", true); diff --git a/boil/library/BoilSimp.java b/boil/library/BoilSimp.java new file mode 100644 index 0000000..b5ea518 --- /dev/null +++ b/boil/library/BoilSimp.java @@ -0,0 +1,758 @@ +package boil.library; + +import syntaxtree.*; +import visitor.*; +import st.*; +import misc.*; +import java.util.*; + +public class BoilSimp extends GJDepthFirst { + + TypeFactory tf = new TypeFactory(); + + // + // Auto class visitors--probably don't need to be overridden. + // + public String visit(NodeList n, SymbolTable symt) { + String mod = ""; + int _count=0; + for ( Enumeration e = n.elements(); e.hasMoreElements(); ) { + mod += e.nextElement().accept(this,symt); + _count++; + } + return mod; + } + + public String visit(NodeListOptional n, SymbolTable symt) { + String mod = ""; + if ( n.present() ) { + int _count=0; + for ( Enumeration e = n.elements(); e.hasMoreElements(); ) { + mod += e.nextElement().accept(this,symt); + _count++; + } + return mod; + } + else + return ""; + } + + public String visit(NodeOptional n, SymbolTable symt) { + if ( n.present() ) + return n.node.accept(this,symt); + else + return ""; + } + + public String visit(NodeSequence n, SymbolTable symt) { + String mod = ""; + int _count=0; + for ( Enumeration e = n.elements(); e.hasMoreElements(); ) { + mod += e.nextElement().accept(this,symt); + _count++; + } + return mod; + } + + public String visit(NodeToken n, SymbolTable symt) { return ""; } + + // + // User-generated visitor methods below + // + + /** + * f0 -> MainClass() + * f1 -> ( TypeDeclaration() )* + * f2 -> + */ + public String visit(Goal n, SymbolTable symt) { + String mod = ""; + mod += n.f0.accept(this, symt); + mod += n.f1.accept(this, symt); + mod += n.f2.accept(this, symt); + return mod; + } + + /** + * 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, SymbolTable symt) { + String id = n.f1.f0.tokenImage; + + symt.setActive(TypeEnum.classname, id); + symt.setActive(TypeEnum.method, "main"); + this.tf.reset(); + String mod = ""; + mod += "func Main()\n"; + + mod += n.f0.accept(this, symt); + n.f1.accept(this, symt); // throw class name away + mod += n.f2.accept(this, symt); + mod += n.f3.accept(this, symt); + mod += n.f4.accept(this, symt); + mod += n.f5.accept(this, symt); + mod += n.f6.accept(this, symt); + mod += n.f7.accept(this, symt); + mod += n.f8.accept(this, symt); + mod += n.f9.accept(this, symt); + mod += n.f10.accept(this, symt); + n.f11.accept(this, symt); // throw boiler 'args' variable away + mod += n.f12.accept(this, symt); + mod += n.f13.accept(this, symt); + mod += n.f14.accept(this, symt); // FIXME + mod += n.f15.accept(this, symt); + mod += n.f16.accept(this, symt); + mod += n.f17.accept(this, symt); + + mod += " goto :exit\nerror:\n" + + " Error(\"Mem exhausted\")\n goto :exit\n" + + "exit:\n ret\n\n"; + + symt.removeActive(TypeEnum.method); + return mod; + } + + /** + * f0 -> ClassDeclaration() + * | ClassExtendsDeclaration() + */ + public String visit(TypeDeclaration n, SymbolTable symt) { + String mod = ""; + mod += n.f0.accept(this, symt); + return mod; + } + + /** + * f0 -> "class" + * f1 -> Identifier() + * f2 -> "{" + * f3 -> ( VarDeclaration() )* + * f4 -> ( MethodDeclaration() )* + * f5 -> "}" + */ + public String visit(ClassDeclaration n, SymbolTable symt) { + String id = n.f1.f0.tokenImage; + symt.setActive(TypeEnum.classname, id); + String mod = ""; + + mod += n.f0.accept(this, symt); + n.f1.accept(this, symt); + mod += String.format("const functable_%s\n", id); + for (MethodInstance mtd : symt.getClass(id).getMethods()) { + mod += String.format(" :%s_%s\n", id, mtd); + } + mod += "\n"; + mod += n.f2.accept(this, symt); + mod += n.f3.accept(this, symt); + mod += n.f4.accept(this, symt); + mod += n.f5.accept(this, symt); + + return mod; + } + + /** + * f0 -> "class" + * f1 -> Identifier() + * f2 -> "extends" + * f3 -> Identifier() + * f4 -> "{" + * f5 -> ( VarDeclaration() )* + * f6 -> ( MethodDeclaration() )* + * f7 -> "}" + */ + public String visit(ClassExtendsDeclaration n, SymbolTable symt) { + String id = n.f1.f0.tokenImage; + symt.setActive(TypeEnum.classname, id); + String mod = ""; + + mod += n.f0.accept(this, symt); + mod += n.f1.accept(this, symt); + mod += n.f2.accept(this, symt); + mod += n.f3.accept(this, symt); + mod += n.f4.accept(this, symt); + mod += n.f5.accept(this, symt); + mod += n.f6.accept(this, symt); + mod += n.f7.accept(this, symt); + return mod; + } + + /** + * f0 -> Type() + * f1 -> Identifier() + * f2 -> ";" + */ + public String visit(VarDeclaration n, SymbolTable symt) { + String mod = ""; + + n.f0.accept(this, symt); + String id = n.f1.accept(this, symt); + mod += String.format(" %s = HeapAllocZ(32)\n", + this.tf.addNewAlias(symt.getType(id))); // FIXME add proper allocation size + mod += String.format(" if0 %s goto :error\n", + this.tf.retrieveAlias(symt.getType(id))); + mod += n.f2.accept(this, symt); + return mod; + } + + /** + * 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, SymbolTable symt) { + String id = n.f2.f0.tokenImage; + symt.setActive(TypeEnum.method, id); + this.tf.reset(); + String mod = ""; + + mod += n.f0.accept(this, symt); + n.f1.accept(this, symt); + n.f2.accept(this, symt); + mod += "func " + symt.getActive(TypeEnum.classname) + "_" + id + "(this"; + mod += n.f3.accept(this, symt); + String args = n.f4.accept(this, symt); + mod += String.format("%s)\n", args); + mod += n.f5.accept(this, symt); + mod += n.f6.accept(this, symt); + mod += n.f7.accept(this, symt); + mod += n.f8.accept(this, symt); + mod += n.f9.accept(this, symt); + n.f10.accept(this, symt); // FIXME + mod += n.f11.accept(this, symt); + mod += n.f12.accept(this, symt); + + mod += " ret\n\n"; + + + symt.removeActive(TypeEnum.method); + return mod; + } + + /** + * f0 -> FormalParameter() + * f1 -> ( FormalParameterRest() )* + */ + public String visit(FormalParameterList n, SymbolTable symt) { + String mod = ""; + String arg = n.f0.accept(this, symt); + if (arg != null) + mod += " " + arg; + mod += n.f1.accept(this, symt); + return mod; + } + + /** + * f0 -> Type() + * f1 -> Identifier() + */ + public String visit(FormalParameter n, SymbolTable symt) { + String mod = ""; + mod += n.f0.accept(this, symt); + mod += n.f1.accept(this, symt); + return mod; + } + + /** + * f0 -> "," + * f1 -> FormalParameter() + */ + public String visit(FormalParameterRest n, SymbolTable symt) { + String mod = ""; + mod += n.f0.accept(this, symt); + String arg = n.f1.accept(this, symt); + if (arg != null) + mod += " " + arg; + return mod; + } + + /** + * f0 -> ArrayType() + * | BooleanType() + * | IntegerType() + * | Identifier() + */ + public String visit(Type n, SymbolTable symt) { + String mod = ""; + mod += n.f0.accept(this, symt); + return mod; + } + + /** + * f0 -> "int" + * f1 -> "[" + * f2 -> "]" + */ + public String visit(ArrayType n, SymbolTable symt) { + String mod = ""; + mod += n.f0.accept(this, symt); + mod += n.f1.accept(this, symt); + mod += n.f2.accept(this, symt); + return mod; + } + + /** + * f0 -> "boolean" + */ + public String visit(BooleanType n, SymbolTable symt) { + String mod = ""; + mod += n.f0.accept(this, symt); + return mod; + } + + /** + * f0 -> "int" + */ + public String visit(IntegerType n, SymbolTable symt) { + String mod = ""; + mod += n.f0.accept(this, symt);; + return mod; + } + + /** + * f0 -> Block() + * | AssignmentStatement() + * | ArrayAssignmentStatement() + * | IfStatement() + * | WhileStatement() + * | PrintStatement() + */ + public String visit(Statement n, SymbolTable symt) { + String mod = ""; + mod += n.f0.accept(this, symt); + return mod; + } + + /** + * f0 -> "{" + * f1 -> ( Statement() )* + * f2 -> "}" + */ + public String visit(Block n, SymbolTable symt) { + String mod = ""; + mod += n.f0.accept(this, symt); + mod += n.f1.accept(this, symt); + mod += n.f2.accept(this, symt); + return mod; + } + + /** + * f0 -> Identifier() + * f1 -> "=" + * f2 -> Expression() + * f3 -> ";" + */ + public String visit(AssignmentStatement n, SymbolTable symt) { + String mod = ""; + + String id = n.f0.accept(this, symt); + mod += String.format(" [%s] = ", this.tf.retrieveAlias(symt.getType(id))); + mod += n.f1.accept(this, symt); + mod += n.f2.accept(this, symt); + mod += n.f3.accept(this, symt); + return mod; + } + + /** + * f0 -> Identifier() + * f1 -> "[" + * f2 -> Expression() + * f3 -> "]" + * f4 -> "=" + * f5 -> Expression() + * f6 -> ";" + */ + public String visit(ArrayAssignmentStatement n, SymbolTable symt) { + String mod = ""; + n.f0.accept(this, symt); + mod += n.f1.accept(this, symt); + mod += n.f2.accept(this, symt); + mod += n.f3.accept(this, symt); + mod += n.f4.accept(this, symt); + mod += n.f5.accept(this, symt); + mod += n.f6.accept(this, symt); + return mod; + } + + /** + * f0 -> "if" + * f1 -> "(" + * f2 -> Expression() + * f3 -> ")" + * f4 -> Statement() + * f5 -> "else" + * f6 -> Statement() + */ + public String visit(IfStatement n, SymbolTable symt) { + String mod = ""; + mod += n.f0.accept(this, symt); + mod += n.f1.accept(this, symt); + mod += n.f2.accept(this, symt); + mod += n.f3.accept(this, symt); + mod += n.f4.accept(this, symt); + mod += n.f5.accept(this, symt); + mod += n.f6.accept(this, symt); + return mod; + } + + /** + * f0 -> "while" + * f1 -> "(" + * f2 -> Expression() + * f3 -> ")" + * f4 -> Statement() + */ + public String visit(WhileStatement n, SymbolTable symt) { + String mod = ""; + mod += n.f0.accept(this, symt); + mod += n.f1.accept(this, symt); + mod += n.f2.accept(this, symt); + mod += n.f3.accept(this, symt); + mod += n.f4.accept(this, symt); + return mod; + } + + /** + * f0 -> "System.out.println" + * f1 -> "(" + * f2 -> Expression() + * f3 -> ")" + * f4 -> ";" + */ + public String visit(PrintStatement n, SymbolTable symt) { + String mod = ""; + mod += n.f0.accept(this, symt); + mod += n.f1.accept(this, symt); + mod += n.f2.accept(this, symt); + mod += n.f3.accept(this, symt); + mod += n.f4.accept(this, symt); + return mod; + } + + /** + * f0 -> AndExpression() + * | CompareExpression() + * | PlusExpression() + * | MinusExpression() + * | TimesExpression() + * | ArrayLookup() + * | ArrayLength() + * | MessageSend() + * | PrimaryExpression() + */ + public String visit(Expression n, SymbolTable symt) { + String mod = ""; + mod += n.f0.accept(this, symt); + return mod; + } + + /** + * f0 -> PrimaryExpression() + * f1 -> "&&" + * f2 -> PrimaryExpression() + */ + public String visit(AndExpression n, SymbolTable symt) { + String mod = ""; + mod += n.f0.accept(this, symt); + mod += n.f1.accept(this, symt); + mod += n.f2.accept(this, symt); + return mod; + } + + /** + * f0 -> PrimaryExpression() + * f1 -> "<" + * f2 -> PrimaryExpression() + */ + public String visit(CompareExpression n, SymbolTable symt) { + String mod = ""; + mod += n.f0.accept(this, symt); + mod += n.f1.accept(this, symt); + mod += n.f2.accept(this, symt); + return mod; + } + + /** + * f0 -> PrimaryExpression() + * f1 -> "+" + * f2 -> PrimaryExpression() + */ + public String visit(PlusExpression n, SymbolTable symt) { + String mod = ""; + String oper1 = n.f0.accept(this, symt); + mod += n.f1.accept(this, symt); + String oper2 = n.f2.accept(this, symt); + TypeInstance tp1 = new TypeInstance("tp1", TypeEnum.ERROR); + + mod += String.format(" %s = AddS(%s %s)\n", + this.tf.addNewAlias(tp1), + oper1, + oper2); + + return mod; + } + + /** + * f0 -> PrimaryExpression() + * f1 -> "-" + * f2 -> PrimaryExpression() + */ + public String visit(MinusExpression n, SymbolTable symt) { + String mod = ""; + mod += n.f0.accept(this, symt); + mod += n.f1.accept(this, symt); + mod += n.f2.accept(this, symt); + return mod; + } + + /** + * f0 -> PrimaryExpression() + * f1 -> "*" + * f2 -> PrimaryExpression() + */ + public String visit(TimesExpression n, SymbolTable symt) { + String mod = ""; + mod += n.f0.accept(this, symt); + mod += n.f1.accept(this, symt); + mod += n.f2.accept(this, symt); + return mod; + } + + /** + * f0 -> PrimaryExpression() + * f1 -> "[" + * f2 -> PrimaryExpression() + * f3 -> "]" + */ + public String visit(ArrayLookup n, SymbolTable symt) { + String mod = ""; + mod += n.f0.accept(this, symt); + mod += n.f1.accept(this, symt); + mod += n.f2.accept(this, symt); + mod += n.f3.accept(this, symt); + return mod; + } + + /** + * f0 -> PrimaryExpression() + * f1 -> "." + * f2 -> "length" + */ + public String visit(ArrayLength n, SymbolTable symt) { + String mod = ""; + mod += n.f0.accept(this, symt); + mod += n.f1.accept(this, symt); + mod += n.f2.accept(this, symt); + return mod; + } + + /** + * f0 -> PrimaryExpression() + * f1 -> "." + * f2 -> Identifier() + * f3 -> "(" + * f4 -> ( ExpressionList() )? + * f5 -> ")" + */ + public String visit(MessageSend n, SymbolTable symt) { + String mod = ""; + String id = n.f0.accept(this, symt); + mod += n.f1.accept(this, symt); + String id2 = n.f2.accept(this, symt); + TypeInstance tp1 = new TypeInstance("tp1", TypeEnum.ERROR); // TypeFactory likes to know who it's renting to + TypeInstance tp2 = new TypeInstance("tp2", TypeEnum.ERROR); + + TypeInstance cur = symt.getType(id); + int mtdIndex = cur.getClassInstance() + .getMethods().indexOf(symt.getMethod(id2)) * 4; + + mod += String.format(" %s = [%s+%d]\n", + this.tf.addNewAlias(tp1), + this.tf.retrieveAlias(cur), + 0); + + mod += String.format(" %s = [%s+%d]\n", + this.tf.addNewAlias(tp2), + this.tf.retrieveAlias(tp1), + mtdIndex); + + mod += n.f3.accept(this, symt); + mod = n.f4.accept(this, symt); + mod += n.f5.accept(this, symt); + + mod += String.format(" call %s(%s)\n", + this.tf.retrieveAlias(tp2), + this.tf.retrieveAlias(cur)); + + return mod; + } + + /** + * f0 -> Expression() + * f1 -> ( ExpressionRest() )* + */ + public String visit(ExpressionList n, SymbolTable symt) { + String mod = ""; + mod += n.f0.accept(this, symt); + mod += n.f1.accept(this, symt); + return mod; + } + + /** + * f0 -> "," + * f1 -> Expression() + */ + public String visit(ExpressionRest n, SymbolTable symt) { + String mod = ""; + mod += n.f0.accept(this, symt); + mod += n.f1.accept(this, symt); + return mod; + } + + /** + * f0 -> IntegerLiteral() + * | TrueLiteral() + * | FalseLiteral() + * | Identifier() + * | ThisExpression() + * | ArrayAllocationExpression() + * | AllocationExpression() + * | NotExpression() + * | BracketExpression() + */ + public String visit(PrimaryExpression n, SymbolTable symt) { + String mod = ""; + mod += n.f0.accept(this, symt); + return mod; + } + + /** + * f0 -> + */ + public String visit(IntegerLiteral n, SymbolTable symt) { + String mod = ""; + mod += n.f0.tokenImage; + return mod; + } + + /** + * f0 -> "true" + */ + public String visit(TrueLiteral n, SymbolTable symt) { + String mod = ""; + mod += n.f0.accept(this, symt); + return mod; + } + + /** + * f0 -> "false" + */ + public String visit(FalseLiteral n, SymbolTable symt) { + String mod = ""; + mod += n.f0.accept(this, symt); + return mod; + } + + /** + * f0 -> + */ + public String visit(Identifier n, SymbolTable symt) { + String mod = ""; + mod += n.f0.tokenImage; + return mod; + } + + /** + * f0 -> "this" + */ + public String visit(ThisExpression n, SymbolTable symt) { + String mod = ""; + mod += n.f0.accept(this, symt); + return mod; + } + + /** + * f0 -> "new" + * f1 -> "int" + * f2 -> "[" + * f3 -> Expression() + * f4 -> "]" + */ + public String visit(ArrayAllocationExpression n, SymbolTable symt) { + String mod = ""; + mod += n.f0.accept(this, symt); + mod += n.f1.accept(this, symt); + mod += n.f2.accept(this, symt); + mod += n.f3.accept(this, symt); + mod += n.f4.accept(this, symt); + return mod; + } + + /** + * f0 -> "new" + * f1 -> Identifier() + * f2 -> "(" + * f3 -> ")" + */ + public String visit(AllocationExpression n, SymbolTable symt) { + String mod = ""; + mod += n.f0.accept(this, symt); + String cls = n.f1.accept(this, symt); + mod += String.format(":functable_%s\n", cls); + + mod += n.f2.accept(this, symt); + mod += n.f3.accept(this, symt); + return mod; + } + + /** + * f0 -> "!" + * f1 -> Expression() + */ + public String visit(NotExpression n, SymbolTable symt) { + String mod = ""; + mod += n.f0.accept(this, symt); + mod += n.f1.accept(this, symt); + return mod; + } + + /** + * f0 -> "(" + * f1 -> Expression() + * f2 -> ")" + */ + public String visit(BracketExpression n, SymbolTable symt) { + String mod = ""; + mod += n.f0.accept(this, symt); + mod += n.f1.accept(this, symt); + mod += n.f2.accept(this, symt); + return mod; + } + +} diff --git a/boil/library/TypeFactory.java b/boil/library/TypeFactory.java new file mode 100644 index 0000000..8dd910e --- /dev/null +++ b/boil/library/TypeFactory.java @@ -0,0 +1,25 @@ +package boil.library; + +import java.util.HashMap; +import st.TypeInstance; + +public class TypeFactory { + + private int type_num; + private HashMap map; + + public void reset() { + this.type_num = 0; + this.map = new HashMap<>(); + } + + public String addNewAlias(TypeInstance t) { + String alias = String.format("t.%d", this.type_num++); + this.map.put(t, alias); + return alias; + } + + public String retrieveAlias(TypeInstance t) { + return this.map.get(t); + } +} diff --git a/boil/tests/BinaryTree.java b/boil/tests/BinaryTree.java new file mode 100644 index 0000000..18d1464 --- /dev/null +++ b/boil/tests/BinaryTree.java @@ -0,0 +1,334 @@ +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/BinaryTree.opt.vapor b/boil/tests/BinaryTree.opt.vapor new file mode 100644 index 0000000..ef6ac4e --- /dev/null +++ b/boil/tests/BinaryTree.opt.vapor @@ -0,0 +1,526 @@ + +const empty_BT + +const empty_Tree + + +func Main() + t.0 = call :BT.Start(:empty_BT) + PrintIntS(t.0) + ret + +func BT.Start(this) + root = HeapAllocZ(24) + if root goto :null1 + Error("null pointer") + null1: + ntb = call :Tree.Init(root 16) + if root goto :null2 + Error("null pointer") + null2: + ntb = call :Tree.Print(root) + PrintIntS(100000000) + if root goto :null3 + Error("null pointer") + null3: + ntb = call :Tree.Insert(root 8) + if root goto :null4 + Error("null pointer") + null4: + ntb = call :Tree.Print(root) + if root goto :null5 + Error("null pointer") + null5: + ntb = call :Tree.Insert(root 24) + if root goto :null6 + Error("null pointer") + null6: + ntb = call :Tree.Insert(root 4) + if root goto :null7 + Error("null pointer") + null7: + ntb = call :Tree.Insert(root 12) + if root goto :null8 + Error("null pointer") + null8: + ntb = call :Tree.Insert(root 20) + if root goto :null9 + Error("null pointer") + null9: + ntb = call :Tree.Insert(root 28) + if root goto :null10 + Error("null pointer") + null10: + ntb = call :Tree.Insert(root 14) + if root goto :null11 + Error("null pointer") + null11: + ntb = call :Tree.Print(root) + if root goto :null12 + Error("null pointer") + null12: + t.0 = call :Tree.Search(root 24) + PrintIntS(t.0) + if root goto :null13 + Error("null pointer") + null13: + t.1 = call :Tree.Search(root 12) + PrintIntS(t.1) + if root goto :null14 + Error("null pointer") + null14: + t.2 = call :Tree.Search(root 16) + PrintIntS(t.2) + if root goto :null15 + Error("null pointer") + null15: + t.3 = call :Tree.Search(root 50) + PrintIntS(t.3) + if root goto :null16 + Error("null pointer") + null16: + t.4 = call :Tree.Search(root 12) + PrintIntS(t.4) + if root goto :null17 + Error("null pointer") + null17: + ntb = call :Tree.Delete(root 12) + if root goto :null18 + Error("null pointer") + null18: + ntb = call :Tree.Print(root) + if root goto :null19 + Error("null pointer") + null19: + t.5 = call :Tree.Search(root 12) + PrintIntS(t.5) + ret 0 + +func Tree.Init(this v_key) + [this+8] = v_key + [this+12] = 0 + [this+16] = 0 + ret 1 + +func Tree.SetRight(this rn) + [this+4] = rn + ret 1 + +func Tree.SetLeft(this ln) + [this+0] = ln + ret 1 + +func Tree.GetRight(this) + t.0 = [this+4] + ret t.0 + +func Tree.GetLeft(this) + t.0 = [this+0] + ret t.0 + +func Tree.GetKey(this) + t.0 = [this+8] + ret t.0 + +func Tree.SetKey(this v_key) + [this+8] = v_key + ret 1 + +func Tree.GetHas_Right(this) + t.0 = [this+16] + ret t.0 + +func Tree.GetHas_Left(this) + t.0 = [this+12] + ret t.0 + +func Tree.SetHas_Left(this val) + [this+12] = val + ret 1 + +func Tree.SetHas_Right(this val) + [this+16] = val + ret 1 + +func Tree.Compare(this num1 num2) + ntb = 0 + nti = Add(num2 1) + t.0 = LtS(num1 num2) + if0 t.0 goto :if1_else + ntb = 0 + goto :if1_end + if1_else: + t.1 = LtS(num1 nti) + if t.1 goto :if2_else + ntb = 0 + goto :if2_end + if2_else: + ntb = 1 + if2_end: + if1_end: + ret ntb + +func Tree.Insert(this v_key) + new_node = HeapAllocZ(24) + if new_node goto :null20 + Error("null pointer") + null20: + ntb = call :Tree.Init(new_node v_key) + current_node = this + cont = 1 + while1_top: + if0 cont goto :while1_end + if current_node goto :null21 + Error("null pointer") + null21: + key_aux = call :Tree.GetKey(current_node) + t.0 = LtS(v_key key_aux) + if0 t.0 goto :if3_else + if current_node goto :null22 + Error("null pointer") + null22: + t.1 = call :Tree.GetHas_Left(current_node) + if0 t.1 goto :if4_else + if current_node goto :null23 + Error("null pointer") + null23: + current_node = call :Tree.GetLeft(current_node) + goto :if4_end + if4_else: + cont = 0 + if current_node goto :null24 + Error("null pointer") + null24: + ntb = call :Tree.SetHas_Left(current_node 1) + if current_node goto :null25 + Error("null pointer") + null25: + ntb = call :Tree.SetLeft(current_node new_node) + if4_end: + goto :if3_end + if3_else: + if current_node goto :null26 + Error("null pointer") + null26: + t.2 = call :Tree.GetHas_Right(current_node) + if0 t.2 goto :if5_else + if current_node goto :null27 + Error("null pointer") + null27: + current_node = call :Tree.GetRight(current_node) + goto :if5_end + if5_else: + cont = 0 + if current_node goto :null28 + Error("null pointer") + null28: + ntb = call :Tree.SetHas_Right(current_node 1) + if current_node goto :null29 + Error("null pointer") + null29: + ntb = call :Tree.SetRight(current_node new_node) + if5_end: + if3_end: + goto :while1_top + while1_end: + ret 1 + +func Tree.Delete(this v_key) + current_node = this + parent_node = this + cont = 1 + found = 0 + is_root = 1 + while2_top: + if0 cont goto :while2_end + if current_node goto :null30 + Error("null pointer") + null30: + key_aux = call :Tree.GetKey(current_node) + t.0 = LtS(v_key key_aux) + if0 t.0 goto :if6_else + if current_node goto :null31 + Error("null pointer") + null31: + t.1 = call :Tree.GetHas_Left(current_node) + if0 t.1 goto :if7_else + parent_node = current_node + if current_node goto :null32 + Error("null pointer") + null32: + current_node = call :Tree.GetLeft(current_node) + goto :if7_end + if7_else: + cont = 0 + if7_end: + goto :if6_end + if6_else: + t.2 = LtS(key_aux v_key) + if0 t.2 goto :if8_else + if current_node goto :null33 + Error("null pointer") + null33: + t.3 = call :Tree.GetHas_Right(current_node) + if0 t.3 goto :if9_else + parent_node = current_node + if current_node goto :null34 + Error("null pointer") + null34: + current_node = call :Tree.GetRight(current_node) + goto :if9_end + if9_else: + cont = 0 + if9_end: + goto :if8_end + if8_else: + if0 is_root goto :if10_else + if current_node goto :null35 + Error("null pointer") + null35: + t.4 = call :Tree.GetHas_Right(current_node) + if t.4 goto :if11_else + if current_node goto :null36 + Error("null pointer") + null36: + t.5 = call :Tree.GetHas_Left(current_node) + if t.5 goto :if11_else + ntb = 1 + goto :if11_end + if11_else: + ntb = call :Tree.Remove(this parent_node current_node) + if11_end: + goto :if10_end + if10_else: + ntb = call :Tree.Remove(this parent_node current_node) + if10_end: + found = 1 + cont = 0 + if8_end: + if6_end: + is_root = 0 + goto :while2_top + while2_end: + ret found + +func Tree.Remove(this p_node c_node) + if c_node goto :null37 + Error("null pointer") + null37: + t.0 = call :Tree.GetHas_Left(c_node) + if0 t.0 goto :if12_else + ntb = call :Tree.RemoveLeft(this p_node c_node) + goto :if12_end + if12_else: + if c_node goto :null38 + Error("null pointer") + null38: + t.1 = call :Tree.GetHas_Right(c_node) + if0 t.1 goto :if13_else + ntb = call :Tree.RemoveRight(this p_node c_node) + goto :if13_end + if13_else: + if c_node goto :null39 + Error("null pointer") + null39: + auxkey1 = call :Tree.GetKey(c_node) + if p_node goto :null40 + Error("null pointer") + null40: + t.2 = call :Tree.GetLeft(p_node) + if t.2 goto :null41 + Error("null pointer") + null41: + auxkey2 = call :Tree.GetKey(t.2) + t.3 = call :Tree.Compare(this auxkey1 auxkey2) + if0 t.3 goto :if14_else + if p_node goto :null42 + Error("null pointer") + null42: + t.4 = [this+20] + ntb = call :Tree.SetLeft(p_node t.4) + if p_node goto :null43 + Error("null pointer") + null43: + ntb = call :Tree.SetHas_Left(p_node 0) + goto :if14_end + if14_else: + if p_node goto :null44 + Error("null pointer") + null44: + t.5 = [this+20] + ntb = call :Tree.SetRight(p_node t.5) + if p_node goto :null45 + Error("null pointer") + null45: + ntb = call :Tree.SetHas_Right(p_node 0) + if14_end: + if13_end: + if12_end: + ret 1 + +func Tree.RemoveRight(this p_node c_node) + while3_top: + if c_node goto :null46 + Error("null pointer") + null46: + t.0 = call :Tree.GetHas_Right(c_node) + if0 t.0 goto :while3_end + if c_node goto :null47 + Error("null pointer") + null47: + if c_node goto :null48 + Error("null pointer") + null48: + t.1 = call :Tree.GetRight(c_node) + if t.1 goto :null49 + Error("null pointer") + null49: + t.2 = call :Tree.GetKey(t.1) + ntb = call :Tree.SetKey(c_node t.2) + p_node = c_node + if c_node goto :null50 + Error("null pointer") + null50: + c_node = call :Tree.GetRight(c_node) + goto :while3_top + while3_end: + if p_node goto :null51 + Error("null pointer") + null51: + t.3 = [this+20] + ntb = call :Tree.SetRight(p_node t.3) + if p_node goto :null52 + Error("null pointer") + null52: + ntb = call :Tree.SetHas_Right(p_node 0) + ret 1 + +func Tree.RemoveLeft(this p_node c_node) + while4_top: + if c_node goto :null53 + Error("null pointer") + null53: + t.0 = call :Tree.GetHas_Left(c_node) + if0 t.0 goto :while4_end + if c_node goto :null54 + Error("null pointer") + null54: + if c_node goto :null55 + Error("null pointer") + null55: + t.1 = call :Tree.GetLeft(c_node) + if t.1 goto :null56 + Error("null pointer") + null56: + t.2 = call :Tree.GetKey(t.1) + ntb = call :Tree.SetKey(c_node t.2) + p_node = c_node + if c_node goto :null57 + Error("null pointer") + null57: + c_node = call :Tree.GetLeft(c_node) + goto :while4_top + while4_end: + if p_node goto :null58 + Error("null pointer") + null58: + t.3 = [this+20] + ntb = call :Tree.SetLeft(p_node t.3) + if p_node goto :null59 + Error("null pointer") + null59: + ntb = call :Tree.SetHas_Left(p_node 0) + ret 1 + +func Tree.Search(this v_key) + current_node = this + cont = 1 + ifound = 0 + while5_top: + if0 cont goto :while5_end + if current_node goto :null60 + Error("null pointer") + null60: + key_aux = call :Tree.GetKey(current_node) + t.0 = LtS(v_key key_aux) + if0 t.0 goto :if15_else + if current_node goto :null61 + Error("null pointer") + null61: + t.1 = call :Tree.GetHas_Left(current_node) + if0 t.1 goto :if16_else + if current_node goto :null62 + Error("null pointer") + null62: + current_node = call :Tree.GetLeft(current_node) + goto :if16_end + if16_else: + cont = 0 + if16_end: + goto :if15_end + if15_else: + t.2 = LtS(key_aux v_key) + if0 t.2 goto :if17_else + if current_node goto :null63 + Error("null pointer") + null63: + t.3 = call :Tree.GetHas_Right(current_node) + if0 t.3 goto :if18_else + if current_node goto :null64 + Error("null pointer") + null64: + current_node = call :Tree.GetRight(current_node) + goto :if18_end + if18_else: + cont = 0 + if18_end: + goto :if17_end + if17_else: + ifound = 1 + cont = 0 + if17_end: + if15_end: + goto :while5_top + while5_end: + ret ifound + +func Tree.Print(this) + current_node = this + ntb = call :Tree.RecPrint(this current_node) + ret 1 + +func Tree.RecPrint(this node) + if node goto :null65 + Error("null pointer") + null65: + t.0 = call :Tree.GetHas_Left(node) + if0 t.0 goto :if19_else + if node goto :null66 + Error("null pointer") + null66: + t.1 = call :Tree.GetLeft(node) + ntb = call :Tree.RecPrint(this t.1) + goto :if19_end + if19_else: + ntb = 1 + if19_end: + if node goto :null67 + Error("null pointer") + null67: + t.2 = call :Tree.GetKey(node) + PrintIntS(t.2) + if node goto :null68 + Error("null pointer") + null68: + t.3 = call :Tree.GetHas_Right(node) + if0 t.3 goto :if20_else + if node goto :null69 + Error("null pointer") + null69: + t.4 = call :Tree.GetRight(node) + ntb = call :Tree.RecPrint(this t.4) + goto :if20_end + if20_else: + ntb = 1 + if20_end: + ret 1 diff --git a/boil/tests/BinaryTree.vapor b/boil/tests/BinaryTree.vapor new file mode 100644 index 0000000..275cfe3 --- /dev/null +++ b/boil/tests/BinaryTree.vapor @@ -0,0 +1,719 @@ + +const vmt_BT + :BT.Start + +const vmt_Tree + :Tree.Init + :Tree.SetRight + :Tree.SetLeft + :Tree.GetRight + :Tree.GetLeft + :Tree.GetKey + :Tree.SetKey + :Tree.GetHas_Right + :Tree.GetHas_Left + :Tree.SetHas_Left + :Tree.SetHas_Right + :Tree.Compare + :Tree.Insert + :Tree.Delete + :Tree.Remove + :Tree.RemoveRight + :Tree.RemoveLeft + :Tree.Search + :Tree.Print + :Tree.RecPrint + + +func Main() + t.0 = HeapAllocZ(4) + [t.0] = :vmt_BT + if t.0 goto :null1 + Error("null pointer") + null1: + t.1 = [t.0] + t.1 = [t.1+0] + t.2 = call t.1(t.0) + PrintIntS(t.2) + ret + +func BT.Start(this) + t.0 = HeapAllocZ(28) + [t.0] = :vmt_Tree + root = t.0 + if root goto :null2 + Error("null pointer") + null2: + t.1 = [root] + t.1 = [t.1+0] + ntb = call t.1(root 16) + if root goto :null3 + Error("null pointer") + null3: + t.2 = [root] + t.2 = [t.2+72] + ntb = call t.2(root) + PrintIntS(100000000) + if root goto :null4 + Error("null pointer") + null4: + t.3 = [root] + t.3 = [t.3+48] + ntb = call t.3(root 8) + if root goto :null5 + Error("null pointer") + null5: + t.4 = [root] + t.4 = [t.4+72] + ntb = call t.4(root) + if root goto :null6 + Error("null pointer") + null6: + t.5 = [root] + t.5 = [t.5+48] + ntb = call t.5(root 24) + if root goto :null7 + Error("null pointer") + null7: + t.6 = [root] + t.6 = [t.6+48] + ntb = call t.6(root 4) + if root goto :null8 + Error("null pointer") + null8: + t.7 = [root] + t.7 = [t.7+48] + ntb = call t.7(root 12) + if root goto :null9 + Error("null pointer") + null9: + t.8 = [root] + t.8 = [t.8+48] + ntb = call t.8(root 20) + if root goto :null10 + Error("null pointer") + null10: + t.9 = [root] + t.9 = [t.9+48] + ntb = call t.9(root 28) + if root goto :null11 + Error("null pointer") + null11: + t.10 = [root] + t.10 = [t.10+48] + ntb = call t.10(root 14) + if root goto :null12 + Error("null pointer") + null12: + t.11 = [root] + t.11 = [t.11+72] + ntb = call t.11(root) + if root goto :null13 + Error("null pointer") + null13: + t.12 = [root] + t.12 = [t.12+68] + t.13 = call t.12(root 24) + PrintIntS(t.13) + if root goto :null14 + Error("null pointer") + null14: + t.14 = [root] + t.14 = [t.14+68] + t.15 = call t.14(root 12) + PrintIntS(t.15) + if root goto :null15 + Error("null pointer") + null15: + t.16 = [root] + t.16 = [t.16+68] + t.17 = call t.16(root 16) + PrintIntS(t.17) + if root goto :null16 + Error("null pointer") + null16: + t.18 = [root] + t.18 = [t.18+68] + t.19 = call t.18(root 50) + PrintIntS(t.19) + if root goto :null17 + Error("null pointer") + null17: + t.20 = [root] + t.20 = [t.20+68] + t.21 = call t.20(root 12) + PrintIntS(t.21) + if root goto :null18 + Error("null pointer") + null18: + t.22 = [root] + t.22 = [t.22+52] + ntb = call t.22(root 12) + if root goto :null19 + Error("null pointer") + null19: + t.23 = [root] + t.23 = [t.23+72] + ntb = call t.23(root) + if root goto :null20 + Error("null pointer") + null20: + t.24 = [root] + t.24 = [t.24+68] + t.25 = call t.24(root 12) + PrintIntS(t.25) + ret 0 + +func Tree.Init(this v_key) + [this+12] = v_key + [this+16] = 0 + [this+20] = 0 + ret 1 + +func Tree.SetRight(this rn) + [this+8] = rn + ret 1 + +func Tree.SetLeft(this ln) + [this+4] = ln + ret 1 + +func Tree.GetRight(this) + t.0 = [this+8] + ret t.0 + +func Tree.GetLeft(this) + t.0 = [this+4] + ret t.0 + +func Tree.GetKey(this) + t.0 = [this+12] + ret t.0 + +func Tree.SetKey(this v_key) + [this+12] = v_key + ret 1 + +func Tree.GetHas_Right(this) + t.0 = [this+20] + ret t.0 + +func Tree.GetHas_Left(this) + t.0 = [this+16] + ret t.0 + +func Tree.SetHas_Left(this val) + [this+16] = val + ret 1 + +func Tree.SetHas_Right(this val) + [this+20] = val + ret 1 + +func Tree.Compare(this num1 num2) + ntb = 0 + nti = Add(num2 1) + t.0 = LtS(num1 num2) + if0 t.0 goto :if1_else + ntb = 0 + goto :if1_end + if1_else: + t.1 = LtS(num1 nti) + t.2 = Sub(1 t.1) + if0 t.2 goto :if2_else + ntb = 0 + goto :if2_end + if2_else: + ntb = 1 + if2_end: + if1_end: + ret ntb + +func Tree.Insert(this v_key) + t.0 = HeapAllocZ(28) + [t.0] = :vmt_Tree + new_node = t.0 + if new_node goto :null21 + Error("null pointer") + null21: + t.1 = [new_node] + t.1 = [t.1+0] + ntb = call t.1(new_node v_key) + current_node = this + cont = 1 + while1_top: + if0 cont goto :while1_end + if current_node goto :null22 + Error("null pointer") + null22: + t.2 = [current_node] + t.2 = [t.2+20] + key_aux = call t.2(current_node) + t.3 = LtS(v_key key_aux) + if0 t.3 goto :if3_else + if current_node goto :null23 + Error("null pointer") + null23: + t.4 = [current_node] + t.4 = [t.4+32] + t.5 = call t.4(current_node) + if0 t.5 goto :if4_else + if current_node goto :null24 + Error("null pointer") + null24: + t.6 = [current_node] + t.6 = [t.6+16] + current_node = call t.6(current_node) + goto :if4_end + if4_else: + cont = 0 + if current_node goto :null25 + Error("null pointer") + null25: + t.7 = [current_node] + t.7 = [t.7+36] + ntb = call t.7(current_node 1) + if current_node goto :null26 + Error("null pointer") + null26: + t.8 = [current_node] + t.8 = [t.8+8] + ntb = call t.8(current_node new_node) + if4_end: + goto :if3_end + if3_else: + if current_node goto :null27 + Error("null pointer") + null27: + t.9 = [current_node] + t.9 = [t.9+28] + t.10 = call t.9(current_node) + if0 t.10 goto :if5_else + if current_node goto :null28 + Error("null pointer") + null28: + t.11 = [current_node] + t.11 = [t.11+12] + current_node = call t.11(current_node) + goto :if5_end + if5_else: + cont = 0 + if current_node goto :null29 + Error("null pointer") + null29: + t.12 = [current_node] + t.12 = [t.12+40] + ntb = call t.12(current_node 1) + if current_node goto :null30 + Error("null pointer") + null30: + t.13 = [current_node] + t.13 = [t.13+4] + ntb = call t.13(current_node new_node) + if5_end: + if3_end: + goto :while1_top + while1_end: + ret 1 + +func Tree.Delete(this v_key) + current_node = this + parent_node = this + cont = 1 + found = 0 + is_root = 1 + while2_top: + if0 cont goto :while2_end + if current_node goto :null31 + Error("null pointer") + null31: + t.0 = [current_node] + t.0 = [t.0+20] + key_aux = call t.0(current_node) + t.1 = LtS(v_key key_aux) + if0 t.1 goto :if6_else + if current_node goto :null32 + Error("null pointer") + null32: + t.2 = [current_node] + t.2 = [t.2+32] + t.3 = call t.2(current_node) + if0 t.3 goto :if7_else + parent_node = current_node + if current_node goto :null33 + Error("null pointer") + null33: + t.4 = [current_node] + t.4 = [t.4+16] + current_node = call t.4(current_node) + goto :if7_end + if7_else: + cont = 0 + if7_end: + goto :if6_end + if6_else: + t.5 = LtS(key_aux v_key) + if0 t.5 goto :if8_else + if current_node goto :null34 + Error("null pointer") + null34: + t.6 = [current_node] + t.6 = [t.6+28] + t.7 = call t.6(current_node) + if0 t.7 goto :if9_else + parent_node = current_node + if current_node goto :null35 + Error("null pointer") + null35: + t.8 = [current_node] + t.8 = [t.8+12] + current_node = call t.8(current_node) + goto :if9_end + if9_else: + cont = 0 + if9_end: + goto :if8_end + if8_else: + if0 is_root goto :if10_else + if current_node goto :null36 + Error("null pointer") + null36: + t.10 = [current_node] + t.10 = [t.10+28] + t.11 = call t.10(current_node) + t.12 = Sub(1 t.11) + if0 t.12 goto :ss1_else + if current_node goto :null37 + Error("null pointer") + null37: + t.13 = [current_node] + t.13 = [t.13+32] + t.14 = call t.13(current_node) + t.9 = Sub(1 t.14) + goto :ss1_end + ss1_else: + t.9 = 0 + ss1_end: + if0 t.9 goto :if11_else + ntb = 1 + goto :if11_end + if11_else: + t.15 = [this] + t.15 = [t.15+56] + ntb = call t.15(this parent_node current_node) + if11_end: + goto :if10_end + if10_else: + t.16 = [this] + t.16 = [t.16+56] + ntb = call t.16(this parent_node current_node) + if10_end: + found = 1 + cont = 0 + if8_end: + if6_end: + is_root = 0 + goto :while2_top + while2_end: + ret found + +func Tree.Remove(this p_node c_node) + if c_node goto :null38 + Error("null pointer") + null38: + t.0 = [c_node] + t.0 = [t.0+32] + t.1 = call t.0(c_node) + if0 t.1 goto :if12_else + t.2 = [this] + t.2 = [t.2+64] + ntb = call t.2(this p_node c_node) + goto :if12_end + if12_else: + if c_node goto :null39 + Error("null pointer") + null39: + t.3 = [c_node] + t.3 = [t.3+28] + t.4 = call t.3(c_node) + if0 t.4 goto :if13_else + t.5 = [this] + t.5 = [t.5+60] + ntb = call t.5(this p_node c_node) + goto :if13_end + if13_else: + if c_node goto :null40 + Error("null pointer") + null40: + t.6 = [c_node] + t.6 = [t.6+20] + auxkey1 = call t.6(c_node) + if p_node goto :null41 + Error("null pointer") + null41: + t.7 = [p_node] + t.7 = [t.7+16] + t.8 = call t.7(p_node) + if t.8 goto :null42 + Error("null pointer") + null42: + t.9 = [t.8] + t.9 = [t.9+20] + auxkey2 = call t.9(t.8) + t.10 = [this] + t.10 = [t.10+44] + t.11 = call t.10(this auxkey1 auxkey2) + if0 t.11 goto :if14_else + if p_node goto :null43 + Error("null pointer") + null43: + t.12 = [p_node] + t.12 = [t.12+8] + t.13 = [this+24] + ntb = call t.12(p_node t.13) + if p_node goto :null44 + Error("null pointer") + null44: + t.14 = [p_node] + t.14 = [t.14+36] + ntb = call t.14(p_node 0) + goto :if14_end + if14_else: + if p_node goto :null45 + Error("null pointer") + null45: + t.15 = [p_node] + t.15 = [t.15+4] + t.16 = [this+24] + ntb = call t.15(p_node t.16) + if p_node goto :null46 + Error("null pointer") + null46: + t.17 = [p_node] + t.17 = [t.17+40] + ntb = call t.17(p_node 0) + if14_end: + if13_end: + if12_end: + ret 1 + +func Tree.RemoveRight(this p_node c_node) + while3_top: + if c_node goto :null47 + Error("null pointer") + null47: + t.0 = [c_node] + t.0 = [t.0+28] + t.1 = call t.0(c_node) + if0 t.1 goto :while3_end + if c_node goto :null48 + Error("null pointer") + null48: + t.2 = [c_node] + t.2 = [t.2+24] + if c_node goto :null49 + Error("null pointer") + null49: + t.3 = [c_node] + t.3 = [t.3+12] + t.4 = call t.3(c_node) + if t.4 goto :null50 + Error("null pointer") + null50: + t.5 = [t.4] + t.5 = [t.5+20] + t.6 = call t.5(t.4) + ntb = call t.2(c_node t.6) + p_node = c_node + if c_node goto :null51 + Error("null pointer") + null51: + t.7 = [c_node] + t.7 = [t.7+12] + c_node = call t.7(c_node) + goto :while3_top + while3_end: + if p_node goto :null52 + Error("null pointer") + null52: + t.8 = [p_node] + t.8 = [t.8+4] + t.9 = [this+24] + ntb = call t.8(p_node t.9) + if p_node goto :null53 + Error("null pointer") + null53: + t.10 = [p_node] + t.10 = [t.10+40] + ntb = call t.10(p_node 0) + ret 1 + +func Tree.RemoveLeft(this p_node c_node) + while4_top: + if c_node goto :null54 + Error("null pointer") + null54: + t.0 = [c_node] + t.0 = [t.0+32] + t.1 = call t.0(c_node) + if0 t.1 goto :while4_end + if c_node goto :null55 + Error("null pointer") + null55: + t.2 = [c_node] + t.2 = [t.2+24] + if c_node goto :null56 + Error("null pointer") + null56: + t.3 = [c_node] + t.3 = [t.3+16] + t.4 = call t.3(c_node) + if t.4 goto :null57 + Error("null pointer") + null57: + t.5 = [t.4] + t.5 = [t.5+20] + t.6 = call t.5(t.4) + ntb = call t.2(c_node t.6) + p_node = c_node + if c_node goto :null58 + Error("null pointer") + null58: + t.7 = [c_node] + t.7 = [t.7+16] + c_node = call t.7(c_node) + goto :while4_top + while4_end: + if p_node goto :null59 + Error("null pointer") + null59: + t.8 = [p_node] + t.8 = [t.8+8] + t.9 = [this+24] + ntb = call t.8(p_node t.9) + if p_node goto :null60 + Error("null pointer") + null60: + t.10 = [p_node] + t.10 = [t.10+36] + ntb = call t.10(p_node 0) + ret 1 + +func Tree.Search(this v_key) + current_node = this + cont = 1 + ifound = 0 + while5_top: + if0 cont goto :while5_end + if current_node goto :null61 + Error("null pointer") + null61: + t.0 = [current_node] + t.0 = [t.0+20] + key_aux = call t.0(current_node) + t.1 = LtS(v_key key_aux) + if0 t.1 goto :if15_else + if current_node goto :null62 + Error("null pointer") + null62: + t.2 = [current_node] + t.2 = [t.2+32] + t.3 = call t.2(current_node) + if0 t.3 goto :if16_else + if current_node goto :null63 + Error("null pointer") + null63: + t.4 = [current_node] + t.4 = [t.4+16] + current_node = call t.4(current_node) + goto :if16_end + if16_else: + cont = 0 + if16_end: + goto :if15_end + if15_else: + t.5 = LtS(key_aux v_key) + if0 t.5 goto :if17_else + if current_node goto :null64 + Error("null pointer") + null64: + t.6 = [current_node] + t.6 = [t.6+28] + t.7 = call t.6(current_node) + if0 t.7 goto :if18_else + if current_node goto :null65 + Error("null pointer") + null65: + t.8 = [current_node] + t.8 = [t.8+12] + current_node = call t.8(current_node) + goto :if18_end + if18_else: + cont = 0 + if18_end: + goto :if17_end + if17_else: + ifound = 1 + cont = 0 + if17_end: + if15_end: + goto :while5_top + while5_end: + ret ifound + +func Tree.Print(this) + current_node = this + t.0 = [this] + t.0 = [t.0+76] + ntb = call t.0(this current_node) + ret 1 + +func Tree.RecPrint(this node) + if node goto :null66 + Error("null pointer") + null66: + t.0 = [node] + t.0 = [t.0+32] + t.1 = call t.0(node) + if0 t.1 goto :if19_else + t.2 = [this] + t.2 = [t.2+76] + if node goto :null67 + Error("null pointer") + null67: + t.3 = [node] + t.3 = [t.3+16] + t.4 = call t.3(node) + ntb = call t.2(this t.4) + goto :if19_end + if19_else: + ntb = 1 + if19_end: + if node goto :null68 + Error("null pointer") + null68: + t.5 = [node] + t.5 = [t.5+20] + t.6 = call t.5(node) + PrintIntS(t.6) + if node goto :null69 + Error("null pointer") + null69: + t.7 = [node] + t.7 = [t.7+28] + t.8 = call t.7(node) + if0 t.8 goto :if20_else + t.9 = [this] + t.9 = [t.9+76] + if node goto :null70 + Error("null pointer") + null70: + t.10 = [node] + t.10 = [t.10+12] + t.11 = call t.10(node) + ntb = call t.9(this t.11) + goto :if20_end + if20_else: + ntb = 1 + if20_end: + ret 1 diff --git a/boil/tests/BubbleSort.java b/boil/tests/BubbleSort.java new file mode 100644 index 0000000..e5645a9 --- /dev/null +++ b/boil/tests/BubbleSort.java @@ -0,0 +1,93 @@ +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/BubbleSort.opt.vapor b/boil/tests/BubbleSort.opt.vapor new file mode 100644 index 0000000..a118894 --- /dev/null +++ b/boil/tests/BubbleSort.opt.vapor @@ -0,0 +1,277 @@ + +const empty_BBS + + +func Main() + t.0 = HeapAllocZ(8) + if t.0 goto :null1 + Error("null pointer") + null1: + t.1 = call :BBS.Start(t.0 10) + PrintIntS(t.1) + ret + +func BBS.Start(this sz) + aux01 = call :BBS.Init(this sz) + aux01 = call :BBS.Print(this) + PrintIntS(99999) + aux01 = call :BBS.Sort(this) + aux01 = call :BBS.Print(this) + ret 0 + +func BBS.Sort(this) + t.0 = [this+4] + i = Sub(t.0 1) + aux02 = Sub(0 1) + while1_top: + t.1 = LtS(aux02 i) + if0 t.1 goto :while1_end + j = 1 + while2_top: + t.2 = Add(i 1) + t.3 = LtS(j t.2) + if0 t.3 goto :while2_end + aux07 = Sub(j 1) + t.4 = [this+0] + if t.4 goto :null2 + Error("null pointer") + null2: + t.5 = [t.4] + t.5 = Lt(aux07 t.5) + if t.5 goto :bounds1 + Error("array index out of bounds") + bounds1: + t.5 = MulS(aux07 4) + t.5 = Add(t.5 t.4) + aux04 = [t.5+4] + t.6 = [this+0] + if t.6 goto :null3 + Error("null pointer") + null3: + t.7 = [t.6] + t.7 = Lt(j t.7) + if t.7 goto :bounds2 + Error("array index out of bounds") + bounds2: + t.7 = MulS(j 4) + t.7 = Add(t.7 t.6) + aux05 = [t.7+4] + t.8 = LtS(aux05 aux04) + if0 t.8 goto :if1_else + aux06 = Sub(j 1) + t.9 = [this+0] + if t.9 goto :null4 + Error("null pointer") + null4: + t.10 = [t.9] + t.10 = Lt(aux06 t.10) + if t.10 goto :bounds3 + Error("array index out of bounds") + bounds3: + t.10 = MulS(aux06 4) + t.10 = Add(t.10 t.9) + t = [t.10+4] + t.11 = [this+0] + if t.11 goto :null5 + Error("null pointer") + null5: + t.12 = [t.11] + t.12 = Lt(aux06 t.12) + if t.12 goto :bounds4 + Error("array index out of bounds") + bounds4: + t.12 = MulS(aux06 4) + t.12 = Add(t.12 t.11) + t.13 = [this+0] + if t.13 goto :null6 + Error("null pointer") + null6: + t.14 = [t.13] + t.14 = Lt(j t.14) + if t.14 goto :bounds5 + Error("array index out of bounds") + bounds5: + t.14 = MulS(j 4) + t.14 = Add(t.14 t.13) + t.15 = [t.14+4] + [t.12+4] = t.15 + t.16 = [this+0] + if t.16 goto :null7 + Error("null pointer") + null7: + t.17 = [t.16] + t.17 = Lt(j t.17) + if t.17 goto :bounds6 + Error("array index out of bounds") + bounds6: + t.17 = MulS(j 4) + t.17 = Add(t.17 t.16) + [t.17+4] = t + goto :if1_end + if1_else: + nt = 0 + if1_end: + j = Add(j 1) + goto :while2_top + while2_end: + i = Sub(i 1) + goto :while1_top + while1_end: + ret 0 + +func BBS.Print(this) + j = 0 + while3_top: + t.0 = [this+4] + t.1 = LtS(j t.0) + if0 t.1 goto :while3_end + t.2 = [this+0] + if t.2 goto :null8 + Error("null pointer") + null8: + t.3 = [t.2] + t.3 = Lt(j t.3) + if t.3 goto :bounds7 + Error("array index out of bounds") + bounds7: + t.3 = MulS(j 4) + t.3 = Add(t.3 t.2) + t.4 = [t.3+4] + PrintIntS(t.4) + j = Add(j 1) + goto :while3_top + while3_end: + ret 0 + +func BBS.Init(this sz) + [this+4] = sz + t.0 = call :AllocArray(sz) + [this+0] = t.0 + t.1 = [this+0] + if t.1 goto :null9 + Error("null pointer") + null9: + t.2 = [t.1] + t.2 = Lt(0 t.2) + if t.2 goto :bounds8 + Error("array index out of bounds") + bounds8: + t.2 = MulS(0 4) + t.2 = Add(t.2 t.1) + [t.2+4] = 20 + t.3 = [this+0] + if t.3 goto :null10 + Error("null pointer") + null10: + t.4 = [t.3] + t.4 = Lt(1 t.4) + if t.4 goto :bounds9 + Error("array index out of bounds") + bounds9: + t.4 = MulS(1 4) + t.4 = Add(t.4 t.3) + [t.4+4] = 7 + t.5 = [this+0] + if t.5 goto :null11 + Error("null pointer") + null11: + t.6 = [t.5] + t.6 = Lt(2 t.6) + if t.6 goto :bounds10 + Error("array index out of bounds") + bounds10: + t.6 = MulS(2 4) + t.6 = Add(t.6 t.5) + [t.6+4] = 12 + t.7 = [this+0] + if t.7 goto :null12 + Error("null pointer") + null12: + t.8 = [t.7] + t.8 = Lt(3 t.8) + if t.8 goto :bounds11 + Error("array index out of bounds") + bounds11: + t.8 = MulS(3 4) + t.8 = Add(t.8 t.7) + [t.8+4] = 18 + t.9 = [this+0] + if t.9 goto :null13 + Error("null pointer") + null13: + t.10 = [t.9] + t.10 = Lt(4 t.10) + if t.10 goto :bounds12 + Error("array index out of bounds") + bounds12: + t.10 = MulS(4 4) + t.10 = Add(t.10 t.9) + [t.10+4] = 2 + t.11 = [this+0] + if t.11 goto :null14 + Error("null pointer") + null14: + t.12 = [t.11] + t.12 = Lt(5 t.12) + if t.12 goto :bounds13 + Error("array index out of bounds") + bounds13: + t.12 = MulS(5 4) + t.12 = Add(t.12 t.11) + [t.12+4] = 11 + t.13 = [this+0] + if t.13 goto :null15 + Error("null pointer") + null15: + t.14 = [t.13] + t.14 = Lt(6 t.14) + if t.14 goto :bounds14 + Error("array index out of bounds") + bounds14: + t.14 = MulS(6 4) + t.14 = Add(t.14 t.13) + [t.14+4] = 6 + t.15 = [this+0] + if t.15 goto :null16 + Error("null pointer") + null16: + t.16 = [t.15] + t.16 = Lt(7 t.16) + if t.16 goto :bounds15 + Error("array index out of bounds") + bounds15: + t.16 = MulS(7 4) + t.16 = Add(t.16 t.15) + [t.16+4] = 9 + t.17 = [this+0] + if t.17 goto :null17 + Error("null pointer") + null17: + t.18 = [t.17] + t.18 = Lt(8 t.18) + if t.18 goto :bounds16 + Error("array index out of bounds") + bounds16: + t.18 = MulS(8 4) + t.18 = Add(t.18 t.17) + [t.18+4] = 19 + t.19 = [this+0] + if t.19 goto :null18 + Error("null pointer") + null18: + t.20 = [t.19] + t.20 = Lt(9 t.20) + if t.20 goto :bounds17 + Error("array index out of bounds") + bounds17: + t.20 = MulS(9 4) + t.20 = Add(t.20 t.19) + [t.20+4] = 5 + ret 0 + +func AllocArray(size) + bytes = MulS(size 4) + bytes = Add(bytes 4) + v = HeapAllocZ(bytes) + [v] = size + ret v diff --git a/boil/tests/BubbleSort.vapor b/boil/tests/BubbleSort.vapor new file mode 100644 index 0000000..cedba69 --- /dev/null +++ b/boil/tests/BubbleSort.vapor @@ -0,0 +1,292 @@ + +const vmt_BBS + :BBS.Start + :BBS.Sort + :BBS.Print + :BBS.Init + + +func Main() + t.0 = HeapAllocZ(12) + [t.0] = :vmt_BBS + if t.0 goto :null1 + Error("null pointer") + null1: + t.1 = [t.0] + t.1 = [t.1+0] + t.2 = call t.1(t.0 10) + PrintIntS(t.2) + ret + +func BBS.Start(this sz) + t.0 = [this] + t.0 = [t.0+12] + aux01 = call t.0(this sz) + t.1 = [this] + t.1 = [t.1+8] + aux01 = call t.1(this) + PrintIntS(99999) + t.2 = [this] + t.2 = [t.2+4] + aux01 = call t.2(this) + t.3 = [this] + t.3 = [t.3+8] + aux01 = call t.3(this) + ret 0 + +func BBS.Sort(this) + t.0 = [this+8] + i = Sub(t.0 1) + aux02 = Sub(0 1) + while1_top: + t.1 = LtS(aux02 i) + if0 t.1 goto :while1_end + j = 1 + while2_top: + t.2 = Add(i 1) + t.3 = LtS(j t.2) + if0 t.3 goto :while2_end + aux07 = Sub(j 1) + t.4 = [this+4] + if t.4 goto :null2 + Error("null pointer") + null2: + t.5 = [t.4] + t.5 = Lt(aux07 t.5) + if t.5 goto :bounds1 + Error("array index out of bounds") + bounds1: + t.5 = MulS(aux07 4) + t.5 = Add(t.5 t.4) + aux04 = [t.5+4] + t.6 = [this+4] + if t.6 goto :null3 + Error("null pointer") + null3: + t.7 = [t.6] + t.7 = Lt(j t.7) + if t.7 goto :bounds2 + Error("array index out of bounds") + bounds2: + t.7 = MulS(j 4) + t.7 = Add(t.7 t.6) + aux05 = [t.7+4] + t.8 = LtS(aux05 aux04) + if0 t.8 goto :if1_else + aux06 = Sub(j 1) + t.9 = [this+4] + if t.9 goto :null4 + Error("null pointer") + null4: + t.10 = [t.9] + t.10 = Lt(aux06 t.10) + if t.10 goto :bounds3 + Error("array index out of bounds") + bounds3: + t.10 = MulS(aux06 4) + t.10 = Add(t.10 t.9) + t = [t.10+4] + t.11 = [this+4] + if t.11 goto :null5 + Error("null pointer") + null5: + t.12 = [t.11] + t.12 = Lt(aux06 t.12) + if t.12 goto :bounds4 + Error("array index out of bounds") + bounds4: + t.12 = MulS(aux06 4) + t.12 = Add(t.12 t.11) + t.13 = [this+4] + if t.13 goto :null6 + Error("null pointer") + null6: + t.14 = [t.13] + t.14 = Lt(j t.14) + if t.14 goto :bounds5 + Error("array index out of bounds") + bounds5: + t.14 = MulS(j 4) + t.14 = Add(t.14 t.13) + t.15 = [t.14+4] + [t.12+4] = t.15 + t.16 = [this+4] + if t.16 goto :null7 + Error("null pointer") + null7: + t.17 = [t.16] + t.17 = Lt(j t.17) + if t.17 goto :bounds6 + Error("array index out of bounds") + bounds6: + t.17 = MulS(j 4) + t.17 = Add(t.17 t.16) + [t.17+4] = t + goto :if1_end + if1_else: + nt = 0 + if1_end: + j = Add(j 1) + goto :while2_top + while2_end: + i = Sub(i 1) + goto :while1_top + while1_end: + ret 0 + +func BBS.Print(this) + j = 0 + while3_top: + t.0 = [this+8] + t.1 = LtS(j t.0) + if0 t.1 goto :while3_end + t.2 = [this+4] + if t.2 goto :null8 + Error("null pointer") + null8: + t.3 = [t.2] + t.3 = Lt(j t.3) + if t.3 goto :bounds7 + Error("array index out of bounds") + bounds7: + t.3 = MulS(j 4) + t.3 = Add(t.3 t.2) + t.4 = [t.3+4] + PrintIntS(t.4) + j = Add(j 1) + goto :while3_top + while3_end: + ret 0 + +func BBS.Init(this sz) + [this+8] = sz + t.0 = call :AllocArray(sz) + [this+4] = t.0 + t.1 = [this+4] + if t.1 goto :null9 + Error("null pointer") + null9: + t.2 = [t.1] + t.2 = Lt(0 t.2) + if t.2 goto :bounds8 + Error("array index out of bounds") + bounds8: + t.2 = MulS(0 4) + t.2 = Add(t.2 t.1) + [t.2+4] = 20 + t.3 = [this+4] + if t.3 goto :null10 + Error("null pointer") + null10: + t.4 = [t.3] + t.4 = Lt(1 t.4) + if t.4 goto :bounds9 + Error("array index out of bounds") + bounds9: + t.4 = MulS(1 4) + t.4 = Add(t.4 t.3) + [t.4+4] = 7 + t.5 = [this+4] + if t.5 goto :null11 + Error("null pointer") + null11: + t.6 = [t.5] + t.6 = Lt(2 t.6) + if t.6 goto :bounds10 + Error("array index out of bounds") + bounds10: + t.6 = MulS(2 4) + t.6 = Add(t.6 t.5) + [t.6+4] = 12 + t.7 = [this+4] + if t.7 goto :null12 + Error("null pointer") + null12: + t.8 = [t.7] + t.8 = Lt(3 t.8) + if t.8 goto :bounds11 + Error("array index out of bounds") + bounds11: + t.8 = MulS(3 4) + t.8 = Add(t.8 t.7) + [t.8+4] = 18 + t.9 = [this+4] + if t.9 goto :null13 + Error("null pointer") + null13: + t.10 = [t.9] + t.10 = Lt(4 t.10) + if t.10 goto :bounds12 + Error("array index out of bounds") + bounds12: + t.10 = MulS(4 4) + t.10 = Add(t.10 t.9) + [t.10+4] = 2 + t.11 = [this+4] + if t.11 goto :null14 + Error("null pointer") + null14: + t.12 = [t.11] + t.12 = Lt(5 t.12) + if t.12 goto :bounds13 + Error("array index out of bounds") + bounds13: + t.12 = MulS(5 4) + t.12 = Add(t.12 t.11) + [t.12+4] = 11 + t.13 = [this+4] + if t.13 goto :null15 + Error("null pointer") + null15: + t.14 = [t.13] + t.14 = Lt(6 t.14) + if t.14 goto :bounds14 + Error("array index out of bounds") + bounds14: + t.14 = MulS(6 4) + t.14 = Add(t.14 t.13) + [t.14+4] = 6 + t.15 = [this+4] + if t.15 goto :null16 + Error("null pointer") + null16: + t.16 = [t.15] + t.16 = Lt(7 t.16) + if t.16 goto :bounds15 + Error("array index out of bounds") + bounds15: + t.16 = MulS(7 4) + t.16 = Add(t.16 t.15) + [t.16+4] = 9 + t.17 = [this+4] + if t.17 goto :null17 + Error("null pointer") + null17: + t.18 = [t.17] + t.18 = Lt(8 t.18) + if t.18 goto :bounds16 + Error("array index out of bounds") + bounds16: + t.18 = MulS(8 4) + t.18 = Add(t.18 t.17) + [t.18+4] = 19 + t.19 = [this+4] + if t.19 goto :null18 + Error("null pointer") + null18: + t.20 = [t.19] + t.20 = Lt(9 t.20) + if t.20 goto :bounds17 + Error("array index out of bounds") + bounds17: + t.20 = MulS(9 4) + t.20 = Add(t.20 t.19) + [t.20+4] = 5 + ret 0 + +func AllocArray(size) + bytes = MulS(size 4) + bytes = Add(bytes 4) + v = HeapAllocZ(bytes) + [v] = size + ret v diff --git a/boil/tests/Factorial.java b/boil/tests/Factorial.java new file mode 100644 index 0000000..d938bb6 --- /dev/null +++ b/boil/tests/Factorial.java @@ -0,0 +1,16 @@ +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/Factorial.opt.vapor b/boil/tests/Factorial.opt.vapor new file mode 100644 index 0000000..aca17fe --- /dev/null +++ b/boil/tests/Factorial.opt.vapor @@ -0,0 +1,20 @@ + +const empty_Fac + + +func Main() + t.0 = call :Fac.ComputeFac(:empty_Fac 10) + PrintIntS(t.0) + ret + +func Fac.ComputeFac(this num) + t.0 = LtS(num 1) + if0 t.0 goto :if1_else + num_aux = 1 + goto :if1_end + if1_else: + t.1 = Sub(num 1) + t.2 = call :Fac.ComputeFac(this t.1) + num_aux = MulS(num t.2) + if1_end: + ret num_aux diff --git a/boil/tests/Factorial.vapor b/boil/tests/Factorial.vapor new file mode 100644 index 0000000..28e1126 --- /dev/null +++ b/boil/tests/Factorial.vapor @@ -0,0 +1,30 @@ + +const vmt_Fac + :Fac.ComputeFac + + +func Main() + t.0 = HeapAllocZ(4) + [t.0] = :vmt_Fac + if t.0 goto :null1 + Error("null pointer") + null1: + t.1 = [t.0] + t.1 = [t.1+0] + t.2 = call t.1(t.0 10) + PrintIntS(t.2) + ret + +func Fac.ComputeFac(this num) + t.0 = LtS(num 1) + if0 t.0 goto :if1_else + num_aux = 1 + goto :if1_end + if1_else: + t.1 = [this] + t.1 = [t.1+0] + t.2 = Sub(num 1) + t.3 = call t.1(this t.2) + num_aux = MulS(num t.3) + if1_end: + ret num_aux diff --git a/boil/tests/LinearSearch.java b/boil/tests/LinearSearch.java new file mode 100644 index 0000000..daddd94 --- /dev/null +++ b/boil/tests/LinearSearch.java @@ -0,0 +1,99 @@ +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/LinearSearch.opt.vapor b/boil/tests/LinearSearch.opt.vapor new file mode 100644 index 0000000..302de05 --- /dev/null +++ b/boil/tests/LinearSearch.opt.vapor @@ -0,0 +1,130 @@ + +const empty_LS + + +func Main() + t.0 = HeapAllocZ(8) + if t.0 goto :null1 + Error("null pointer") + null1: + t.1 = call :LS.Start(t.0 10) + PrintIntS(t.1) + ret + +func LS.Start(this sz) + aux01 = call :LS.Init(this sz) + aux02 = call :LS.Print(this) + PrintIntS(9999) + t.0 = call :LS.Search(this 8) + PrintIntS(t.0) + t.1 = call :LS.Search(this 12) + PrintIntS(t.1) + t.2 = call :LS.Search(this 17) + PrintIntS(t.2) + t.3 = call :LS.Search(this 50) + PrintIntS(t.3) + ret 55 + +func LS.Print(this) + j = 1 + while1_top: + t.0 = [this+4] + t.1 = LtS(j t.0) + if0 t.1 goto :while1_end + t.2 = [this+0] + if t.2 goto :null2 + Error("null pointer") + null2: + t.3 = [t.2] + t.3 = Lt(j t.3) + if t.3 goto :bounds1 + Error("array index out of bounds") + bounds1: + t.3 = MulS(j 4) + t.3 = Add(t.3 t.2) + t.4 = [t.3+4] + PrintIntS(t.4) + j = Add(j 1) + goto :while1_top + while1_end: + ret 0 + +func LS.Search(this num) + j = 1 + ls01 = 0 + ifound = 0 + while2_top: + t.0 = [this+4] + t.1 = LtS(j t.0) + if0 t.1 goto :while2_end + t.2 = [this+0] + if t.2 goto :null3 + Error("null pointer") + null3: + t.3 = [t.2] + t.3 = Lt(j t.3) + if t.3 goto :bounds2 + Error("array index out of bounds") + bounds2: + t.3 = MulS(j 4) + t.3 = Add(t.3 t.2) + aux01 = [t.3+4] + aux02 = Add(num 1) + t.4 = LtS(aux01 num) + if0 t.4 goto :if1_else + nt = 0 + goto :if1_end + if1_else: + t.5 = LtS(aux01 aux02) + if t.5 goto :if2_else + nt = 0 + goto :if2_end + if2_else: + ls01 = 1 + ifound = 1 + j = [this+4] + if2_end: + if1_end: + j = Add(j 1) + goto :while2_top + while2_end: + ret ifound + +func LS.Init(this sz) + [this+4] = sz + t.0 = call :AllocArray(sz) + [this+0] = t.0 + j = 1 + t.1 = [this+4] + k = Add(t.1 1) + while3_top: + t.2 = [this+4] + t.3 = LtS(j t.2) + if0 t.3 goto :while3_end + aux01 = MulS(2 j) + aux02 = Sub(k 3) + t.4 = [this+0] + if t.4 goto :null4 + Error("null pointer") + null4: + t.5 = [t.4] + t.5 = Lt(j t.5) + if t.5 goto :bounds3 + Error("array index out of bounds") + bounds3: + t.5 = MulS(j 4) + t.5 = Add(t.5 t.4) + t.6 = Add(aux01 aux02) + [t.5+4] = t.6 + j = Add(j 1) + k = Sub(k 1) + goto :while3_top + while3_end: + ret 0 + +func AllocArray(size) + bytes = MulS(size 4) + bytes = Add(bytes 4) + v = HeapAllocZ(bytes) + [v] = size + ret v diff --git a/boil/tests/LinearSearch.vapor b/boil/tests/LinearSearch.vapor new file mode 100644 index 0000000..db4884a --- /dev/null +++ b/boil/tests/LinearSearch.vapor @@ -0,0 +1,150 @@ + +const vmt_LS + :LS.Start + :LS.Print + :LS.Search + :LS.Init + + +func Main() + t.0 = HeapAllocZ(12) + [t.0] = :vmt_LS + if t.0 goto :null1 + Error("null pointer") + null1: + t.1 = [t.0] + t.1 = [t.1+0] + t.2 = call t.1(t.0 10) + PrintIntS(t.2) + ret + +func LS.Start(this sz) + t.0 = [this] + t.0 = [t.0+12] + aux01 = call t.0(this sz) + t.1 = [this] + t.1 = [t.1+4] + aux02 = call t.1(this) + PrintIntS(9999) + t.2 = [this] + t.2 = [t.2+8] + t.3 = call t.2(this 8) + PrintIntS(t.3) + t.4 = [this] + t.4 = [t.4+8] + t.5 = call t.4(this 12) + PrintIntS(t.5) + t.6 = [this] + t.6 = [t.6+8] + t.7 = call t.6(this 17) + PrintIntS(t.7) + t.8 = [this] + t.8 = [t.8+8] + t.9 = call t.8(this 50) + PrintIntS(t.9) + ret 55 + +func LS.Print(this) + j = 1 + while1_top: + t.0 = [this+8] + t.1 = LtS(j t.0) + if0 t.1 goto :while1_end + t.2 = [this+4] + if t.2 goto :null2 + Error("null pointer") + null2: + t.3 = [t.2] + t.3 = Lt(j t.3) + if t.3 goto :bounds1 + Error("array index out of bounds") + bounds1: + t.3 = MulS(j 4) + t.3 = Add(t.3 t.2) + t.4 = [t.3+4] + PrintIntS(t.4) + j = Add(j 1) + goto :while1_top + while1_end: + ret 0 + +func LS.Search(this num) + j = 1 + ls01 = 0 + ifound = 0 + while2_top: + t.0 = [this+8] + t.1 = LtS(j t.0) + if0 t.1 goto :while2_end + t.2 = [this+4] + if t.2 goto :null3 + Error("null pointer") + null3: + t.3 = [t.2] + t.3 = Lt(j t.3) + if t.3 goto :bounds2 + Error("array index out of bounds") + bounds2: + t.3 = MulS(j 4) + t.3 = Add(t.3 t.2) + aux01 = [t.3+4] + aux02 = Add(num 1) + t.4 = LtS(aux01 num) + if0 t.4 goto :if1_else + nt = 0 + goto :if1_end + if1_else: + t.5 = LtS(aux01 aux02) + t.6 = Sub(1 t.5) + if0 t.6 goto :if2_else + nt = 0 + goto :if2_end + if2_else: + ls01 = 1 + ifound = 1 + j = [this+8] + if2_end: + if1_end: + j = Add(j 1) + goto :while2_top + while2_end: + ret ifound + +func LS.Init(this sz) + [this+8] = sz + t.0 = call :AllocArray(sz) + [this+4] = t.0 + j = 1 + t.1 = [this+8] + k = Add(t.1 1) + while3_top: + t.2 = [this+8] + t.3 = LtS(j t.2) + if0 t.3 goto :while3_end + aux01 = MulS(2 j) + aux02 = Sub(k 3) + t.4 = [this+4] + if t.4 goto :null4 + Error("null pointer") + null4: + t.5 = [t.4] + t.5 = Lt(j t.5) + if t.5 goto :bounds3 + Error("array index out of bounds") + bounds3: + t.5 = MulS(j 4) + t.5 = Add(t.5 t.4) + t.6 = Add(aux01 aux02) + [t.5+4] = t.6 + j = Add(j 1) + k = Sub(k 1) + goto :while3_top + while3_end: + ret 0 + +func AllocArray(size) + bytes = MulS(size 4) + bytes = Add(bytes 4) + v = HeapAllocZ(bytes) + [v] = size + ret v diff --git a/boil/tests/LinkedList.java b/boil/tests/LinkedList.java new file mode 100644 index 0000000..69adc33 --- /dev/null +++ b/boil/tests/LinkedList.java @@ -0,0 +1,278 @@ +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/LinkedList.opt.vapor b/boil/tests/LinkedList.opt.vapor new file mode 100644 index 0000000..aaca62c --- /dev/null +++ b/boil/tests/LinkedList.opt.vapor @@ -0,0 +1,373 @@ + +const empty_Element + +const empty_List + +const empty_LL + + +func Main() + t.0 = call :LL.Start(:empty_LL) + PrintIntS(t.0) + ret + +func Element.Init(this v_Age v_Salary v_Married) + [this+0] = v_Age + [this+4] = v_Salary + [this+8] = v_Married + ret 1 + +func Element.GetAge(this) + t.0 = [this+0] + ret t.0 + +func Element.GetSalary(this) + t.0 = [this+4] + ret t.0 + +func Element.GetMarried(this) + t.0 = [this+8] + ret t.0 + +func Element.Equal(this other) + ret_val = 1 + if other goto :null1 + Error("null pointer") + null1: + aux01 = call :Element.GetAge(other) + t.0 = [this+0] + t.1 = call :Element.Compare(this aux01 t.0) + if t.1 goto :if1_else + ret_val = 0 + goto :if1_end + if1_else: + if other goto :null2 + Error("null pointer") + null2: + aux02 = call :Element.GetSalary(other) + t.2 = [this+4] + t.3 = call :Element.Compare(this aux02 t.2) + if t.3 goto :if2_else + ret_val = 0 + goto :if2_end + if2_else: + t.4 = [this+8] + if0 t.4 goto :if3_else + if other goto :null3 + Error("null pointer") + null3: + t.5 = call :Element.GetMarried(other) + if t.5 goto :if4_else + ret_val = 0 + goto :if4_end + if4_else: + nt = 0 + if4_end: + goto :if3_end + if3_else: + if other goto :null4 + Error("null pointer") + null4: + t.6 = call :Element.GetMarried(other) + if0 t.6 goto :if5_else + ret_val = 0 + goto :if5_end + if5_else: + nt = 0 + if5_end: + if3_end: + if2_end: + if1_end: + ret ret_val + +func Element.Compare(this num1 num2) + retval = 0 + aux02 = Add(num2 1) + t.0 = LtS(num1 num2) + if0 t.0 goto :if6_else + retval = 0 + goto :if6_end + if6_else: + t.1 = LtS(num1 aux02) + if t.1 goto :if7_else + retval = 0 + goto :if7_end + if7_else: + retval = 1 + if7_end: + if6_end: + ret retval + +func List.Init(this) + [this+8] = 1 + ret 1 + +func List.InitNew(this v_elem v_next v_end) + [this+8] = v_end + [this+0] = v_elem + [this+4] = v_next + ret 1 + +func List.Insert(this new_elem) + aux03 = this + aux02 = HeapAllocZ(12) + if aux02 goto :null5 + Error("null pointer") + null5: + ret_val = call :List.InitNew(aux02 new_elem aux03 0) + ret aux02 + +func List.SetNext(this v_next) + [this+4] = v_next + ret 1 + +func List.Delete(this e) + my_head = this + ret_val = 0 + aux04 = Sub(0 1) + aux01 = this + prev = this + var_end = [this+8] + var_elem = [this+0] + while1_top: + if var_end goto :ss1_else + t.0 = Sub(1 ret_val) + goto :ss1_end + ss1_else: + t.0 = 0 + ss1_end: + if0 t.0 goto :while1_end + if e goto :null6 + Error("null pointer") + null6: + t.1 = call :Element.Equal(e var_elem) + if0 t.1 goto :if8_else + ret_val = 1 + t.2 = LtS(aux04 0) + if0 t.2 goto :if9_else + if aux01 goto :null7 + Error("null pointer") + null7: + my_head = call :List.GetNext(aux01) + goto :if9_end + if9_else: + t.3 = Sub(0 555) + PrintIntS(t.3) + if prev goto :null8 + Error("null pointer") + null8: + if aux01 goto :null9 + Error("null pointer") + null9: + t.4 = call :List.GetNext(aux01) + aux05 = call :List.SetNext(prev t.4) + t.5 = Sub(0 555) + PrintIntS(t.5) + if9_end: + goto :if8_end + if8_else: + nt = 0 + if8_end: + if ret_val goto :if10_else + prev = aux01 + if aux01 goto :null10 + Error("null pointer") + null10: + aux01 = call :List.GetNext(aux01) + if aux01 goto :null11 + Error("null pointer") + null11: + var_end = call :List.GetEnd(aux01) + if aux01 goto :null12 + Error("null pointer") + null12: + var_elem = call :List.GetElem(aux01) + aux04 = 1 + goto :if10_end + if10_else: + nt = 0 + if10_end: + goto :while1_top + while1_end: + ret my_head + +func List.Search(this e) + int_ret_val = 0 + aux01 = this + var_end = [this+8] + var_elem = [this+0] + while2_top: + t.0 = Sub(1 var_end) + if0 t.0 goto :while2_end + if e goto :null13 + Error("null pointer") + null13: + t.1 = call :Element.Equal(e var_elem) + if0 t.1 goto :if11_else + int_ret_val = 1 + goto :if11_end + if11_else: + nt = 0 + if11_end: + if aux01 goto :null14 + Error("null pointer") + null14: + aux01 = call :List.GetNext(aux01) + if aux01 goto :null15 + Error("null pointer") + null15: + var_end = call :List.GetEnd(aux01) + if aux01 goto :null16 + Error("null pointer") + null16: + var_elem = call :List.GetElem(aux01) + goto :while2_top + while2_end: + ret int_ret_val + +func List.GetEnd(this) + t.0 = [this+8] + ret t.0 + +func List.GetElem(this) + t.0 = [this+0] + ret t.0 + +func List.GetNext(this) + t.0 = [this+4] + ret t.0 + +func List.Print(this) + aux01 = this + var_end = [this+8] + var_elem = [this+0] + while3_top: + t.0 = Sub(1 var_end) + if0 t.0 goto :while3_end + if var_elem goto :null17 + Error("null pointer") + null17: + t.1 = call :Element.GetAge(var_elem) + PrintIntS(t.1) + if aux01 goto :null18 + Error("null pointer") + null18: + aux01 = call :List.GetNext(aux01) + if aux01 goto :null19 + Error("null pointer") + null19: + var_end = call :List.GetEnd(aux01) + if aux01 goto :null20 + Error("null pointer") + null20: + var_elem = call :List.GetElem(aux01) + goto :while3_top + while3_end: + ret 1 + +func LL.Start(this) + last_elem = HeapAllocZ(12) + if last_elem goto :null21 + Error("null pointer") + null21: + aux01 = call :List.Init(last_elem) + head = last_elem + if head goto :null22 + Error("null pointer") + null22: + aux01 = call :List.Init(head) + if head goto :null23 + Error("null pointer") + null23: + aux01 = call :List.Print(head) + el01 = HeapAllocZ(12) + if el01 goto :null24 + Error("null pointer") + null24: + aux01 = call :Element.Init(el01 25 37000 0) + if head goto :null25 + Error("null pointer") + null25: + head = call :List.Insert(head el01) + if head goto :null26 + Error("null pointer") + null26: + aux01 = call :List.Print(head) + PrintIntS(10000000) + el01 = HeapAllocZ(12) + if el01 goto :null27 + Error("null pointer") + null27: + aux01 = call :Element.Init(el01 39 42000 1) + el02 = el01 + if head goto :null28 + Error("null pointer") + null28: + head = call :List.Insert(head el01) + if head goto :null29 + Error("null pointer") + null29: + aux01 = call :List.Print(head) + PrintIntS(10000000) + el01 = HeapAllocZ(12) + if el01 goto :null30 + Error("null pointer") + null30: + aux01 = call :Element.Init(el01 22 34000 0) + if head goto :null31 + Error("null pointer") + null31: + head = call :List.Insert(head el01) + if head goto :null32 + Error("null pointer") + null32: + aux01 = call :List.Print(head) + el03 = HeapAllocZ(12) + if el03 goto :null33 + Error("null pointer") + null33: + aux01 = call :Element.Init(el03 27 34000 0) + if head goto :null34 + Error("null pointer") + null34: + t.0 = call :List.Search(head el02) + PrintIntS(t.0) + if head goto :null35 + Error("null pointer") + null35: + t.1 = call :List.Search(head el03) + PrintIntS(t.1) + PrintIntS(10000000) + el01 = HeapAllocZ(12) + if el01 goto :null36 + Error("null pointer") + null36: + aux01 = call :Element.Init(el01 28 35000 0) + if head goto :null37 + Error("null pointer") + null37: + head = call :List.Insert(head el01) + if head goto :null38 + Error("null pointer") + null38: + aux01 = call :List.Print(head) + PrintIntS(2220000) + if head goto :null39 + Error("null pointer") + null39: + head = call :List.Delete(head el02) + if head goto :null40 + Error("null pointer") + null40: + aux01 = call :List.Print(head) + PrintIntS(33300000) + if head goto :null41 + Error("null pointer") + null41: + head = call :List.Delete(head el01) + if head goto :null42 + Error("null pointer") + null42: + aux01 = call :List.Print(head) + PrintIntS(44440000) + ret 0 diff --git a/boil/tests/LinkedList.vapor b/boil/tests/LinkedList.vapor new file mode 100644 index 0000000..bebdf94 --- /dev/null +++ b/boil/tests/LinkedList.vapor @@ -0,0 +1,505 @@ + +const vmt_Element + :Element.Init + :Element.GetAge + :Element.GetSalary + :Element.GetMarried + :Element.Equal + :Element.Compare + +const vmt_List + :List.Init + :List.InitNew + :List.Insert + :List.SetNext + :List.Delete + :List.Search + :List.GetEnd + :List.GetElem + :List.GetNext + :List.Print + +const vmt_LL + :LL.Start + + +func Main() + t.0 = HeapAllocZ(4) + [t.0] = :vmt_LL + if t.0 goto :null1 + Error("null pointer") + null1: + t.1 = [t.0] + t.1 = [t.1+0] + t.2 = call t.1(t.0) + PrintIntS(t.2) + ret + +func Element.Init(this v_Age v_Salary v_Married) + [this+4] = v_Age + [this+8] = v_Salary + [this+12] = v_Married + ret 1 + +func Element.GetAge(this) + t.0 = [this+4] + ret t.0 + +func Element.GetSalary(this) + t.0 = [this+8] + ret t.0 + +func Element.GetMarried(this) + t.0 = [this+12] + ret t.0 + +func Element.Equal(this other) + ret_val = 1 + if other goto :null2 + Error("null pointer") + null2: + t.0 = [other] + t.0 = [t.0+4] + aux01 = call t.0(other) + t.1 = [this] + t.1 = [t.1+20] + t.2 = [this+4] + t.3 = call t.1(this aux01 t.2) + t.4 = Sub(1 t.3) + if0 t.4 goto :if1_else + ret_val = 0 + goto :if1_end + if1_else: + if other goto :null3 + Error("null pointer") + null3: + t.5 = [other] + t.5 = [t.5+8] + aux02 = call t.5(other) + t.6 = [this] + t.6 = [t.6+20] + t.7 = [this+8] + t.8 = call t.6(this aux02 t.7) + t.9 = Sub(1 t.8) + if0 t.9 goto :if2_else + ret_val = 0 + goto :if2_end + if2_else: + t.10 = [this+12] + if0 t.10 goto :if3_else + if other goto :null4 + Error("null pointer") + null4: + t.11 = [other] + t.11 = [t.11+12] + t.12 = call t.11(other) + t.13 = Sub(1 t.12) + if0 t.13 goto :if4_else + ret_val = 0 + goto :if4_end + if4_else: + nt = 0 + if4_end: + goto :if3_end + if3_else: + if other goto :null5 + Error("null pointer") + null5: + t.14 = [other] + t.14 = [t.14+12] + t.15 = call t.14(other) + if0 t.15 goto :if5_else + ret_val = 0 + goto :if5_end + if5_else: + nt = 0 + if5_end: + if3_end: + if2_end: + if1_end: + ret ret_val + +func Element.Compare(this num1 num2) + retval = 0 + aux02 = Add(num2 1) + t.0 = LtS(num1 num2) + if0 t.0 goto :if6_else + retval = 0 + goto :if6_end + if6_else: + t.1 = LtS(num1 aux02) + t.2 = Sub(1 t.1) + if0 t.2 goto :if7_else + retval = 0 + goto :if7_end + if7_else: + retval = 1 + if7_end: + if6_end: + ret retval + +func List.Init(this) + [this+12] = 1 + ret 1 + +func List.InitNew(this v_elem v_next v_end) + [this+12] = v_end + [this+4] = v_elem + [this+8] = v_next + ret 1 + +func List.Insert(this new_elem) + aux03 = this + t.0 = HeapAllocZ(16) + [t.0] = :vmt_List + aux02 = t.0 + if aux02 goto :null6 + Error("null pointer") + null6: + t.1 = [aux02] + t.1 = [t.1+4] + ret_val = call t.1(aux02 new_elem aux03 0) + ret aux02 + +func List.SetNext(this v_next) + [this+8] = v_next + ret 1 + +func List.Delete(this e) + my_head = this + ret_val = 0 + aux04 = Sub(0 1) + aux01 = this + prev = this + var_end = [this+12] + var_elem = [this+4] + while1_top: + t.1 = Sub(1 var_end) + if0 t.1 goto :ss1_else + t.0 = Sub(1 ret_val) + goto :ss1_end + ss1_else: + t.0 = 0 + ss1_end: + if0 t.0 goto :while1_end + if e goto :null7 + Error("null pointer") + null7: + t.2 = [e] + t.2 = [t.2+16] + t.3 = call t.2(e var_elem) + if0 t.3 goto :if8_else + ret_val = 1 + t.4 = LtS(aux04 0) + if0 t.4 goto :if9_else + if aux01 goto :null8 + Error("null pointer") + null8: + t.5 = [aux01] + t.5 = [t.5+32] + my_head = call t.5(aux01) + goto :if9_end + if9_else: + t.6 = Sub(0 555) + PrintIntS(t.6) + if prev goto :null9 + Error("null pointer") + null9: + t.7 = [prev] + t.7 = [t.7+12] + if aux01 goto :null10 + Error("null pointer") + null10: + t.8 = [aux01] + t.8 = [t.8+32] + t.9 = call t.8(aux01) + aux05 = call t.7(prev t.9) + t.10 = Sub(0 555) + PrintIntS(t.10) + if9_end: + goto :if8_end + if8_else: + nt = 0 + if8_end: + t.11 = Sub(1 ret_val) + if0 t.11 goto :if10_else + prev = aux01 + if aux01 goto :null11 + Error("null pointer") + null11: + t.12 = [aux01] + t.12 = [t.12+32] + aux01 = call t.12(aux01) + if aux01 goto :null12 + Error("null pointer") + null12: + t.13 = [aux01] + t.13 = [t.13+24] + var_end = call t.13(aux01) + if aux01 goto :null13 + Error("null pointer") + null13: + t.14 = [aux01] + t.14 = [t.14+28] + var_elem = call t.14(aux01) + aux04 = 1 + goto :if10_end + if10_else: + nt = 0 + if10_end: + goto :while1_top + while1_end: + ret my_head + +func List.Search(this e) + int_ret_val = 0 + aux01 = this + var_end = [this+12] + var_elem = [this+4] + while2_top: + t.0 = Sub(1 var_end) + if0 t.0 goto :while2_end + if e goto :null14 + Error("null pointer") + null14: + t.1 = [e] + t.1 = [t.1+16] + t.2 = call t.1(e var_elem) + if0 t.2 goto :if11_else + int_ret_val = 1 + goto :if11_end + if11_else: + nt = 0 + if11_end: + if aux01 goto :null15 + Error("null pointer") + null15: + t.3 = [aux01] + t.3 = [t.3+32] + aux01 = call t.3(aux01) + if aux01 goto :null16 + Error("null pointer") + null16: + t.4 = [aux01] + t.4 = [t.4+24] + var_end = call t.4(aux01) + if aux01 goto :null17 + Error("null pointer") + null17: + t.5 = [aux01] + t.5 = [t.5+28] + var_elem = call t.5(aux01) + goto :while2_top + while2_end: + ret int_ret_val + +func List.GetEnd(this) + t.0 = [this+12] + ret t.0 + +func List.GetElem(this) + t.0 = [this+4] + ret t.0 + +func List.GetNext(this) + t.0 = [this+8] + ret t.0 + +func List.Print(this) + aux01 = this + var_end = [this+12] + var_elem = [this+4] + while3_top: + t.0 = Sub(1 var_end) + if0 t.0 goto :while3_end + if var_elem goto :null18 + Error("null pointer") + null18: + t.1 = [var_elem] + t.1 = [t.1+4] + t.2 = call t.1(var_elem) + PrintIntS(t.2) + if aux01 goto :null19 + Error("null pointer") + null19: + t.3 = [aux01] + t.3 = [t.3+32] + aux01 = call t.3(aux01) + if aux01 goto :null20 + Error("null pointer") + null20: + t.4 = [aux01] + t.4 = [t.4+24] + var_end = call t.4(aux01) + if aux01 goto :null21 + Error("null pointer") + null21: + t.5 = [aux01] + t.5 = [t.5+28] + var_elem = call t.5(aux01) + goto :while3_top + while3_end: + ret 1 + +func LL.Start(this) + t.0 = HeapAllocZ(16) + [t.0] = :vmt_List + last_elem = t.0 + if last_elem goto :null22 + Error("null pointer") + null22: + t.1 = [last_elem] + t.1 = [t.1+0] + aux01 = call t.1(last_elem) + head = last_elem + if head goto :null23 + Error("null pointer") + null23: + t.2 = [head] + t.2 = [t.2+0] + aux01 = call t.2(head) + if head goto :null24 + Error("null pointer") + null24: + t.3 = [head] + t.3 = [t.3+36] + aux01 = call t.3(head) + t.4 = HeapAllocZ(16) + [t.4] = :vmt_Element + el01 = t.4 + if el01 goto :null25 + Error("null pointer") + null25: + t.5 = [el01] + t.5 = [t.5+0] + aux01 = call t.5(el01 25 37000 0) + if head goto :null26 + Error("null pointer") + null26: + t.6 = [head] + t.6 = [t.6+8] + head = call t.6(head el01) + if head goto :null27 + Error("null pointer") + null27: + t.7 = [head] + t.7 = [t.7+36] + aux01 = call t.7(head) + PrintIntS(10000000) + t.8 = HeapAllocZ(16) + [t.8] = :vmt_Element + el01 = t.8 + if el01 goto :null28 + Error("null pointer") + null28: + t.9 = [el01] + t.9 = [t.9+0] + aux01 = call t.9(el01 39 42000 1) + el02 = el01 + if head goto :null29 + Error("null pointer") + null29: + t.10 = [head] + t.10 = [t.10+8] + head = call t.10(head el01) + if head goto :null30 + Error("null pointer") + null30: + t.11 = [head] + t.11 = [t.11+36] + aux01 = call t.11(head) + PrintIntS(10000000) + t.12 = HeapAllocZ(16) + [t.12] = :vmt_Element + el01 = t.12 + if el01 goto :null31 + Error("null pointer") + null31: + t.13 = [el01] + t.13 = [t.13+0] + aux01 = call t.13(el01 22 34000 0) + if head goto :null32 + Error("null pointer") + null32: + t.14 = [head] + t.14 = [t.14+8] + head = call t.14(head el01) + if head goto :null33 + Error("null pointer") + null33: + t.15 = [head] + t.15 = [t.15+36] + aux01 = call t.15(head) + t.16 = HeapAllocZ(16) + [t.16] = :vmt_Element + el03 = t.16 + if el03 goto :null34 + Error("null pointer") + null34: + t.17 = [el03] + t.17 = [t.17+0] + aux01 = call t.17(el03 27 34000 0) + if head goto :null35 + Error("null pointer") + null35: + t.18 = [head] + t.18 = [t.18+20] + t.19 = call t.18(head el02) + PrintIntS(t.19) + if head goto :null36 + Error("null pointer") + null36: + t.20 = [head] + t.20 = [t.20+20] + t.21 = call t.20(head el03) + PrintIntS(t.21) + PrintIntS(10000000) + t.22 = HeapAllocZ(16) + [t.22] = :vmt_Element + el01 = t.22 + if el01 goto :null37 + Error("null pointer") + null37: + t.23 = [el01] + t.23 = [t.23+0] + aux01 = call t.23(el01 28 35000 0) + if head goto :null38 + Error("null pointer") + null38: + t.24 = [head] + t.24 = [t.24+8] + head = call t.24(head el01) + if head goto :null39 + Error("null pointer") + null39: + t.25 = [head] + t.25 = [t.25+36] + aux01 = call t.25(head) + PrintIntS(2220000) + if head goto :null40 + Error("null pointer") + null40: + t.26 = [head] + t.26 = [t.26+16] + head = call t.26(head el02) + if head goto :null41 + Error("null pointer") + null41: + t.27 = [head] + t.27 = [t.27+36] + aux01 = call t.27(head) + PrintIntS(33300000) + if head goto :null42 + Error("null pointer") + null42: + t.28 = [head] + t.28 = [t.28+16] + head = call t.28(head el01) + if head goto :null43 + Error("null pointer") + null43: + t.29 = [head] + t.29 = [t.29+36] + aux01 = call t.29(head) + PrintIntS(44440000) + ret 0 diff --git a/boil/tests/MoreThan4.java b/boil/tests/MoreThan4.java new file mode 100644 index 0000000..4960f01 --- /dev/null +++ b/boil/tests/MoreThan4.java @@ -0,0 +1,29 @@ +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/MoreThan4.opt.vapor b/boil/tests/MoreThan4.opt.vapor new file mode 100644 index 0000000..a59d1b5 --- /dev/null +++ b/boil/tests/MoreThan4.opt.vapor @@ -0,0 +1,27 @@ + +const empty_MT4 + + +func Main() + t.0 = call :MT4.Start(:empty_MT4 1 2 3 4 5 6) + PrintIntS(t.0) + ret + +func MT4.Start(this p1 p2 p3 p4 p5 p6) + PrintIntS(p1) + PrintIntS(p2) + PrintIntS(p3) + PrintIntS(p4) + PrintIntS(p5) + PrintIntS(p6) + aux = call :MT4.Change(this p6 p5 p4 p3 p2 p1) + ret aux + +func MT4.Change(this p1 p2 p3 p4 p5 p6) + PrintIntS(p1) + PrintIntS(p2) + PrintIntS(p3) + PrintIntS(p4) + PrintIntS(p5) + PrintIntS(p6) + ret 0 diff --git a/boil/tests/MoreThan4.vapor b/boil/tests/MoreThan4.vapor new file mode 100644 index 0000000..6067f8e --- /dev/null +++ b/boil/tests/MoreThan4.vapor @@ -0,0 +1,38 @@ + +const vmt_MT4 + :MT4.Start + :MT4.Change + + +func Main() + t.0 = HeapAllocZ(4) + [t.0] = :vmt_MT4 + if t.0 goto :null1 + Error("null pointer") + null1: + t.1 = [t.0] + t.1 = [t.1+0] + t.2 = call t.1(t.0 1 2 3 4 5 6) + PrintIntS(t.2) + ret + +func MT4.Start(this p1 p2 p3 p4 p5 p6) + PrintIntS(p1) + PrintIntS(p2) + PrintIntS(p3) + PrintIntS(p4) + PrintIntS(p5) + PrintIntS(p6) + t.0 = [this] + t.0 = [t.0+4] + aux = call t.0(this p6 p5 p4 p3 p2 p1) + ret aux + +func MT4.Change(this p1 p2 p3 p4 p5 p6) + PrintIntS(p1) + PrintIntS(p2) + PrintIntS(p3) + PrintIntS(p4) + PrintIntS(p5) + PrintIntS(p6) + ret 0 diff --git a/boil/tests/QuickSort.java b/boil/tests/QuickSort.java new file mode 100644 index 0000000..5893390 --- /dev/null +++ b/boil/tests/QuickSort.java @@ -0,0 +1,112 @@ +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 { n.f8.accept(this, symt); n.f9.accept(this, symt); n.f10.accept(this, symt); - // TypeInstance args = n.f11.accept(this, symt); // FIXME Type in the main class declaration uses an illegal minijava type? + // TypeInstance args = n.f11.accept(this, symt); n.f12.accept(this, symt); n.f13.accept(this, symt); TypeInstance var_dec = n.f14.accept(this, symt); diff --git a/typecheck/tests/IsPositive.java b/typecheck/tests/IsPositive.java index 087cd3f..09bcf1d 100644 --- a/typecheck/tests/IsPositive.java +++ b/typecheck/tests/IsPositive.java @@ -1,12 +1,24 @@ class IsPositive{ public static void main(String[] a){ - System.out.println(new Positive().isPos(10)); + System.out.println(new Positive().isPositive(10)); } } class Positive { - public bool isPos(int num){ - bool positive ; + public boolean isPositive(int num){ + boolean positive ; + + if (0 < num) + positive = true ; + else + positive = false ; + return positive ; + } +} + +class Positive2 extends Positive { + public boolean isPositive(int num){ + boolean positive ; if (0 < num) positive = true ; diff --git a/vaporize/library/TypeFactory.java b/vaporize/library/TypeFactory.java deleted file mode 100644 index b73862f..0000000 --- a/vaporize/library/TypeFactory.java +++ /dev/null @@ -1,25 +0,0 @@ -package vaporize.library; - -import java.util.HashMap; -import st.TypeInstance; - -public class TypeFactory { - - private int type_num; - private HashMap map; - - public void reset() { - this.type_num = 0; - this.map = new HashMap<>(); - } - - public String addNewAlias(TypeInstance t) { - String alias = String.format("t.%d", this.type_num++); - this.map.put(t, alias); - return alias; - } - - public String retrieveAlias(TypeInstance t) { - return this.map.get(t); - } -} diff --git a/vaporize/library/VaporizeSimp.java b/vaporize/library/VaporizeSimp.java index a7faf88..6c69ea2 100644 --- a/vaporize/library/VaporizeSimp.java +++ b/vaporize/library/VaporizeSimp.java @@ -1,60 +1,58 @@ package vaporize.library; import syntaxtree.*; -import visitor.*; +package visitor; import st.*; import misc.*; import java.util.*; -public class VaporizeSimp extends GJDepthFirst { - - TypeFactory tf = new TypeFactory(); +public class VaporizeSimp implements GJVisitor { // // Auto class visitors--probably don't need to be overridden. // - public String visit(NodeList n, SymbolTable symt) { - String mod = ""; + public R visit(NodeList n, A argu) { + R _ret=null; int _count=0; for ( Enumeration e = n.elements(); e.hasMoreElements(); ) { - mod += e.nextElement().accept(this,symt); + e.nextElement().accept(this,argu); _count++; } - return mod; + return _ret; } - public String visit(NodeListOptional n, SymbolTable symt) { - String mod = ""; + public R visit(NodeListOptional n, A argu) { if ( n.present() ) { + R _ret=null; int _count=0; for ( Enumeration e = n.elements(); e.hasMoreElements(); ) { - mod += e.nextElement().accept(this,symt); + e.nextElement().accept(this,argu); _count++; } - return mod; + return _ret; } else - return ""; + return null; } - public String visit(NodeOptional n, SymbolTable symt) { + public R visit(NodeOptional n, A argu) { if ( n.present() ) - return n.node.accept(this,symt); + return n.node.accept(this,argu); else - return ""; + return null; } - public String visit(NodeSequence n, SymbolTable symt) { - String mod = ""; + public R visit(NodeSequence n, A argu) { + R _ret=null; int _count=0; for ( Enumeration e = n.elements(); e.hasMoreElements(); ) { - mod += e.nextElement().accept(this,symt); + e.nextElement().accept(this,argu); _count++; } - return mod; + return _ret; } - public String visit(NodeToken n, SymbolTable symt) { return ""; } + public R visit(NodeToken n, A argu) { return null; } // // User-generated visitor methods below @@ -65,12 +63,12 @@ public class VaporizeSimp extends GJDepthFirst { * f1 -> ( TypeDeclaration() )* * f2 -> */ - public String visit(Goal n, SymbolTable symt) { - String mod = ""; - mod += n.f0.accept(this, symt); - mod += n.f1.accept(this, symt); - mod += n.f2.accept(this, symt); - return mod; + public R visit(Goal n, A argu) { + R _ret=null; + n.f0.accept(this, argu); + n.f1.accept(this, argu); + n.f2.accept(this, argu); + return _ret; } /** @@ -93,50 +91,37 @@ public class VaporizeSimp extends GJDepthFirst { * f16 -> "}" * f17 -> "}" */ - public String visit(MainClass n, SymbolTable symt) { - String id = n.f1.f0.tokenImage; - - symt.setActive(TypeEnum.classname, id); - symt.setActive(TypeEnum.method, "main"); - this.tf.reset(); - String mod = ""; - mod += "func Main()\n"; - - mod += n.f0.accept(this, symt); - n.f1.accept(this, symt); // throw class name away - mod += n.f2.accept(this, symt); - mod += n.f3.accept(this, symt); - mod += n.f4.accept(this, symt); - mod += n.f5.accept(this, symt); - mod += n.f6.accept(this, symt); - mod += n.f7.accept(this, symt); - mod += n.f8.accept(this, symt); - mod += n.f9.accept(this, symt); - mod += n.f10.accept(this, symt); - n.f11.accept(this, symt); // throw boiler 'args' variable away - mod += n.f12.accept(this, symt); - mod += n.f13.accept(this, symt); - mod += n.f14.accept(this, symt); // FIXME - mod += n.f15.accept(this, symt); - mod += n.f16.accept(this, symt); - mod += n.f17.accept(this, symt); - - mod += " goto :exit\nerror:\n" + - " Error(\"Mem exhausted\")\n goto :exit\n" + - "exit:\n ret\n\n"; - - symt.removeActive(TypeEnum.method); - return mod; + public R visit(MainClass n, A argu) { + R _ret=null; + n.f0.accept(this, argu); + n.f1.accept(this, argu); + n.f2.accept(this, argu); + n.f3.accept(this, argu); + n.f4.accept(this, argu); + n.f5.accept(this, argu); + n.f6.accept(this, argu); + n.f7.accept(this, argu); + n.f8.accept(this, argu); + n.f9.accept(this, argu); + n.f10.accept(this, argu); + n.f11.accept(this, argu); + n.f12.accept(this, argu); + n.f13.accept(this, argu); + n.f14.accept(this, argu); + n.f15.accept(this, argu); + n.f16.accept(this, argu); + n.f17.accept(this, argu); + return _ret; } /** * f0 -> ClassDeclaration() * | ClassExtendsDeclaration() */ - public String visit(TypeDeclaration n, SymbolTable symt) { - String mod = ""; - mod += n.f0.accept(this, symt); - return mod; + public R visit(TypeDeclaration n, A argu) { + R _ret=null; + n.f0.accept(this, argu); + return _ret; } /** @@ -147,24 +132,15 @@ public class VaporizeSimp extends GJDepthFirst { * f4 -> ( MethodDeclaration() )* * f5 -> "}" */ - public String visit(ClassDeclaration n, SymbolTable symt) { - String id = n.f1.f0.tokenImage; - symt.setActive(TypeEnum.classname, id); - String mod = ""; - - mod += n.f0.accept(this, symt); - n.f1.accept(this, symt); - mod += String.format("const functable_%s\n", id); - for (MethodInstance mtd : symt.getClass(id).getMethods()) { - mod += String.format(" :%s_%s\n", id, mtd); - } - mod += "\n"; - mod += n.f2.accept(this, symt); - mod += n.f3.accept(this, symt); - mod += n.f4.accept(this, symt); - mod += n.f5.accept(this, symt); - - return mod; + public R visit(ClassDeclaration n, A argu) { + R _ret=null; + n.f0.accept(this, argu); + n.f1.accept(this, argu); + n.f2.accept(this, argu); + n.f3.accept(this, argu); + n.f4.accept(this, argu); + n.f5.accept(this, argu); + return _ret; } /** @@ -177,20 +153,17 @@ public class VaporizeSimp extends GJDepthFirst { * f6 -> ( MethodDeclaration() )* * f7 -> "}" */ - public String visit(ClassExtendsDeclaration n, SymbolTable symt) { - String id = n.f1.f0.tokenImage; - symt.setActive(TypeEnum.classname, id); - String mod = ""; - - mod += n.f0.accept(this, symt); - mod += n.f1.accept(this, symt); - mod += n.f2.accept(this, symt); - mod += n.f3.accept(this, symt); - mod += n.f4.accept(this, symt); - mod += n.f5.accept(this, symt); - mod += n.f6.accept(this, symt); - mod += n.f7.accept(this, symt); - return mod; + public R visit(ClassExtendsDeclaration n, A argu) { + R _ret=null; + n.f0.accept(this, argu); + n.f1.accept(this, argu); + n.f2.accept(this, argu); + n.f3.accept(this, argu); + n.f4.accept(this, argu); + n.f5.accept(this, argu); + n.f6.accept(this, argu); + n.f7.accept(this, argu); + return _ret; } /** @@ -198,17 +171,12 @@ public class VaporizeSimp extends GJDepthFirst { * f1 -> Identifier() * f2 -> ";" */ - public String visit(VarDeclaration n, SymbolTable symt) { - String mod = ""; - - n.f0.accept(this, symt); - String id = n.f1.accept(this, symt); - mod += String.format(" %s = HeapAllocZ(32)\n", - this.tf.addNewAlias(symt.getType(id))); // FIXME add proper allocation size - mod += String.format(" if0 %s goto :error\n", - this.tf.retrieveAlias(symt.getType(id))); - mod += n.f2.accept(this, symt); - return mod; + public R visit(VarDeclaration n, A argu) { + R _ret=null; + n.f0.accept(this, argu); + n.f1.accept(this, argu); + n.f2.accept(this, argu); + return _ret; } /** @@ -226,70 +194,55 @@ public class VaporizeSimp extends GJDepthFirst { * f11 -> ";" * f12 -> "}" */ - public String visit(MethodDeclaration n, SymbolTable symt) { - String id = n.f2.f0.tokenImage; - symt.setActive(TypeEnum.method, id); - this.tf.reset(); - String mod = ""; - - mod += n.f0.accept(this, symt); - n.f1.accept(this, symt); - n.f2.accept(this, symt); - mod += "func " + symt.getActive(TypeEnum.classname) + "_" + id + "(this"; - mod += n.f3.accept(this, symt); - String args = n.f4.accept(this, symt); - mod += String.format("%s)\n", args); - mod += n.f5.accept(this, symt); - mod += n.f6.accept(this, symt); - mod += n.f7.accept(this, symt); - mod += n.f8.accept(this, symt); - mod += n.f9.accept(this, symt); - n.f10.accept(this, symt); // FIXME - mod += n.f11.accept(this, symt); - mod += n.f12.accept(this, symt); - - mod += " ret\n\n"; - - - symt.removeActive(TypeEnum.method); - return mod; + public R visit(MethodDeclaration n, A argu) { + R _ret=null; + n.f0.accept(this, argu); + n.f1.accept(this, argu); + n.f2.accept(this, argu); + n.f3.accept(this, argu); + n.f4.accept(this, argu); + n.f5.accept(this, argu); + n.f6.accept(this, argu); + n.f7.accept(this, argu); + n.f8.accept(this, argu); + n.f9.accept(this, argu); + n.f10.accept(this, argu); + n.f11.accept(this, argu); + n.f12.accept(this, argu); + return _ret; } /** * f0 -> FormalParameter() * f1 -> ( FormalParameterRest() )* */ - public String visit(FormalParameterList n, SymbolTable symt) { - String mod = ""; - String arg = n.f0.accept(this, symt); - if (arg != null) - mod += " " + arg; - mod += n.f1.accept(this, symt); - return mod; + public R visit(FormalParameterList n, A argu) { + R _ret=null; + n.f0.accept(this, argu); + n.f1.accept(this, argu); + return _ret; } /** * f0 -> Type() * f1 -> Identifier() */ - public String visit(FormalParameter n, SymbolTable symt) { - String mod = ""; - mod += n.f0.accept(this, symt); - mod += n.f1.accept(this, symt); - return mod; + public R visit(FormalParameter n, A argu) { + R _ret=null; + n.f0.accept(this, argu); + n.f1.accept(this, argu); + return _ret; } /** * f0 -> "," * f1 -> FormalParameter() */ - public String visit(FormalParameterRest n, SymbolTable symt) { - String mod = ""; - mod += n.f0.accept(this, symt); - String arg = n.f1.accept(this, symt); - if (arg != null) - mod += " " + arg; - return mod; + public R visit(FormalParameterRest n, A argu) { + R _ret=null; + n.f0.accept(this, argu); + n.f1.accept(this, argu); + return _ret; } /** @@ -298,10 +251,10 @@ public class VaporizeSimp extends GJDepthFirst { * | IntegerType() * | Identifier() */ - public String visit(Type n, SymbolTable symt) { - String mod = ""; - mod += n.f0.accept(this, symt); - return mod; + public R visit(Type n, A argu) { + R _ret=null; + n.f0.accept(this, argu); + return _ret; } /** @@ -309,30 +262,30 @@ public class VaporizeSimp extends GJDepthFirst { * f1 -> "[" * f2 -> "]" */ - public String visit(ArrayType n, SymbolTable symt) { - String mod = ""; - mod += n.f0.accept(this, symt); - mod += n.f1.accept(this, symt); - mod += n.f2.accept(this, symt); - return mod; + public R visit(ArrayType n, A argu) { + R _ret=null; + n.f0.accept(this, argu); + n.f1.accept(this, argu); + n.f2.accept(this, argu); + return _ret; } /** * f0 -> "boolean" */ - public String visit(BooleanType n, SymbolTable symt) { - String mod = ""; - mod += n.f0.accept(this, symt); - return mod; + public R visit(BooleanType n, A argu) { + R _ret=null; + n.f0.accept(this, argu); + return _ret; } /** * f0 -> "int" */ - public String visit(IntegerType n, SymbolTable symt) { - String mod = ""; - mod += n.f0.accept(this, symt);; - return mod; + public R visit(IntegerType n, A argu) { + R _ret=null; + n.f0.accept(this, argu); + return _ret; } /** @@ -343,10 +296,10 @@ public class VaporizeSimp extends GJDepthFirst { * | WhileStatement() * | PrintStatement() */ - public String visit(Statement n, SymbolTable symt) { - String mod = ""; - mod += n.f0.accept(this, symt); - return mod; + public R visit(Statement n, A argu) { + R _ret=null; + n.f0.accept(this, argu); + return _ret; } /** @@ -354,12 +307,12 @@ public class VaporizeSimp extends GJDepthFirst { * f1 -> ( Statement() )* * f2 -> "}" */ - public String visit(Block n, SymbolTable symt) { - String mod = ""; - mod += n.f0.accept(this, symt); - mod += n.f1.accept(this, symt); - mod += n.f2.accept(this, symt); - return mod; + public R visit(Block n, A argu) { + R _ret=null; + n.f0.accept(this, argu); + n.f1.accept(this, argu); + n.f2.accept(this, argu); + return _ret; } /** @@ -368,15 +321,13 @@ public class VaporizeSimp extends GJDepthFirst { * f2 -> Expression() * f3 -> ";" */ - public String visit(AssignmentStatement n, SymbolTable symt) { - String mod = ""; - - String id = n.f0.accept(this, symt); - mod += String.format(" [%s] = ", this.tf.retrieveAlias(symt.getType(id))); - mod += n.f1.accept(this, symt); - mod += n.f2.accept(this, symt); - mod += n.f3.accept(this, symt); - return mod; + public R visit(AssignmentStatement n, A argu) { + R _ret=null; + n.f0.accept(this, argu); + n.f1.accept(this, argu); + n.f2.accept(this, argu); + n.f3.accept(this, argu); + return _ret; } /** @@ -388,16 +339,16 @@ public class VaporizeSimp extends GJDepthFirst { * f5 -> Expression() * f6 -> ";" */ - public String visit(ArrayAssignmentStatement n, SymbolTable symt) { - String mod = ""; - n.f0.accept(this, symt); - mod += n.f1.accept(this, symt); - mod += n.f2.accept(this, symt); - mod += n.f3.accept(this, symt); - mod += n.f4.accept(this, symt); - mod += n.f5.accept(this, symt); - mod += n.f6.accept(this, symt); - return mod; + public R visit(ArrayAssignmentStatement n, A argu) { + R _ret=null; + n.f0.accept(this, argu); + n.f1.accept(this, argu); + n.f2.accept(this, argu); + n.f3.accept(this, argu); + n.f4.accept(this, argu); + n.f5.accept(this, argu); + n.f6.accept(this, argu); + return _ret; } /** @@ -409,16 +360,16 @@ public class VaporizeSimp extends GJDepthFirst { * f5 -> "else" * f6 -> Statement() */ - public String visit(IfStatement n, SymbolTable symt) { - String mod = ""; - mod += n.f0.accept(this, symt); - mod += n.f1.accept(this, symt); - mod += n.f2.accept(this, symt); - mod += n.f3.accept(this, symt); - mod += n.f4.accept(this, symt); - mod += n.f5.accept(this, symt); - mod += n.f6.accept(this, symt); - return mod; + public R visit(IfStatement n, A argu) { + R _ret=null; + n.f0.accept(this, argu); + n.f1.accept(this, argu); + n.f2.accept(this, argu); + n.f3.accept(this, argu); + n.f4.accept(this, argu); + n.f5.accept(this, argu); + n.f6.accept(this, argu); + return _ret; } /** @@ -428,14 +379,14 @@ public class VaporizeSimp extends GJDepthFirst { * f3 -> ")" * f4 -> Statement() */ - public String visit(WhileStatement n, SymbolTable symt) { - String mod = ""; - mod += n.f0.accept(this, symt); - mod += n.f1.accept(this, symt); - mod += n.f2.accept(this, symt); - mod += n.f3.accept(this, symt); - mod += n.f4.accept(this, symt); - return mod; + public R visit(WhileStatement n, A argu) { + R _ret=null; + n.f0.accept(this, argu); + n.f1.accept(this, argu); + n.f2.accept(this, argu); + n.f3.accept(this, argu); + n.f4.accept(this, argu); + return _ret; } /** @@ -445,14 +396,14 @@ public class VaporizeSimp extends GJDepthFirst { * f3 -> ")" * f4 -> ";" */ - public String visit(PrintStatement n, SymbolTable symt) { - String mod = ""; - mod += n.f0.accept(this, symt); - mod += n.f1.accept(this, symt); - mod += n.f2.accept(this, symt); - mod += n.f3.accept(this, symt); - mod += n.f4.accept(this, symt); - return mod; + public R visit(PrintStatement n, A argu) { + R _ret=null; + n.f0.accept(this, argu); + n.f1.accept(this, argu); + n.f2.accept(this, argu); + n.f3.accept(this, argu); + n.f4.accept(this, argu); + return _ret; } /** @@ -466,10 +417,10 @@ public class VaporizeSimp extends GJDepthFirst { * | MessageSend() * | PrimaryExpression() */ - public String visit(Expression n, SymbolTable symt) { - String mod = ""; - mod += n.f0.accept(this, symt); - return mod; + public R visit(Expression n, A argu) { + R _ret=null; + n.f0.accept(this, argu); + return _ret; } /** @@ -477,12 +428,12 @@ public class VaporizeSimp extends GJDepthFirst { * f1 -> "&&" * f2 -> PrimaryExpression() */ - public String visit(AndExpression n, SymbolTable symt) { - String mod = ""; - mod += n.f0.accept(this, symt); - mod += n.f1.accept(this, symt); - mod += n.f2.accept(this, symt); - return mod; + public R visit(AndExpression n, A argu) { + R _ret=null; + n.f0.accept(this, argu); + n.f1.accept(this, argu); + n.f2.accept(this, argu); + return _ret; } /** @@ -490,12 +441,12 @@ public class VaporizeSimp extends GJDepthFirst { * f1 -> "<" * f2 -> PrimaryExpression() */ - public String visit(CompareExpression n, SymbolTable symt) { - String mod = ""; - mod += n.f0.accept(this, symt); - mod += n.f1.accept(this, symt); - mod += n.f2.accept(this, symt); - return mod; + public R visit(CompareExpression n, A argu) { + R _ret=null; + n.f0.accept(this, argu); + n.f1.accept(this, argu); + n.f2.accept(this, argu); + return _ret; } /** @@ -503,19 +454,12 @@ public class VaporizeSimp extends GJDepthFirst { * f1 -> "+" * f2 -> PrimaryExpression() */ - public String visit(PlusExpression n, SymbolTable symt) { - String mod = ""; - String oper1 = n.f0.accept(this, symt); - mod += n.f1.accept(this, symt); - String oper2 = n.f2.accept(this, symt); - TypeInstance tp1 = new TypeInstance("tp1", TypeEnum.ERROR); - - mod += String.format(" %s = AddS(%s %s)\n", - this.tf.addNewAlias(tp1), - oper1, - oper2); - - return mod; + public R visit(PlusExpression n, A argu) { + R _ret=null; + n.f0.accept(this, argu); + n.f1.accept(this, argu); + n.f2.accept(this, argu); + return _ret; } /** @@ -523,12 +467,12 @@ public class VaporizeSimp extends GJDepthFirst { * f1 -> "-" * f2 -> PrimaryExpression() */ - public String visit(MinusExpression n, SymbolTable symt) { - String mod = ""; - mod += n.f0.accept(this, symt); - mod += n.f1.accept(this, symt); - mod += n.f2.accept(this, symt); - return mod; + public R visit(MinusExpression n, A argu) { + R _ret=null; + n.f0.accept(this, argu); + n.f1.accept(this, argu); + n.f2.accept(this, argu); + return _ret; } /** @@ -536,12 +480,12 @@ public class VaporizeSimp extends GJDepthFirst { * f1 -> "*" * f2 -> PrimaryExpression() */ - public String visit(TimesExpression n, SymbolTable symt) { - String mod = ""; - mod += n.f0.accept(this, symt); - mod += n.f1.accept(this, symt); - mod += n.f2.accept(this, symt); - return mod; + public R visit(TimesExpression n, A argu) { + R _ret=null; + n.f0.accept(this, argu); + n.f1.accept(this, argu); + n.f2.accept(this, argu); + return _ret; } /** @@ -550,13 +494,13 @@ public class VaporizeSimp extends GJDepthFirst { * f2 -> PrimaryExpression() * f3 -> "]" */ - public String visit(ArrayLookup n, SymbolTable symt) { - String mod = ""; - mod += n.f0.accept(this, symt); - mod += n.f1.accept(this, symt); - mod += n.f2.accept(this, symt); - mod += n.f3.accept(this, symt); - return mod; + public R visit(ArrayLookup n, A argu) { + R _ret=null; + n.f0.accept(this, argu); + n.f1.accept(this, argu); + n.f2.accept(this, argu); + n.f3.accept(this, argu); + return _ret; } /** @@ -564,12 +508,12 @@ public class VaporizeSimp extends GJDepthFirst { * f1 -> "." * f2 -> "length" */ - public String visit(ArrayLength n, SymbolTable symt) { - String mod = ""; - mod += n.f0.accept(this, symt); - mod += n.f1.accept(this, symt); - mod += n.f2.accept(this, symt); - return mod; + public R visit(ArrayLength n, A argu) { + R _ret=null; + n.f0.accept(this, argu); + n.f1.accept(this, argu); + n.f2.accept(this, argu); + return _ret; } /** @@ -580,59 +524,37 @@ public class VaporizeSimp extends GJDepthFirst { * f4 -> ( ExpressionList() )? * f5 -> ")" */ - public String visit(MessageSend n, SymbolTable symt) { - String mod = ""; - String id = n.f0.accept(this, symt); - mod += n.f1.accept(this, symt); - String id2 = n.f2.accept(this, symt); - TypeInstance tp1 = new TypeInstance("tp1", TypeEnum.ERROR); // TypeFactory likes to know who it's renting to - TypeInstance tp2 = new TypeInstance("tp2", TypeEnum.ERROR); - - TypeInstance cur = symt.getType(id); - int mtdIndex = cur.getClassInstance() - .getMethods().indexOf(symt.getMethod(id2)) * 4; - - mod += String.format(" %s = [%s+%d]\n", - this.tf.addNewAlias(tp1), - this.tf.retrieveAlias(cur), - 0); - - mod += String.format(" %s = [%s+%d]\n", - this.tf.addNewAlias(tp2), - this.tf.retrieveAlias(tp1), - mtdIndex); - - mod += n.f3.accept(this, symt); - mod = n.f4.accept(this, symt); - mod += n.f5.accept(this, symt); - - mod += String.format(" call %s(%s)\n", - this.tf.retrieveAlias(tp2), - this.tf.retrieveAlias(cur)); - - return mod; + public R visit(MessageSend n, A argu) { + R _ret=null; + n.f0.accept(this, argu); + n.f1.accept(this, argu); + n.f2.accept(this, argu); + n.f3.accept(this, argu); + n.f4.accept(this, argu); + n.f5.accept(this, argu); + return _ret; } /** * f0 -> Expression() * f1 -> ( ExpressionRest() )* */ - public String visit(ExpressionList n, SymbolTable symt) { - String mod = ""; - mod += n.f0.accept(this, symt); - mod += n.f1.accept(this, symt); - return mod; + public R visit(ExpressionList n, A argu) { + R _ret=null; + n.f0.accept(this, argu); + n.f1.accept(this, argu); + return _ret; } /** * f0 -> "," * f1 -> Expression() */ - public String visit(ExpressionRest n, SymbolTable symt) { - String mod = ""; - mod += n.f0.accept(this, symt); - mod += n.f1.accept(this, symt); - return mod; + public R visit(ExpressionRest n, A argu) { + R _ret=null; + n.f0.accept(this, argu); + n.f1.accept(this, argu); + return _ret; } /** @@ -646,55 +568,55 @@ public class VaporizeSimp extends GJDepthFirst { * | NotExpression() * | BracketExpression() */ - public String visit(PrimaryExpression n, SymbolTable symt) { - String mod = ""; - mod += n.f0.accept(this, symt); - return mod; + public R visit(PrimaryExpression n, A argu) { + R _ret=null; + n.f0.accept(this, argu); + return _ret; } /** * f0 -> */ - public String visit(IntegerLiteral n, SymbolTable symt) { - String mod = ""; - mod += n.f0.tokenImage; - return mod; + public R visit(IntegerLiteral n, A argu) { + R _ret=null; + n.f0.accept(this, argu); + return _ret; } /** * f0 -> "true" */ - public String visit(TrueLiteral n, SymbolTable symt) { - String mod = ""; - mod += n.f0.accept(this, symt); - return mod; + public R visit(TrueLiteral n, A argu) { + R _ret=null; + n.f0.accept(this, argu); + return _ret; } /** * f0 -> "false" */ - public String visit(FalseLiteral n, SymbolTable symt) { - String mod = ""; - mod += n.f0.accept(this, symt); - return mod; + public R visit(FalseLiteral n, A argu) { + R _ret=null; + n.f0.accept(this, argu); + return _ret; } /** * f0 -> */ - public String visit(Identifier n, SymbolTable symt) { - String mod = ""; - mod += n.f0.tokenImage; - return mod; + public R visit(Identifier n, A argu) { + R _ret=null; + n.f0.accept(this, argu); + return _ret; } /** * f0 -> "this" */ - public String visit(ThisExpression n, SymbolTable symt) { - String mod = ""; - mod += n.f0.accept(this, symt); - return mod; + public R visit(ThisExpression n, A argu) { + R _ret=null; + n.f0.accept(this, argu); + return _ret; } /** @@ -704,14 +626,14 @@ public class VaporizeSimp extends GJDepthFirst { * f3 -> Expression() * f4 -> "]" */ - public String visit(ArrayAllocationExpression n, SymbolTable symt) { - String mod = ""; - mod += n.f0.accept(this, symt); - mod += n.f1.accept(this, symt); - mod += n.f2.accept(this, symt); - mod += n.f3.accept(this, symt); - mod += n.f4.accept(this, symt); - return mod; + public R visit(ArrayAllocationExpression n, A argu) { + R _ret=null; + n.f0.accept(this, argu); + n.f1.accept(this, argu); + n.f2.accept(this, argu); + n.f3.accept(this, argu); + n.f4.accept(this, argu); + return _ret; } /** @@ -720,26 +642,24 @@ public class VaporizeSimp extends GJDepthFirst { * f2 -> "(" * f3 -> ")" */ - public String visit(AllocationExpression n, SymbolTable symt) { - String mod = ""; - mod += n.f0.accept(this, symt); - String cls = n.f1.accept(this, symt); - mod += String.format(":functable_%s\n", cls); - - mod += n.f2.accept(this, symt); - mod += n.f3.accept(this, symt); - return mod; + public R visit(AllocationExpression n, A argu) { + R _ret=null; + n.f0.accept(this, argu); + n.f1.accept(this, argu); + n.f2.accept(this, argu); + n.f3.accept(this, argu); + return _ret; } /** * f0 -> "!" * f1 -> Expression() */ - public String visit(NotExpression n, SymbolTable symt) { - String mod = ""; - mod += n.f0.accept(this, symt); - mod += n.f1.accept(this, symt); - return mod; + public R visit(NotExpression n, A argu) { + R _ret=null; + n.f0.accept(this, argu); + n.f1.accept(this, argu); + return _ret; } /** @@ -747,12 +667,12 @@ public class VaporizeSimp extends GJDepthFirst { * f1 -> Expression() * f2 -> ")" */ - public String visit(BracketExpression n, SymbolTable symt) { - String mod = ""; - mod += n.f0.accept(this, symt); - mod += n.f1.accept(this, symt); - mod += n.f2.accept(this, symt); - return mod; + public R visit(BracketExpression n, A argu) { + R _ret=null; + n.f0.accept(this, argu); + n.f1.accept(this, argu); + n.f2.accept(this, argu); + return _ret; } } diff --git a/vaporize/tests/BinaryTree.java b/vaporize/tests/BinaryTree.java deleted file mode 100644 index 18d1464..0000000 --- a/vaporize/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/vaporize/tests/BinaryTree.opt.vapor b/vaporize/tests/BinaryTree.opt.vapor deleted file mode 100644 index ef6ac4e..0000000 --- a/vaporize/tests/BinaryTree.opt.vapor +++ /dev/null @@ -1,526 +0,0 @@ - -const empty_BT - -const empty_Tree - - -func Main() - t.0 = call :BT.Start(:empty_BT) - PrintIntS(t.0) - ret - -func BT.Start(this) - root = HeapAllocZ(24) - if root goto :null1 - Error("null pointer") - null1: - ntb = call :Tree.Init(root 16) - if root goto :null2 - Error("null pointer") - null2: - ntb = call :Tree.Print(root) - PrintIntS(100000000) - if root goto :null3 - Error("null pointer") - null3: - ntb = call :Tree.Insert(root 8) - if root goto :null4 - Error("null pointer") - null4: - ntb = call :Tree.Print(root) - if root goto :null5 - Error("null pointer") - null5: - ntb = call :Tree.Insert(root 24) - if root goto :null6 - Error("null pointer") - null6: - ntb = call :Tree.Insert(root 4) - if root goto :null7 - Error("null pointer") - null7: - ntb = call :Tree.Insert(root 12) - if root goto :null8 - Error("null pointer") - null8: - ntb = call :Tree.Insert(root 20) - if root goto :null9 - Error("null pointer") - null9: - ntb = call :Tree.Insert(root 28) - if root goto :null10 - Error("null pointer") - null10: - ntb = call :Tree.Insert(root 14) - if root goto :null11 - Error("null pointer") - null11: - ntb = call :Tree.Print(root) - if root goto :null12 - Error("null pointer") - null12: - t.0 = call :Tree.Search(root 24) - PrintIntS(t.0) - if root goto :null13 - Error("null pointer") - null13: - t.1 = call :Tree.Search(root 12) - PrintIntS(t.1) - if root goto :null14 - Error("null pointer") - null14: - t.2 = call :Tree.Search(root 16) - PrintIntS(t.2) - if root goto :null15 - Error("null pointer") - null15: - t.3 = call :Tree.Search(root 50) - PrintIntS(t.3) - if root goto :null16 - Error("null pointer") - null16: - t.4 = call :Tree.Search(root 12) - PrintIntS(t.4) - if root goto :null17 - Error("null pointer") - null17: - ntb = call :Tree.Delete(root 12) - if root goto :null18 - Error("null pointer") - null18: - ntb = call :Tree.Print(root) - if root goto :null19 - Error("null pointer") - null19: - t.5 = call :Tree.Search(root 12) - PrintIntS(t.5) - ret 0 - -func Tree.Init(this v_key) - [this+8] = v_key - [this+12] = 0 - [this+16] = 0 - ret 1 - -func Tree.SetRight(this rn) - [this+4] = rn - ret 1 - -func Tree.SetLeft(this ln) - [this+0] = ln - ret 1 - -func Tree.GetRight(this) - t.0 = [this+4] - ret t.0 - -func Tree.GetLeft(this) - t.0 = [this+0] - ret t.0 - -func Tree.GetKey(this) - t.0 = [this+8] - ret t.0 - -func Tree.SetKey(this v_key) - [this+8] = v_key - ret 1 - -func Tree.GetHas_Right(this) - t.0 = [this+16] - ret t.0 - -func Tree.GetHas_Left(this) - t.0 = [this+12] - ret t.0 - -func Tree.SetHas_Left(this val) - [this+12] = val - ret 1 - -func Tree.SetHas_Right(this val) - [this+16] = val - ret 1 - -func Tree.Compare(this num1 num2) - ntb = 0 - nti = Add(num2 1) - t.0 = LtS(num1 num2) - if0 t.0 goto :if1_else - ntb = 0 - goto :if1_end - if1_else: - t.1 = LtS(num1 nti) - if t.1 goto :if2_else - ntb = 0 - goto :if2_end - if2_else: - ntb = 1 - if2_end: - if1_end: - ret ntb - -func Tree.Insert(this v_key) - new_node = HeapAllocZ(24) - if new_node goto :null20 - Error("null pointer") - null20: - ntb = call :Tree.Init(new_node v_key) - current_node = this - cont = 1 - while1_top: - if0 cont goto :while1_end - if current_node goto :null21 - Error("null pointer") - null21: - key_aux = call :Tree.GetKey(current_node) - t.0 = LtS(v_key key_aux) - if0 t.0 goto :if3_else - if current_node goto :null22 - Error("null pointer") - null22: - t.1 = call :Tree.GetHas_Left(current_node) - if0 t.1 goto :if4_else - if current_node goto :null23 - Error("null pointer") - null23: - current_node = call :Tree.GetLeft(current_node) - goto :if4_end - if4_else: - cont = 0 - if current_node goto :null24 - Error("null pointer") - null24: - ntb = call :Tree.SetHas_Left(current_node 1) - if current_node goto :null25 - Error("null pointer") - null25: - ntb = call :Tree.SetLeft(current_node new_node) - if4_end: - goto :if3_end - if3_else: - if current_node goto :null26 - Error("null pointer") - null26: - t.2 = call :Tree.GetHas_Right(current_node) - if0 t.2 goto :if5_else - if current_node goto :null27 - Error("null pointer") - null27: - current_node = call :Tree.GetRight(current_node) - goto :if5_end - if5_else: - cont = 0 - if current_node goto :null28 - Error("null pointer") - null28: - ntb = call :Tree.SetHas_Right(current_node 1) - if current_node goto :null29 - Error("null pointer") - null29: - ntb = call :Tree.SetRight(current_node new_node) - if5_end: - if3_end: - goto :while1_top - while1_end: - ret 1 - -func Tree.Delete(this v_key) - current_node = this - parent_node = this - cont = 1 - found = 0 - is_root = 1 - while2_top: - if0 cont goto :while2_end - if current_node goto :null30 - Error("null pointer") - null30: - key_aux = call :Tree.GetKey(current_node) - t.0 = LtS(v_key key_aux) - if0 t.0 goto :if6_else - if current_node goto :null31 - Error("null pointer") - null31: - t.1 = call :Tree.GetHas_Left(current_node) - if0 t.1 goto :if7_else - parent_node = current_node - if current_node goto :null32 - Error("null pointer") - null32: - current_node = call :Tree.GetLeft(current_node) - goto :if7_end - if7_else: - cont = 0 - if7_end: - goto :if6_end - if6_else: - t.2 = LtS(key_aux v_key) - if0 t.2 goto :if8_else - if current_node goto :null33 - Error("null pointer") - null33: - t.3 = call :Tree.GetHas_Right(current_node) - if0 t.3 goto :if9_else - parent_node = current_node - if current_node goto :null34 - Error("null pointer") - null34: - current_node = call :Tree.GetRight(current_node) - goto :if9_end - if9_else: - cont = 0 - if9_end: - goto :if8_end - if8_else: - if0 is_root goto :if10_else - if current_node goto :null35 - Error("null pointer") - null35: - t.4 = call :Tree.GetHas_Right(current_node) - if t.4 goto :if11_else - if current_node goto :null36 - Error("null pointer") - null36: - t.5 = call :Tree.GetHas_Left(current_node) - if t.5 goto :if11_else - ntb = 1 - goto :if11_end - if11_else: - ntb = call :Tree.Remove(this parent_node current_node) - if11_end: - goto :if10_end - if10_else: - ntb = call :Tree.Remove(this parent_node current_node) - if10_end: - found = 1 - cont = 0 - if8_end: - if6_end: - is_root = 0 - goto :while2_top - while2_end: - ret found - -func Tree.Remove(this p_node c_node) - if c_node goto :null37 - Error("null pointer") - null37: - t.0 = call :Tree.GetHas_Left(c_node) - if0 t.0 goto :if12_else - ntb = call :Tree.RemoveLeft(this p_node c_node) - goto :if12_end - if12_else: - if c_node goto :null38 - Error("null pointer") - null38: - t.1 = call :Tree.GetHas_Right(c_node) - if0 t.1 goto :if13_else - ntb = call :Tree.RemoveRight(this p_node c_node) - goto :if13_end - if13_else: - if c_node goto :null39 - Error("null pointer") - null39: - auxkey1 = call :Tree.GetKey(c_node) - if p_node goto :null40 - Error("null pointer") - null40: - t.2 = call :Tree.GetLeft(p_node) - if t.2 goto :null41 - Error("null pointer") - null41: - auxkey2 = call :Tree.GetKey(t.2) - t.3 = call :Tree.Compare(this auxkey1 auxkey2) - if0 t.3 goto :if14_else - if p_node goto :null42 - Error("null pointer") - null42: - t.4 = [this+20] - ntb = call :Tree.SetLeft(p_node t.4) - if p_node goto :null43 - Error("null pointer") - null43: - ntb = call :Tree.SetHas_Left(p_node 0) - goto :if14_end - if14_else: - if p_node goto :null44 - Error("null pointer") - null44: - t.5 = [this+20] - ntb = call :Tree.SetRight(p_node t.5) - if p_node goto :null45 - Error("null pointer") - null45: - ntb = call :Tree.SetHas_Right(p_node 0) - if14_end: - if13_end: - if12_end: - ret 1 - -func Tree.RemoveRight(this p_node c_node) - while3_top: - if c_node goto :null46 - Error("null pointer") - null46: - t.0 = call :Tree.GetHas_Right(c_node) - if0 t.0 goto :while3_end - if c_node goto :null47 - Error("null pointer") - null47: - if c_node goto :null48 - Error("null pointer") - null48: - t.1 = call :Tree.GetRight(c_node) - if t.1 goto :null49 - Error("null pointer") - null49: - t.2 = call :Tree.GetKey(t.1) - ntb = call :Tree.SetKey(c_node t.2) - p_node = c_node - if c_node goto :null50 - Error("null pointer") - null50: - c_node = call :Tree.GetRight(c_node) - goto :while3_top - while3_end: - if p_node goto :null51 - Error("null pointer") - null51: - t.3 = [this+20] - ntb = call :Tree.SetRight(p_node t.3) - if p_node goto :null52 - Error("null pointer") - null52: - ntb = call :Tree.SetHas_Right(p_node 0) - ret 1 - -func Tree.RemoveLeft(this p_node c_node) - while4_top: - if c_node goto :null53 - Error("null pointer") - null53: - t.0 = call :Tree.GetHas_Left(c_node) - if0 t.0 goto :while4_end - if c_node goto :null54 - Error("null pointer") - null54: - if c_node goto :null55 - Error("null pointer") - null55: - t.1 = call :Tree.GetLeft(c_node) - if t.1 goto :null56 - Error("null pointer") - null56: - t.2 = call :Tree.GetKey(t.1) - ntb = call :Tree.SetKey(c_node t.2) - p_node = c_node - if c_node goto :null57 - Error("null pointer") - null57: - c_node = call :Tree.GetLeft(c_node) - goto :while4_top - while4_end: - if p_node goto :null58 - Error("null pointer") - null58: - t.3 = [this+20] - ntb = call :Tree.SetLeft(p_node t.3) - if p_node goto :null59 - Error("null pointer") - null59: - ntb = call :Tree.SetHas_Left(p_node 0) - ret 1 - -func Tree.Search(this v_key) - current_node = this - cont = 1 - ifound = 0 - while5_top: - if0 cont goto :while5_end - if current_node goto :null60 - Error("null pointer") - null60: - key_aux = call :Tree.GetKey(current_node) - t.0 = LtS(v_key key_aux) - if0 t.0 goto :if15_else - if current_node goto :null61 - Error("null pointer") - null61: - t.1 = call :Tree.GetHas_Left(current_node) - if0 t.1 goto :if16_else - if current_node goto :null62 - Error("null pointer") - null62: - current_node = call :Tree.GetLeft(current_node) - goto :if16_end - if16_else: - cont = 0 - if16_end: - goto :if15_end - if15_else: - t.2 = LtS(key_aux v_key) - if0 t.2 goto :if17_else - if current_node goto :null63 - Error("null pointer") - null63: - t.3 = call :Tree.GetHas_Right(current_node) - if0 t.3 goto :if18_else - if current_node goto :null64 - Error("null pointer") - null64: - current_node = call :Tree.GetRight(current_node) - goto :if18_end - if18_else: - cont = 0 - if18_end: - goto :if17_end - if17_else: - ifound = 1 - cont = 0 - if17_end: - if15_end: - goto :while5_top - while5_end: - ret ifound - -func Tree.Print(this) - current_node = this - ntb = call :Tree.RecPrint(this current_node) - ret 1 - -func Tree.RecPrint(this node) - if node goto :null65 - Error("null pointer") - null65: - t.0 = call :Tree.GetHas_Left(node) - if0 t.0 goto :if19_else - if node goto :null66 - Error("null pointer") - null66: - t.1 = call :Tree.GetLeft(node) - ntb = call :Tree.RecPrint(this t.1) - goto :if19_end - if19_else: - ntb = 1 - if19_end: - if node goto :null67 - Error("null pointer") - null67: - t.2 = call :Tree.GetKey(node) - PrintIntS(t.2) - if node goto :null68 - Error("null pointer") - null68: - t.3 = call :Tree.GetHas_Right(node) - if0 t.3 goto :if20_else - if node goto :null69 - Error("null pointer") - null69: - t.4 = call :Tree.GetRight(node) - ntb = call :Tree.RecPrint(this t.4) - goto :if20_end - if20_else: - ntb = 1 - if20_end: - ret 1 diff --git a/vaporize/tests/BinaryTree.vapor b/vaporize/tests/BinaryTree.vapor deleted file mode 100644 index 275cfe3..0000000 --- a/vaporize/tests/BinaryTree.vapor +++ /dev/null @@ -1,719 +0,0 @@ - -const vmt_BT - :BT.Start - -const vmt_Tree - :Tree.Init - :Tree.SetRight - :Tree.SetLeft - :Tree.GetRight - :Tree.GetLeft - :Tree.GetKey - :Tree.SetKey - :Tree.GetHas_Right - :Tree.GetHas_Left - :Tree.SetHas_Left - :Tree.SetHas_Right - :Tree.Compare - :Tree.Insert - :Tree.Delete - :Tree.Remove - :Tree.RemoveRight - :Tree.RemoveLeft - :Tree.Search - :Tree.Print - :Tree.RecPrint - - -func Main() - t.0 = HeapAllocZ(4) - [t.0] = :vmt_BT - if t.0 goto :null1 - Error("null pointer") - null1: - t.1 = [t.0] - t.1 = [t.1+0] - t.2 = call t.1(t.0) - PrintIntS(t.2) - ret - -func BT.Start(this) - t.0 = HeapAllocZ(28) - [t.0] = :vmt_Tree - root = t.0 - if root goto :null2 - Error("null pointer") - null2: - t.1 = [root] - t.1 = [t.1+0] - ntb = call t.1(root 16) - if root goto :null3 - Error("null pointer") - null3: - t.2 = [root] - t.2 = [t.2+72] - ntb = call t.2(root) - PrintIntS(100000000) - if root goto :null4 - Error("null pointer") - null4: - t.3 = [root] - t.3 = [t.3+48] - ntb = call t.3(root 8) - if root goto :null5 - Error("null pointer") - null5: - t.4 = [root] - t.4 = [t.4+72] - ntb = call t.4(root) - if root goto :null6 - Error("null pointer") - null6: - t.5 = [root] - t.5 = [t.5+48] - ntb = call t.5(root 24) - if root goto :null7 - Error("null pointer") - null7: - t.6 = [root] - t.6 = [t.6+48] - ntb = call t.6(root 4) - if root goto :null8 - Error("null pointer") - null8: - t.7 = [root] - t.7 = [t.7+48] - ntb = call t.7(root 12) - if root goto :null9 - Error("null pointer") - null9: - t.8 = [root] - t.8 = [t.8+48] - ntb = call t.8(root 20) - if root goto :null10 - Error("null pointer") - null10: - t.9 = [root] - t.9 = [t.9+48] - ntb = call t.9(root 28) - if root goto :null11 - Error("null pointer") - null11: - t.10 = [root] - t.10 = [t.10+48] - ntb = call t.10(root 14) - if root goto :null12 - Error("null pointer") - null12: - t.11 = [root] - t.11 = [t.11+72] - ntb = call t.11(root) - if root goto :null13 - Error("null pointer") - null13: - t.12 = [root] - t.12 = [t.12+68] - t.13 = call t.12(root 24) - PrintIntS(t.13) - if root goto :null14 - Error("null pointer") - null14: - t.14 = [root] - t.14 = [t.14+68] - t.15 = call t.14(root 12) - PrintIntS(t.15) - if root goto :null15 - Error("null pointer") - null15: - t.16 = [root] - t.16 = [t.16+68] - t.17 = call t.16(root 16) - PrintIntS(t.17) - if root goto :null16 - Error("null pointer") - null16: - t.18 = [root] - t.18 = [t.18+68] - t.19 = call t.18(root 50) - PrintIntS(t.19) - if root goto :null17 - Error("null pointer") - null17: - t.20 = [root] - t.20 = [t.20+68] - t.21 = call t.20(root 12) - PrintIntS(t.21) - if root goto :null18 - Error("null pointer") - null18: - t.22 = [root] - t.22 = [t.22+52] - ntb = call t.22(root 12) - if root goto :null19 - Error("null pointer") - null19: - t.23 = [root] - t.23 = [t.23+72] - ntb = call t.23(root) - if root goto :null20 - Error("null pointer") - null20: - t.24 = [root] - t.24 = [t.24+68] - t.25 = call t.24(root 12) - PrintIntS(t.25) - ret 0 - -func Tree.Init(this v_key) - [this+12] = v_key - [this+16] = 0 - [this+20] = 0 - ret 1 - -func Tree.SetRight(this rn) - [this+8] = rn - ret 1 - -func Tree.SetLeft(this ln) - [this+4] = ln - ret 1 - -func Tree.GetRight(this) - t.0 = [this+8] - ret t.0 - -func Tree.GetLeft(this) - t.0 = [this+4] - ret t.0 - -func Tree.GetKey(this) - t.0 = [this+12] - ret t.0 - -func Tree.SetKey(this v_key) - [this+12] = v_key - ret 1 - -func Tree.GetHas_Right(this) - t.0 = [this+20] - ret t.0 - -func Tree.GetHas_Left(this) - t.0 = [this+16] - ret t.0 - -func Tree.SetHas_Left(this val) - [this+16] = val - ret 1 - -func Tree.SetHas_Right(this val) - [this+20] = val - ret 1 - -func Tree.Compare(this num1 num2) - ntb = 0 - nti = Add(num2 1) - t.0 = LtS(num1 num2) - if0 t.0 goto :if1_else - ntb = 0 - goto :if1_end - if1_else: - t.1 = LtS(num1 nti) - t.2 = Sub(1 t.1) - if0 t.2 goto :if2_else - ntb = 0 - goto :if2_end - if2_else: - ntb = 1 - if2_end: - if1_end: - ret ntb - -func Tree.Insert(this v_key) - t.0 = HeapAllocZ(28) - [t.0] = :vmt_Tree - new_node = t.0 - if new_node goto :null21 - Error("null pointer") - null21: - t.1 = [new_node] - t.1 = [t.1+0] - ntb = call t.1(new_node v_key) - current_node = this - cont = 1 - while1_top: - if0 cont goto :while1_end - if current_node goto :null22 - Error("null pointer") - null22: - t.2 = [current_node] - t.2 = [t.2+20] - key_aux = call t.2(current_node) - t.3 = LtS(v_key key_aux) - if0 t.3 goto :if3_else - if current_node goto :null23 - Error("null pointer") - null23: - t.4 = [current_node] - t.4 = [t.4+32] - t.5 = call t.4(current_node) - if0 t.5 goto :if4_else - if current_node goto :null24 - Error("null pointer") - null24: - t.6 = [current_node] - t.6 = [t.6+16] - current_node = call t.6(current_node) - goto :if4_end - if4_else: - cont = 0 - if current_node goto :null25 - Error("null pointer") - null25: - t.7 = [current_node] - t.7 = [t.7+36] - ntb = call t.7(current_node 1) - if current_node goto :null26 - Error("null pointer") - null26: - t.8 = [current_node] - t.8 = [t.8+8] - ntb = call t.8(current_node new_node) - if4_end: - goto :if3_end - if3_else: - if current_node goto :null27 - Error("null pointer") - null27: - t.9 = [current_node] - t.9 = [t.9+28] - t.10 = call t.9(current_node) - if0 t.10 goto :if5_else - if current_node goto :null28 - Error("null pointer") - null28: - t.11 = [current_node] - t.11 = [t.11+12] - current_node = call t.11(current_node) - goto :if5_end - if5_else: - cont = 0 - if current_node goto :null29 - Error("null pointer") - null29: - t.12 = [current_node] - t.12 = [t.12+40] - ntb = call t.12(current_node 1) - if current_node goto :null30 - Error("null pointer") - null30: - t.13 = [current_node] - t.13 = [t.13+4] - ntb = call t.13(current_node new_node) - if5_end: - if3_end: - goto :while1_top - while1_end: - ret 1 - -func Tree.Delete(this v_key) - current_node = this - parent_node = this - cont = 1 - found = 0 - is_root = 1 - while2_top: - if0 cont goto :while2_end - if current_node goto :null31 - Error("null pointer") - null31: - t.0 = [current_node] - t.0 = [t.0+20] - key_aux = call t.0(current_node) - t.1 = LtS(v_key key_aux) - if0 t.1 goto :if6_else - if current_node goto :null32 - Error("null pointer") - null32: - t.2 = [current_node] - t.2 = [t.2+32] - t.3 = call t.2(current_node) - if0 t.3 goto :if7_else - parent_node = current_node - if current_node goto :null33 - Error("null pointer") - null33: - t.4 = [current_node] - t.4 = [t.4+16] - current_node = call t.4(current_node) - goto :if7_end - if7_else: - cont = 0 - if7_end: - goto :if6_end - if6_else: - t.5 = LtS(key_aux v_key) - if0 t.5 goto :if8_else - if current_node goto :null34 - Error("null pointer") - null34: - t.6 = [current_node] - t.6 = [t.6+28] - t.7 = call t.6(current_node) - if0 t.7 goto :if9_else - parent_node = current_node - if current_node goto :null35 - Error("null pointer") - null35: - t.8 = [current_node] - t.8 = [t.8+12] - current_node = call t.8(current_node) - goto :if9_end - if9_else: - cont = 0 - if9_end: - goto :if8_end - if8_else: - if0 is_root goto :if10_else - if current_node goto :null36 - Error("null pointer") - null36: - t.10 = [current_node] - t.10 = [t.10+28] - t.11 = call t.10(current_node) - t.12 = Sub(1 t.11) - if0 t.12 goto :ss1_else - if current_node goto :null37 - Error("null pointer") - null37: - t.13 = [current_node] - t.13 = [t.13+32] - t.14 = call t.13(current_node) - t.9 = Sub(1 t.14) - goto :ss1_end - ss1_else: - t.9 = 0 - ss1_end: - if0 t.9 goto :if11_else - ntb = 1 - goto :if11_end - if11_else: - t.15 = [this] - t.15 = [t.15+56] - ntb = call t.15(this parent_node current_node) - if11_end: - goto :if10_end - if10_else: - t.16 = [this] - t.16 = [t.16+56] - ntb = call t.16(this parent_node current_node) - if10_end: - found = 1 - cont = 0 - if8_end: - if6_end: - is_root = 0 - goto :while2_top - while2_end: - ret found - -func Tree.Remove(this p_node c_node) - if c_node goto :null38 - Error("null pointer") - null38: - t.0 = [c_node] - t.0 = [t.0+32] - t.1 = call t.0(c_node) - if0 t.1 goto :if12_else - t.2 = [this] - t.2 = [t.2+64] - ntb = call t.2(this p_node c_node) - goto :if12_end - if12_else: - if c_node goto :null39 - Error("null pointer") - null39: - t.3 = [c_node] - t.3 = [t.3+28] - t.4 = call t.3(c_node) - if0 t.4 goto :if13_else - t.5 = [this] - t.5 = [t.5+60] - ntb = call t.5(this p_node c_node) - goto :if13_end - if13_else: - if c_node goto :null40 - Error("null pointer") - null40: - t.6 = [c_node] - t.6 = [t.6+20] - auxkey1 = call t.6(c_node) - if p_node goto :null41 - Error("null pointer") - null41: - t.7 = [p_node] - t.7 = [t.7+16] - t.8 = call t.7(p_node) - if t.8 goto :null42 - Error("null pointer") - null42: - t.9 = [t.8] - t.9 = [t.9+20] - auxkey2 = call t.9(t.8) - t.10 = [this] - t.10 = [t.10+44] - t.11 = call t.10(this auxkey1 auxkey2) - if0 t.11 goto :if14_else - if p_node goto :null43 - Error("null pointer") - null43: - t.12 = [p_node] - t.12 = [t.12+8] - t.13 = [this+24] - ntb = call t.12(p_node t.13) - if p_node goto :null44 - Error("null pointer") - null44: - t.14 = [p_node] - t.14 = [t.14+36] - ntb = call t.14(p_node 0) - goto :if14_end - if14_else: - if p_node goto :null45 - Error("null pointer") - null45: - t.15 = [p_node] - t.15 = [t.15+4] - t.16 = [this+24] - ntb = call t.15(p_node t.16) - if p_node goto :null46 - Error("null pointer") - null46: - t.17 = [p_node] - t.17 = [t.17+40] - ntb = call t.17(p_node 0) - if14_end: - if13_end: - if12_end: - ret 1 - -func Tree.RemoveRight(this p_node c_node) - while3_top: - if c_node goto :null47 - Error("null pointer") - null47: - t.0 = [c_node] - t.0 = [t.0+28] - t.1 = call t.0(c_node) - if0 t.1 goto :while3_end - if c_node goto :null48 - Error("null pointer") - null48: - t.2 = [c_node] - t.2 = [t.2+24] - if c_node goto :null49 - Error("null pointer") - null49: - t.3 = [c_node] - t.3 = [t.3+12] - t.4 = call t.3(c_node) - if t.4 goto :null50 - Error("null pointer") - null50: - t.5 = [t.4] - t.5 = [t.5+20] - t.6 = call t.5(t.4) - ntb = call t.2(c_node t.6) - p_node = c_node - if c_node goto :null51 - Error("null pointer") - null51: - t.7 = [c_node] - t.7 = [t.7+12] - c_node = call t.7(c_node) - goto :while3_top - while3_end: - if p_node goto :null52 - Error("null pointer") - null52: - t.8 = [p_node] - t.8 = [t.8+4] - t.9 = [this+24] - ntb = call t.8(p_node t.9) - if p_node goto :null53 - Error("null pointer") - null53: - t.10 = [p_node] - t.10 = [t.10+40] - ntb = call t.10(p_node 0) - ret 1 - -func Tree.RemoveLeft(this p_node c_node) - while4_top: - if c_node goto :null54 - Error("null pointer") - null54: - t.0 = [c_node] - t.0 = [t.0+32] - t.1 = call t.0(c_node) - if0 t.1 goto :while4_end - if c_node goto :null55 - Error("null pointer") - null55: - t.2 = [c_node] - t.2 = [t.2+24] - if c_node goto :null56 - Error("null pointer") - null56: - t.3 = [c_node] - t.3 = [t.3+16] - t.4 = call t.3(c_node) - if t.4 goto :null57 - Error("null pointer") - null57: - t.5 = [t.4] - t.5 = [t.5+20] - t.6 = call t.5(t.4) - ntb = call t.2(c_node t.6) - p_node = c_node - if c_node goto :null58 - Error("null pointer") - null58: - t.7 = [c_node] - t.7 = [t.7+16] - c_node = call t.7(c_node) - goto :while4_top - while4_end: - if p_node goto :null59 - Error("null pointer") - null59: - t.8 = [p_node] - t.8 = [t.8+8] - t.9 = [this+24] - ntb = call t.8(p_node t.9) - if p_node goto :null60 - Error("null pointer") - null60: - t.10 = [p_node] - t.10 = [t.10+36] - ntb = call t.10(p_node 0) - ret 1 - -func Tree.Search(this v_key) - current_node = this - cont = 1 - ifound = 0 - while5_top: - if0 cont goto :while5_end - if current_node goto :null61 - Error("null pointer") - null61: - t.0 = [current_node] - t.0 = [t.0+20] - key_aux = call t.0(current_node) - t.1 = LtS(v_key key_aux) - if0 t.1 goto :if15_else - if current_node goto :null62 - Error("null pointer") - null62: - t.2 = [current_node] - t.2 = [t.2+32] - t.3 = call t.2(current_node) - if0 t.3 goto :if16_else - if current_node goto :null63 - Error("null pointer") - null63: - t.4 = [current_node] - t.4 = [t.4+16] - current_node = call t.4(current_node) - goto :if16_end - if16_else: - cont = 0 - if16_end: - goto :if15_end - if15_else: - t.5 = LtS(key_aux v_key) - if0 t.5 goto :if17_else - if current_node goto :null64 - Error("null pointer") - null64: - t.6 = [current_node] - t.6 = [t.6+28] - t.7 = call t.6(current_node) - if0 t.7 goto :if18_else - if current_node goto :null65 - Error("null pointer") - null65: - t.8 = [current_node] - t.8 = [t.8+12] - current_node = call t.8(current_node) - goto :if18_end - if18_else: - cont = 0 - if18_end: - goto :if17_end - if17_else: - ifound = 1 - cont = 0 - if17_end: - if15_end: - goto :while5_top - while5_end: - ret ifound - -func Tree.Print(this) - current_node = this - t.0 = [this] - t.0 = [t.0+76] - ntb = call t.0(this current_node) - ret 1 - -func Tree.RecPrint(this node) - if node goto :null66 - Error("null pointer") - null66: - t.0 = [node] - t.0 = [t.0+32] - t.1 = call t.0(node) - if0 t.1 goto :if19_else - t.2 = [this] - t.2 = [t.2+76] - if node goto :null67 - Error("null pointer") - null67: - t.3 = [node] - t.3 = [t.3+16] - t.4 = call t.3(node) - ntb = call t.2(this t.4) - goto :if19_end - if19_else: - ntb = 1 - if19_end: - if node goto :null68 - Error("null pointer") - null68: - t.5 = [node] - t.5 = [t.5+20] - t.6 = call t.5(node) - PrintIntS(t.6) - if node goto :null69 - Error("null pointer") - null69: - t.7 = [node] - t.7 = [t.7+28] - t.8 = call t.7(node) - if0 t.8 goto :if20_else - t.9 = [this] - t.9 = [t.9+76] - if node goto :null70 - Error("null pointer") - null70: - t.10 = [node] - t.10 = [t.10+12] - t.11 = call t.10(node) - ntb = call t.9(this t.11) - goto :if20_end - if20_else: - ntb = 1 - if20_end: - ret 1 diff --git a/vaporize/tests/BubbleSort.java b/vaporize/tests/BubbleSort.java deleted file mode 100644 index e5645a9..0000000 --- a/vaporize/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/vaporize/tests/BubbleSort.opt.vapor b/vaporize/tests/BubbleSort.opt.vapor deleted file mode 100644 index a118894..0000000 --- a/vaporize/tests/BubbleSort.opt.vapor +++ /dev/null @@ -1,277 +0,0 @@ - -const empty_BBS - - -func Main() - t.0 = HeapAllocZ(8) - if t.0 goto :null1 - Error("null pointer") - null1: - t.1 = call :BBS.Start(t.0 10) - PrintIntS(t.1) - ret - -func BBS.Start(this sz) - aux01 = call :BBS.Init(this sz) - aux01 = call :BBS.Print(this) - PrintIntS(99999) - aux01 = call :BBS.Sort(this) - aux01 = call :BBS.Print(this) - ret 0 - -func BBS.Sort(this) - t.0 = [this+4] - i = Sub(t.0 1) - aux02 = Sub(0 1) - while1_top: - t.1 = LtS(aux02 i) - if0 t.1 goto :while1_end - j = 1 - while2_top: - t.2 = Add(i 1) - t.3 = LtS(j t.2) - if0 t.3 goto :while2_end - aux07 = Sub(j 1) - t.4 = [this+0] - if t.4 goto :null2 - Error("null pointer") - null2: - t.5 = [t.4] - t.5 = Lt(aux07 t.5) - if t.5 goto :bounds1 - Error("array index out of bounds") - bounds1: - t.5 = MulS(aux07 4) - t.5 = Add(t.5 t.4) - aux04 = [t.5+4] - t.6 = [this+0] - if t.6 goto :null3 - Error("null pointer") - null3: - t.7 = [t.6] - t.7 = Lt(j t.7) - if t.7 goto :bounds2 - Error("array index out of bounds") - bounds2: - t.7 = MulS(j 4) - t.7 = Add(t.7 t.6) - aux05 = [t.7+4] - t.8 = LtS(aux05 aux04) - if0 t.8 goto :if1_else - aux06 = Sub(j 1) - t.9 = [this+0] - if t.9 goto :null4 - Error("null pointer") - null4: - t.10 = [t.9] - t.10 = Lt(aux06 t.10) - if t.10 goto :bounds3 - Error("array index out of bounds") - bounds3: - t.10 = MulS(aux06 4) - t.10 = Add(t.10 t.9) - t = [t.10+4] - t.11 = [this+0] - if t.11 goto :null5 - Error("null pointer") - null5: - t.12 = [t.11] - t.12 = Lt(aux06 t.12) - if t.12 goto :bounds4 - Error("array index out of bounds") - bounds4: - t.12 = MulS(aux06 4) - t.12 = Add(t.12 t.11) - t.13 = [this+0] - if t.13 goto :null6 - Error("null pointer") - null6: - t.14 = [t.13] - t.14 = Lt(j t.14) - if t.14 goto :bounds5 - Error("array index out of bounds") - bounds5: - t.14 = MulS(j 4) - t.14 = Add(t.14 t.13) - t.15 = [t.14+4] - [t.12+4] = t.15 - t.16 = [this+0] - if t.16 goto :null7 - Error("null pointer") - null7: - t.17 = [t.16] - t.17 = Lt(j t.17) - if t.17 goto :bounds6 - Error("array index out of bounds") - bounds6: - t.17 = MulS(j 4) - t.17 = Add(t.17 t.16) - [t.17+4] = t - goto :if1_end - if1_else: - nt = 0 - if1_end: - j = Add(j 1) - goto :while2_top - while2_end: - i = Sub(i 1) - goto :while1_top - while1_end: - ret 0 - -func BBS.Print(this) - j = 0 - while3_top: - t.0 = [this+4] - t.1 = LtS(j t.0) - if0 t.1 goto :while3_end - t.2 = [this+0] - if t.2 goto :null8 - Error("null pointer") - null8: - t.3 = [t.2] - t.3 = Lt(j t.3) - if t.3 goto :bounds7 - Error("array index out of bounds") - bounds7: - t.3 = MulS(j 4) - t.3 = Add(t.3 t.2) - t.4 = [t.3+4] - PrintIntS(t.4) - j = Add(j 1) - goto :while3_top - while3_end: - ret 0 - -func BBS.Init(this sz) - [this+4] = sz - t.0 = call :AllocArray(sz) - [this+0] = t.0 - t.1 = [this+0] - if t.1 goto :null9 - Error("null pointer") - null9: - t.2 = [t.1] - t.2 = Lt(0 t.2) - if t.2 goto :bounds8 - Error("array index out of bounds") - bounds8: - t.2 = MulS(0 4) - t.2 = Add(t.2 t.1) - [t.2+4] = 20 - t.3 = [this+0] - if t.3 goto :null10 - Error("null pointer") - null10: - t.4 = [t.3] - t.4 = Lt(1 t.4) - if t.4 goto :bounds9 - Error("array index out of bounds") - bounds9: - t.4 = MulS(1 4) - t.4 = Add(t.4 t.3) - [t.4+4] = 7 - t.5 = [this+0] - if t.5 goto :null11 - Error("null pointer") - null11: - t.6 = [t.5] - t.6 = Lt(2 t.6) - if t.6 goto :bounds10 - Error("array index out of bounds") - bounds10: - t.6 = MulS(2 4) - t.6 = Add(t.6 t.5) - [t.6+4] = 12 - t.7 = [this+0] - if t.7 goto :null12 - Error("null pointer") - null12: - t.8 = [t.7] - t.8 = Lt(3 t.8) - if t.8 goto :bounds11 - Error("array index out of bounds") - bounds11: - t.8 = MulS(3 4) - t.8 = Add(t.8 t.7) - [t.8+4] = 18 - t.9 = [this+0] - if t.9 goto :null13 - Error("null pointer") - null13: - t.10 = [t.9] - t.10 = Lt(4 t.10) - if t.10 goto :bounds12 - Error("array index out of bounds") - bounds12: - t.10 = MulS(4 4) - t.10 = Add(t.10 t.9) - [t.10+4] = 2 - t.11 = [this+0] - if t.11 goto :null14 - Error("null pointer") - null14: - t.12 = [t.11] - t.12 = Lt(5 t.12) - if t.12 goto :bounds13 - Error("array index out of bounds") - bounds13: - t.12 = MulS(5 4) - t.12 = Add(t.12 t.11) - [t.12+4] = 11 - t.13 = [this+0] - if t.13 goto :null15 - Error("null pointer") - null15: - t.14 = [t.13] - t.14 = Lt(6 t.14) - if t.14 goto :bounds14 - Error("array index out of bounds") - bounds14: - t.14 = MulS(6 4) - t.14 = Add(t.14 t.13) - [t.14+4] = 6 - t.15 = [this+0] - if t.15 goto :null16 - Error("null pointer") - null16: - t.16 = [t.15] - t.16 = Lt(7 t.16) - if t.16 goto :bounds15 - Error("array index out of bounds") - bounds15: - t.16 = MulS(7 4) - t.16 = Add(t.16 t.15) - [t.16+4] = 9 - t.17 = [this+0] - if t.17 goto :null17 - Error("null pointer") - null17: - t.18 = [t.17] - t.18 = Lt(8 t.18) - if t.18 goto :bounds16 - Error("array index out of bounds") - bounds16: - t.18 = MulS(8 4) - t.18 = Add(t.18 t.17) - [t.18+4] = 19 - t.19 = [this+0] - if t.19 goto :null18 - Error("null pointer") - null18: - t.20 = [t.19] - t.20 = Lt(9 t.20) - if t.20 goto :bounds17 - Error("array index out of bounds") - bounds17: - t.20 = MulS(9 4) - t.20 = Add(t.20 t.19) - [t.20+4] = 5 - ret 0 - -func AllocArray(size) - bytes = MulS(size 4) - bytes = Add(bytes 4) - v = HeapAllocZ(bytes) - [v] = size - ret v diff --git a/vaporize/tests/BubbleSort.vapor b/vaporize/tests/BubbleSort.vapor deleted file mode 100644 index cedba69..0000000 --- a/vaporize/tests/BubbleSort.vapor +++ /dev/null @@ -1,292 +0,0 @@ - -const vmt_BBS - :BBS.Start - :BBS.Sort - :BBS.Print - :BBS.Init - - -func Main() - t.0 = HeapAllocZ(12) - [t.0] = :vmt_BBS - if t.0 goto :null1 - Error("null pointer") - null1: - t.1 = [t.0] - t.1 = [t.1+0] - t.2 = call t.1(t.0 10) - PrintIntS(t.2) - ret - -func BBS.Start(this sz) - t.0 = [this] - t.0 = [t.0+12] - aux01 = call t.0(this sz) - t.1 = [this] - t.1 = [t.1+8] - aux01 = call t.1(this) - PrintIntS(99999) - t.2 = [this] - t.2 = [t.2+4] - aux01 = call t.2(this) - t.3 = [this] - t.3 = [t.3+8] - aux01 = call t.3(this) - ret 0 - -func BBS.Sort(this) - t.0 = [this+8] - i = Sub(t.0 1) - aux02 = Sub(0 1) - while1_top: - t.1 = LtS(aux02 i) - if0 t.1 goto :while1_end - j = 1 - while2_top: - t.2 = Add(i 1) - t.3 = LtS(j t.2) - if0 t.3 goto :while2_end - aux07 = Sub(j 1) - t.4 = [this+4] - if t.4 goto :null2 - Error("null pointer") - null2: - t.5 = [t.4] - t.5 = Lt(aux07 t.5) - if t.5 goto :bounds1 - Error("array index out of bounds") - bounds1: - t.5 = MulS(aux07 4) - t.5 = Add(t.5 t.4) - aux04 = [t.5+4] - t.6 = [this+4] - if t.6 goto :null3 - Error("null pointer") - null3: - t.7 = [t.6] - t.7 = Lt(j t.7) - if t.7 goto :bounds2 - Error("array index out of bounds") - bounds2: - t.7 = MulS(j 4) - t.7 = Add(t.7 t.6) - aux05 = [t.7+4] - t.8 = LtS(aux05 aux04) - if0 t.8 goto :if1_else - aux06 = Sub(j 1) - t.9 = [this+4] - if t.9 goto :null4 - Error("null pointer") - null4: - t.10 = [t.9] - t.10 = Lt(aux06 t.10) - if t.10 goto :bounds3 - Error("array index out of bounds") - bounds3: - t.10 = MulS(aux06 4) - t.10 = Add(t.10 t.9) - t = [t.10+4] - t.11 = [this+4] - if t.11 goto :null5 - Error("null pointer") - null5: - t.12 = [t.11] - t.12 = Lt(aux06 t.12) - if t.12 goto :bounds4 - Error("array index out of bounds") - bounds4: - t.12 = MulS(aux06 4) - t.12 = Add(t.12 t.11) - t.13 = [this+4] - if t.13 goto :null6 - Error("null pointer") - null6: - t.14 = [t.13] - t.14 = Lt(j t.14) - if t.14 goto :bounds5 - Error("array index out of bounds") - bounds5: - t.14 = MulS(j 4) - t.14 = Add(t.14 t.13) - t.15 = [t.14+4] - [t.12+4] = t.15 - t.16 = [this+4] - if t.16 goto :null7 - Error("null pointer") - null7: - t.17 = [t.16] - t.17 = Lt(j t.17) - if t.17 goto :bounds6 - Error("array index out of bounds") - bounds6: - t.17 = MulS(j 4) - t.17 = Add(t.17 t.16) - [t.17+4] = t - goto :if1_end - if1_else: - nt = 0 - if1_end: - j = Add(j 1) - goto :while2_top - while2_end: - i = Sub(i 1) - goto :while1_top - while1_end: - ret 0 - -func BBS.Print(this) - j = 0 - while3_top: - t.0 = [this+8] - t.1 = LtS(j t.0) - if0 t.1 goto :while3_end - t.2 = [this+4] - if t.2 goto :null8 - Error("null pointer") - null8: - t.3 = [t.2] - t.3 = Lt(j t.3) - if t.3 goto :bounds7 - Error("array index out of bounds") - bounds7: - t.3 = MulS(j 4) - t.3 = Add(t.3 t.2) - t.4 = [t.3+4] - PrintIntS(t.4) - j = Add(j 1) - goto :while3_top - while3_end: - ret 0 - -func BBS.Init(this sz) - [this+8] = sz - t.0 = call :AllocArray(sz) - [this+4] = t.0 - t.1 = [this+4] - if t.1 goto :null9 - Error("null pointer") - null9: - t.2 = [t.1] - t.2 = Lt(0 t.2) - if t.2 goto :bounds8 - Error("array index out of bounds") - bounds8: - t.2 = MulS(0 4) - t.2 = Add(t.2 t.1) - [t.2+4] = 20 - t.3 = [this+4] - if t.3 goto :null10 - Error("null pointer") - null10: - t.4 = [t.3] - t.4 = Lt(1 t.4) - if t.4 goto :bounds9 - Error("array index out of bounds") - bounds9: - t.4 = MulS(1 4) - t.4 = Add(t.4 t.3) - [t.4+4] = 7 - t.5 = [this+4] - if t.5 goto :null11 - Error("null pointer") - null11: - t.6 = [t.5] - t.6 = Lt(2 t.6) - if t.6 goto :bounds10 - Error("array index out of bounds") - bounds10: - t.6 = MulS(2 4) - t.6 = Add(t.6 t.5) - [t.6+4] = 12 - t.7 = [this+4] - if t.7 goto :null12 - Error("null pointer") - null12: - t.8 = [t.7] - t.8 = Lt(3 t.8) - if t.8 goto :bounds11 - Error("array index out of bounds") - bounds11: - t.8 = MulS(3 4) - t.8 = Add(t.8 t.7) - [t.8+4] = 18 - t.9 = [this+4] - if t.9 goto :null13 - Error("null pointer") - null13: - t.10 = [t.9] - t.10 = Lt(4 t.10) - if t.10 goto :bounds12 - Error("array index out of bounds") - bounds12: - t.10 = MulS(4 4) - t.10 = Add(t.10 t.9) - [t.10+4] = 2 - t.11 = [this+4] - if t.11 goto :null14 - Error("null pointer") - null14: - t.12 = [t.11] - t.12 = Lt(5 t.12) - if t.12 goto :bounds13 - Error("array index out of bounds") - bounds13: - t.12 = MulS(5 4) - t.12 = Add(t.12 t.11) - [t.12+4] = 11 - t.13 = [this+4] - if t.13 goto :null15 - Error("null pointer") - null15: - t.14 = [t.13] - t.14 = Lt(6 t.14) - if t.14 goto :bounds14 - Error("array index out of bounds") - bounds14: - t.14 = MulS(6 4) - t.14 = Add(t.14 t.13) - [t.14+4] = 6 - t.15 = [this+4] - if t.15 goto :null16 - Error("null pointer") - null16: - t.16 = [t.15] - t.16 = Lt(7 t.16) - if t.16 goto :bounds15 - Error("array index out of bounds") - bounds15: - t.16 = MulS(7 4) - t.16 = Add(t.16 t.15) - [t.16+4] = 9 - t.17 = [this+4] - if t.17 goto :null17 - Error("null pointer") - null17: - t.18 = [t.17] - t.18 = Lt(8 t.18) - if t.18 goto :bounds16 - Error("array index out of bounds") - bounds16: - t.18 = MulS(8 4) - t.18 = Add(t.18 t.17) - [t.18+4] = 19 - t.19 = [this+4] - if t.19 goto :null18 - Error("null pointer") - null18: - t.20 = [t.19] - t.20 = Lt(9 t.20) - if t.20 goto :bounds17 - Error("array index out of bounds") - bounds17: - t.20 = MulS(9 4) - t.20 = Add(t.20 t.19) - [t.20+4] = 5 - ret 0 - -func AllocArray(size) - bytes = MulS(size 4) - bytes = Add(bytes 4) - v = HeapAllocZ(bytes) - [v] = size - ret v diff --git a/vaporize/tests/Factorial.java b/vaporize/tests/Factorial.java deleted file mode 100644 index d938bb6..0000000 --- a/vaporize/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/vaporize/tests/Factorial.opt.vapor b/vaporize/tests/Factorial.opt.vapor deleted file mode 100644 index aca17fe..0000000 --- a/vaporize/tests/Factorial.opt.vapor +++ /dev/null @@ -1,20 +0,0 @@ - -const empty_Fac - - -func Main() - t.0 = call :Fac.ComputeFac(:empty_Fac 10) - PrintIntS(t.0) - ret - -func Fac.ComputeFac(this num) - t.0 = LtS(num 1) - if0 t.0 goto :if1_else - num_aux = 1 - goto :if1_end - if1_else: - t.1 = Sub(num 1) - t.2 = call :Fac.ComputeFac(this t.1) - num_aux = MulS(num t.2) - if1_end: - ret num_aux diff --git a/vaporize/tests/Factorial.vapor b/vaporize/tests/Factorial.vapor deleted file mode 100644 index 28e1126..0000000 --- a/vaporize/tests/Factorial.vapor +++ /dev/null @@ -1,30 +0,0 @@ - -const vmt_Fac - :Fac.ComputeFac - - -func Main() - t.0 = HeapAllocZ(4) - [t.0] = :vmt_Fac - if t.0 goto :null1 - Error("null pointer") - null1: - t.1 = [t.0] - t.1 = [t.1+0] - t.2 = call t.1(t.0 10) - PrintIntS(t.2) - ret - -func Fac.ComputeFac(this num) - t.0 = LtS(num 1) - if0 t.0 goto :if1_else - num_aux = 1 - goto :if1_end - if1_else: - t.1 = [this] - t.1 = [t.1+0] - t.2 = Sub(num 1) - t.3 = call t.1(this t.2) - num_aux = MulS(num t.3) - if1_end: - ret num_aux diff --git a/vaporize/tests/LinearSearch.java b/vaporize/tests/LinearSearch.java deleted file mode 100644 index daddd94..0000000 --- a/vaporize/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/vaporize/tests/LinearSearch.opt.vapor b/vaporize/tests/LinearSearch.opt.vapor deleted file mode 100644 index 302de05..0000000 --- a/vaporize/tests/LinearSearch.opt.vapor +++ /dev/null @@ -1,130 +0,0 @@ - -const empty_LS - - -func Main() - t.0 = HeapAllocZ(8) - if t.0 goto :null1 - Error("null pointer") - null1: - t.1 = call :LS.Start(t.0 10) - PrintIntS(t.1) - ret - -func LS.Start(this sz) - aux01 = call :LS.Init(this sz) - aux02 = call :LS.Print(this) - PrintIntS(9999) - t.0 = call :LS.Search(this 8) - PrintIntS(t.0) - t.1 = call :LS.Search(this 12) - PrintIntS(t.1) - t.2 = call :LS.Search(this 17) - PrintIntS(t.2) - t.3 = call :LS.Search(this 50) - PrintIntS(t.3) - ret 55 - -func LS.Print(this) - j = 1 - while1_top: - t.0 = [this+4] - t.1 = LtS(j t.0) - if0 t.1 goto :while1_end - t.2 = [this+0] - if t.2 goto :null2 - Error("null pointer") - null2: - t.3 = [t.2] - t.3 = Lt(j t.3) - if t.3 goto :bounds1 - Error("array index out of bounds") - bounds1: - t.3 = MulS(j 4) - t.3 = Add(t.3 t.2) - t.4 = [t.3+4] - PrintIntS(t.4) - j = Add(j 1) - goto :while1_top - while1_end: - ret 0 - -func LS.Search(this num) - j = 1 - ls01 = 0 - ifound = 0 - while2_top: - t.0 = [this+4] - t.1 = LtS(j t.0) - if0 t.1 goto :while2_end - t.2 = [this+0] - if t.2 goto :null3 - Error("null pointer") - null3: - t.3 = [t.2] - t.3 = Lt(j t.3) - if t.3 goto :bounds2 - Error("array index out of bounds") - bounds2: - t.3 = MulS(j 4) - t.3 = Add(t.3 t.2) - aux01 = [t.3+4] - aux02 = Add(num 1) - t.4 = LtS(aux01 num) - if0 t.4 goto :if1_else - nt = 0 - goto :if1_end - if1_else: - t.5 = LtS(aux01 aux02) - if t.5 goto :if2_else - nt = 0 - goto :if2_end - if2_else: - ls01 = 1 - ifound = 1 - j = [this+4] - if2_end: - if1_end: - j = Add(j 1) - goto :while2_top - while2_end: - ret ifound - -func LS.Init(this sz) - [this+4] = sz - t.0 = call :AllocArray(sz) - [this+0] = t.0 - j = 1 - t.1 = [this+4] - k = Add(t.1 1) - while3_top: - t.2 = [this+4] - t.3 = LtS(j t.2) - if0 t.3 goto :while3_end - aux01 = MulS(2 j) - aux02 = Sub(k 3) - t.4 = [this+0] - if t.4 goto :null4 - Error("null pointer") - null4: - t.5 = [t.4] - t.5 = Lt(j t.5) - if t.5 goto :bounds3 - Error("array index out of bounds") - bounds3: - t.5 = MulS(j 4) - t.5 = Add(t.5 t.4) - t.6 = Add(aux01 aux02) - [t.5+4] = t.6 - j = Add(j 1) - k = Sub(k 1) - goto :while3_top - while3_end: - ret 0 - -func AllocArray(size) - bytes = MulS(size 4) - bytes = Add(bytes 4) - v = HeapAllocZ(bytes) - [v] = size - ret v diff --git a/vaporize/tests/LinearSearch.vapor b/vaporize/tests/LinearSearch.vapor deleted file mode 100644 index db4884a..0000000 --- a/vaporize/tests/LinearSearch.vapor +++ /dev/null @@ -1,150 +0,0 @@ - -const vmt_LS - :LS.Start - :LS.Print - :LS.Search - :LS.Init - - -func Main() - t.0 = HeapAllocZ(12) - [t.0] = :vmt_LS - if t.0 goto :null1 - Error("null pointer") - null1: - t.1 = [t.0] - t.1 = [t.1+0] - t.2 = call t.1(t.0 10) - PrintIntS(t.2) - ret - -func LS.Start(this sz) - t.0 = [this] - t.0 = [t.0+12] - aux01 = call t.0(this sz) - t.1 = [this] - t.1 = [t.1+4] - aux02 = call t.1(this) - PrintIntS(9999) - t.2 = [this] - t.2 = [t.2+8] - t.3 = call t.2(this 8) - PrintIntS(t.3) - t.4 = [this] - t.4 = [t.4+8] - t.5 = call t.4(this 12) - PrintIntS(t.5) - t.6 = [this] - t.6 = [t.6+8] - t.7 = call t.6(this 17) - PrintIntS(t.7) - t.8 = [this] - t.8 = [t.8+8] - t.9 = call t.8(this 50) - PrintIntS(t.9) - ret 55 - -func LS.Print(this) - j = 1 - while1_top: - t.0 = [this+8] - t.1 = LtS(j t.0) - if0 t.1 goto :while1_end - t.2 = [this+4] - if t.2 goto :null2 - Error("null pointer") - null2: - t.3 = [t.2] - t.3 = Lt(j t.3) - if t.3 goto :bounds1 - Error("array index out of bounds") - bounds1: - t.3 = MulS(j 4) - t.3 = Add(t.3 t.2) - t.4 = [t.3+4] - PrintIntS(t.4) - j = Add(j 1) - goto :while1_top - while1_end: - ret 0 - -func LS.Search(this num) - j = 1 - ls01 = 0 - ifound = 0 - while2_top: - t.0 = [this+8] - t.1 = LtS(j t.0) - if0 t.1 goto :while2_end - t.2 = [this+4] - if t.2 goto :null3 - Error("null pointer") - null3: - t.3 = [t.2] - t.3 = Lt(j t.3) - if t.3 goto :bounds2 - Error("array index out of bounds") - bounds2: - t.3 = MulS(j 4) - t.3 = Add(t.3 t.2) - aux01 = [t.3+4] - aux02 = Add(num 1) - t.4 = LtS(aux01 num) - if0 t.4 goto :if1_else - nt = 0 - goto :if1_end - if1_else: - t.5 = LtS(aux01 aux02) - t.6 = Sub(1 t.5) - if0 t.6 goto :if2_else - nt = 0 - goto :if2_end - if2_else: - ls01 = 1 - ifound = 1 - j = [this+8] - if2_end: - if1_end: - j = Add(j 1) - goto :while2_top - while2_end: - ret ifound - -func LS.Init(this sz) - [this+8] = sz - t.0 = call :AllocArray(sz) - [this+4] = t.0 - j = 1 - t.1 = [this+8] - k = Add(t.1 1) - while3_top: - t.2 = [this+8] - t.3 = LtS(j t.2) - if0 t.3 goto :while3_end - aux01 = MulS(2 j) - aux02 = Sub(k 3) - t.4 = [this+4] - if t.4 goto :null4 - Error("null pointer") - null4: - t.5 = [t.4] - t.5 = Lt(j t.5) - if t.5 goto :bounds3 - Error("array index out of bounds") - bounds3: - t.5 = MulS(j 4) - t.5 = Add(t.5 t.4) - t.6 = Add(aux01 aux02) - [t.5+4] = t.6 - j = Add(j 1) - k = Sub(k 1) - goto :while3_top - while3_end: - ret 0 - -func AllocArray(size) - bytes = MulS(size 4) - bytes = Add(bytes 4) - v = HeapAllocZ(bytes) - [v] = size - ret v diff --git a/vaporize/tests/LinkedList.java b/vaporize/tests/LinkedList.java deleted file mode 100644 index 69adc33..0000000 --- a/vaporize/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/vaporize/tests/LinkedList.opt.vapor b/vaporize/tests/LinkedList.opt.vapor deleted file mode 100644 index aaca62c..0000000 --- a/vaporize/tests/LinkedList.opt.vapor +++ /dev/null @@ -1,373 +0,0 @@ - -const empty_Element - -const empty_List - -const empty_LL - - -func Main() - t.0 = call :LL.Start(:empty_LL) - PrintIntS(t.0) - ret - -func Element.Init(this v_Age v_Salary v_Married) - [this+0] = v_Age - [this+4] = v_Salary - [this+8] = v_Married - ret 1 - -func Element.GetAge(this) - t.0 = [this+0] - ret t.0 - -func Element.GetSalary(this) - t.0 = [this+4] - ret t.0 - -func Element.GetMarried(this) - t.0 = [this+8] - ret t.0 - -func Element.Equal(this other) - ret_val = 1 - if other goto :null1 - Error("null pointer") - null1: - aux01 = call :Element.GetAge(other) - t.0 = [this+0] - t.1 = call :Element.Compare(this aux01 t.0) - if t.1 goto :if1_else - ret_val = 0 - goto :if1_end - if1_else: - if other goto :null2 - Error("null pointer") - null2: - aux02 = call :Element.GetSalary(other) - t.2 = [this+4] - t.3 = call :Element.Compare(this aux02 t.2) - if t.3 goto :if2_else - ret_val = 0 - goto :if2_end - if2_else: - t.4 = [this+8] - if0 t.4 goto :if3_else - if other goto :null3 - Error("null pointer") - null3: - t.5 = call :Element.GetMarried(other) - if t.5 goto :if4_else - ret_val = 0 - goto :if4_end - if4_else: - nt = 0 - if4_end: - goto :if3_end - if3_else: - if other goto :null4 - Error("null pointer") - null4: - t.6 = call :Element.GetMarried(other) - if0 t.6 goto :if5_else - ret_val = 0 - goto :if5_end - if5_else: - nt = 0 - if5_end: - if3_end: - if2_end: - if1_end: - ret ret_val - -func Element.Compare(this num1 num2) - retval = 0 - aux02 = Add(num2 1) - t.0 = LtS(num1 num2) - if0 t.0 goto :if6_else - retval = 0 - goto :if6_end - if6_else: - t.1 = LtS(num1 aux02) - if t.1 goto :if7_else - retval = 0 - goto :if7_end - if7_else: - retval = 1 - if7_end: - if6_end: - ret retval - -func List.Init(this) - [this+8] = 1 - ret 1 - -func List.InitNew(this v_elem v_next v_end) - [this+8] = v_end - [this+0] = v_elem - [this+4] = v_next - ret 1 - -func List.Insert(this new_elem) - aux03 = this - aux02 = HeapAllocZ(12) - if aux02 goto :null5 - Error("null pointer") - null5: - ret_val = call :List.InitNew(aux02 new_elem aux03 0) - ret aux02 - -func List.SetNext(this v_next) - [this+4] = v_next - ret 1 - -func List.Delete(this e) - my_head = this - ret_val = 0 - aux04 = Sub(0 1) - aux01 = this - prev = this - var_end = [this+8] - var_elem = [this+0] - while1_top: - if var_end goto :ss1_else - t.0 = Sub(1 ret_val) - goto :ss1_end - ss1_else: - t.0 = 0 - ss1_end: - if0 t.0 goto :while1_end - if e goto :null6 - Error("null pointer") - null6: - t.1 = call :Element.Equal(e var_elem) - if0 t.1 goto :if8_else - ret_val = 1 - t.2 = LtS(aux04 0) - if0 t.2 goto :if9_else - if aux01 goto :null7 - Error("null pointer") - null7: - my_head = call :List.GetNext(aux01) - goto :if9_end - if9_else: - t.3 = Sub(0 555) - PrintIntS(t.3) - if prev goto :null8 - Error("null pointer") - null8: - if aux01 goto :null9 - Error("null pointer") - null9: - t.4 = call :List.GetNext(aux01) - aux05 = call :List.SetNext(prev t.4) - t.5 = Sub(0 555) - PrintIntS(t.5) - if9_end: - goto :if8_end - if8_else: - nt = 0 - if8_end: - if ret_val goto :if10_else - prev = aux01 - if aux01 goto :null10 - Error("null pointer") - null10: - aux01 = call :List.GetNext(aux01) - if aux01 goto :null11 - Error("null pointer") - null11: - var_end = call :List.GetEnd(aux01) - if aux01 goto :null12 - Error("null pointer") - null12: - var_elem = call :List.GetElem(aux01) - aux04 = 1 - goto :if10_end - if10_else: - nt = 0 - if10_end: - goto :while1_top - while1_end: - ret my_head - -func List.Search(this e) - int_ret_val = 0 - aux01 = this - var_end = [this+8] - var_elem = [this+0] - while2_top: - t.0 = Sub(1 var_end) - if0 t.0 goto :while2_end - if e goto :null13 - Error("null pointer") - null13: - t.1 = call :Element.Equal(e var_elem) - if0 t.1 goto :if11_else - int_ret_val = 1 - goto :if11_end - if11_else: - nt = 0 - if11_end: - if aux01 goto :null14 - Error("null pointer") - null14: - aux01 = call :List.GetNext(aux01) - if aux01 goto :null15 - Error("null pointer") - null15: - var_end = call :List.GetEnd(aux01) - if aux01 goto :null16 - Error("null pointer") - null16: - var_elem = call :List.GetElem(aux01) - goto :while2_top - while2_end: - ret int_ret_val - -func List.GetEnd(this) - t.0 = [this+8] - ret t.0 - -func List.GetElem(this) - t.0 = [this+0] - ret t.0 - -func List.GetNext(this) - t.0 = [this+4] - ret t.0 - -func List.Print(this) - aux01 = this - var_end = [this+8] - var_elem = [this+0] - while3_top: - t.0 = Sub(1 var_end) - if0 t.0 goto :while3_end - if var_elem goto :null17 - Error("null pointer") - null17: - t.1 = call :Element.GetAge(var_elem) - PrintIntS(t.1) - if aux01 goto :null18 - Error("null pointer") - null18: - aux01 = call :List.GetNext(aux01) - if aux01 goto :null19 - Error("null pointer") - null19: - var_end = call :List.GetEnd(aux01) - if aux01 goto :null20 - Error("null pointer") - null20: - var_elem = call :List.GetElem(aux01) - goto :while3_top - while3_end: - ret 1 - -func LL.Start(this) - last_elem = HeapAllocZ(12) - if last_elem goto :null21 - Error("null pointer") - null21: - aux01 = call :List.Init(last_elem) - head = last_elem - if head goto :null22 - Error("null pointer") - null22: - aux01 = call :List.Init(head) - if head goto :null23 - Error("null pointer") - null23: - aux01 = call :List.Print(head) - el01 = HeapAllocZ(12) - if el01 goto :null24 - Error("null pointer") - null24: - aux01 = call :Element.Init(el01 25 37000 0) - if head goto :null25 - Error("null pointer") - null25: - head = call :List.Insert(head el01) - if head goto :null26 - Error("null pointer") - null26: - aux01 = call :List.Print(head) - PrintIntS(10000000) - el01 = HeapAllocZ(12) - if el01 goto :null27 - Error("null pointer") - null27: - aux01 = call :Element.Init(el01 39 42000 1) - el02 = el01 - if head goto :null28 - Error("null pointer") - null28: - head = call :List.Insert(head el01) - if head goto :null29 - Error("null pointer") - null29: - aux01 = call :List.Print(head) - PrintIntS(10000000) - el01 = HeapAllocZ(12) - if el01 goto :null30 - Error("null pointer") - null30: - aux01 = call :Element.Init(el01 22 34000 0) - if head goto :null31 - Error("null pointer") - null31: - head = call :List.Insert(head el01) - if head goto :null32 - Error("null pointer") - null32: - aux01 = call :List.Print(head) - el03 = HeapAllocZ(12) - if el03 goto :null33 - Error("null pointer") - null33: - aux01 = call :Element.Init(el03 27 34000 0) - if head goto :null34 - Error("null pointer") - null34: - t.0 = call :List.Search(head el02) - PrintIntS(t.0) - if head goto :null35 - Error("null pointer") - null35: - t.1 = call :List.Search(head el03) - PrintIntS(t.1) - PrintIntS(10000000) - el01 = HeapAllocZ(12) - if el01 goto :null36 - Error("null pointer") - null36: - aux01 = call :Element.Init(el01 28 35000 0) - if head goto :null37 - Error("null pointer") - null37: - head = call :List.Insert(head el01) - if head goto :null38 - Error("null pointer") - null38: - aux01 = call :List.Print(head) - PrintIntS(2220000) - if head goto :null39 - Error("null pointer") - null39: - head = call :List.Delete(head el02) - if head goto :null40 - Error("null pointer") - null40: - aux01 = call :List.Print(head) - PrintIntS(33300000) - if head goto :null41 - Error("null pointer") - null41: - head = call :List.Delete(head el01) - if head goto :null42 - Error("null pointer") - null42: - aux01 = call :List.Print(head) - PrintIntS(44440000) - ret 0 diff --git a/vaporize/tests/LinkedList.vapor b/vaporize/tests/LinkedList.vapor deleted file mode 100644 index bebdf94..0000000 --- a/vaporize/tests/LinkedList.vapor +++ /dev/null @@ -1,505 +0,0 @@ - -const vmt_Element - :Element.Init - :Element.GetAge - :Element.GetSalary - :Element.GetMarried - :Element.Equal - :Element.Compare - -const vmt_List - :List.Init - :List.InitNew - :List.Insert - :List.SetNext - :List.Delete - :List.Search - :List.GetEnd - :List.GetElem - :List.GetNext - :List.Print - -const vmt_LL - :LL.Start - - -func Main() - t.0 = HeapAllocZ(4) - [t.0] = :vmt_LL - if t.0 goto :null1 - Error("null pointer") - null1: - t.1 = [t.0] - t.1 = [t.1+0] - t.2 = call t.1(t.0) - PrintIntS(t.2) - ret - -func Element.Init(this v_Age v_Salary v_Married) - [this+4] = v_Age - [this+8] = v_Salary - [this+12] = v_Married - ret 1 - -func Element.GetAge(this) - t.0 = [this+4] - ret t.0 - -func Element.GetSalary(this) - t.0 = [this+8] - ret t.0 - -func Element.GetMarried(this) - t.0 = [this+12] - ret t.0 - -func Element.Equal(this other) - ret_val = 1 - if other goto :null2 - Error("null pointer") - null2: - t.0 = [other] - t.0 = [t.0+4] - aux01 = call t.0(other) - t.1 = [this] - t.1 = [t.1+20] - t.2 = [this+4] - t.3 = call t.1(this aux01 t.2) - t.4 = Sub(1 t.3) - if0 t.4 goto :if1_else - ret_val = 0 - goto :if1_end - if1_else: - if other goto :null3 - Error("null pointer") - null3: - t.5 = [other] - t.5 = [t.5+8] - aux02 = call t.5(other) - t.6 = [this] - t.6 = [t.6+20] - t.7 = [this+8] - t.8 = call t.6(this aux02 t.7) - t.9 = Sub(1 t.8) - if0 t.9 goto :if2_else - ret_val = 0 - goto :if2_end - if2_else: - t.10 = [this+12] - if0 t.10 goto :if3_else - if other goto :null4 - Error("null pointer") - null4: - t.11 = [other] - t.11 = [t.11+12] - t.12 = call t.11(other) - t.13 = Sub(1 t.12) - if0 t.13 goto :if4_else - ret_val = 0 - goto :if4_end - if4_else: - nt = 0 - if4_end: - goto :if3_end - if3_else: - if other goto :null5 - Error("null pointer") - null5: - t.14 = [other] - t.14 = [t.14+12] - t.15 = call t.14(other) - if0 t.15 goto :if5_else - ret_val = 0 - goto :if5_end - if5_else: - nt = 0 - if5_end: - if3_end: - if2_end: - if1_end: - ret ret_val - -func Element.Compare(this num1 num2) - retval = 0 - aux02 = Add(num2 1) - t.0 = LtS(num1 num2) - if0 t.0 goto :if6_else - retval = 0 - goto :if6_end - if6_else: - t.1 = LtS(num1 aux02) - t.2 = Sub(1 t.1) - if0 t.2 goto :if7_else - retval = 0 - goto :if7_end - if7_else: - retval = 1 - if7_end: - if6_end: - ret retval - -func List.Init(this) - [this+12] = 1 - ret 1 - -func List.InitNew(this v_elem v_next v_end) - [this+12] = v_end - [this+4] = v_elem - [this+8] = v_next - ret 1 - -func List.Insert(this new_elem) - aux03 = this - t.0 = HeapAllocZ(16) - [t.0] = :vmt_List - aux02 = t.0 - if aux02 goto :null6 - Error("null pointer") - null6: - t.1 = [aux02] - t.1 = [t.1+4] - ret_val = call t.1(aux02 new_elem aux03 0) - ret aux02 - -func List.SetNext(this v_next) - [this+8] = v_next - ret 1 - -func List.Delete(this e) - my_head = this - ret_val = 0 - aux04 = Sub(0 1) - aux01 = this - prev = this - var_end = [this+12] - var_elem = [this+4] - while1_top: - t.1 = Sub(1 var_end) - if0 t.1 goto :ss1_else - t.0 = Sub(1 ret_val) - goto :ss1_end - ss1_else: - t.0 = 0 - ss1_end: - if0 t.0 goto :while1_end - if e goto :null7 - Error("null pointer") - null7: - t.2 = [e] - t.2 = [t.2+16] - t.3 = call t.2(e var_elem) - if0 t.3 goto :if8_else - ret_val = 1 - t.4 = LtS(aux04 0) - if0 t.4 goto :if9_else - if aux01 goto :null8 - Error("null pointer") - null8: - t.5 = [aux01] - t.5 = [t.5+32] - my_head = call t.5(aux01) - goto :if9_end - if9_else: - t.6 = Sub(0 555) - PrintIntS(t.6) - if prev goto :null9 - Error("null pointer") - null9: - t.7 = [prev] - t.7 = [t.7+12] - if aux01 goto :null10 - Error("null pointer") - null10: - t.8 = [aux01] - t.8 = [t.8+32] - t.9 = call t.8(aux01) - aux05 = call t.7(prev t.9) - t.10 = Sub(0 555) - PrintIntS(t.10) - if9_end: - goto :if8_end - if8_else: - nt = 0 - if8_end: - t.11 = Sub(1 ret_val) - if0 t.11 goto :if10_else - prev = aux01 - if aux01 goto :null11 - Error("null pointer") - null11: - t.12 = [aux01] - t.12 = [t.12+32] - aux01 = call t.12(aux01) - if aux01 goto :null12 - Error("null pointer") - null12: - t.13 = [aux01] - t.13 = [t.13+24] - var_end = call t.13(aux01) - if aux01 goto :null13 - Error("null pointer") - null13: - t.14 = [aux01] - t.14 = [t.14+28] - var_elem = call t.14(aux01) - aux04 = 1 - goto :if10_end - if10_else: - nt = 0 - if10_end: - goto :while1_top - while1_end: - ret my_head - -func List.Search(this e) - int_ret_val = 0 - aux01 = this - var_end = [this+12] - var_elem = [this+4] - while2_top: - t.0 = Sub(1 var_end) - if0 t.0 goto :while2_end - if e goto :null14 - Error("null pointer") - null14: - t.1 = [e] - t.1 = [t.1+16] - t.2 = call t.1(e var_elem) - if0 t.2 goto :if11_else - int_ret_val = 1 - goto :if11_end - if11_else: - nt = 0 - if11_end: - if aux01 goto :null15 - Error("null pointer") - null15: - t.3 = [aux01] - t.3 = [t.3+32] - aux01 = call t.3(aux01) - if aux01 goto :null16 - Error("null pointer") - null16: - t.4 = [aux01] - t.4 = [t.4+24] - var_end = call t.4(aux01) - if aux01 goto :null17 - Error("null pointer") - null17: - t.5 = [aux01] - t.5 = [t.5+28] - var_elem = call t.5(aux01) - goto :while2_top - while2_end: - ret int_ret_val - -func List.GetEnd(this) - t.0 = [this+12] - ret t.0 - -func List.GetElem(this) - t.0 = [this+4] - ret t.0 - -func List.GetNext(this) - t.0 = [this+8] - ret t.0 - -func List.Print(this) - aux01 = this - var_end = [this+12] - var_elem = [this+4] - while3_top: - t.0 = Sub(1 var_end) - if0 t.0 goto :while3_end - if var_elem goto :null18 - Error("null pointer") - null18: - t.1 = [var_elem] - t.1 = [t.1+4] - t.2 = call t.1(var_elem) - PrintIntS(t.2) - if aux01 goto :null19 - Error("null pointer") - null19: - t.3 = [aux01] - t.3 = [t.3+32] - aux01 = call t.3(aux01) - if aux01 goto :null20 - Error("null pointer") - null20: - t.4 = [aux01] - t.4 = [t.4+24] - var_end = call t.4(aux01) - if aux01 goto :null21 - Error("null pointer") - null21: - t.5 = [aux01] - t.5 = [t.5+28] - var_elem = call t.5(aux01) - goto :while3_top - while3_end: - ret 1 - -func LL.Start(this) - t.0 = HeapAllocZ(16) - [t.0] = :vmt_List - last_elem = t.0 - if last_elem goto :null22 - Error("null pointer") - null22: - t.1 = [last_elem] - t.1 = [t.1+0] - aux01 = call t.1(last_elem) - head = last_elem - if head goto :null23 - Error("null pointer") - null23: - t.2 = [head] - t.2 = [t.2+0] - aux01 = call t.2(head) - if head goto :null24 - Error("null pointer") - null24: - t.3 = [head] - t.3 = [t.3+36] - aux01 = call t.3(head) - t.4 = HeapAllocZ(16) - [t.4] = :vmt_Element - el01 = t.4 - if el01 goto :null25 - Error("null pointer") - null25: - t.5 = [el01] - t.5 = [t.5+0] - aux01 = call t.5(el01 25 37000 0) - if head goto :null26 - Error("null pointer") - null26: - t.6 = [head] - t.6 = [t.6+8] - head = call t.6(head el01) - if head goto :null27 - Error("null pointer") - null27: - t.7 = [head] - t.7 = [t.7+36] - aux01 = call t.7(head) - PrintIntS(10000000) - t.8 = HeapAllocZ(16) - [t.8] = :vmt_Element - el01 = t.8 - if el01 goto :null28 - Error("null pointer") - null28: - t.9 = [el01] - t.9 = [t.9+0] - aux01 = call t.9(el01 39 42000 1) - el02 = el01 - if head goto :null29 - Error("null pointer") - null29: - t.10 = [head] - t.10 = [t.10+8] - head = call t.10(head el01) - if head goto :null30 - Error("null pointer") - null30: - t.11 = [head] - t.11 = [t.11+36] - aux01 = call t.11(head) - PrintIntS(10000000) - t.12 = HeapAllocZ(16) - [t.12] = :vmt_Element - el01 = t.12 - if el01 goto :null31 - Error("null pointer") - null31: - t.13 = [el01] - t.13 = [t.13+0] - aux01 = call t.13(el01 22 34000 0) - if head goto :null32 - Error("null pointer") - null32: - t.14 = [head] - t.14 = [t.14+8] - head = call t.14(head el01) - if head goto :null33 - Error("null pointer") - null33: - t.15 = [head] - t.15 = [t.15+36] - aux01 = call t.15(head) - t.16 = HeapAllocZ(16) - [t.16] = :vmt_Element - el03 = t.16 - if el03 goto :null34 - Error("null pointer") - null34: - t.17 = [el03] - t.17 = [t.17+0] - aux01 = call t.17(el03 27 34000 0) - if head goto :null35 - Error("null pointer") - null35: - t.18 = [head] - t.18 = [t.18+20] - t.19 = call t.18(head el02) - PrintIntS(t.19) - if head goto :null36 - Error("null pointer") - null36: - t.20 = [head] - t.20 = [t.20+20] - t.21 = call t.20(head el03) - PrintIntS(t.21) - PrintIntS(10000000) - t.22 = HeapAllocZ(16) - [t.22] = :vmt_Element - el01 = t.22 - if el01 goto :null37 - Error("null pointer") - null37: - t.23 = [el01] - t.23 = [t.23+0] - aux01 = call t.23(el01 28 35000 0) - if head goto :null38 - Error("null pointer") - null38: - t.24 = [head] - t.24 = [t.24+8] - head = call t.24(head el01) - if head goto :null39 - Error("null pointer") - null39: - t.25 = [head] - t.25 = [t.25+36] - aux01 = call t.25(head) - PrintIntS(2220000) - if head goto :null40 - Error("null pointer") - null40: - t.26 = [head] - t.26 = [t.26+16] - head = call t.26(head el02) - if head goto :null41 - Error("null pointer") - null41: - t.27 = [head] - t.27 = [t.27+36] - aux01 = call t.27(head) - PrintIntS(33300000) - if head goto :null42 - Error("null pointer") - null42: - t.28 = [head] - t.28 = [t.28+16] - head = call t.28(head el01) - if head goto :null43 - Error("null pointer") - null43: - t.29 = [head] - t.29 = [t.29+36] - aux01 = call t.29(head) - PrintIntS(44440000) - ret 0 diff --git a/vaporize/tests/MoreThan4.java b/vaporize/tests/MoreThan4.java deleted file mode 100644 index 4960f01..0000000 --- a/vaporize/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/vaporize/tests/MoreThan4.opt.vapor b/vaporize/tests/MoreThan4.opt.vapor deleted file mode 100644 index a59d1b5..0000000 --- a/vaporize/tests/MoreThan4.opt.vapor +++ /dev/null @@ -1,27 +0,0 @@ - -const empty_MT4 - - -func Main() - t.0 = call :MT4.Start(:empty_MT4 1 2 3 4 5 6) - PrintIntS(t.0) - ret - -func MT4.Start(this p1 p2 p3 p4 p5 p6) - PrintIntS(p1) - PrintIntS(p2) - PrintIntS(p3) - PrintIntS(p4) - PrintIntS(p5) - PrintIntS(p6) - aux = call :MT4.Change(this p6 p5 p4 p3 p2 p1) - ret aux - -func MT4.Change(this p1 p2 p3 p4 p5 p6) - PrintIntS(p1) - PrintIntS(p2) - PrintIntS(p3) - PrintIntS(p4) - PrintIntS(p5) - PrintIntS(p6) - ret 0 diff --git a/vaporize/tests/MoreThan4.vapor b/vaporize/tests/MoreThan4.vapor deleted file mode 100644 index 6067f8e..0000000 --- a/vaporize/tests/MoreThan4.vapor +++ /dev/null @@ -1,38 +0,0 @@ - -const vmt_MT4 - :MT4.Start - :MT4.Change - - -func Main() - t.0 = HeapAllocZ(4) - [t.0] = :vmt_MT4 - if t.0 goto :null1 - Error("null pointer") - null1: - t.1 = [t.0] - t.1 = [t.1+0] - t.2 = call t.1(t.0 1 2 3 4 5 6) - PrintIntS(t.2) - ret - -func MT4.Start(this p1 p2 p3 p4 p5 p6) - PrintIntS(p1) - PrintIntS(p2) - PrintIntS(p3) - PrintIntS(p4) - PrintIntS(p5) - PrintIntS(p6) - t.0 = [this] - t.0 = [t.0+4] - aux = call t.0(this p6 p5 p4 p3 p2 p1) - ret aux - -func MT4.Change(this p1 p2 p3 p4 p5 p6) - PrintIntS(p1) - PrintIntS(p2) - PrintIntS(p3) - PrintIntS(p4) - PrintIntS(p5) - PrintIntS(p6) - ret 0 diff --git a/vaporize/tests/QuickSort.java b/vaporize/tests/QuickSort.java deleted file mode 100644 index 5893390..0000000 --- a/vaporize/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