Fix a few VM issues which were causing subtle failures in the test cases.
Includes a new VM method, newCall, which must be called before pushing a call onto the stack to make sure that base is set correctly. A couple of weird issues remain with autoload.lua.
This commit is contained in:
@@ -1,11 +1,14 @@
|
||||
-- Clear out builtin math package
|
||||
math = nil
|
||||
|
||||
local function autoload(table, key)
|
||||
local chunk = loadfile("/"..key..".luac")
|
||||
local chunk = loadfile(key..".luac")
|
||||
table[key] = chunk()
|
||||
end
|
||||
|
||||
autoload_mt = { __index = autoload }
|
||||
|
||||
setmetatable(_G, autoload_mt)
|
||||
setmetatable(_G, { __index = autoload } )
|
||||
|
||||
-- local result = math.sqrt(9.0)
|
||||
-- print("x=", result)
|
||||
print("square root of 9.0 is ", math.sqrt(9.0))
|
||||
print("math.pi=", math.pi);
|
||||
|
||||
Binary file not shown.
4
src/test/res/calls-expected.out
Normal file
4
src/test/res/calls-expected.out
Normal file
@@ -0,0 +1,4 @@
|
||||
15
|
||||
15
|
||||
1.2246467991473532E-16
|
||||
1.2246467991473532E-16
|
||||
24
src/test/res/calls.lua
Normal file
24
src/test/res/calls.lua
Normal file
@@ -0,0 +1,24 @@
|
||||
local function f(x)
|
||||
-- tailcall to a builtin
|
||||
return math.sin(x)
|
||||
end
|
||||
|
||||
local function factorial(i)
|
||||
local function helper(sum, n)
|
||||
if n <= 0 then
|
||||
return sum
|
||||
else
|
||||
-- tail call to a nested Lua function
|
||||
return helper(n + sum, n - 1)
|
||||
end
|
||||
end
|
||||
return helper(0, i)
|
||||
end
|
||||
|
||||
local result1 = factorial(5)
|
||||
print(result1)
|
||||
print(factorial(5))
|
||||
|
||||
local result2 = f(math.pi)
|
||||
print(result2)
|
||||
print(f(math.pi))
|
||||
BIN
src/test/res/calls.luac
Normal file
BIN
src/test/res/calls.luac
Normal file
Binary file not shown.
Reference in New Issue
Block a user