Improve call stack handling to prepare for propert tail call handling.
This commit is contained in:
2
pom.xml
2
pom.xml
@@ -8,6 +8,6 @@
|
||||
<name>LuaJ Interpreter</name>
|
||||
|
||||
<build>
|
||||
<finalName>LuaJ</finalName>
|
||||
<finalName>luaj</finalName>
|
||||
</build>
|
||||
</project>
|
||||
|
||||
@@ -27,15 +27,15 @@ final class Builtin extends LFunction {
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "Builtin('"+NAMES[id]+"')";
|
||||
return "builtin."+NAMES[id];
|
||||
}
|
||||
|
||||
// perform a lua call
|
||||
public void luaStackCall(StackState state, int base) {
|
||||
public void luaStackCall(StackState state, int base, int top) {
|
||||
int returnValues = 0;
|
||||
switch ( id ) {
|
||||
case PRINT:
|
||||
for ( int i=base+1, n=state.top; i<n; i++ ) {
|
||||
for ( int i=base+1; i<top; i++ ) {
|
||||
System.out.print( String.valueOf(state.stack[i]) );
|
||||
System.out.print( "\t" );
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,4 +36,9 @@ public class Proto extends LValue {
|
||||
public int numparams;
|
||||
public boolean is_vararg;
|
||||
public int maxstacksize;
|
||||
|
||||
|
||||
public String toString() {
|
||||
return "proto: "+hashCode();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,8 @@ package lua.value;
|
||||
|
||||
public class LFunction extends LValue {
|
||||
|
||||
|
||||
public String toString() {
|
||||
return "function: "+hashCode();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ public class LTable extends LValue {
|
||||
}
|
||||
|
||||
// perform a lua call
|
||||
public void luaStackCall(StackState state, int base) {
|
||||
public void luaStackCall(StackState state, int base, int top) {
|
||||
if ( e.hasMoreElements() ) {
|
||||
LValue key = (LValue) e.nextElement();
|
||||
state.adjustTop(base+2);
|
||||
|
||||
@@ -16,7 +16,7 @@ public class LValue {
|
||||
}
|
||||
|
||||
// perform a lua call, return number of results actually produced
|
||||
public void luaStackCall(StackState state, int base) {
|
||||
public void luaStackCall(StackState state, int base, int top) {
|
||||
luaUnsupportedOperation();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#!/bin/bash
|
||||
LUA_HOME=/cygdrive/c/programs/lua5.1
|
||||
TESTS="test1 test2 test3 test4 test5"
|
||||
TESTS="test2"
|
||||
TESTS="test3"
|
||||
for x in $TESTS
|
||||
do
|
||||
echo compiling $x
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user