Exemplo n.º 1
0
 public static ESeq registered() {
   ESeq res = ERT.NIL;
   for (EAtom reg : register.keySet()) {
     res = res.cons(reg);
   }
   return res;
 }
Exemplo n.º 2
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;
      }
    }
Exemplo n.º 3
0
 public static ESeq make(int... messages) {
   ESeq result = ERT.NIL;
   for (int i = messages.length - 1; i >= 0; i--) {
     result = result.cons(ERT.box(messages[i]));
   }
   return result;
 }
Exemplo n.º 4
0
 /**
  * @param messages
  * @return
  */
 public static ESeq make(Object... messages) {
   ESeq result = ERT.NIL;
   for (int i = messages.length - 1; i >= 0; i--) {
     result = result.cons((EObject) messages[i]);
   }
   return result;
 }
Exemplo n.º 5
0
 public static EObject apply_last(EProc proc, EObject mod, EObject fun, EObject args)
     throws Pausable {
   ESeq seq = args.testSeq();
   if (seq == null) {
     throw ERT.badarg(mod, fun, args);
   }
   return apply_list_last(proc, mod, fun, seq, seq.length());
 }
Exemplo n.º 6
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();
 }
Exemplo n.º 7
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;
  }
Exemplo n.º 8
0
 /**
  * @param s
  * @return
  */
 public static EPID loopkup_pid(ESeq name) {
   String str = name.stringValue();
   for (EProc p : EProc.all_tasks.values()) {
     if (p.self_handle().toString().equals(str)) {
       return p.self_handle();
     }
   }
   throw ERT.badarg(name);
 }
Exemplo n.º 9
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;
    }
  }
Exemplo n.º 10
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();
  }
Exemplo n.º 11
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;
  }
Exemplo n.º 12
0
 public ErlangError(EObject reason, Throwable cause, EObject... args) {
   super(reason, cause);
   this.args = ESeq.fromArray(args);
 }
Exemplo n.º 13
0
 public ErlangError(EObject reason, EObject... args) {
   super(reason);
   this.args = ESeq.fromArray(args);
 }
Exemplo n.º 14
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;
  }
Exemplo n.º 15
0
  public static void print_all_stack_traces() {
    System.err.println("== Trace ==");

    Mailbox<EObject> mbox = new Mailbox<>(EProc.process_count());

    ESeq all = EProc.processes();
    for (EObject o : all) {
      EInternalPID pid = (EInternalPID) o;
      pid.task().printStackTrace(mbox);
    }

    while (true) {
      EObject o = mbox.getb(1000);
      if (o == null) break;

      ETuple2 tup = ETuple2.cast(o);
      EHandle handle = tup.elm(1).testHandle();
      ESeq stack = tup.elm(2).testSeq();

      System.err.println("\n == " + handle + " : " + handle.name);
      for (EObject elm : stack) {

        ETuple4 tup4 = ETuple4.cast(elm);

        if (tup4 != null) {
          ESeq args = tup4.elem3.testSeq();
          ESmall arity = tup4.elem3.testSmall();
          if (arity == null && args != null) {
            arity = ERT.box(args.length());
          }

          StringBuffer file_line = new StringBuffer();

          ESeq info = tup4.elem4.testSeq();
          if (info != null) {
            String file = "?";
            int line = -1;
            for (EObject inf : info) {
              ETuple2 t;
              if ((t = ETuple2.cast(inf)) != null) {
                ESmall n;
                EString f;
                if (t.elem1 == ErlangException.am_line && ((n = t.elem2.testSmall()) != null)) {
                  line = n.value;
                } else if (t.elem1 == ErlangException.am_file
                    && ((f = t.elem2.testString()) != null)) {
                  file = f.stringValue();
                }
              }
            }
            if (line != -1) {
              file_line.append('(').append(file).append(':').append(line).append(')');
            }
          }

          String module = tup4.elem1.toString();
          String mfa;
          System.err.print(mfa = make_width(20, module) + ":" + tup4.elem2 + "/" + arity);
          System.err.println(" " + make_width(65 - mfa.length(), file_line.toString()));
        } else {
          System.err.println(elm);
        }
      }
    }
  }