Package wyvern.tools.typedAST.interfaces

Examples of wyvern.tools.typedAST.interfaces.Value


    writer.writeArgs(function, env);
  }

  @Override
  public Value evaluateApplication(Application app, Environment argEnv) {
    Value argValue = app.getArgument().evaluate(argEnv);
    Environment bodyEnv = env;
    List<NameBinding> bindings = function.getArgBindings();
    if (bindings.size() == 1)
      bodyEnv = bodyEnv.extend(new ValueBinding(bindings.get(0).getName(), argValue));
    else if (bindings.size() > 1 && argValue instanceof TupleValue)
View Full Code Here


  @Override
  public void evalDecl(Environment evalEnv, Environment declEnv) {
    if (declEnv.getValue(binding.getName()) != null)
      return;
     
    Value defValue = null;
    if (definition != null)
      defValue = definition.evaluate(evalEnv);
    ValueBinding vb = (ValueBinding) declEnv.lookup(binding.getName());
    vb.setValue(defValue);
  }
View Full Code Here

    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);
    } catch (CopperParserException e) {
      System.err.print("Parsing error: ");
View Full Code Here

  @Override
  public Type typecheck(Environment env, Optional<Type> expected) {
    Type dslType = expected.orElseGet(this::getDefaultType);

    Value vparser =
        Util.invokeValue(((MetaType) dslType).getMetaObj(),
            "getParser", UnitVal.getInstance(FileLocation.UNKNOWN));
    ExtParser parser = (ExtParser) Util.toJavaObject(vparser, ExtParser.class);

    try {
View Full Code Here

    }

    @Override
    public TypedAST transform(TypedAST input) {
      if (input instanceof ToastExpression) {
        Value result = input.evaluate(evalEnv);
        TypedAST iExn = Util.toJavaClass((Obj)result, TypedAST.class);
        if (!(iExn instanceof Obj))
          return iExn;
        TypedAST equivExn = Util.toJavaClass((Obj)iExn, TypedAST.class);
        return equivExn;
View Full Code Here

    return Util.javaToWyvType(TypedAST.class);
  }

  @Override
  public Value evaluate(Environment env) {
    Value res = exn.evaluate(env);

    return Util.toWyvObj(res);
  }
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

    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

    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

    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

TOP

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

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.