Example #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);
  }
Example #2
0
 @Specialization
 public ErlList keys(ErlMap map) {
   return ErlList.fromArray(map.getKeyArray());
 }
Example #3
0
  @Specialization
  protected Object subtract(Object lhs, Object rhs) {

    return ErlList.fromObject(lhs).subtract(ErlList.fromObject(rhs));
  }
Example #4
0
  @Specialization
  protected Object subtract(ErlList lhs, ErlList rhs) {

    return lhs.subtract(rhs);
  }
Example #5
0
  @Specialization
  public ErlTuple makeTuple(Object arg1, Object arg2, Object arg3) {

    return makeTuple(ErlContext.decodeInt(arg1), arg2, ErlList.fromObject(arg3));
  }