Package org.eclipse.imp.pdb.facts

Examples of org.eclipse.imp.pdb.facts.IMap


      @Override
      public Response serve(String uri, Method method, Map<String, String> headers, Map<String, String> parms,
          Map<String, String> files) {
        IConstructor methodVal = makeMethod(method);
        IMap headersVal = makeMap(headers);
        IMap paramsVal= makeMap(parms);
        IMap filesVal= makeMap(files);
        ISourceLocation loc = vf.sourceLocation(URIUtil.assumeCorrect("request", "", uri));
        try {
          synchronized (callee.getEval()) {
            callee.getEval().__setInterrupt(false);
            Result<IValue> response = callee.call(argTypes, new IValue[] { loc, methodVal, headersVal, paramsVal, filesVal }, null);
            return translateResponse(method, response.getValue())
          }
        }
        catch (Throw rascalException) {
          ctx.getStdErr().println(rascalException.getMessage());
          return new Response(Status.INTERNAL_ERROR, "text/plain", rascalException.getMessage());
        }
        catch (Throwable unexpected) {
          ctx.getStdErr().println(unexpected.getMessage());
          unexpected.printStackTrace(ctx.getStdErr());
          return new Response(Status.INTERNAL_ERROR, "text/plain", unexpected.getMessage());
        }
      }

      private Response translateResponse(Method method, IValue value) {
        IConstructor cons = (IConstructor) value;
        initMethodAndStatusValues(ctx);
       
        if (cons.getName().equals("fileResponse")) {
          return translateFileResponse(method, cons);
        }
        else {
          return translateTextResponse(method, cons);
        }
      }
     
      private Response translateFileResponse(Method method, IConstructor cons) {
        ISourceLocation l = (ISourceLocation) cons.get("file");
        IString mimeType = (IString) cons.get("mimeType");
        IMap header = (IMap) cons.get("header");
        URI uri = l.getURI();
       
        Response response;
        try {
          response = new Response(Status.OK, mimeType.getValue(), ctx.getResolverRegistry().getInputStream(uri));
          addHeaders(response, header);
          return response;
        } catch (IOException e) {
          e.printStackTrace(ctx.getStdErr());
          return new Response(Status.NOT_FOUND, "text/plain", l + " not found.\n" + e);
        }
      }

      private Response translateTextResponse(Method method, IConstructor cons) {
        IString mimeType = (IString) cons.get("mimeType");
        IMap header = (IMap) cons.get("header");
        IString data = (IString) cons.get("content");
        Status status = translateStatus((IConstructor) cons.get("status"));
       
        if (method != Method.HEAD) {
          switch (status) {
          case BAD_REQUEST:
          case UNAUTHORIZED:
          case NOT_FOUND:
          case FORBIDDEN:
          case RANGE_NOT_SATISFIABLE:
          case INTERNAL_ERROR:
            if (data.length() == 0) {
              data = vf.string(status.getDescription());
            }
          default:
            break;
          }
        }
        Response response = new Response(status, mimeType.getValue(), data.getValue());
        addHeaders(response, header);
        return response;
      }

      private void addHeaders(Response response, IMap header) {
        // TODO add first class support for cache control on the Rascal side. For
        // now we prevent any form of client-side caching with this.. hopefully.
        response.addHeader("Cache-Control", "no-cache, no-store, must-revalidate");
        response.addHeader("Pragma", "no-cache");
        response.addHeader("Expires", "0");
       
        for (IValue key : header) {
          response.addHeader(((IString) key).getValue(), ((IString) header.get(key)).getValue());
        }
      }

      private Status translateStatus(IConstructor cons) {
        initMethodAndStatusValues(ctx);
View Full Code Here


      }
      throw new ImplementationError("class for cached parser " + className + " could not be found");
    }

    ParserGenerator pg = eval.getParserGenerator();
    IMap definitions = currentModule.getSyntaxDefinition();
   
    Class<IGTD<IConstructor, IConstructor, ISourceLocation>> parser = eval.getHeap().getObjectParser(currentModule.getName(), definitions);

    if (parser == null || force) {
      String parserName = currentModule.getName(); // .replaceAll("::", ".");
View Full Code Here

    }
  }

  private IValue traverseMapOnce(IValue subject, CaseBlockList casesOrRules,
      DIRECTION direction, PROGRESS progress, FIXEDPOINT fixedpoint, TraverseResult tr) {
    IMap map = (IMap) subject;
    if(!map.isEmpty()){
      IMapWriter w = eval.getValueFactory().mapWriter(map.getType());
      Iterator<Entry<IValue,IValue>> iter = map.entryIterator();
      boolean hasChanged = false;
      boolean hasMatched = false;
     
      while (iter.hasNext()) {
        Entry<IValue,IValue> entry = iter.next();
View Full Code Here

          String[] keyValue = param.split("=");
          res.put(vf.string(keyValue[0]), vf.string(keyValue[1]));
        }
      }
     
      IMap map = res.done();
      return makeResult(map.getType(), map, ctx);
    }

    default:
      throw new UndeclaredField(name, getTypeFactory().sourceLocationType(), ctx.getCurrentAST());
    }
View Full Code Here

   
    if(testResultListener == null){
      testResultListener = (ITestResultListener) new DefaultTestResultListener(stderr);
    }
   
    IMap symbol_definitions = (IMap) program.get("symbol_definitions");
   
    RVM rvm = new RVM(new RascalExecutionContext(vf, symbol_definitions, debug.getValue(), profile.getValue(), ctx, testResultListener));
   
    ArrayList<String> initializers = new ArrayList<String>();    // initializers of imported modules
    ArrayList<String> testsuites =  new ArrayList<String>()// testsuites of imported modules
   
    Iterator<Entry<IValue, IValue>> entries = imported_types.entryIterator();
    while(entries.hasNext()) {
      Entry<IValue, IValue> entry = entries.next();
      rvm.declareConstructor(((IString) entry.getKey()).getValue(), (IConstructor) entry.getValue());
    }
   
    for(IValue imp : imported_functions){
      IConstructor declaration = (IConstructor) imp;
      if (declaration.getName().contentEquals("FUNCTION")) {
        String name = ((IString) declaration.get("qname")).getValue();
       
        if(name.endsWith("_init(list(value());)#0")){
          initializers.add(name);
        }
        if(name.endsWith("_testsuite(list(value());)#0")){
          testsuites.add(name);
        }
        loadInstructions(name, declaration, rvm, false);
      }
      if (declaration.getName().contentEquals("COROUTINE")) {
        String name = ((IString) declaration.get("qname")).getValue();
        loadInstructions(name, declaration, rvm, true);
      }
    }
   
    // Overloading resolution of imported functions
    rvm.addResolver(imported_overloading_resolvers);
    rvm.fillOverloadedStore(imported_overloaded_functions);

    IMap types = (IMap) program.get("types");
    entries = types.entryIterator();
    while(entries.hasNext()) {
      Entry<IValue, IValue> entry = entries.next();
      rvm.declareConstructor(((IString) entry.getKey()).getValue(), (IConstructor) entry.getValue());
    }
   
    IMap declarations = (IMap) program.get("declarations");
    for (IValue dname : declarations) {
      IConstructor declaration = (IConstructor) declarations.get(dname);

      if (declaration.getName().contentEquals("FUNCTION")) {
        String name = ((IString) declaration.get("qname")).getValue();
        if(name.endsWith(main) || name.endsWith(mu_main)) {
          uid_main = name;      // Get main's uid in current module
View Full Code Here

    if(scopeIn.equals("")) {
      scopeIn = null;
    }
   
    Integer nlocals = ((IInteger) declaration.get("nlocals")).intValue();
    IMap localNames = ((IMap) declaration.get("localNames"));
    Integer nformals = ((IInteger) declaration.get("nformals")).intValue();
    Integer maxstack = ((IInteger) declaration.get("maxStack")).intValue();
    IList code = (IList) declaration.get("instructions");
    ISourceLocation src = (ISourceLocation) declaration.get("src");
    CodeBlock codeblock = new CodeBlock(vf);
View Full Code Here

   */
  public IValue parse(IString moduleName, IValue start, IMap robust, URI location, char[] input, List<Frame> stacktrace) {
    Type reified = start.getType();
    IConstructor startSort = checkPreconditions(start, reified);
   
    IMap syntax = (IMap) ((IConstructor) start).get(1);
    try {
      IConstructor pt = parseObject(moduleName, startSort, robust, location, input, syntax);

      if (TreeAdapter.isAppl(pt)) {
        if (SymbolAdapter.isStart(TreeAdapter.getType(pt))) {
View Full Code Here

//        }
//        throw new ImplementationError("class for cached parser " + className + " could not be found");
//      }

      ParserGenerator pg = getParserGenerator();
      IMap definitions = syntax;
     
      Class<IGTD<IConstructor, IConstructor, ISourceLocation>> parser = getObjectParser(name, start);

      if (parser == null || force) {
        String parserName = name; // .replaceAll("::", ".");
View Full Code Here

        b[i] = c.getType();
        i++;
      }
    }
    HashMap<String, IValue> map = new HashMap<String, IValue>();
    IMap annoMap = (IMap) t.get(annoKey);
    if (annoMap != null) {
      Iterator<IValue> iterator = annoMap.iterator();
      while (iterator.hasNext()) {
        IValue k = iterator.next();
        String ky = ((IString) k).getValue();
        IValue v = annoMap.get(k);
        map.put(ky, v);
      }
    }
   
    // keyword parameters
View Full Code Here

  }
 
  public IValue typeToValue(Type t, RascalExecutionContext rex) {
   
    TypeStore store = new TypeStore();
    IMap definitions = rex.getSymbolDefinitions();
    TypeReifier tr = new TypeReifier(vf);
    tr.declareAbstractDataTypes(definitions, store);
   
    IConstructor symbol = typeToSymbol(t, store);
   
View Full Code Here

TOP

Related Classes of org.eclipse.imp.pdb.facts.IMap

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.