Package wyvern.tools.typedAST.interfaces

Examples of wyvern.tools.typedAST.interfaces.TypedAST


public class TrivDSLParser implements ExtParser {
  @Override
  public TypedAST parse(ParseBuffer input) {
    New newv = new New(new HashMap<>(), null);
    TypedAST dbody = new IntegerConstant(Integer.parseInt(input.getSrcString().trim()));
    newv.setBody(new DeclSequence(Arrays.asList(new DefDeclaration("getValue", new Arrow(Unit.getInstance(), Int.getInstance()), new ArrayList<>(), dbody, false))));
    return newv;
  }
View Full Code Here


    String in2 = "import wyv:in1\n" +
           "val n:A.MyNum = { 5 }\n" +
           "n.getValue()";
    WyvernResolver.clearFiles();
    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)");
  }
View Full Code Here

            "  metadata:HasParser = myNumMetadata\n" +
            "val n:MyNum = ~\n" +
            "  5\n" +
            "n.getValue()";

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


    Type parserType = Util.javaToWyvType(ExtParser.class);
    Type metaType = Util.javaToWyvType(HasParser.class);


    final ExtParser parseri = str -> {
      New newv = new New(new HashMap<>(), null);
      TypedAST dbody = new IntegerConstant(Integer.parseInt(str.getSrcString().trim()));
      newv.setBody(new DeclSequence(Arrays.asList(new DefDeclaration("getValue", new Arrow(Unit.getInstance(), Int.getInstance()), new ArrayList<>(), dbody, false))));
      return newv;
    };

    HasParser inner = new HasParser() {
View Full Code Here

  @Test
  public void testImport1() throws IOException, CopperParserException {
    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);
  }
View Full Code Here

 
  @Test
  public void testMultiExn() throws IOException, CopperParserException {
    String input =
        "5\n6";
    TypedAST res = (TypedAST)new Wyvern().parse(new StringReader(input), "test input");
  }
View Full Code Here

        "import java:java.lang.Long\n" +
        "class C\n" +
        "  def d():Long = Long.create(\"192\")\n" +
        "val k = 4\n";

    TypedAST res = (TypedAST)new Wyvern().parse(new StringReader(input), "test input");
    res.typecheck(Globals.getStandardEnv(), Optional.<Type>empty());
    Environment out = ((Declaration)res).evalDecl(Globals.getStandardEnv());
  }
View Full Code Here

            "val c = A.C.create()\n" +
            "c.d()\n";

    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);
  }
View Full Code Here

            "M.Tp.t()";

    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);
  }
View Full Code Here

    Assert.assertEquals(19, (int)finalRes);
  }

  @Test
  public void testSplice1() throws IOException, CopperParserException {
    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);
  }
View Full Code Here

    WyvernResolver.clearFiles();
    WyvernResolver.addFile("tokenizer", tokenizer);
    WyvernResolver.addFile("parser", parser);
    WyvernResolver.addFile("typer", typer);

    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());
  }
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.