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>
|
<name>LuaJ Interpreter</name>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
<finalName>LuaJ</finalName>
|
<finalName>luaj</finalName>
|
||||||
</build>
|
</build>
|
||||||
</project>
|
</project>
|
||||||
|
|||||||
@@ -27,15 +27,15 @@ final class Builtin extends LFunction {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "Builtin('"+NAMES[id]+"')";
|
return "builtin."+NAMES[id];
|
||||||
}
|
}
|
||||||
|
|
||||||
// perform a lua call
|
// perform a lua call
|
||||||
public void luaStackCall(StackState state, int base) {
|
public void luaStackCall(StackState state, int base, int top) {
|
||||||
int returnValues = 0;
|
int returnValues = 0;
|
||||||
switch ( id ) {
|
switch ( id ) {
|
||||||
case PRINT:
|
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( String.valueOf(state.stack[i]) );
|
||||||
System.out.print( "\t" );
|
System.out.print( "\t" );
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
package lua.io;
|
package lua.io;
|
||||||
|
|
||||||
import lua.StackState;
|
import lua.StackState;
|
||||||
import lua.value.LInteger;
|
|
||||||
import lua.value.LNil;
|
|
||||||
import lua.value.LValue;
|
import lua.value.LValue;
|
||||||
|
|
||||||
public class Closure extends LValue {
|
public class Closure extends LValue {
|
||||||
@@ -17,29 +15,12 @@ public class Closure extends LValue {
|
|||||||
upVals[i] = new UpVal( p.upvalues[i] );
|
upVals[i] = new UpVal( p.upvalues[i] );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// perform a lua call
|
// perform a lua call
|
||||||
public void luaStackCall(StackState state, int base) {
|
public void luaStackCall(StackState state, int base, int top) {
|
||||||
// skip over closure
|
state.setupCall( this, base, top );
|
||||||
base++;
|
}
|
||||||
if ( p.is_vararg ) {
|
|
||||||
|
public String toString() {
|
||||||
// adjust stack to bury varargs under base
|
return "closure: "+hashCode();
|
||||||
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 );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,4 +36,9 @@ public class Proto extends LValue {
|
|||||||
public int numparams;
|
public int numparams;
|
||||||
public boolean is_vararg;
|
public boolean is_vararg;
|
||||||
public int maxstacksize;
|
public int maxstacksize;
|
||||||
|
|
||||||
|
|
||||||
|
public String toString() {
|
||||||
|
return "proto: "+hashCode();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ package lua.value;
|
|||||||
|
|
||||||
public class LFunction extends LValue {
|
public class LFunction extends LValue {
|
||||||
|
|
||||||
|
public String toString() {
|
||||||
|
return "function: "+hashCode();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ public class LTable extends LValue {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// perform a lua call
|
// perform a lua call
|
||||||
public void luaStackCall(StackState state, int base) {
|
public void luaStackCall(StackState state, int base, int top) {
|
||||||
if ( e.hasMoreElements() ) {
|
if ( e.hasMoreElements() ) {
|
||||||
LValue key = (LValue) e.nextElement();
|
LValue key = (LValue) e.nextElement();
|
||||||
state.adjustTop(base+2);
|
state.adjustTop(base+2);
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ public class LValue {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// perform a lua call, return number of results actually produced
|
// 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();
|
luaUnsupportedOperation();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
LUA_HOME=/cygdrive/c/programs/lua5.1
|
LUA_HOME=/cygdrive/c/programs/lua5.1
|
||||||
TESTS="test1 test2 test3 test4 test5"
|
TESTS="test1 test2 test3 test4 test5"
|
||||||
TESTS="test2"
|
TESTS="test3"
|
||||||
for x in $TESTS
|
for x in $TESTS
|
||||||
do
|
do
|
||||||
echo compiling $x
|
echo compiling $x
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user