Esempio n. 1
0
  private boolean step() {
    if (next != NONE) return true;

    while (next == NONE) {
      if (buffer.isEmpty()) {
        if (completed) {
          return false;
        } else if (sourceIter.hasNext()) {
          Object iter = null;
          if (multi) iter = xf.applyTo(RT.cons(null, sourceIter.next()));
          else iter = xf.invoke(null, sourceIter.next());

          if (RT.isReduced(iter)) {
            xf.invoke(null);
            completed = true;
          }
        } else {
          xf.invoke(null);
          completed = true;
        }
      } else {
        next = buffer.remove();
      }
    }
    return true;
  }
Esempio n. 2
0
 public void notifyWatches(Object oldval, Object newval) {
   IPersistentMap ws = watches;
   if (ws.count() > 0) {
     for (ISeq s = ws.seq(); s != null; s = s.next()) {
       Map.Entry e = (Map.Entry) s.first();
       IFn fn = (IFn) e.getValue();
       if (fn != null) fn.invoke(e.getKey(), this, oldval, newval);
     }
   }
 }
Esempio n. 3
0
 final synchronized Object sval() {
   if (fn != null) {
     sv = fn.invoke();
     fn = null;
   }
   if (sv != null) return sv;
   return s;
 }
Esempio n. 4
0
 @Override
 protected void service(HttpServletRequest req, HttpServletResponse resp)
     throws ServletException, IOException {
   try {
     serviceMethod.invoke(this, req, resp);
   } catch (Exception e) {
     throw new ServletException(e);
   }
 }
Esempio n. 5
0
 protected void validate(IFn vf, Object val) {
   try {
     if (vf != null && !RT.booleanCast(vf.invoke(val)))
       throw new IllegalStateException("Invalid reference state");
   } catch (RuntimeException re) {
     throw re;
   } catch (Exception e) {
     throw new IllegalStateException("Invalid reference state", e);
   }
 }
Esempio n. 6
0
 final synchronized Object sval() {
   if (fn != null) {
     try {
       sv = fn.invoke();
       fn = null;
     } catch (RuntimeException e) {
       throw e;
     } catch (Exception e) {
       throw Util.runtimeException(e);
     }
   }
   if (sv != null) return sv;
   return s;
 }
Esempio n. 7
0
 Object doCommute(Ref ref, IFn fn, ISeq args) {
   if (!info.running()) throw retryex;
   if (!vals.containsKey(ref)) {
     Object val = null;
     try {
       ref.lock.readLock().lock();
       val = ref.tvals == null ? null : ref.tvals.val;
     } finally {
       ref.lock.readLock().unlock();
     }
     vals.put(ref, val);
   }
   ArrayList<CFn> fns = commutes.get(ref);
   if (fns == null) commutes.put(ref, fns = new ArrayList<CFn>());
   fns.add(new CFn(fn, args));
   Object ret = fn.applyTo(RT.cons(vals.get(ref), args));
   vals.put(ref, ret);
   return ret;
 }
Esempio n. 8
0
  private TransformerIterator(IFn xform, Iterator sourceIter, boolean multi) {
    this.sourceIter = sourceIter;
    this.xf =
        (IFn)
            xform.invoke(
                new AFn() {
                  public Object invoke() {
                    return null;
                  }

                  public Object invoke(Object acc) {
                    return acc;
                  }

                  public Object invoke(Object acc, Object o) {
                    buffer = buffer.add(o);
                    return acc;
                  }
                });
    this.multi = multi;
  }
Esempio n. 9
0
 public static Object applyToHelper(IFn ifn, ISeq arglist) throws Exception {
   switch (RT.boundedLength(arglist, 20)) {
     case 0:
       arglist = null;
       return ifn.invoke();
     case 1:
       Object a1 = arglist.first();
       arglist = null;
       return ifn.invoke(a1);
     case 2:
       return ifn.invoke(
           arglist.first(), Util.ret1((arglist = arglist.next()).first(), arglist = null));
     case 3:
       return ifn.invoke(
           arglist.first(),
           (arglist = arglist.next()).first(),
           Util.ret1((arglist = arglist.next()).first(), arglist = null));
     case 4:
       return ifn.invoke(
           arglist.first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           Util.ret1((arglist = arglist.next()).first(), arglist = null));
     case 5:
       return ifn.invoke(
           arglist.first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           Util.ret1((arglist = arglist.next()).first(), arglist = null));
     case 6:
       return ifn.invoke(
           arglist.first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           Util.ret1((arglist = arglist.next()).first(), arglist = null));
     case 7:
       return ifn.invoke(
           arglist.first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           Util.ret1((arglist = arglist.next()).first(), arglist = null));
     case 8:
       return ifn.invoke(
           arglist.first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           Util.ret1((arglist = arglist.next()).first(), arglist = null));
     case 9:
       return ifn.invoke(
           arglist.first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           Util.ret1((arglist = arglist.next()).first(), arglist = null));
     case 10:
       return ifn.invoke(
           arglist.first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           Util.ret1((arglist = arglist.next()).first(), arglist = null));
     case 11:
       return ifn.invoke(
           arglist.first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           Util.ret1((arglist = arglist.next()).first(), arglist = null));
     case 12:
       return ifn.invoke(
           arglist.first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           Util.ret1((arglist = arglist.next()).first(), arglist = null));
     case 13:
       return ifn.invoke(
           arglist.first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           Util.ret1((arglist = arglist.next()).first(), arglist = null));
     case 14:
       return ifn.invoke(
           arglist.first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           Util.ret1((arglist = arglist.next()).first(), arglist = null));
     case 15:
       return ifn.invoke(
           arglist.first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           Util.ret1((arglist = arglist.next()).first(), arglist = null));
     case 16:
       return ifn.invoke(
           arglist.first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           Util.ret1((arglist = arglist.next()).first(), arglist = null));
     case 17:
       return ifn.invoke(
           arglist.first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           Util.ret1((arglist = arglist.next()).first(), arglist = null));
     case 18:
       return ifn.invoke(
           arglist.first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           Util.ret1((arglist = arglist.next()).first(), arglist = null));
     case 19:
       return ifn.invoke(
           arglist.first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           Util.ret1((arglist = arglist.next()).first(), arglist = null));
     case 20:
       return ifn.invoke(
           arglist.first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           Util.ret1((arglist = arglist.next()).first(), arglist = null));
     default:
       return ifn.invoke(
           arglist.first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           (arglist = arglist.next()).first(),
           RT.seqToArray(Util.ret1(arglist.next(), arglist = null)));
   }
 }