Package org.rascalmpl.interpreter.env

Examples of org.rascalmpl.interpreter.env.Environment


  public static Result<IValue> evalComprehension(IEvaluator<Result<IValue>> eval,
      java.util.List<Expression> generators, ComprehensionWriter w) {
    int size = generators.size();
    IBooleanResult[] gens = new IBooleanResult[size];
    Environment[] olds = new Environment[size];
    Environment old = eval.getCurrentEnvt();
    int i = 0;

    try {
      olds[0] = eval.getCurrentEnvt();
      eval.pushEnv();
View Full Code Here


    StringBuilder sb = new StringBuilder();
    sb.append("public ").append(tagStr).append("Type ").append(tagStr).append("() { ");
    sb.append(" return getTypedResource(").append(uriLoc.toString()).append(",#").append(tagStr).append("Type); }");
    IConstructor declTree = ctx.getEvaluator().parseCommand(ctx.getEvaluator().getMonitor(), sb.toString(), ctx.getCurrentAST().getLocation().getURI());
    Command cmd = new ASTBuilder().buildCommand(declTree);
    Environment env = ctx.getCurrentEnvt();
    ctx.setCurrentEnvt(env.getRoot());
    Result<IValue> fun0 = ctx.getEvaluator().eval(ctx.getEvaluator().getMonitor(), cmd);
    ctx.unwind(env);

    currentOutStream.println("Generated function " + fun0.toString());
    currentOutStream.flush();
View Full Code Here

      super(__param1, __param2);
    }

    @Override
    public Type typeOf(Environment __eval, boolean instantiateTypeParameters, IEvaluator<Result<IValue>> eval) {
      Environment theEnv = __eval.getHeap().getEnvironmentForName(
          getName(), __eval);
      String name = org.rascalmpl.interpreter.utils.Names.typeName(this
          .getName());

      if (theEnv != null) {
        Type type = theEnv.lookupAlias(name);

        if (type != null) {
          return type;
        }

        Type tree = theEnv.lookupAbstractDataType(name);

        if (tree != null) {
          return tree;
        }

        Type symbol = theEnv.lookupConcreteSyntaxType(name);

        if (symbol != null) {
          return symbol;
        }
      }
View Full Code Here

    if (callTracing) {
      printStartTrace();
    }

    Environment old = ctx.getCurrentEnvt();

    try {
      ctx.pushEnv(getName());

     

      Environment env = ctx.getCurrentEnvt();
      bindTypeParameters(actualTypesTuple, formals, env);
     
      IValue result = invoke(oActuals);
     
      Type resultType = getReturnType().instantiate(env.getTypeBindings());
     
      resultValue = ResultFactory.makeResult(resultType, result, eval);
      storeMemoizedResult(actuals, keyArgValues, resultValue);
      return resultValue;
    }
View Full Code Here

  protected Object[] addKeywordActuals(Object[] oldActuals, Type formals, Map<String, IValue> keyArgValues) {
    if (!getFunctionType().hasKeywordParameters()) {
      return oldActuals;
    }
   
    Environment env = new Environment(declarationEnvironment, vf.sourceLocation(URIUtil.rootScheme("initializer")), "keyword parameter initializer");
    Environment old = ctx.getCurrentEnvt();
   
    try {
      // we set up an environment to hold the positional parameter values
      ctx.setCurrentEnvt(env);
      for (int i = 0; i < formals.getArity(); i++) {
View Full Code Here

    @Override
    public Type typeOf(Environment __eval, boolean instantiateTypeParameters, IEvaluator<Result<IValue>> eval) {
      String name;
      Type type = null;
      Environment theEnv = __eval.getHeap().getEnvironmentForName(
          this.getName(), __eval);

      name = org.rascalmpl.interpreter.utils.Names.typeName(this
          .getName());

      if (theEnv != null) {
        type = theEnv.lookupAlias(name);

        if (type == null) {
          type = theEnv.lookupAbstractDataType(name);
        }
      }

      if (type != null) {
        Map<Type, Type> bindings = new HashMap<Type, Type>();
View Full Code Here

      throw new UninitializedVariable(Names.name(getName()), this);
    }

    @Override
    public IMatchingResult buildMatcher(IEvaluatorContext eval) {
      Environment env = eval.getCurrentEnvt();
      Type type = getType().typeOf(env, true, eval.getEvaluator());

      type = type.instantiate(env.getTypeBindings());
     
      return new TypedVariablePattern(eval, this, type, getName());
    }
View Full Code Here

  }


  public static boolean matchAndEval(Result<IValue> subject, Expression pat, Statement stat, IEvaluator<Result<IValue>> eval) {
    boolean debug = false;
    Environment old = eval.getCurrentEnvt();
    eval.pushEnv();
 
    try {
      IMatchingResult mp = pat.getMatcher(eval);
      mp.initMatch(subject);
View Full Code Here

        return matchEvalAndReplace(subject, rule.getPattern(), conditions, insert, eval);
      }
    }
    
    public static boolean matchEvalAndReplace(Result<IValue> subject, Expression pat, List<Expression> conditions, Expression replacementExpr, IEvaluator<Result<IValue>> eval) {
      Environment old = eval.getCurrentEnvt();
      try {
        IMatchingResult mp = pat.getMatcher(eval);
        mp.initMatch(subject);

        while (mp.hasNext()) {
          if (eval.isInterrupted())
            throw new InterruptException(eval.getStackTrace(), eval.getCurrentAST().getLocation());
          if (mp.next()) {
            int size = conditions.size();
           
            if (size == 0) {
               throw new Insert(replacementExpr.interpret(eval), mp, mp.getType(eval.getCurrentEnvt(), null));
            }
           
            IBooleanResult[] gens = new IBooleanResult[size];
            Environment[] olds = new Environment[size];
            Environment old2 = eval.getCurrentEnvt();

            int i = 0;
            try {
              olds[0] = eval.getCurrentEnvt();
              eval.pushEnv();
View Full Code Here

    throw new IllegalOperationException(
        "Facade cannot be viewed as with keyword parameters.", getType());
  }

  protected void bindKeywordArgs(Map<String, IValue> keyArgValues) {
      Environment env = ctx.getCurrentEnvt();
 
      if (functionType.hasKeywordParameters()) {
          for (String kwparam : functionType.getKeywordParameterTypes().getFieldNames()){
              Type kwType = functionType.getKeywordParameterType(kwparam);
 
              if (keyArgValues.containsKey(kwparam)){
                  IValue r = keyArgValues.get(kwparam);
 
                  if(!r.getType().isSubtypeOf(kwType)) {
                      throw new UnexpectedKeywordArgumentType(kwparam, kwType, r.getType(), ctx.getCurrentAST());
                  }
 
                  env.declareVariable(kwType, kwparam);
                  env.storeVariable(kwparam, ResultFactory.makeResult(kwType, r, ctx));
              }
              else {
                  env.declareVariable(kwType, kwparam);
                  Expression def = getKeywordParameterDefaults().get(kwparam);
                  Result<IValue> kwResult = def.interpret(eval);
                  env.storeVariable(kwparam, kwResult);
              }
          }
      }
      // TODO: what if the caller provides more arguments then are declared? They are
      // silently lost here.
View Full Code Here

TOP

Related Classes of org.rascalmpl.interpreter.env.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.