@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); }
@Specialization public ErlMap remove(Object arg1, Object arg2) { if (arg2 instanceof ErlMap) { return remove(arg1, (ErlMap) arg2); } throw ErlControlException.makeBadmap(arg2); }
@Specialization public ErlList keys(Object arg) { if (arg instanceof ErlMap) { return keys((ErlMap) arg); } throw ErlControlException.makeBadmap(arg); }
@Override public ErlFunction executeGeneric(VirtualFrame frame) { try { return refNode.executeFunction(frame); } catch (UnexpectedResultException ex) { throw ErlControlException.makeUndef(); } }
@Specialization public boolean exit(ErlPort port, Object reason) { ErlContext.notImplemented(); throw ErlControlException.makeBadarg(); }