Package org.rascalmpl.interpreter.env

Examples of org.rascalmpl.interpreter.env.Environment


    return firstTime;
  }
 
  @Override
  public boolean next() {
    Environment old = ctx.getCurrentEnvt();
    ctx.pushEnv();
    try {
      firstTime = false;
      return !arg.next();
    }
View Full Code Here


    Result<IValue> result = getMemoizedResult(actuals, keyArgValues);
    if (result !=  null) {
      return result;
    }
 
    Environment old = ctx.getCurrentEnvt();
    AbstractAST currentAST = ctx.getCurrentAST();
    AbstractAST oldAST = currentAST;
    Stack<Accumulator> oldAccus = ctx.getAccumulators();

    try {
      String label = isAnonymous() ? "Anonymous Function" : name;
      Environment environment = new Environment(declarationEnvironment, ctx.getCurrentEnvt(), currentAST != null ? currentAST.getLocation() : null, ast.getLocation(), label);
      ctx.setCurrentEnvt(environment);
     
      IMatchingResult[] matchers = prepareFormals(ctx);
      ctx.setAccumulators(accumulators);
      ctx.pushEnv();
View Full Code Here

    for(int i = 0; i < patternSize; i += delta){
      IMatchingResult child = patternChildren.get(i);
      isListVar[i] = false;
      plusList[i] = false;
      isBindingVar[i] = false;
      Environment env = ctx.getCurrentEnvt();

      if (child instanceof TypedMultiVariablePattern) {
        TypedMultiVariablePattern tmvVar = (TypedMultiVariablePattern) child;
        Type tmvType = tmvVar.getType(env, null);
        String name = tmvVar.getName();

        varName[i] = name;
        isListVar[i] = true;
        listVarOccurrences[i] = 1;
        ++nListVar;

        if(!tmvVar.isAnonymous() && allVars.contains(name)) {
          throw new RedeclaredVariable(name, getAST());
        } else if(tmvType.comparable(listSubject.getType().getElementType())
            || (tmvVar.bindingInstance() && tmvType.comparable(listSubject.getType()))) {
          tmvVar.convertToListType();
          if (!tmvVar.isAnonymous()) {
            allVars.add(name);
          }
          isBindingVar[i] = true;
        } else {
          hasNext = false;
          return;
        }
      }
      else if(child instanceof MultiVariablePattern){
        MultiVariablePattern multiVar = (MultiVariablePattern) child;
        String name = multiVar.getName();
        varName[i] = name;
        isListVar[i] = true;
        nListVar++;

        if(!multiVar.isAnonymous() && allVars.contains(name)){
          isBindingVar[i] = false;
        } else if(multiVar.isAnonymous()){
          isBindingVar[i] = true;
        } else {
          allVars.add(name);
          Result<IValue> varRes = env.getVariable(name);

          if (varRes == null || multiVar.bindingInstance()) {
            isBindingVar[i] = true;
          } else {
            isBindingVar[i] = false;
            Type varType = varRes.getType();
            if (isAnyListType(varType)){ 
              if (!varType.comparable(listSubjectType)) {    
                hasNext = false;
                return;
              }
            } else {
              if(!(varType instanceof NonTerminalType) && !(varType.comparable(staticListSubjectElementType))) {
                hasNext = false;
                return;
              }
            }
          }
        }
      }
      else if (child instanceof ConcreteListVariablePattern) {
        ConcreteListVariablePattern listVar = (ConcreteListVariablePattern) child;
        String name = listVar.getName();
        varName[i] = name;
        isListVar[i] = true;
        if (!listVar.isAnonymous()) {
          allVars.add(name);
        }
        plusList[i] = listVar.isPlusList();
        isBindingVar[i] = true;
        listVarOccurrences[i] = 1;
        nListVar++;
      }
      else if(child instanceof QualifiedNamePattern){
        QualifiedNamePattern qualName = (QualifiedNamePattern) child;
        String name = qualName.getName();
        varName[i] = name;
        if(!qualName.isAnonymous() && allVars.contains(name)){
          /*
           * A variable that was declared earlier in the pattern
           */
          isListVar[i] = true;
          nListVar++;
          listVarOccurrences[i]++;
        } else if(qualName.isAnonymous()){
          /*
           * Nothing to do
           */
        } else {
          Result<IValue> varRes = env.getVariable(name);

          if(varRes == null || qualName.bindingInstance()){
            // A completely new non-list variable, nothing to do
          } else {
            Type varType = varRes.getType();
View Full Code Here

          .getConditions();

      int size = generators.size();
      IBooleanResult[] gens = new IBooleanResult[size];
      Environment[] olds = new Environment[size];
      Environment old = __eval.getCurrentEnvt();

      String label = null;
      if (!this.getLabel().isEmpty()) {
        label = org.rascalmpl.interpreter.utils.Names.name(this
            .getLabel().getName());
View Full Code Here

      if (env == null) {
        env = new ModuleEnvironment(name, heap);
        heap.addModule(env);
      }

      Environment oldEnv = eval.getCurrentEnvt();
      eval.setCurrentEnvt(env); // such that declarations end up in
      // the module scope
      try {
        // the header is already evaluated at parse time,
        // including imports and extends and syntax definitions
View Full Code Here

    return !stop && pat.hasNext();
  }
 
  @Override
  public boolean next() {
    Environment old = ctx.getCurrentEnvt();

    while (pat.hasNext()) {
      try {
        ctx.pushEnv();
        if (pat.next()) {
View Full Code Here

    super(ctx, x);
   
    this.name = name;
    if(debug)System.err.println("QualifiedNamePattern: " + name);
    this.anonymous = getName().equals("_");
    Environment env = ctx.getCurrentEnvt();
   
    // Look for this variable while we are constructing this pattern
    if(anonymous) {
      declaredType = TypeFactory.getInstance().valueType();
    } else {
      Result<IValue> varRes = env.getSimpleVariable(name);
      if (varRes == null || varRes.getType() == null) {
        declaredType = TypeFactory.getInstance().valueType();
      } else {
        declaredType = varRes.getType();
      }
View Full Code Here

    @Override
    public IMatchingResult buildMatcher(IEvaluatorContext eval) {
      org.rascalmpl.ast.Expression arg = this.getArgument();
      if (arg.hasType() && arg.hasName()) {
        Environment env = eval.getCurrentEnvt();
        Type type = arg.getType().typeOf(env, true, eval.getEvaluator());
        type = type.instantiate(env.getTypeBindings());
       
        // TODO: Question, should we allow non terminal types in splices?
        if (type instanceof NonTerminalType) {
          throw new UnsupportedOperation("splicing match", type, this);
//          throw new ImplementationError(null);
View Full Code Here

      org.rascalmpl.ast.Expression result = getResult();
      java.util.List<org.rascalmpl.ast.Expression> generators = getGenerators();
      int size = generators.size();
      IBooleanResult[] gens = new IBooleanResult[size];
      Environment[] olds = new Environment[size];
      Environment old = __eval.getCurrentEnvt();
      int i = 0;

      Result<IValue> it = init.interpret(__eval);

      try {
View Full Code Here

    }

    @Override
    public Result<IValue> interpret(IEvaluator<Result<IValue>> __eval) {

      Environment old = __eval.getCurrentEnvt();

      try {
        __eval.pushEnv();
        __eval.setCurrentAST(this.getExpression());
        return this.getExpression().interpret(__eval);
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.