Package erjang

Examples of erjang.ESeq


  @BIF
  public static EObject spawn_link(EProc proc, EObject mod, EObject fun, EObject args) throws Pausable {
   
    EAtom m = mod.testAtom();
    EAtom f = fun.testAtom();
    ESeq  a = args.testSeq();
   
    if (m==null||f==null||a==null)
      throw ERT.badarg(mod, fun, args);
   
    EProc p2 = new EProc(proc.group_leader(), m, f, a);
View Full Code Here


  @BIF
  public static EObject spawn_opt(EProc self, EObject tup) throws Pausable {
    ETuple t;
    EAtom m;
    EAtom f;
    ESeq a;
    ESeq o;
    if ((t=tup.testTuple()) == null
        || t.arity() != 4
        || (m=t.elm(1).testAtom()) == null
        || (f=t.elm(2).testAtom()) == null
        || (a=t.elm(3).testSeq()) == null
        || (o=t.elm(4).testSeq()) == null
        ) throw ERT.badarg(tup);
   
    boolean link = false;
    boolean monitor = false;
    EAtom priority = null;
   
    for (; !o.isNil(); o = o.tail() ) {
      EObject val = o.head();
     
      ETuple2 t2;
      if (val == am_link) {
        link = true;
      } else if (val == am_monitor) {
View Full Code Here

  @BIF
  public static EObject spawn(EProc proc, EObject mod, EObject fun, EObject args) {
   
    EAtom m = mod.testAtom();
    EAtom f = fun.testAtom();
    ESeq  a = args.testSeq();
   
    if (m==null||f==null||a==null)
      throw ERT.badarg(mod, fun, args);
   
    EProc p2 = new EProc(proc.group_leader(), m, f, a);
View Full Code Here

  }

  static public EObject demonitor(ETask<?> self, EObject ref, EObject options) throws Pausable {
    ERef r = ref.testReference();
   
    ESeq o = options.testSeq();
   
    if (r==null||o==null)
      throw ERT.badarg(ref, options);

    boolean flush = (!o.isNil() && o.head()==am_flush);

    EObject found = self.demonitor(r);

    if (found == null) {
      return ERT.FALSE;
View Full Code Here

  @BIF
  public static EObject hibernate(EProc self, EObject a1, EObject a2, EObject a3) {
   
    EAtom m = a1.testAtom();
    EAtom f = a2.testAtom();
    ESeq  a = a3.testSeq();
   
    if (m == null || f == null || a == null) {
      throw ERT.badarg(a1, a2, a3);
    }
   
    int arity = a.length();
   
    EFun target = EModuleManager.resolve(new FunID(m,f,arity));
   
    if (target == null) {
      throw new ErlangUndefined(m, f, new ESmall(arity));
    }
   
    self.tail = target;
    a = a.reverse();
    switch (arity) {
    default:
      throw new NotImplemented("hibernate w/" + arity + " args");
    case 7:
      self.arg6 = a.head(); a = a.tail();
    case 6:
      self.arg5 = a.head(); a = a.tail();
    case 5:
      self.arg4 = a.head(); a = a.tail();
    case 4:
      self.arg3 = a.head(); a = a.tail();
    case 3:
      self.arg2 = a.head(); a = a.tail();
    case 2:
      self.arg1 = a.head(); a = a.tail();
    case 1:
      self.arg0 = a.head(); // a = a.tail();
    case 0:
    }   
   
    throw ErjangHibernateException.INSTANCE;
   
View Full Code Here

    this.vars = new HashMap<Integer,EObject>();
    this.value = value;
  }

  public ESeq makeList() {
    ESeq res = ERT.NIL;
    for (int i = varnames.length-1; i >= 0; i--) {
      res = res.cons(vars.get(varnames[i]));
    }
    return res;
  }
View Full Code Here

      outbytes[outbytes.length - 1] = 0x0;
     
      return new EBinary(outbytes);
    }
    else {
      ESeq input = arg.testSeq();
      List<Byte> bytes = new ArrayList<Byte>();
      byte[] out;
     
      while (!input.isNil()) {
        Integer el = input.head().testSmall().intValue();
        bytes.add(el.byteValue());
        input = input.tail();
      }
      out = new byte[bytes.size() + 1];
      for (int i = 0; i < bytes.size(); ++i) {
        out[i] = bytes.get(i);
      }
View Full Code Here

      throw ERT.badarg(charlist, encodingSpec);

    CharArrayWriter out = new CharArrayWriter();
    CharCollector collector = new CharCollector(encoding, out);

    ESeq rest = ERT.NIL;
    try {
      rest = charlist.collectCharList(collector, rest);
    } catch (CharCollector.InvalidElementException e) {
      throw ERT.badarg(charlist, encodingSpec);
    } catch (CharCollector.CollectingException e) {
      EObject data = output_converter.convert(out);
      return ETuple.make(ERROR_ATOM, data, e.restOfInput);
    } catch (IOException e) {
      throw new Error(e); // Not supposed to happen.
    }

    try {
      collector.end();

      if (rest != ERT.NIL) {
        return ETuple.make(INCOMPLETE_ATOM, 
                   output_converter.convert(out),
                   ErlConvert.iolist_to_binary(rest.reverse()));
      }
     
    } catch (CharCollector.PartialDecodingException e) {
      EObject data = output_converter.convert(out);
      return ETuple.make(INCOMPLETE_ATOM, data);
View Full Code Here

  public static ESeq decode_options(byte[] ops) {
    return decode_options(ops, 0);
  }

  public static ESeq decode_options(byte[] ops, int i) {
    ESeq l = ERT.NIL;
    for (; i < ops.length; i++) {
      switch(ops[i]) {
      case 'g': l = l.cons(EAtom.intern("global")); break;
      case 'u': l = l.cons(EAtom.intern("unicode")); break;
      case 'i': l = l.cons(EAtom.intern("caseless")); break;
      case 'f': l = l.cons(EAtom.intern("firstline")); break;
      case 'm': l = l.cons(EAtom.intern("multiline")); break;
      case 's': l = l.cons(EAtom.intern("dotall")); break;
      default: throw new RuntimeException("unsupported regex option '"+((char)ops[i])+"'");
      }
    }
    return l;
  }
View Full Code Here

    return testSeq();
  }

  @Override
  public ECons testNonEmptyList() {
    ESeq seq = testSeq();
    if (seq == null || seq.isNil())
      return null;
    return seq;
  }
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.