Esempio n. 1
0
    public void update(boolean how, ESeq flags, EPID self) {
      ETuple2 t;
      EPID p;
      while (!flags.isNil()) {
        EObject flag = flags.head();
        flags = flags.tail();

        if (flag == am_arity) {
          arity = how;
        } else if (flag == am_call) {
          call = how;
        } else if (flag == am_send) {
          send = how;
        } else if (flag == am_receive) {
          receive = how;
        } else if (flag == am_procs) {
          procs = how;
        } else if (flag == am_silent) {
          silent = how;
        } else if ((t = ETuple2.cast(flag)) != null && t.elem1 == am_tracer) {
          tracer = t.elem2.testPID();
        } else if (flag == am_all) {
          call = how;
          arity = how;
          send = how;
          receive = how;
        } else {
          throw ERT.badarg(flag);
        }
      }

      if (how == true && tracer == null) {
        tracer = self;
      }
    }
Esempio n. 2
0
  @Override
  public String toString() {

    try {
      // TODO: make this faster, we generate too many exceptions
      // on account of this piece of code!
      ESeq str = EString.make(this);
      return str.toString();
    } catch (ErlangException e) {
      // ignor e//
    }

    StringBuffer sb = new StringBuffer("[");

    assert (this instanceof EList);

    ESeq val = this;
    while ((val.testNil()) == null) {
      if (val != this) {
        sb.append(",");
      }
      sb.append(val.head());
      val = val.tail();
    }

    sb.append("]");
    return sb.toString();
  }
Esempio n. 3
0
  public static EObject apply_list_last(EProc proc, EObject mod, EObject fun, ESeq seq, int len)
      throws Pausable {
    EAtom f = fun.testAtom();
    ESeq a = seq.testSeq();

    if (f == null || a == null) throw ERT.badarg(mod, fun, seq);

    EFun found = resolve_fun(mod, fun, len);

    if (len > 9) {
      // TODO: make it real tail recursion in stead
      return found.invoke(proc, a.toArray());
    }

    proc.tail = found;
    a = a.reverse();

    switch (len) {
      default:
        throw new NotImplemented();
      case 9:
        proc.arg8 = a.head();
        a = a.tail();
      case 8:
        proc.arg7 = a.head();
        a = a.tail();
      case 7:
        proc.arg6 = a.head();
        a = a.tail();
      case 6:
        proc.arg5 = a.head();
        a = a.tail();
      case 5:
        proc.arg4 = a.head();
        a = a.tail();
      case 4:
        proc.arg3 = a.head();
        a = a.tail();
      case 3:
        proc.arg2 = a.head();
        a = a.tail();
      case 2:
        proc.arg1 = a.head();
        a = a.tail();
      case 1:
        proc.arg0 = a.head();
        a = a.tail();
      case 0:
    }

    return EProc.TAIL_MARKER;
  }
Esempio n. 4
0
 @Override
 public void encode(EOutputStream eos) {
   int len = this.length();
   eos.write_list_head(len);
   ESeq curr = this;
   while (!curr.isNil()) {
     eos.write_any(curr.head());
     curr = curr.tail();
   }
   eos.write_nil();
 }
Esempio n. 5
0
  @Override
  public int hashCode() {

    int h = 0;
    ESeq curr = this;
    do {
      h = 31 * h + curr.head().hashCode();
      curr = curr.tail();
    } while (curr != ERT.NIL);

    return h;
  }
Esempio n. 6
0
  @BIF
  public static EInteger trace(EProc self_proc, EObject arg0, EObject arg1, EObject arg2) {
    EInternalPID pid = arg0.testInternalPID();
    EAtom all = arg0.testAtom();
    EObject how = arg1.testBoolean();
    ESeq flags = arg2.testSeq();

    if ((pid == null && all != am_all) || how == null || flags == null) {
      throw ERT.badarg(arg0, arg1, arg2);
    }

    EInternalPID self = self_proc.self_handle();

    if (all == am_all) {
      ESeq allprocs = EProc.processes();
      int result = allprocs.length();
      global_trace_flags.update(how == ERT.TRUE, flags, self);
      while (!allprocs.isNil()) {
        EProc proc = allprocs.head().testInternalPID().task();
        allprocs = allprocs.tail();

        if (proc.trace_flags != null) {
          proc.trace_flags.update(how == ERT.TRUE, flags, self);
        }
      }

      return ERT.box(result);

    } else {
      EProc proc = pid.task();

      if (!proc.is_alive_dirtyread()) {
        return ESmall.ZERO;
      }

      if (proc.trace_flags == null) {
        proc.trace_flags = global_trace_flags.clone();
      }

      proc.trace_flags.update(how == ERT.TRUE, flags, self);

      return ESmall.ONE;
    }
  }
Esempio n. 7
0
  public ESeq getTrace() {
    ESeq trace = super.getTrace();

    if (args != null && !trace.isNil()) {

      ETuple4 first = ETuple4.cast(trace.head().testTuple());
      ESeq res = trace.tail().testSeq();

      ETuple4 fa = new ETuple4();
      fa.elem1 = first.elem1;
      fa.elem2 = first.elem2;
      fa.elem3 = args;
      fa.elem4 = first.elem4;

      trace = res.cons(fa);
    }

    return trace;
  }