Package erjang

Examples of erjang.ESeq


      this.limit = limit;
    }
 
    public EObject select() {
      int count = 0;
      ESeq vals = ERT.NIL;
     
      ISeq map_seq = this.ent;
      while (seq_has_more(map_seq) && (limit < 0 || count < limit)) {
       
        IMapEntry mape = (IMapEntry) map_seq.first();
        map_seq = map_seq.next();
       
        ETuple candidate = (ETuple) mape.getValue();
        EObject res;
        if ((res = matcher.match(candidate)) != null) {
          count += 1;
          vals = vals.cons(res);
        }
      }
      if (ordered) vals = vals.reverse();

      if (vals == ERT.NIL) {
        return Native.am_$end_of_table;
      } else if (!seq_has_more(map_seq)) {
        return new ETuple2(vals, Native.am_$end_of_table);
View Full Code Here


  private static EAtom am_on_load = EAtom.intern("on_load");
  private static Field CRC32_crc;
 
  @BIF
  static EObject apply(EProc proc, EObject fun, EObject args) throws Pausable {
    ESeq a = args.testSeq();
    if (a==null) throw ERT.badarg(fun,args);
   
    EObject res;
    EFun f = fun.testFunction();
    if (f != null) {
      res = apply_last(proc, f, a);
    } else {

      ETuple t = fun.testTuple();
      if (t == null) {
        throw ERT.badfun(fun);
      }
 
      ETuple2 t2 = ETuple2.cast(t);
      if (t2 == null) {
        throw ERT.badarg(fun,args);
      }
     
      EAtom mn = t2.elem1.testAtom();
      EAtom fn = t2.elem2.testAtom();
     
      FunID funspec;
      f = EModuleManager.resolve(funspec=new FunID(mn,fn,a.length()));
     
      if (f == null) {
        throw ERT.undef(funspec, a.toArray());
      }
     
      res = apply_last(proc, f, a);
    }
   
View Full Code Here

    EAtom mod = one.testAtom();
    ETuple t = one.testTuple();
    JavaObject jo = one.testJavaObject();
   
    EAtom fun = two.testAtom();
    ESeq  args = three.testSeq();
   
    if ((mod==null && t == null && jo == null)||fun==null||args==null) throw ERT.badarg(one, two, three);
   
    EFun f = ERT.resolve_fun(one, fun, args.length());
   
    EObject res = apply_last(proc, f, args);
   
    while (res == EProc.TAIL_MARKER) {
      res = proc.tail.go(proc);
View Full Code Here

    return res;
  }

  public static EObject apply_last(EProc proc, EFun fun, ESeq args)
      throws Pausable {
    ESeq rargs = args.reverse();
    int len = args.length();
    switch(len) {   
    case 11:
      proc.arg10 = rargs.head(); rargs = rargs.tail();
    case 10:
      proc.arg9 = rargs.head(); rargs = rargs.tail();
    case 9:
      proc.arg8 = rargs.head(); rargs = rargs.tail();
    case 8:
      proc.arg7 = rargs.head(); rargs = rargs.tail();
    case 7:
      proc.arg6 = rargs.head(); rargs = rargs.tail();
    case 6:
      proc.arg5 = rargs.head(); rargs = rargs.tail();
    case 5:
      proc.arg4 = rargs.head(); rargs = rargs.tail();
    case 4:
      proc.arg3 = rargs.head(); rargs = rargs.tail();
    case 3:
      proc.arg2 = rargs.head(); rargs = rargs.tail();
    case 2:
      proc.arg1 = rargs.head(); rargs = rargs.tail();
    case 1:
      proc.arg0 = rargs.head();
    case 0:
      break;
     
    default:
      return fun.apply(proc, args);
View Full Code Here

      super(owner.self_handle(), new ExecDriverInstance(name));

      this.command = command;

      // argument can be any list, ... turn it into a string
      ESeq es = name.elem2.testString();
      if (es == null) {
        ECons cons;
        EAtom am;
        if ((cons = name.elem2.testCons()) != null) {
          es = EString.make(cons);
        } else if ((am = name.elem2.testAtom()) != null) {
          es = EString.fromString(am.getName());
        } else {
          throw ERT.badarg(name, portSetting);
        }
      }

      String full_cmd = es.stringValue();

      String[] cmd;
      if (name.elem1 == ErlPort.am_spawn) {
        cmd = split_with_quotes(full_cmd);
      } else {
View Full Code Here

    EDriver res = drivers.get(name);
    return res;
    }

  public static ESeq getLoaded() {
    ESeq res = ERT.NIL;
    for (String driver : drivers.keySet()) {
      res = res.cons(EString.fromString(driver));
    }
    return res;
  }
View Full Code Here

      }});
  }
 
  @Override
  protected ESeq lookup(EObject key) {
    ESeq res = ERT.NIL;
   
    // no need to run in_tx if we're only reading
    EObject val = (EObject) deref().valAt(key);
    if (val != null) {
      return res.cons(val);
    } else {
      return res;
    }
  }
View Full Code Here

  }
 
  @Override
  public ESeq match(EPattern matcher) {   
    IPersistentMap map = deref();
    ESeq res = ERT.NIL;
   
    EObject key = matcher.getKey(keypos1);
    if (key == null) {
      res = matcher.match(res, (Map<EObject, ETuple>) map);
      if (ordered) res = res.reverse();
    } else {
      ETuple candidate = (ETuple) map.valAt(key);
      if (candidate != null) {
        res =  matcher.match(res, candidate);
      }
View Full Code Here

  }
 
  @Override
  public ESeq match_object(EPattern matcher) {   
    IPersistentMap map = deref();
    ESeq res = ERT.NIL;
   
    EObject key = matcher.getKey(keypos1);
    if (key == null) {
      res = matcher.match_members(res, (Map<EObject, ETuple>) map);
      if (ordered) res = res.reverse();
    } else {
      ETuple candidate = (ETuple) map.valAt(key);
      if (candidate != null) {
        res =  matcher.match_members(res, candidate);
      }
View Full Code Here

      if ((tup = val.testTuple()) != null) {
        ETuple2 tup2;
        if ((tup2 = ETuple2.cast(tup)) != null) {

          if (tup2.elem1 == am_args) {
            ESeq list = tup2.elem2.testSeq();
            EObject[] nargs = list.toArray();

            String[] new_cmd = new String[nargs.length + 1];
            new_cmd[0] = cmd[0];
            for (int i = 0; i < nargs.length; i++) {
              new_cmd[i + 1] = EString.make(nargs[i])
                  .stringValue();
            }
            cmd = new_cmd;

          } else if (tup2.elem1 == am_arg0) {
            String[] new_cmd = new String[2];
            new_cmd[0] = cmd[0];
            new_cmd[1] = EString.make(tup2.elem2).stringValue();

          } else if (tup2.elem1 == am_packet) {
            packet = tup2.elem2.asInt();
            mode = Mode.PACKET;

          } else if (tup2.elem1 == am_cd) {
            cwd = EString.make(tup2.elem2).stringValue();

          } else if (tup2.elem1 == am_env) {

            ESeq ee;
            if ((ee = tup2.elem2.testSeq()) == null) {
              throw ERT.badarg();
            }

            EObject[] envs = ee.toArray();
            for (int i = 0; i < envs.length; i++) {
              ETuple2 e = ETuple2.cast(envs[i].testTuple());
              if (e.elem2 == ERT.FALSE) {
                env.remove(EString.make(e.elem1).stringValue());
              } else {
View Full Code Here

TOP

Related Classes of erjang.ESeq

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.