Fix bug in compiler affecting functions with many locals.
This commit is contained in:
@@ -52,7 +52,7 @@ public class LuaThread extends LuaValue implements Runnable {
|
|||||||
public LuaValue err;
|
public LuaValue err;
|
||||||
|
|
||||||
|
|
||||||
public static final int MAX_CALLSTACK = 64;
|
public static final int MAX_CALLSTACK = 256;
|
||||||
public final LuaFunction[] callstack = new LuaFunction[MAX_CALLSTACK];
|
public final LuaFunction[] callstack = new LuaFunction[MAX_CALLSTACK];
|
||||||
public int calls = 0;
|
public int calls = 0;
|
||||||
|
|
||||||
|
|||||||
@@ -68,10 +68,10 @@ public class LuaValue extends Varargs {
|
|||||||
public static final LuaString METATABLE = valueOf("__metatable");
|
public static final LuaString METATABLE = valueOf("__metatable");
|
||||||
public static final LuaString EMPTYSTRING = valueOf("");
|
public static final LuaString EMPTYSTRING = valueOf("");
|
||||||
|
|
||||||
private static int MAXLOCALS = 200;
|
private static int MAXSTACK = 250;
|
||||||
public static final LuaValue[] NILS = new LuaValue[MAXLOCALS];
|
public static final LuaValue[] NILS = new LuaValue[MAXSTACK];
|
||||||
static {
|
static {
|
||||||
for ( int i=0; i<MAXLOCALS; i++ )
|
for ( int i=0; i<MAXSTACK; i++ )
|
||||||
NILS[i] = NIL;
|
NILS[i] = NIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -38,8 +38,8 @@ import org.luaj.vm2.compiler.LexState.expdesc;
|
|||||||
|
|
||||||
public class FuncState extends LuaC {
|
public class FuncState extends LuaC {
|
||||||
class upvaldesc {
|
class upvaldesc {
|
||||||
byte k;
|
short k;
|
||||||
byte info;
|
short info;
|
||||||
};
|
};
|
||||||
|
|
||||||
static class BlockCnt {
|
static class BlockCnt {
|
||||||
@@ -129,8 +129,8 @@ public class FuncState extends LuaC {
|
|||||||
f.upvalues[f.nups] = name;
|
f.upvalues[f.nups] = name;
|
||||||
_assert (v.k == LexState.VLOCAL || v.k == LexState.VUPVAL);
|
_assert (v.k == LexState.VLOCAL || v.k == LexState.VUPVAL);
|
||||||
upvalues[f.nups] = new upvaldesc();
|
upvalues[f.nups] = new upvaldesc();
|
||||||
upvalues[f.nups].k = (byte) (v.k);
|
upvalues[f.nups].k = (short) (v.k);
|
||||||
upvalues[f.nups].info = (byte) (v.u.s.info);
|
upvalues[f.nups].info = (short) (v.u.s.info);
|
||||||
return f.nups++;
|
return f.nups++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -47,6 +47,7 @@ public class CompatibiltyTest {
|
|||||||
public void testErrors() { runTest("errors"); }
|
public void testErrors() { runTest("errors"); }
|
||||||
public void testFunctions() { runTest("functions"); }
|
public void testFunctions() { runTest("functions"); }
|
||||||
public void testIoLib() { runTest("iolib"); }
|
public void testIoLib() { runTest("iolib"); }
|
||||||
|
public void testManyUpvals() { runTest("manyupvals"); }
|
||||||
public void testMathLib() { runTest("mathlib"); }
|
public void testMathLib() { runTest("mathlib"); }
|
||||||
public void testOsLib() { runTest("oslib"); }
|
public void testOsLib() { runTest("oslib"); }
|
||||||
public void testStringLib() { runTest("stringlib"); }
|
public void testStringLib() { runTest("stringlib"); }
|
||||||
|
|||||||
38
test/lua/manyupvals.lua
Normal file
38
test/lua/manyupvals.lua
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
local t = {}
|
||||||
|
local template = [[
|
||||||
|
local f<i>
|
||||||
|
do
|
||||||
|
local result
|
||||||
|
function f<i>()
|
||||||
|
if not result then
|
||||||
|
result = f<i-2>() + f<i-1>()
|
||||||
|
end
|
||||||
|
return result
|
||||||
|
end
|
||||||
|
end
|
||||||
|
]]
|
||||||
|
t[1] = [[
|
||||||
|
local f1
|
||||||
|
f1 = function() return 1 end
|
||||||
|
]]
|
||||||
|
t[2] = [[
|
||||||
|
local f2
|
||||||
|
f2 = function() return 1 end
|
||||||
|
]]
|
||||||
|
for i = 3, 199 do
|
||||||
|
t[i] = template:gsub("<([^>]+)>", function(s)
|
||||||
|
local c = assert(loadstring('return '..s), 'could not compile: '..s)
|
||||||
|
setfenv(c, { i = i })
|
||||||
|
return c()
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
t[200] = [[
|
||||||
|
print("5th fibonacci number is", f5())
|
||||||
|
print("10th fibonacci number is", f10())
|
||||||
|
print("199th fibonacci number is", f199())
|
||||||
|
]]
|
||||||
|
|
||||||
|
local s = table.concat(t)
|
||||||
|
print(s)
|
||||||
|
f = loadstring(s)
|
||||||
|
f()
|
||||||
Reference in New Issue
Block a user