コード例 #1
0
ファイル: ERT.java プロジェクト: trifork/erjang
    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;
      }
    }
コード例 #2
0
ファイル: EList.java プロジェクト: vladdu/erjang
  @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();
  }
コード例 #3
0
ファイル: ERT.java プロジェクト: trifork/erjang
  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;
  }
コード例 #4
0
ファイル: EList.java プロジェクト: vladdu/erjang
 @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();
 }
コード例 #5
0
ファイル: EList.java プロジェクト: vladdu/erjang
  @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;
  }
コード例 #6
0
ファイル: ERT.java プロジェクト: trifork/erjang
  @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;
    }
  }
コード例 #7
0
ファイル: ErlangError.java プロジェクト: nivertech/erjang
  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;
  }