Exemplo n.º 1
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.º 2
0
  private static EObject send_to_remote(
      EProc proc, ETuple dest, EAtom node_name, EAtom reg_name, EObject msg, EObject options)
      throws Pausable {
    // INVARIANT: t == ETuple.make(node_name, reg_name)

    if (node_name == getLocalNode().node) { // We're talking to ourselves
      send_to_locally_registered(proc, reg_name, msg);
      return am_ok; // Even if the process does not exist.
      // TODO: Return 'noconnect' if options contain noconnect?...
    } else { // We're talking to another node
      if (ipclog.isLoggable(Level.FINE)) {
        ipclog.fine("sending msg " + dest + " ! " + msg);
      }

      EAbstractNode node = EPeer.get(node_name);
      if (node == null) {
        EObject[] args =
            (options != null
                ? new EObject[] {dest, msg, options}
                : new EObject[] {dest, msg, ERT.NIL});
        return erlang__dsend__3.invoke(proc, args);
      } else {
        node.dsig_reg_send(proc.self_handle(), reg_name, msg);
        return am_ok;
      }
    }
  }
Exemplo n.º 3
0
  /**
   * Read an arbitrary Erlang term from the stream.
   *
   * @return the Erlang term.
   * @exception IOException if the stream does not contain a known Erlang type at the next position.
   */
  public EObject read_any() throws IOException {
    // calls one of the above functions, depending on o
    final int tag = peek1skip_version();

    switch (tag) {
      case EExternal.smallIntTag:
      case EExternal.intTag:
      case EExternal.smallBigTag:
      case EExternal.largeBigTag:
        return EInteger.read(this);

      case EExternal.atomCacheRef:
      case EExternal.atomTag:
      case EExternal.smallAtomTag:
        return EAtom.read(this);

      case EExternal.floatTag:
      case EExternal.newFloatTag:
        return EDouble.read(this);

      case EExternal.refTag:
      case EExternal.newRefTag:
        return ERef.read(this);

      case EExternal.portTag:
        return EPort.read(this);

      case EExternal.pidTag:
        return EPID.read(this);

      case EExternal.stringTag:
        return EString.read(this);

      case EExternal.listTag:
      case EExternal.nilTag:
        if ((flags & DECODE_INT_LISTS_AS_STRINGS) != 0) {
          final int savePos = getPos();
          try {
            return EString.read(this);
          } catch (final IOException e) {
          }
          setPos(savePos);
        }
        return EList.read(this);

      case EExternal.smallTupleTag:
      case EExternal.largeTupleTag:
        return ETuple.read(this);

      case EExternal.binTag:
        return EBinary.read(this);

      case EExternal.bitBinTag:
        return EBitString.read(this);

      case EExternal.compressedTag:
        return read_compressed();

      case EExternal.newFunTag:
      case EExternal.funTag:
        return EFun.read(this);

      case EExternal.externalFunTag:
        return read_external_fun();

      default:
        throw new IOException("Unknown data type: " + tag + " at position " + getPos());
    }
  }