Package wyvern.tools.typedAST.core.binding.evaluation

Examples of wyvern.tools.typedAST.core.binding.evaluation.ValueBinding


  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

      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

    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

  }

  @Override
  public void evalDecl(Environment evalEnv, Environment declEnv) {
    JClosure closure = new JClosure(methods, evalEnv);
    ValueBinding vb = (ValueBinding) declEnv.lookup(getName());
    vb.setValue(closure);
  }
View Full Code Here

    return newEnv;
  }

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

  public void evalDecl(Environment evalEnv, Environment declEnv) {
    if (declEvalEnv == null)
      declEvalEnv = declEnv.extend(evalEnv);
    Obj classObj = new Obj(getClassEnv(evalEnv));
   
    ValueBinding vb = (ValueBinding) declEnv.lookup(nameBinding.getName());
    vb.setValue(classObj);
  }
View Full Code Here

  }

  @Override
  public Value evaluateInvocation(Invocation exp, Environment env) {
    String operation = exp.getOperationName();
    return getIntEnv().getValue(operation, env.extend(new ValueBinding("this", this)));
  }
View Full Code Here

      public ExtParser getParser() {
        return parseri;
      }
    };

    TypeDeclaration.attrEvalEnv = Environment.getEmptyEnvironment().extend(new ValueBinding("myNumMetadata", Util.toWyvObj(inner)));
    Assert.assertEquals(res.typecheck(Globals.getStandardEnv().extend(new NameBindingImpl("myNumMetadata", metaType)), Optional.empty()), Int.getInstance());
    res = new DSLTransformer().transform(res);
    Assert.assertEquals(res.evaluate(Globals.getStandardEnv().extend(new ValueBinding("myNumMetadata", Util.toWyvObj(inner)))).toString(), "IntegerConstant(5)");
  }
View Full Code Here

      public ExtParser getParser() {
        return parseri;
      }
    };

    TypeDeclaration.attrEvalEnv = Environment.getEmptyEnvironment().extend(new ValueBinding("myNumMetadata", Util.toWyvObj(inner))).extend(new TypeBinding("HasParser", metaType));
    Assert.assertEquals(res.typecheck(Globals.getStandardEnv().extend(new NameBindingImpl("myNumMetadata", metaType)), Optional.empty()), Int.getInstance());
    res = new DSLTransformer().transform(res);
    Assert.assertEquals(res.evaluate(Globals.getStandardEnv().extend(new ValueBinding("myNumMetadata", Util.toWyvObj(inner)))).toString(), "IntegerConstant(5)");
  }
View Full Code Here

TOP

Related Classes of wyvern.tools.typedAST.core.binding.evaluation.ValueBinding

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.