// note: subscript does not preserve names in the base, so no name handling (of base) is needed here
public static RAny executeSubscript(RInt index, RArray base, ASTNode ast) {
final int isize = index.size();
if (isize == 0) { throw RError.getSelectLessThanOne(ast); }
int i = 0;
RAny b = base;
if (isize > 1) {
// the upper levels of recursive indexes have to be treated differently from the lowest level (the error semantics is different)
// also, we know that the upper levels must be lists
for (; i < isize - 1; i++) {
if (!(b instanceof RList)) {
if (base instanceof RList) {
throw RError.getRecursiveIndexingFailed(ast, i + 1);
} else {
throw RError.getSelectMoreThanOne(ast);
}
}
RList l = (RList) b;
int indexv = index.getInt(i);
int bsize = l.size();
int isel = convertDereferencingIndex(indexv, i, bsize, ast);
b = l.getRAny(isel);
}
}
// selection at the last level
int indexv = index.getInt(i);
if (!(b instanceof RArray)) {
// TODO: support language objects
if (indexv == 1) { throw RError.getInvalidTypeLength(ast, b.typeOf(), 1); // FIXME: a very obscure error message but what GNU-R returns
}
if (indexv > 1) { throw RError.getSubscriptBounds(ast); }
throw RError.getSelectLessThanOne(ast);
}
RArray a = (RArray) b;