Beispiel #1
0
  @Specialization
  public ErlTuple makeTuple(long num, Object defaultElement, ErlList list) {

    if (num < 0 || num > Integer.MAX_VALUE) {
      throw ErlControlException.makeBadarg();
    }

    Object[] arr = new Object[(int) num];
    for (int i = 0; i < (int) num; ++i) {
      arr[i] = defaultElement;
    }

    ErlList tail = list;
    while (ErlList.NIL != tail) {

      Object h = tail.getHead();

      if (h instanceof ErlTuple) {

        ErlTuple init = (ErlTuple) h;

        if (2 == init.getSize()) {

          final int idx = ErlContext.decodeInt(init.getElement(1)) - 1;

          if (0 <= idx && idx < arr.length) {
            arr[idx] = init.getElement(2);
          } else {
            throw ErlControlException.makeBadarg();
          }
        } else {
          throw ErlControlException.makeBadarg();
        }
      } else {
        throw ErlControlException.makeBadarg();
      }

      Object t = tail.getTail();

      if (t instanceof ErlList) {
        tail = (ErlList) t;
      } else {
        throw ErlControlException.makeBadarg();
      }
    }

    return ErlTuple.fromArray(arr);
  }
Beispiel #2
0
 @Specialization
 public boolean exit(ErlPort port, Object reason) {
   ErlContext.notImplemented();
   throw ErlControlException.makeBadarg();
 }