Rework the main API"s that implement the calling convention. Provide utility methods to get arguments that were supplied, and provide return values. Add a VM interface to clarify the relationship between the VM, things that call the VM, and things that are called by the VM. Make the code more closely aligned with the C++ version.

This commit is contained in:
James Roseborough
2007-07-24 05:06:10 +00:00
parent 56f33b373d
commit 8bf4c82a12
17 changed files with 424 additions and 862 deletions

View File

@@ -1,6 +1,6 @@
package lua.value;
import lua.CallFrame;
import lua.VM;
public class LFunction extends LValue {
@@ -11,21 +11,19 @@ public class LFunction extends LValue {
return "function: "+hashCode();
}
public void luaSetTable(CallFrame call, int base, LValue table, LValue key, LValue val) {
call.top = base;
call.push( this );
call.push( table );
call.push( key );
call.push( val );
this.luaStackCall(call, base, call.top, 1);
public void luaSetTable(VM vm, LValue table, LValue key, LValue val) {
vm.push( this );
vm.push( table );
vm.push( key );
vm.push( val );
this.luaStackCall(vm);
}
public void luaGetTable(CallFrame call, int base, LValue table, LValue key) {
call.top = base;
call.push( this );
call.push( table );
call.push( key );
this.luaStackCall(call, base, call.top, 1);
public void luaGetTable(VM vm, LValue table, LValue key) {
vm.push( this );
vm.push( table );
vm.push( key );
this.luaStackCall(vm);
}
public LString luaGetType() {

View File

@@ -27,11 +27,6 @@ public class LString extends LValue {
return m_hash;
}
// TODO: what to do with LuaState?
public LString(StackState l, String string) {
this(string);
}
public boolean luaBinCmpUnknown(int opcode, LValue lhs) {
return lhs.luaBinCmpString(opcode, m_string);
}

View File

@@ -3,7 +3,7 @@ package lua.value;
import java.util.Enumeration;
import java.util.Hashtable;
import lua.CallFrame;
import lua.VM;
public class LTable extends LValue {
@@ -39,12 +39,12 @@ public class LTable extends LValue {
return (LValue) m_hash.get( new LString(key) );
}
public void luaSetTable(CallFrame call, int base, LValue table, LValue key, LValue val) {
public void luaSetTable(VM vm, LValue table, LValue key, LValue val) {
if ( m_metatable != null ) {
if ( ! m_hash.containsKey(key) ) {
LValue event = (LValue) m_metatable.m_hash.get( TM_NEWINDEX );
if ( event != null && event != LNil.NIL ) {
event.luaSetTable( call, base, table, key, val );
event.luaSetTable( vm, table, key, val );
return;
}
}
@@ -52,19 +52,21 @@ public class LTable extends LValue {
m_hash.put( key, val );
}
public void luaGetTable(CallFrame call, int base, LValue table, LValue key) {
public void luaGetTable(VM vm, LValue table, LValue key) {
LValue val = (LValue) m_hash.get(key);
if ( val == null || val == LNil.NIL ) {
if ( m_metatable != null ) {
LValue event = (LValue) m_metatable.m_hash.get( TM_INDEX );
if ( event != null && event != LNil.NIL ) {
event.luaGetTable( call, base, table, key );
event.luaGetTable( vm, table, key );
return;
}
}
val = LNil.NIL;
}
call.stack[base] = val;
// stack.stack[base] = val;
vm.push(val);
}
public String toString() {
@@ -107,19 +109,14 @@ public class LTable extends LValue {
}
// perform a lua call
public void luaStackCall(CallFrame call, int base, int top, int nresults) {
public void luaStackCall(VM vm) {
if ( e.hasMoreElements() ) {
LValue key = (LValue) e.nextElement();
LValue val = (LValue) t.m_hash.get(key);
call.stack[base] = key;
call.stack[base+1] = val;
call.top = base+2;
} else {
call.stack[base] = LNil.NIL;
call.top = base+1;
vm.setResult();
vm.push( key );
vm.push( val );
}
if ( nresults >= 0 )
call.adjustTop(base + nresults);
}
}

View File

@@ -1,7 +1,7 @@
package lua.value;
import lua.CallFrame;
import lua.Lua;
import lua.VM;
abstract
public class LValue {
@@ -20,7 +20,7 @@ public class LValue {
}
// perform a lua call, return number of results actually produced
public void luaStackCall(CallFrame call, int base, int top, int nresults) {
public void luaStackCall(VM vm) {
luaUnsupportedOperation();
}
@@ -72,20 +72,21 @@ public class LValue {
}
/** set a value in a table
* @param call the stack state
* @param base the base of the stack, in case a function is put on the stack
* @param vm the calling vm
* @param table the table to operate on
* @param the key to set
* @param the value to set
*/
public void luaSetTable(CallFrame call, int base, LValue table, LValue key, LValue val) {
public void luaSetTable(VM vm, LValue table, LValue key, LValue val) {
luaUnsupportedOperation();
}
/** Get a value from a table
* @param base TODO
* @param table TODO*/
public void luaGetTable(CallFrame call, int base, LValue table, LValue key) {
* @param vm the calling vm
* @param table the table from which to get the value
* @param key the key to look up
*/
public void luaGetTable(VM vm, LValue table, LValue key) {
luaUnsupportedOperation();
}