Package wyvern.tools.types

Examples of wyvern.tools.types.Environment


    }
    return newEnv;
  }
 
  public final Environment bindDecls(Environment bodyEnv, Environment declEnv) {
    Environment newEnv = declEnv;
    for (Declaration d : this.getDeclIterator()) {
      d.evalDecl(bodyEnv, declEnv);
    }
    return newEnv;
  }
View Full Code Here


    return newEnv;
  }

  @Override
  public Environment extendType(Environment env, Environment against) {
    Environment nenv = env;
    for (Declaration d : this.getDeclIterator()) {
      nenv = d.extendType(nenv, against);
    }
    return nenv;
  }
View Full Code Here

    return nenv;
  }

  @Override
  public Environment extendName(Environment env, Environment against) {
    Environment nenv = env;
    for (Declaration d : this.getDeclIterator()) {
      nenv = d.extendName(nenv, against);
    }
    return nenv;
  }
View Full Code Here

    }
    return nenv;
  }

  public final Environment extend(Environment old, Environment against) {
    Environment wtypes = extendType(old, against);
    Environment newEnv = extendName(wtypes, against);
    for (EnvironmentExtender d : this.getEnvExts())
      newEnv = d.extend(newEnv, against);
    return newEnv;
  }
View Full Code Here

        return Util.javaToWyvType(src.getType());
    }

    @Override
    protected Environment doExtend(Environment old, Environment against) {
        Environment newEnv = old;
        return newEnv;
    }
View Full Code Here

    }
  }

    @Override
    public Environment extendWithValue(Environment old) {
        Environment newEnv = old.extend(new JavaFieldValueBinding(nameBinding.getName(), nameBinding.getType()));
        return newEnv;
    }
View Full Code Here

  }

  public static Environment getTypeEquivalentEnvironment(DeclSequence decls, boolean useClassMembers) {
    LinkedList<Declaration> seq = new LinkedList<>();

    Environment newEnv = Environment.getEmptyEnvironment();
    // Generate an appropriate type member for every class member.
    for (Declaration d : decls.getDeclIterator()) {
      if (d instanceof DefDeclaration) {
        if (((DefDeclaration) d).isClassMember() != useClassMembers)
          continue;
        newEnv = d.extend(newEnv, newEnv);
      } else if (d instanceof VarDeclaration) {
        if (((VarDeclaration) d).isClassMember() != useClassMembers)
          continue;

        VarDeclaration vd = (VarDeclaration) d;
        String propName = vd.getName();
        Type type = vd.getType();
        FileLocation line = vd.getLocation();


        newEnv = newEnv.extend(new NameBindingImpl(propName, type));
        newEnv = newEnv.extend(
            new NameBindingImpl(
                "set" + propName.substring(0,1).toUpperCase() + propName.substring(1),
                new Arrow(type, Unit.getInstance())));
      } else if (d instanceof ValDeclaration) {
        if (((ValDeclaration) d).isClassMember() != useClassMembers)
          continue;

        ValDeclaration vd = (ValDeclaration) d;
        String propName = vd.getName();
        Type type = vd.getType();
        FileLocation line = vd.getLocation();

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

        newEnv = getter.extend(newEnv, newEnv);
      } else if (d instanceof TypeDeclaration) {
        newEnv = d.extend(newEnv, newEnv);
      } else if (d instanceof ClassDeclaration) {
        ClassDeclaration cd = (ClassDeclaration) d;
        TypeType tt = ((ClassType) cd.getType()).getEquivType();
        newEnv = newEnv.extend(new NameBindingImpl(cd.getName(), tt));
      } else {
        System.out.println("Unsupported class member in class to type converter: " + d.getClass());
      }
    }
    return newEnv;
View Full Code Here

        .forEach(term -> {
          term.setCode("()");
          term.setReturnType("Unit");
        });

    Environment ntEnv = res.getGrammars().stream().map(res::getGrammar)
        .flatMap(grm -> grm.getElementsOfType(CopperElementType.NON_TERMINAL).stream().map(grm::getGrammarElement))
        .map(this::parseType).map(pair->(Pair<String, Type>)pair)
        .collect(() -> new Reference<Environment>(Environment.getEmptyEnvironment()),
            (env, elem) -> env.set(env.get().extend(new NameBindingImpl(elem.first(), elem.second()))),
            (a, b) -> a.set(a.get().extend(b.get()))).get();
   
    final Environment savedNtEnv = ntEnv;
    ntEnv = res.getGrammars().stream().map(res::getGrammar)
        .flatMap(grm -> grm.getElementsOfType(CopperElementType.TERMINAL).stream().map(grm::getGrammarElement))
        .map(this::parseType).map(pair -> (Pair<String, Type>) pair)
        .collect(() -> new Reference<Environment>(savedNtEnv),
            (env, elem) -> env.set(env.get().extend(new NameBindingImpl(elem.first(), elem.second()))),
            (a, b) -> a.set(a.get().extend(b.get()))).get();


    HashMap<String, Pair<Type,SpliceBindExn>> toGen = new HashMap<>();
    HashMap<String, TypedAST> toGenDefs = new HashMap<>();
    Reference<Integer> methNum = new Reference<>(0);

    String wyvClassName = res.getClassName();
    String javaClassName = wyvClassName + "$java";

    final Environment savedNtEnv2 = ntEnv;
    res.getGrammars().stream().map(res::getGrammar)
        .flatMap(grm->grm.getElementsOfType(CopperElementType.PRODUCTION).stream().map(grm::getGrammarElement).<Production>map(el->(Production)el))
        .<Pair<Production, List<NameBinding>>>map(prod->new Pair<Production, List<NameBinding>>(prod, CopperTSL.<Type,String,Optional<NameBinding>>
            zip(prod.getRhs().stream().map(cer->savedNtEnv2.lookup(cer.getName().toString()).getType()), prod.getRhsVarNames().stream(),
            (type, name) -> (name == null)?Optional.empty():Optional.of(new NameBindingImpl(name, type)))
            .<NameBinding>flatMap(o -> o.isPresent() ? Stream.of(o.get()) : Stream.empty())
            .collect(Collectors.<NameBinding>toList()))
        ).forEach(updateCode(toGen,ntEnv,methNum, res.getClassName()));
View Full Code Here

  public Environment extendName(Environment env, Environment against) {
    return body.extendName(env, against);
  }

  private void evalMeta(Environment evalEnv) {
    Environment extMetaEnv = evalEnv
        .lookupBinding("metaEnv", MetadataInnerBinding.class)
        .map(MetadataInnerBinding::getInnerEnv).orElse(Environment.getEmptyEnvironment());

    Environment metaEnv = Globals.getStandardEnv().extend(TypeDeclaration.attrEvalEnv).extend(extMetaEnv);
    metadata.get().map(obj->obj.typecheck(metaEnv, Optional.<Type>empty()));

    metadataObj.set(metadata.get().map(obj -> obj.evaluate(metaEnv)).orElse(new Obj(Environment.getEmptyEnvironment())));
  }
View Full Code Here

    return lastType;
  }

  @Override
  public Value evaluate(Environment env) {
    Environment iEnv = env;
    Value lastVal = UnitVal.getInstance(this.getLocation());
    for (TypedAST exp : this) {
      if (exp instanceof EnvironmentExtender) {
        iEnv = ((EnvironmentExtender)exp).evalDecl(iEnv);
      } else {
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.