Improve call stack handling to prepare for propert tail call handling.

This commit is contained in:
James Roseborough
2007-06-15 06:41:40 +00:00
parent 19bd995ba6
commit be20581731
10 changed files with 21 additions and 33 deletions

View File

@@ -1,8 +1,6 @@
package lua.io;
import lua.StackState;
import lua.value.LInteger;
import lua.value.LNil;
import lua.value.LValue;
public class Closure extends LValue {
@@ -17,29 +15,12 @@ public class Closure extends LValue {
upVals[i] = new UpVal( p.upvalues[i] );
}
// perform a lua call
public void luaStackCall(StackState state, int base) {
// skip over closure
base++;
if ( p.is_vararg ) {
// adjust stack to bury varargs under base
int top = state.top;
int nsupplied = top-base;
int nrequired = p.numparams;
int nvarargs = Math.max( 0, nsupplied - nrequired );
for ( int i=0; i<nrequired; i++ )
state.stack[top+i+1] = (i<nsupplied? state.stack[base+i]: LNil.NIL);
state.stack[top] = new LInteger( nvarargs );
state.top = top + nrequired + 1;
base = top+1;
} else {
// normal non-varargs call
state.adjustTop( base+p.numparams );
}
state.vmExecute( this, base );
public void luaStackCall(StackState state, int base, int top) {
state.setupCall( this, base, top );
}
public String toString() {
return "closure: "+hashCode();
}
}