Package wyvern.tools.types

Examples of wyvern.tools.types.Environment


/**
* Useful type functionality
*/
public class TypeDeclUtils {
  public static Environment getTypeEquivalentEnvironment(Environment src) {
    Environment tev = Environment.getEmptyEnvironment();

    for (Binding b : src.getBindings()) {
      // 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! :-)");
     
View Full Code Here


      return resolved.extendType(in, in);
    }

    @Override
    public Environment extendNames(Environment in) {
      Environment oldMetaEnv = in.lookupBinding("metaEnv", MetadataInnerBinding.class).map(mb -> mb.getInnerEnv()).orElse(Environment.getEmptyEnvironment());
      return resolved.extendName(in, in).extend(new MetadataInnerBinding(bindVal(extendVal(resolved.extend(oldMetaEnv, oldMetaEnv)))));
    }
View Full Code Here

      return resolved.extendName(in, in).extend(new MetadataInnerBinding(bindVal(extendVal(resolved.extend(oldMetaEnv, oldMetaEnv)))));
    }

    @Override
    public Environment extend(Environment in) {
      Environment oldMetaEnv = in.lookupBinding("metaEnv", MetadataInnerBinding.class).map(mb -> mb.getInnerEnv()).orElse(Environment.getEmptyEnvironment());
      return resolved.extend(in, in).extend(new MetadataInnerBinding(bindVal(extendVal(resolved.extend(oldMetaEnv, oldMetaEnv)))));
    }
View Full Code Here

  }

  @Override
  protected Type doTypecheck(Environment env, Optional<Type> expected) {
    decl.typecheck(env, Optional.empty());
    Environment newEnv = decl.extendWithDecls(env);
    Type bodyType = body.typecheck(newEnv, Optional.empty());
    return bodyType;
  }
View Full Code Here

    return bodyType;
  }

  @Override
  public Value evaluate(Environment env) {
    Environment newEnv = decl.evalDecls(env);
    return body.evaluate(newEnv);
  }
View Full Code Here

        "  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

  public MetadataInnerBinding(Reference<Environment> rEnv) {
    innerEnv = rEnv;
  }

  public MetadataInnerBinding from(Environment env) {
    Environment oldEnv = env.lookupBinding("metaVal", MetadataInnerBinding.class)
        .map(MetadataInnerBinding::getInnerEnv).orElse(Environment.getEmptyEnvironment());
    return new MetadataInnerBinding(new Reference<>(() -> oldEnv.extend(innerEnv.get())));
  }
View Full Code Here

  }


  @Override
  public Value evaluateApplication(Application app, Environment env) {
    Environment iEnv = evalEnv.extend(env);
    Value[] values = vFromV(app.getArgument().evaluate(env));;
    Type[] wyvTypes = new Type[values.length];
    for (int ii = 0; ii < wyvTypes.length; ii++)
        wyvTypes[ii] = values[ii].getType();
    if (wyvTypes.length == 1 && wyvTypes[0] instanceof Unit)
View Full Code Here

      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


    // FIXME: Currently allow this and class in both class and object methods. :(


    Environment genv = env.extend(new ClassBinding("class", this));
    Environment oenv = genv.extend(new NameBindingImpl("this", getObjectType()));



    if (decls != null) {
      if (this.typeEquivalentEnvironmentRef.get() == null)
        typeEquivalentEnvironmentRef.set(TypeDeclUtils.getTypeEquivalentEnvironment(decls,true));
      for (Declaration decl : decls.getDeclIterator()) {
        TypeBinding binding = new TypeBinding(nameBinding.getName(), getObjectType());
        if (decl.isClassMember()) {
          decl.typecheckSelf(genv.extend(binding));
        } else {
          decl.typecheckSelf(oenv.extend(binding));
        }
      }
    }
   
    // check the implements and class implements
View Full Code Here

TOP

Related Classes of wyvern.tools.types.Environment

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.