} else {
n = -n;
}
if(n < 0) {
throw new EvalException("not that many frames on the stack");
}
while (!cptr.isTopLevel()) {
if (cptr.getType() == Type.FUNCTION ) {
if (n == 0) { /* we need to detach the enclosing env */
return cptr.getEnvironment();
} else {
n--;
}
}
cptr = cptr.getParent();
}
if(n == 0 && cptr.isTopLevel()) {
return cptr.getGlobalEnvironment();
}
throw new EvalException("not that many frames on the stack");
}