Package wyvern.tools.typedAST.interfaces

Examples of wyvern.tools.typedAST.interfaces.TypedAST


        +"  def setV(n : Int):Unit = this.testVal = n\n"
        +"  def getV():Int = this.testVal\n"
        +"val h:Hello = Hello.make()\n"
        +"h.setV(10)\n"
        +"h.getV()\n");
    TypedAST pair = wyvern.stdlib.Compiler.compileSources("in1", strs);
    Assert.assertEquals(join(getResult(pair)),"class Hello { static {def make() {new }; def $init() {var testVal = 5}}; var testVal = 5; def setV(n : Int) {val temp$0 = this,temp$0.testVal = n}; def getV() {val temp$2 = this,temp$2.testVal}},val temp$5 = Hello,val temp$4 = temp$5.make,val temp$7 = (),val h = temp$4(temp$7),val temp$9 = h,val temp$8 = temp$9.setV,val temp$11 = 10,temp$8(temp$11),val temp$13 = h,val temp$12 = temp$13.getV,val temp$15 = (),temp$12(temp$15)");
  }
View Full Code Here


    strs.add("if true\n" +
        "  then\n" +
        "    1\n" +
        "  else\n" +
        "    2\n");
    TypedAST pair = wyvern.stdlib.Compiler.compileSources("in1", strs);
    List<Statement> result = getResult(pair);
    Assert.assertEquals(join(result),"label 1,if (true) goto label 2,goto label 3,label 2,val ifRet$0 = 1,goto label 0,label 3,if (true) goto label 4,goto label 5,label 4,val ifRet$0 = 2,goto label 0,label 5,goto label 0,label 0,ifRet$0");
  }
View Full Code Here

        "  then\n" +
        "    x = 1\n" +
        "  else\n" +
        "    x = 2\n" +
        "x");
    TypedAST pair = wyvern.stdlib.Compiler.compileSources("in1", strs);
    List<Statement> result = getResult(pair);
    Assert.assertEquals(join(result),"var x = 0,label 1,if (true) goto label 2,goto label 3,label 2,x = 1,val ifRet$0 = (),goto label 0,label 3,if (true) goto label 4,goto label 5,label 4,x = 2,val ifRet$0 = (),goto label 0,label 5,goto label 0,label 0,ifRet$0,x");
  }
View Full Code Here

        "var y:Int = 0\n" +
        "while x > 0\n" +
        "  x = x-1\n" +
        "  y = y+1\n" +
        "y");
    TypedAST pair = wyvern.stdlib.Compiler.compileSources("in1", strs);
    List<Statement> result = getResult(pair);
    Assert.assertEquals(join(result),"var x = 5,var y = 0,label 0,val temp$0 = x,val temp$1 = 0,val temp$2 = temp$0 > temp$1,if (temp$2) goto label 1,goto label 2,label 1,val temp$3 = x,val temp$4 = 1,val temp$5 = temp$3 - temp$4,x = temp$5,val temp$6 = y,val temp$7 = 1,val temp$8 = temp$6 + temp$7,y = temp$8,goto label 0,label 2,y");
  }
View Full Code Here

  }

  @Override
  public void visit(Fn fn) {
    List<NameBinding> bindings = fn.getArgBindings();
    TypedAST body = fn.getBody();
   
    List<Operand> args = new LinkedList<Operand>();
    List<Statement> innerStatements = new LinkedList<>();

View Full Code Here

  public void testGenericNew2() {
    ArrayList<String> strs = new ArrayList<>();
    strs.add("val test = new\n" +
        "  val x = 2\n" +
        "test\n");
    TypedAST pair = wyvern.stdlib.Compiler.compileSources("in1", strs);
    List<Statement> result = getResult(pair);
    Assert.assertEquals(join(result),"val test = new ,test");
  }
View Full Code Here

    this.expr = new Immediate(new VarRef(mName));
  }

  @Override
  public void visit(Invocation invocation) {
    TypedAST arg = invocation.getArgument();
    TypedAST rec = invocation.getReceiver();
    String name = invocation.getOperationName();
   
    TLFromAST argVisitor = TLFromASTApply(arg);
    TLFromAST recVisitor = TLFromASTApply(rec);
    VarRef temp = getTemp(), argsRes = getTemp();
    if (arg != null) {
      VarRef res = getTemp();
      this.statements.addAll(recVisitor.getStatements());
      this.statements.add(new Defn(new ValDef(temp.getName(), recVisitor.getExpr(), rec.getType())));
      this.statements.addAll(argVisitor.getStatements());
      this.statements.add(new Defn(new ValDef(argsRes.getName(), argVisitor.getExpr(), arg.getType())));
      this.statements.add(new Defn(new ValDef(res.getName(), new BinOp(temp, argsRes, name), invocation.getType())));
      this.expr = new Immediate(res);
      return;
    }

    this.statements.addAll(recVisitor.getStatements());
    this.statements.add(new Defn(new ValDef(temp.getName(), recVisitor.getExpr(), rec.getType())));
    this.expr = new Inv(temp, name);
  }
View Full Code Here

    strs.add("val x = if true \n"
        " then \n"
        + "  1 \n"
        + " else \n"
        + "  2 \n");
    TypedAST pair = wyvern.stdlib.Compiler.compileSources("in1", strs);
    List<Statement> result = getResult(pair);
    Assert.assertEquals("label 1,if (true) goto label 2,goto label 3,label 2,val ifRet$0 = 1,goto label 0,label 3,if (true) goto label 4,goto label 5,label 4,val ifRet$0 = 2,goto label 0,label 5,goto label 0,label 0,val x = ifRet$0", join(result));
  }
View Full Code Here

    return new VarRef("temp$" + tempIdx.getAndIncrement());
  }

  @Override
  public void visit(Application application) {
    TypedAST arg = application.getArgument();
    TypedAST func = application.getFunction();

    VarRef funv = getTemp();
    TLFromAST funcVisitor = TLFromASTApply(func);
    this.statements.addAll(funcVisitor.getStatements());
    this.statements.add(new Defn(new ValDef(funv.getName(), funcVisitor.getExpr(), func.getType())));

    TLFromAST argVisitor = TLFromASTApply(arg);
    this.statements.addAll(argVisitor.getStatements());
    VarRef argv = getTemp();
    this.statements.add(new Defn(new ValDef(argv.getName(), argVisitor.getExpr(), arg.getType())));
View Full Code Here

        "if true \n"
        + " then \n"
        + "  x=1 \n"
        + " else \n"
        + "  x=2 \n");
    TypedAST pair = wyvern.stdlib.Compiler.compileSources("in1", strs);
    List<Statement> result = getResult(pair);
    Assert.assertEquals("var x = 0,label 1,if (true) goto label 2,goto label 3,label 2,x = 1,val ifRet$0 = (),goto label 0,label 3,if (true) goto label 4,goto label 5,label 4,x = 2,val ifRet$0 = (),goto label 0,label 5,goto label 0,label 0,ifRet$0", join(result));
  }
View Full Code Here

TOP

Related Classes of wyvern.tools.typedAST.interfaces.TypedAST

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.