コード例 #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);
  }
コード例 #2
0
ファイル: RemoveBuiltin.java プロジェクト: smarr/graal-erl
  @Specialization
  public ErlMap remove(Object arg1, Object arg2) {

    if (arg2 instanceof ErlMap) {
      return remove(arg1, (ErlMap) arg2);
    }

    throw ErlControlException.makeBadmap(arg2);
  }
コード例 #3
0
ファイル: KeysBuiltin.java プロジェクト: smarr/graal-erl
  @Specialization
  public ErlList keys(Object arg) {

    if (arg instanceof ErlMap) {
      return keys((ErlMap) arg);
    }

    throw ErlControlException.makeBadmap(arg);
  }
コード例 #4
0
  @Override
  public ErlFunction executeGeneric(VirtualFrame frame) {
    try {
      return refNode.executeFunction(frame);

    } catch (UnexpectedResultException ex) {
      throw ErlControlException.makeUndef();
    }
  }
コード例 #5
0
ファイル: Exit2Builtin.java プロジェクト: smarr/graal-erl
 @Specialization
 public boolean exit(ErlPort port, Object reason) {
   ErlContext.notImplemented();
   throw ErlControlException.makeBadarg();
 }