Package org.eclipse.imp.pdb.facts

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


  public IValue listEntries(ISourceLocation sloc, IEvaluatorContext ctx) {
    sloc = ctx.getHeap().resolveSourceLocation(sloc);
   
    try {
      java.lang.String [] entries = ctx.getResolverRegistry().listEntries(sloc.getURI());
      IListWriter w = values.listWriter();
      for(java.lang.String entry : entries){
        w.append(values.string(entry));
      }
      return w.done();
    } catch(FileNotFoundException e){
      throw RuntimeExceptionFactory.pathNotFound(sloc, null, null);
    } catch (IOException e) {
      throw RuntimeExceptionFactory.io(values.string(e.getMessage()), null, null);
    }
View Full Code Here


    this.eval = eval;
    this.traversalContext = new Vector<IValue>();
  }
 
  public IList getContext() {
    IListWriter lw = eval.getValueFactory().listWriter();
    for (IValue v : this.traversalContext)
      lw.append(v);
    return lw.done().reverse();
  }
View Full Code Here

    }
  }

  // REFLECT -- copy in PreludeCompiled
  private IList consumeInputStreamLines(ISourceLocation sloc,  Reader stream, IEvaluatorContext ctx ) {
    IListWriter w = values.listWriter();
   
    BufferedReader in = null;
    try{
      in = new BufferedReader(stream);
      java.lang.String line;
     
      int i = 0;
//      int offset = sloc.getOffset();
      int beginLine = sloc.hasLineColumn() ? sloc.getBeginLine() : -1;
      int beginColumn = sloc.hasLineColumn() ? sloc.getBeginColumn() : -1;
      int endLine = sloc.hasLineColumn() ? sloc.getEndLine() : -1;
      int endColumn = sloc.hasLineColumn() ? sloc.getEndColumn() : -1;

      do{
        line = in.readLine();
        i++;
        if(line != null){
          if(!sloc.hasOffsetLength()){
            w.append(values.string(line));
          }else{
            if(!sloc.hasLineColumn()){
              endColumn = line.length();
            }
            if(i == beginLine){
              if(i == endLine){
                w.append(values.string(line.substring(beginColumn, Math.min(endColumn, line.length()))));
              }else{
                w.append(values.string(line.substring(beginColumn)));
              }
            }else if(i > beginLine){
              if(i == endLine){
                w.append(values.string(line.substring(0, Math.min(endColumn, line.length()))));
              }
              else if(i < endLine){
                w.append(values.string(line));
              }
            }
          }
        }
      }while(line != null);
    }catch(IOException e){
      throw RuntimeExceptionFactory.io(values.string(e.getMessage()), ctx.getCurrentAST(), null);
    }finally{
      if(in != null){
        try{
          in.close();
        }catch(IOException ioex){
          throw RuntimeExceptionFactory.io(values.string(ioex.getMessage()), ctx.getCurrentAST(), null);
        }
      }
    }

    return w.done();
  }
View Full Code Here

      args[0] = cons.get(0);
      IList list = (IList) cons.get(1);
      int len = list.length();

      if (len > 0) {
        IListWriter w = eval.getValueFactory().listWriter(list.getType().getElementType());
        boolean hasChanged = false;
        boolean hasMatched = false;

        for (int i = 0; i < len; i++){
          IValue elem = list.get(i);
          if (i % 2 == 0) { // Recursion to all non-layout elements
            tr.changed = false;
            tr.matched = false;
            w.append(traverseOnce(elem, casesOrRules, direction, progress, fixedpoint, tr));
            hasChanged |= tr.changed;
            hasMatched |= tr.matched;
          } else { // Just copy layout elements
            w.append(list.get(i));
          }
        }
        tr.changed = hasChanged;
        tr.matched = hasMatched;
        args[1] = w.done();
      } else {
        args[1] = list;
      }
    } else {
      // Constructor is not "appl", or at least one of the patterns is not a concrete pattern
View Full Code Here

  private IValue traverseListOnce(IValue subject, CaseBlockList casesOrRules,
      DIRECTION direction, PROGRESS progress, FIXEDPOINT fixedpoint, TraverseResult tr) {
    IList list = (IList) subject;
    int len = list.length();
    if (len > 0){
      IListWriter w = eval.getValueFactory().listWriter(list.getType().getElementType());
      boolean hasChanged = false;
      boolean hasMatched = false;
     
      for (int i = 0; i < len; i++){
        IValue elem = list.get(i);
        tr.changed = false;
        tr.matched = false;
        w.append(traverseOnce(elem, casesOrRules, direction, progress, fixedpoint, tr));
        hasChanged |= tr.changed;
        hasMatched |= tr.matched;
      }
     
      tr.changed = hasChanged;
      tr.matched = hasMatched;
      return w.done();
    } else {
      return subject;
    }
  }
View Full Code Here

    return w.done();
  }
 
  // REFLECT -- copy in PreludeCompiled
  public IList readFileBytes(ISourceLocation sloc, IEvaluatorContext ctx){
    IListWriter w = values.listWriter();
    sloc = ctx.getHeap().resolveSourceLocation(sloc);
   
    BufferedInputStream in = null;
    try{
      InputStream stream = ctx.getResolverRegistry().getInputStream(sloc.getURI());
      in = new BufferedInputStream(stream);
      int read;
      final int size = 256;
      byte bytes[] = new byte[size];
     
      do{
        read = in.read(bytes);
        for (int i = 0; i < read; i++) {
          w.append(values.integer(bytes[i] & 0xff));
        }
      }while(read != -1);
    }catch(FileNotFoundException e){
      throw RuntimeExceptionFactory.pathNotFound(sloc, ctx.getCurrentAST(), null);
    }catch(IOException e){
      throw RuntimeExceptionFactory.io(values.string(e.getMessage()), ctx.getCurrentAST(), null);
    }finally{
      if(in != null){
        try{
          in.close();
        }catch(IOException ioex){
          throw RuntimeExceptionFactory.io(values.string(ioex.getMessage()), ctx.getCurrentAST(), null);
        }
      }
    }

    return w.done();
  }
View Full Code Here

    // we randomly swap some elements to make worst case complexity unlikely
    new Sorting(tmpArr, new Less((ICallableValue) cmpv)).shuffle().sort();


    IListWriter writer = values.listWriter();
    writer.append(tmpArr);
    return writer.done();
  }
View Full Code Here

        if (!ctx.getResolverRegistry().isDirectory(resolved.getURI())) {
          throw RuntimeExceptionFactory.io(vf.string("You can only access ls on a directory, or a container."), ctx.getCurrentAST(), ctx.getStackTrace());
        }
        Result<IValue> resRes = makeResult(getType(), resolved, ctx);

        IListWriter w = ctx.getValueFactory().listWriter();
        Type stringType = tf.stringType();

        for (String elem : ctx.getResolverRegistry().listEntries(resolved.getURI())) {
          w.append(resRes.add(makeResult(stringType, vf.string(elem), ctx)).getValue());
        }

        IList result = w.done();
        // a list of loc's
        return makeResult(result.getType(), result, ctx);
       
      } catch (IOException e) {
        throw RuntimeExceptionFactory.io(vf.string(e.getMessage()), ctx.getCurrentAST(), ctx.getStackTrace());
View Full Code Here

    if (isLexical(tree)) {
      throw new ImplementationError("This is not a context-free production: " + tree);
    }

    IList children = getSymbols(tree);
    IListWriter writer = ValueFactoryFactory.getValueFactory().listWriter(Factory.Args.getElementType());

    for (int i = 0; i < children.length(); i++) {
      IConstructor kid = (IConstructor) children.get(i);
      if (!SymbolAdapter.isLiteral(kid) && !SymbolAdapter.isCILiteral(kid)) {
        writer.append(kid);
      }
      // skip layout
      i++;
    }
   
    return writer.done();
  }
View Full Code Here

    }
    throw new NotYetImplemented(cc);
  }
 
  private static IList ranges2Ranges(List<Range> ranges) {
    IListWriter result = factory.listWriter(Factory.CharRanges.getElementType());
   
    for (Range range : ranges) {
      if (range.isCharacter()) {
        IValue ch = char2int(range.getCharacter());
        result.append(factory.constructor(Factory.CharRange_Single, ch));
      }
      else if (range.isFromTo()) {
        IValue from = char2int(range.getStart());
        IValue to = char2int(range.getEnd());
        result.append(factory.constructor(Factory.CharRange_Range, from, to));
      }
    }
   
    return result.done();
  }
View Full Code Here

TOP

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

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.