Package wyvern.tools.types

Examples of wyvern.tools.types.Environment


  }

  @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)
      for (int i = 0; i < bindings.size(); i++)
        bodyEnv = bodyEnv.extend(new ValueBinding(bindings.get(i).getName(), ((TupleValue)argValue).getValue(i)));
    else if (bindings.size() != 0)
      throw new RuntimeException("Something bad happened!");
   
    return function.getBody().evaluate(bodyEnv);
  }
View Full Code Here


    return extendName(old, against);
  }

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

import wyvern.tools.types.extensions.Str;
import wyvern.tools.types.extensions.Unit;

public class Globals {
  public static Environment getStandardEnv() {
    Environment env = Environment.getEmptyEnvironment();
    env = env.extend(new ImportResolverBinding("java",JavaResolver.getInstance()));
    env = env.extend(new ImportResolverBinding("wyv", WyvernResolver.getInstance()));

    env = env.extend(new TypeBinding("Unit", Unit.getInstance()));
    env = env.extend(new TypeBinding("Int", Int.getInstance()));
    env = env.extend(new TypeBinding("Bool", Bool.getInstance()));
    env = env.extend(new TypeBinding("Str", Str.getInstance()));
   
    env = env.extend(new ValueBinding("null", UnitVal.getInstance(FileLocation.UNKNOWN))); // How to represent  shock/horror  null!?
    env = env.extend(new ValueBinding("true", new BooleanConstant(true)));
    env = env.extend(new ValueBinding("false", new BooleanConstant(false)));
   
    env = env.extend(new ValueBinding("print", new ExternalFunction(arrow(str, unit), (env1, argument) -> {
      System.out.println(((StringConstant)argument).getValue());
      return UnitVal.getInstance(FileLocation.UNKNOWN); // Fake line number! FIXME:
    })));
    env = env.extend(new ValueBinding("printInteger", new ExternalFunction(arrow(integer, unit), (env1, argument) -> {
      System.out.println(((IntegerConstant)argument).getValue());
      return UnitVal.getInstance(FileLocation.UNKNOWN); // Fake line number! FIXME:
    })));
    return env;
  }
View Full Code Here

    return exn;
  }

  @Override
  public Type typecheck(Environment env, Optional<Type> expected) {
    Environment outerEnv = env.lookupBinding("oev", TSLBlock.OuterEnviromentBinding.class)
      .map(oeb->oeb.getStore())
      .orElse(Environment.getEmptyEnvironment());

    List<NameBinding> newBindings = new ArrayList<>();
    for (NameBinding binding : bindings)
      newBindings.add(new NameBindingImpl(binding.getName(), TypeResolver.resolve(binding.getType(), env)));
    bindings = newBindings;


    Optional<Type> resType = expected.map(type -> ((Arrow) type).getResult());

    outerEnv = outerEnv.extend(bindings.stream().reduce(Environment.getEmptyEnvironment(), Environment::extend, (a,b)->b.extend(a)));
    Type exnType = exn.typecheck(outerEnv, resType);
    cached = Optional.of(exnType);
    return getType();
  }
View Full Code Here

    return getType();
  }

  @Override
  public Value evaluate(Environment env) {
    Environment outerEnv = env.lookupBinding("oev", TSLBlock.OuterEnviromentBinding.class)
        .map(oeb->oeb.getStore())
        .orElse(Environment.getEmptyEnvironment());

    return new Closure(this, outerEnv);
  }
View Full Code Here

    return cached.get();
  }

  @Override
  public Type typecheck(Environment env, Optional<Type> expected) {
    Environment outerEnv = env.lookupBinding("oev", TSLBlock.OuterEnviromentBinding.class)
      .map(oeb->oeb.getStore())
      .orElse(Environment.getEmptyEnvironment());
    Type exnType = exn.typecheck(outerEnv, expected);
    cached = Optional.of(exnType);
    return exnType;
View Full Code Here

    return exnType;
  }

  @Override
  public Value evaluate(Environment env) {
    Environment outerEnv = env.lookupBinding("oev", TSLBlock.OuterEnviromentBinding.class)
        .map(oeb->oeb.getStore())
        .orElse(Environment.getEmptyEnvironment());
    return exn.evaluate(outerEnv);
  }
View Full Code Here

  public final Type typecheckSelf(Environment env) {
    return doTypecheck(env);
  }
 
  public final void typecheckAll(Environment env) {
    Environment newEnv = env;
    for (Declaration d = this; d != null; d = d.nextDecl) {
      d.typecheck(newEnv, Optional.empty());
      newEnv = d.doExtend(newEnv, newEnv);
    }
  }
View Full Code Here

    }
  }
 
  @Override
  public final Type typecheck(Environment env, Optional<Type> expected) {
    Environment tEnv = this.extendType(env, env);
    Environment nEnv = extendName(tEnv, tEnv);
    Environment newEnv = extend(nEnv, nEnv);
    return typecheckSelf(newEnv);
  }
View Full Code Here

  public abstract String getName();
  protected abstract Type doTypecheck(Environment env);

  public final Environment extend(Environment old, Environment against) {
    Environment newEnv = doExtend(old, against);
    if (nextDecl != null)
      newEnv = nextDecl.extend(newEnv, newEnv);
    return newEnv;
  }
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.