Package org.rascalmpl.interpreter.env

Examples of org.rascalmpl.interpreter.env.Environment


   
    if (alts.size() == 0) {
      return null;
    }
   
    Environment env = (Environment) environment;
   
    Result<IValue> var = env.getVariable("amb");
   
    if (var != null && var instanceof ICallableValue) {
      Type type = RascalTypeFactory.getInstance().nonTerminalType(ambCluster);
      ICallableValue func = (ICallableValue) var;
      try {
View Full Code Here


  public IConstructor filterProduction(IConstructor tree,
      Object environment) {
    String cons = TreeAdapter.getConstructorName(tree);
   
    if (cons != null) {
      Environment env = (Environment) environment;
      Result<IValue> var = env.getVariable(cons);
     
      if (var != null && var instanceof ICallableValue) {
        ICallableValue function = (ICallableValue) var;
       
       
View Full Code Here

  public Result<IValue> doEval (IValue expected, IList commands, IInteger duration, IEvaluatorContext ctx, boolean forRascal) {
    IEvaluator<Result<IValue>> evaluator = ctx.getEvaluator();
    EvalTimer timer = new EvalTimer(evaluator, duration.intValue());

    Result<IValue> result = null;
    Environment old = evaluator.getCurrentEnvt();
    ModuleEnvironment env = getUniqueModuleEnvironment(evaluator);
   
    try {
      timer.start();
     
View Full Code Here

  public boolean quickcheck(AbstractFunction function, int maxDepth,
      int tries, boolean verbose, PrintWriter out) {

    String fname = function.getName();
 
    Environment declEnv = function.getEnv();
    IValueFactory vf = function.getEval().getValueFactory();
    Type formals = function.getFormals();
    String expected = null;
   
    if(function.hasTag(EXPECT_TAG)){
      expected = ((IString) function.getTag(EXPECT_TAG)).getValue();
    }
   

    Type[] types = new Type[formals.getArity()];
    IValue[] values = new IValue[formals.getArity()];

    for (int n = 0; n < formals.getArity(); n++) {
      types[n] = formals.getFieldType(n);
    }

    if (formals.getArity() == 0) {
      tries = 1;
    }

    TypeParameterVisitor tpvisit = new TypeParameterVisitor();
   
    for (int i = 0; i < tries; i++) {
      values = new IValue[formals.getArity()];

      HashMap<Type, Type> tpbindings = tpvisit.bindTypeParameters(formals);
      for (int n = 0; n < formals.getArity(); n++) {
        values[n] = arbitrary(types[n], maxDepth, declEnv.getRoot(), vf, tpbindings);
      }
      boolean expectedThrown = false;
      try {
        Type[] actualTypes = new Type[formals.getArity()];
        for(int j = 0; j < types.length; j ++) {
View Full Code Here

    }
  }

  private void initMethodAndStatusValues(final IEvaluatorContext ctx) {
    if (methodValues.isEmpty() || statusValues.isEmpty()) {
      Environment env = ctx.getHeap().getModule("util::Webserver");
      Type methodType = env.getAbstractDataType("Method");
      TypeFactory tf = TypeFactory.getInstance();
      methodValues.put(Method.DELETE, vf.constructor(env.getConstructor(methodType, "delete", tf.voidType())));
      methodValues.put(Method.GET, vf.constructor(env.getConstructor(methodType, "get", tf.voidType())));
      methodValues.put(Method.HEAD, vf.constructor(env.getConstructor(methodType, "head", tf.voidType())));
      methodValues.put(Method.POST, vf.constructor(env.getConstructor(methodType, "post", tf.voidType())));
      methodValues.put(Method.PUT, vf.constructor(env.getConstructor(methodType, "put", tf.voidType())));
     
      Type statusType = env.getAbstractDataType("Status");
                       
      statusValues.put(vf.constructor(env.getConstructor(statusType, "ok", tf.voidType())), Status.OK);
      statusValues.put(vf.constructor(env.getConstructor(statusType, "created", tf.voidType())), Status.CREATED);
      statusValues.put(vf.constructor(env.getConstructor(statusType, "accepted", tf.voidType())), Status.ACCEPTED);
      statusValues.put(vf.constructor(env.getConstructor(statusType, "noContent", tf.voidType())), Status.NO_CONTENT);
      statusValues.put(vf.constructor(env.getConstructor(statusType, "partialContent", tf.voidType())), Status.PARTIAL_CONTENT);
      statusValues.put(vf.constructor(env.getConstructor(statusType, "redirect", tf.voidType())), Status.REDIRECT);
      statusValues.put(vf.constructor(env.getConstructor(statusType, "notModified", tf.voidType())), Status.NOT_MODIFIED);
      statusValues.put(vf.constructor(env.getConstructor(statusType, "badRequest", tf.voidType())), Status.BAD_REQUEST);
      statusValues.put(vf.constructor(env.getConstructor(statusType, "unauthorized", tf.voidType())), Status.UNAUTHORIZED);
      statusValues.put(vf.constructor(env.getConstructor(statusType, "forbidden", tf.voidType())), Status.FORBIDDEN);
      statusValues.put(vf.constructor(env.getConstructor(statusType, "notFound", tf.voidType())), Status.NOT_FOUND);
      statusValues.put(vf.constructor(env.getConstructor(statusType, "rangeNotSatisfiable", tf.voidType())), Status.RANGE_NOT_SATISFIABLE);
      statusValues.put(vf.constructor(env.getConstructor(statusType, "internalError", tf.voidType())), Status.INTERNAL_ERROR);
      // yes, we acknowledge our sins
      argTypes[1] = methodType;
    }
  }
View Full Code Here

      }
      env.setBootstrap(needBootstrapParser(data));

      // make sure all the imported and extended modules are loaded
      // since they may provide additional syntax definitions\
      Environment old = eval.getCurrentEnvt();
      try {
        eval.setCurrentEnvt(env);
        env.setInitialized(true);

        eval.event("defining syntax");
View Full Code Here

   * @return true iff variableName is defined in moduleName and the list
   *         variableType contains its type
   */
  public boolean isVariableInModule(String moduleName, String variableName,
      String... variableType) {
    Environment old = evaluator.getCurrentEnvt();
    try {
      evaluator.doImport(null, moduleName);
      ModuleEnvironment env = evaluator.getCurrentEnvt().getImport(
          moduleName);
      Result<IValue> simpleVariable = env.getSimpleVariable(variableName);
View Full Code Here

   * @return true iff procedureName is defined in moduleName and has type
   *         procedureResultType
   */
  public boolean isProcedureInModule(String moduleName, String procedureName,
      String procedureResultType, int arity) {
    Environment old = evaluator.getCurrentEnvt();
    try {
      evaluator.doImport(null, moduleName);
      ModuleEnvironment env = evaluator.getCurrentEnvt().getImport(
          moduleName);
      ArrayList<AbstractFunction> funcs = new ArrayList<AbstractFunction>();
View Full Code Here

    staticSetSubjectType = subject.getType();
    setSubjectElementType = setSubject.getElementType();
    staticSubjectElementType = staticSetSubjectType.isSet() ? staticSetSubjectType.getElementType() : tf.valueType();
   
    if(debug)System.err.println("setSubjectType = " + setSubjectType + ", staticSetSubjectType = " + staticSetSubjectType + ", setSubjectElementType = " + setSubjectElementType + ", staticSubjectElementType =" + staticSubjectElementType);
    Environment env = ctx.getCurrentEnvt();
    //fixedSetElements = ctx.getValueFactory().set(getType(env).getElementType());
    fixedSetElements = ctx.getValueFactory().set(setSubjectElementType);
   
    nVar = 0;
    patVars = new HashSet<String>();
    allVars = new HashMap<String, IVarPattern>();
    varName = new String[patternSize];        // Some overestimations
    isSetVar = new boolean[patternSize];
    isBinding = new boolean[patternSize];
    isNested = new boolean[patternSize];
    varVal = new IValue[patternSize];
    varPat = new IMatchingResult[patternSize];
    varGen = new Iterator<?>[patternSize];
    /*
     * Pass #1: determine the (ordinary and set) variables in the pattern
     */
    for(int i = 0; i < patternSize; i++){
      IMatchingResult child = patternChildren.get(i);
      if(debug)System.err.println("child = " + child);
     
      if (child instanceof TypedMultiVariablePattern) {
        TypedMultiVariablePattern tmvVar = (TypedMultiVariablePattern) child;
        Type childType = child.getType(env, null);
        String name = tmvVar.getName();
       
        if (!tmvVar.isAnonymous() && allVars.containsKey(name)) {
          throw new RedeclaredVariable(name, getAST());
        }
       
        if(childType.comparable(staticSubjectElementType)
            || (tmvVar.bindingInstance() && childType.comparable(staticSetSubjectType))) {
          tmvVar.covertToSetType();
          if (!tmvVar.isAnonymous()) {
            patVars.add(name);
            allVars.put(name,  (IVarPattern)child);
          }
          varName[nVar] = name;
          varPat[nVar] = child;
          isSetVar[nVar] = true;
          isBinding[nVar] = true;
          isNested[nVar] = false;
          ++nVar;
        } else {
          hasNext = false;
          return;
        }
      } else if(child instanceof TypedVariablePattern){
        TypedVariablePattern patVar = (TypedVariablePattern) child;
        Type childType = child.getType(env, null);
        String name = ((TypedVariablePattern)child).getName();
        if(!patVar.isAnonymous() && allVars.containsKey(name)){
          throw new RedeclaredVariable(name, getAST());
        }
        if(childType.comparable(staticSubjectElementType)){
          /*
           * An explicitly declared set or element variable.
           */
          if(!patVar.isAnonymous()){
            patVars.add(name);
            allVars.put(name, (IVarPattern)child);
          }
          varName[nVar] = name;
          varPat[nVar] = child;
          isSetVar[nVar] = false;
          isBinding[nVar] = true;
          isNested[nVar] = false;
          nVar++;
        } else {
          hasNext = false;
          return;
          // We would like to throw new UnexpectedType(setSubject.getType(), childType, getAST());
          // but we can't do this in the context of a visit, because we might actually visit another set!
        }
       
      } else if(child instanceof MultiVariablePattern){
        /*
         * Explicitly declared set variable
         */
        MultiVariablePattern multiVar = (MultiVariablePattern) child;
        String name = multiVar.getName();

        varName[nVar] = name;
        varPat[nVar] = child;
        isSetVar[nVar] = true;
        isBinding[nVar] = true;
        isNested[nVar] = false;
        nVar++;
      } else if(child instanceof QualifiedNamePattern){
        /*
         * Use of a variable
         */
        QualifiedNamePattern qualName = (QualifiedNamePattern) child;
        String name = qualName.getName();
        if (!qualName.isAnonymous() && allVars.containsKey(name)) {
          /*
           * A set/element variable that was declared earlier in the pattern itself,
           * or in a preceding nested pattern element.
           */
          if(!patVars.contains(name)){
            /*
             * It occurred in an earlier nested subpattern.
             */
            varName[nVar] = name;
            varPat[nVar] = child;
            // If is was declared as set in the current pattern then we are sure it is a set variable,
            // otherwise we assume for now that it is not but we check this again later in matchVar.
            isSetVar[nVar] = declaredAsSetVar(name);
            isBinding[nVar] = false;
            isNested[nVar] = false;
            nVar++;
          } else {
            /*
             * Ignore it (we are dealing with sets, remember).
             */
          }
        } else if(qualName.isAnonymous()){
          varName[nVar] = name;
          varPat[nVar] = child;
          isSetVar[nVar] = false;
          isBinding[nVar] = false;
          isNested[nVar] = false;
          nVar++;
        } else  {
          /*
           * A non-anonymous variable, not seen before.
           */
          if(debug)System.err.println("Non-anonymous var, not seen before: " + name);
         
          Result<IValue> varRes = env.getVariable(name);
         
          if(varRes == null || qualName.bindingInstance()){
            // Completely new variable that was not yet declared in this pattern or its subpatterns
            varName[nVar] = name;
            varPat[nVar] = child;
View Full Code Here

   * @return      whether creation succeeded
   */
  private boolean makeGen(int i, ISet elements) {
    if(debug) System.err.println("makeGen: " + i +", " + elements);
   
    Environment env = ctx.getCurrentEnvt();
   
    if(varPat[i] instanceof QualifiedNamePattern){
      QualifiedNamePattern qualName = (QualifiedNamePattern) varPat[i];
      String name = qualName.getName();
      // Binding occurrence of this variable?
      if(isBinding[i] || qualName.isAnonymous() || env.getVariable(name) == null || env.getVariable(name).getValue() == null){
        if(isSetVar(i)){
          varGen[i] = new SubSetGenerator(elements, ctx);
        } else {
          if(elements.size() == 0)
            return false;
          varGen[i] = new SingleElementIterator(elements, ctx);
        }
      } else {
        // Variable has been set before, use its dynamic type to distinguish set variables.
        IValue val = env.getVariable(name).getValue();
       
        if (val != null) {
          if (val != null && val.getType().isSet()){
            isSetVar[i] = true;
            if(elements.equals(val)){
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.