Package wyvern.tools.types

Examples of wyvern.tools.types.Type


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


            "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

    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

  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.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

    WyvernResolver.clearFiles();
    WyvernResolver.addFile("parser", parser);
    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

      boolean suitable = true;
      Class<?>[] parameterTypes = m.getParameterTypes();
      if (wyvTypes.length != parameterTypes.length)
        continue;
      for (int i = 0; i < parameterTypes.length; i++) {
        Type wyv = wyvTypes[i];
        if (!Util.checkTypeCast(wyv, parameterTypes[i])) {
          suitable = false;
          break;
        }
      }
View Full Code Here

    writer.writeArgs(bindings, body);
  }

  @Override
  protected Type doTypecheck(Environment env, Optional<Type> expected) {
    Type argType = null;
    for (int i = 0; i < bindings.size(); i++) {
      NameBinding bdgs = bindings.get(i);
      bindings.set(i, new NameBindingImpl(bdgs.getName(), TypeResolver.resolve(bdgs.getType(), env)));
    }

    if (bindings.size() == 0)
      argType = Unit.getInstance();
    else if (bindings.size() == 1)
      argType = bindings.get(0).getType();
    else
      // TODO: implement multiple args
      throw new RuntimeException("tuple args not implemented");
   
    Environment extEnv = env;
    for (NameBinding bind : bindings) {
      extEnv = extEnv.extend(bind);
    }

    Type resultType = body.typecheck(extEnv, expected.map(exp -> ((Arrow)exp).getResult()));
    return new Arrow(argType, resultType);
  }
View Full Code Here

  protected Type doTypecheck(Environment env, Optional<Type> expected) {
    if (nextExpr == null) {
      if (!(target instanceof Assignable))
        throw new RuntimeException("Invalid target");
      ((Assignable)target).checkAssignment(this, env);
      Type tT = target.typecheck(env, Optional.empty());
      Type vT = value.typecheck(env, Optional.of(tT));
      if (!vT.subtype(tT))
        ToolError.reportError(ErrorMessage.ACTUAL_FORMAL_TYPE_MISMATCH, this);
    } else {
      nextExpr.typecheck(env, Optional.empty());
    }
    return Unit.getInstance();
View Full Code Here

      // System.out.println("Processing: " + b + " which class is " + b.getClass());
     
      if (b instanceof AssignableNameBinding) {
        //Indicates that there is a settable value
        String name = b.getName();
        Type type = b.getType();
        tev = tev.extend(
            new NameBindingImpl("set" + name.substring(0,1).toUpperCase() + name.substring(1),
            new Arrow(type, Unit.getInstance())));
        continue;
      }

      if (b instanceof TypeBinding) {
        if (b.getType() instanceof TypeType) {
          tev = tev.extend(b);
          continue;
        }
        if (b.getType() instanceof ClassType) {
          TypeType tt = ((ClassType) b.getType()).getEquivType();
          tev = tev.extend(new NameBindingImpl(b.getName(), tt));
          continue;
        }
        continue;
      }

      if (!(b instanceof NameBinding))
        continue;

      if (b.getType() instanceof Arrow) {
        tev = tev.extend(b);
        continue;
      }
     
      if (b.getType() instanceof TypeType) {
        tev = tev.extend(b);
        continue;
      }
     
      // System.out.println("Assume it is a getter even if it is wrong! :-)");
     
      String propName = b.getName();
      Type type = b.getType();

      DefDeclaration getter = new DefDeclaration(propName, type,
          new LinkedList<NameBinding>(), null, false, FileLocation.UNKNOWN);

      tev = getter.extend(tev, tev);
View Full Code Here

TOP

Related Classes of wyvern.tools.types.Type

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.