Package wyvern.tools.typedAST.interfaces

Examples of wyvern.tools.typedAST.interfaces.TypedAST.evaluate()


    try {
      Reader reader = new FileReader(file);
      TypedAST res = (TypedAST) new Wyvern().parse(reader, filename);
      res.typecheck(Globals.getStandardEnv(), Optional.empty());
      res = new DSLTransformer().transform(res);
      Value finalV = res.evaluate(Globals.getStandardEnv());
      TreeWriter t = new TreeWriter();
      finalV.writeArgsToTree(t);
      System.out.println(t.getResult());
    } catch (IOException e) {
      System.err.println("Error reading file " + filename);
View Full Code Here


    try (FileInputStream fis = new FileInputStream(file)) {
      TypedAST res = (TypedAST)new Wyvern().parse(new InputStreamReader(fis), "test input");
      Type checkedType = res.typecheck(Globals.getStandardEnv(), Optional.empty());
      System.out.println("Result type: "+checkedType);
      res = new DSLTransformer().transform(res);
      Value finalV = res.evaluate(Globals.getStandardEnv());
      System.out.println("Result: "+finalV);
    }
  }
}
View Full Code Here

    TypedAST res = (TypedAST)new Wyvern().parse(new StringReader(input), "test input");

    Assert.assertEquals(res.typecheck(Globals.getStandardEnv(), Optional.empty()), Int.getInstance());
    res = new DSLTransformer().transform(res);
    Assert.assertEquals(res.evaluate(Globals.getStandardEnv()).toString(), "IntegerConstant(5)");
  }

  @Test
  public void testTrivialDSL3() throws IOException, CopperParserException {
    String input =
View Full Code Here

    WyvernResolver.addFile("in1", input);
    TypedAST res = (TypedAST)new Wyvern().parse(new StringReader(in2), "test input");

    Assert.assertEquals(res.typecheck(Globals.getStandardEnv(), Optional.empty()), Int.getInstance());
    res = new DSLTransformer().transform(res);
    Assert.assertEquals(res.evaluate(Globals.getStandardEnv()).toString(), "IntegerConstant(5)");
  }
  @Test
  public void testTrivialDSL4() throws IOException, CopperParserException {
    String input =
        "type MyNum\n" +
View Full Code Here

    String input =
        "import java:java.lang.Long\n" +
        "Long.create(\"45\")";
    TypedAST res = (TypedAST)new Wyvern().parse(new StringReader(input), "test input");
    res.typecheck(Globals.getStandardEnv(), Optional.<Type>empty());
    Value result = res.evaluate(Globals.getStandardEnv());
    Assert.assertEquals(((Long) ((JavaObj) result).getObj()).longValue(), 45);
  }
 
  @Test
  public void testMultiExn() throws IOException, CopperParserException {
View Full Code Here

    WyvernResolver.clearFiles();
    WyvernResolver.addFile("in1", input1);
    TypedAST res = (TypedAST)new Wyvern().parse(new StringReader(input2), "test input");
    Type result = res.typecheck(Globals.getStandardEnv(), Optional.<Type>empty());
    Value out = res.evaluate(Globals.getStandardEnv());
    Long finalRes = (Long)((JavaObj)out).getObj();
    Assert.assertEquals(192, (long)finalRes);
  }

  @Test
View Full Code Here

    WyvernResolver.clearFiles();
    WyvernResolver.addFile("in1", input1);
    WyvernResolver.addFile("in2", input2);
    TypedAST res = (TypedAST)new Wyvern().parse(new StringReader(input3), "test input");
    Type result = res.typecheck(Globals.getStandardEnv(), Optional.<Type>empty());
    Value out = res.evaluate(Globals.getStandardEnv());
    int finalRes = ((IntegerConstant)out).getValue();
    Assert.assertEquals(19, (int)finalRes);
  }

  @Test
View Full Code Here

    TypedAST testAST = new Sequence(
        new ValDeclaration("x", new IntegerConstant(4), null),
        new Application(new TSLBlock(new Fn(Arrays.asList(new NameBindingImpl("x", Int.getInstance())),
            new SpliceExn(new Variable(new NameBindingImpl("x", Int.getInstance()), null)))), new IntegerConstant(9), null) );
    Type result = testAST.typecheck(Globals.getStandardEnv(), Optional.<Type>empty());
    Value out = testAST.evaluate(Globals.getStandardEnv());
    int finalRes = ((IntegerConstant)out).getValue();
    Assert.assertEquals(4, finalRes);
  }

  @Test
View Full Code Here

    TypedAST res = (TypedAST)new Wyvern().parse(new StringReader(user), "test input");
    Type result = res.typecheck(Globals.getStandardEnv(), Optional.<Type>empty());
    res = new DSLTransformer().transform(res);
    Assert.assertEquals("Int", result.toString());

    Value out = res.evaluate(Globals.getStandardEnv());
    Assert.assertEquals("IntegerConstant(13)", out.toString());
  }

  @Test
  public void lazyTSL() throws IOException, CopperParserException {
View Full Code Here

    WyvernResolver.addFile("supplier", supplier);

    TypedAST res = (TypedAST)new Wyvern().parse(new StringReader(client), "test input");
    Type result = res.typecheck(Globals.getStandardEnv(), Optional.<Type>empty());
    res = new DSLTransformer().transform(res);
    Value finalV = res.evaluate(Globals.getStandardEnv());
  }
}
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. 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.