Refactor call stack and its use throughout. CallFrame now does all bytecode processing, and the callframe is reinitialized anytime something might have changed, like a function call.

This commit is contained in:
James Roseborough
2007-06-27 06:43:33 +00:00
parent 93fc4699a9
commit c8e1934916
20 changed files with 548 additions and 136 deletions

View File

@@ -2,13 +2,13 @@
import java.io.IOException;
import java.io.InputStream;
import lua.GlobalState;
import lua.StackState;
import lua.addon.luajava.LuaJava;
import lua.io.Closure;
import lua.io.LoadState;
import lua.io.Proto;
import lua.value.LString;
import lua.value.LValue;
/**
* Program to run a compiled lua chunk for test purposes,
@@ -30,20 +30,18 @@ public class LuaJavaAppRunner {
// new lua state
StackState state = new StackState();
// push args onto stack
// convert args to lua
LValue[] vargs = new LValue[args.length];
for ( int i=1; i<args.length; i++ )
state.push(new LString(args[i]));
vargs[i] = new LString(args[i]);
// load the file
InputStream is = LuaJavaAppRunner.class.getResourceAsStream( script );
Proto p = LoadState.undump(state, is, script);
// create closure to execute
// create closure and execute
Closure c = new Closure( state, p );
state.push( c );
for ( int i=0; i<args.length; i++ )
state.push( new LString(args[i]) );
state.docall(args.length, 0);
state.doCall(c, vargs, 0);
}
}

View File

@@ -7,6 +7,7 @@ import lua.io.Closure;
import lua.io.LoadState;
import lua.io.Proto;
import lua.value.LString;
import lua.value.LValue;
/**
* Program to run a compiled lua chunk for test purposes
@@ -24,25 +25,17 @@ public class LuacRunner {
// new lua state
StackState state = new StackState();
// push args onto stack
// convert args to lua
LValue[] vargs = new LValue[args.length];
for ( int i=1; i<args.length; i++ )
state.push(new LString(args[i]));
vargs[i] = new LString(args[i]);
// load the file
InputStream is = LuacRunner.class.getResourceAsStream( script );
Proto p = LoadState.undump(state, is, script);
// create closure to execute
// create closure and execute
Closure c = new Closure( state, p );
state.push( c );
for ( int i=0; i<args.length; i++ )
state.push( new LString(args[i]) );
state.docall(args.length, 0);
// print result?
System.out.println("stack:");
for ( int i=0; i<state.top; i++ )
System.out.println(" ["+i+"]="+state.stack[i] );
state.doCall(c, vargs, 0);
}
}

View File

@@ -1,7 +1,7 @@
#!/bin/bash
LUA_HOME=/cygdrive/c/programs/lua5.1
TESTS="test1 test2 test3 test4 test5 swingapp"
TESTS="swingapp"
TESTS="test2"
for x in $TESTS
do
echo compiling $x

View File

@@ -1,4 +1,5 @@
for cycle = 1,100 do
for cycle = 1,10 do
a = 123 + 456
print( a )
@@ -68,17 +69,18 @@ print( func(11, 12, 13) )
print( func(23, 22, 21) )
print( func(func(32,33,34), func(45,46,47), func(58,59,50)) )
--[[
function p(a,...)
print("a",a)
-- print("...",...)
-- print("...,a",...,a)
-- print("a,...",a,...)
print("...",...)
print("...,a",...,a)
print("a,...",a,...)
end
p()
p("q")
p("q","r")
p("q","r","s")
--]]
end

Binary file not shown.

View File

@@ -26,12 +26,13 @@ end
print( myfunc(0.1) )
print( myfunc(0.1) )
--[[
i = 1
table = { "west", "south", "east", "north" }
function next()
i = (i % 4) + 1
if ( i >= 4 ) then
i = 0
end
i = i + 1
return table[i]
end
@@ -76,5 +77,4 @@ function room4 ()
end
room1()
--]]

Binary file not shown.

View File

@@ -5,7 +5,7 @@ obj = luajava.newInstance("SampleClass")
print( obj )
obj.s = "Hello"
print( obj.s )
print( obj.getS() )
print( obj:getS() )
obj.setS( "World" )
obj:setS( "World" )
print( obj.s )

Binary file not shown.