Skip to content

Commit

Permalink
Upgrade gopher-lua to v1.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
sesposito committed May 28, 2024
1 parent 24c07ac commit 0a199db
Show file tree
Hide file tree
Showing 21 changed files with 1,277 additions and 244 deletions.
2 changes: 1 addition & 1 deletion internal/gopher-lua/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -869,7 +869,7 @@ Libraries for GopherLua
- `gluasql <https://github.com/tengattack/gluasql>`_ : A native Go implementation of SQL client for the GopherLua VM.
- `purr <https://github.com/leyafo/purr>`_ : A http mock testing tool.
- `vadv/gopher-lua-libs <https://github.com/vadv/gopher-lua-libs>`_ : Some usefull libraries for GopherLua VM.
- `gluaperiphery <https://github.com/BixData/gluaperiphery>`_ : A periphery library for the GopherLua VM (GPIO, SPI, I2C, MMIO, and Serial peripheral I/O for Linux).
- `gluasocket <https://gitlab.com/megalithic-llc/gluasocket>`_ : A native Go implementation of LuaSocket for the GopherLua VM.
- `glua-async <https://github.com/CuberL/glua-async>`_ : An async/await implement for gopher-lua.
- `gopherlua-debugger <https://github.com/edolphin-ydf/gopherlua-debugger>`_ : A debugger for gopher-lua
- `gluamahonia <https://github.com/super1207/gluamahonia>`_ : An encoding converter for gopher-lua
Expand Down
10 changes: 5 additions & 5 deletions internal/gopher-lua/_glua-tests/goto.lua
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ local function foo ()
::l4:: a[#a + 1] = 4; goto l6;
::l5:: a[#a + 1] = 5; goto l4;
::l6:: assert(a[1] == 3 and a[2] == 1 and a[3] == 2 and
a[4] == 5 and a[5] == 4)
a[4] == 5 and a[5] == 4)
if not a[6] then a[6] = true; goto l3a end -- do it twice
end

Expand All @@ -115,10 +115,10 @@ end
local function foo ()
local a = {}
do
local i = 1
local k = 0
a[0] = function (y) k = y end
::l1:: do
local i = 1
local k = 0
a[0] = function (y) k = y end
::l1:: do
local x
if i > 2 then goto l2 end
a[i] = function (y) if y then x = y else return x + k end end
Expand Down
47 changes: 39 additions & 8 deletions internal/gopher-lua/_glua-tests/issues.lua
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ local x = util.fn(

local s = [=[["a"]['b'][9] - ["a"]['b'][8] > ]=]
local result = {}
for i in s:gmatch([=[[[][^%s,]*[]]]=]) do
for i in s:gmatch([=[[[][^%s,]*[]]]=]) do
table.insert(result, i)
end
assert(result[1] == [=[["a"]['b'][9]]=])
Expand Down Expand Up @@ -231,7 +231,7 @@ end
assert(test(nil) == nil)

-- issue 220
function test()
function test()
function f(v)
return v
end
Expand All @@ -245,22 +245,22 @@ test()
-- issue 222
function test()
local m = {n=2}

function m:f1()
return self:f3() >= self.n
end

function m:f2()
local v1, v2, v3 = m:f1()
assert(v1 == true)
assert(v2 == nil)
assert(v3 == nil)
end

function m:f3()
return 3
end

m:f2()
end
test()
Expand Down Expand Up @@ -333,7 +333,6 @@ end
test()

--issue #331
--[[
function test()
local select_a = function()
return select(3, "1")
Expand Down Expand Up @@ -361,7 +360,6 @@ function test()
assert(false == pcall(select_f))
end
test()
--]]

-- issue #363
-- Any expression enclosed in parentheses always results in only one value.
Expand Down Expand Up @@ -459,3 +457,36 @@ function test()
assert(c == 1)
assert(type(c) == "number")
end
test()

-- issue #452
function test()
local ok, msg = pcall(function()
local ok, msg = xpcall(function() error("fn") end, function(err) error("handler") end)
assert(not ok and msg)
error("expected to reach this.")
end)
assert(not ok)
end
test()

-- issue #455
function test()
local path = "."
local fd, _, code = io.open(path, "r")
assert(fd ~= nil)
local _, _, ecode = fd:read(1)
assert(ecode == 1)
end
test()

-- issue #459
function test()
local a, b = io.popen("ls", nil)
assert(a)
assert(b == nil)
local a, b = io.popen("ls", nil, nil)
assert(a)
assert(b == nil)
end
test()
1 change: 0 additions & 1 deletion internal/gopher-lua/_glua-tests/os.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,3 @@ assert(os.getenv("PATH") ~= "")
assert(os.getenv("_____GLUATEST______") == nil)
assert(os.setenv("_____GLUATEST______", "1"))
assert(os.getenv("_____GLUATEST______") == "1")
assert(os.setenv("_____GLUATEST______", ""))
56 changes: 32 additions & 24 deletions internal/gopher-lua/_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ func freeCallFrameStackSegment(seg *callFrameStackSegment) {
segmentPool.Put(seg)
}

// newAutoGrowingCallFrameStack allocates a new stack for a lua state, which will auto grow up to a max size of at least maxSize.
// newCallFrameStack allocates a new stack for a lua state, which will auto grow up to a max size of at least maxSize.
// it will actually grow up to the next segment size multiple after maxSize, where the segment size is dictated by
// FramesPerSegment.
func newAutoGrowingCallFrameStack(maxSize int) callFrameStack {
Expand Down Expand Up @@ -398,25 +398,26 @@ func (rg *registry) forceResize(newSize int) {
copy(newSlice, rg.array[:rg.top]) // should we copy the area beyond top? there shouldn't be any valid values there so it shouldn't be necessary.
rg.array = newSlice
}
func (rg *registry) SetTop(top int) {
// +inline-call rg.checkSize top
oldtop := rg.top
rg.top = top
for i := oldtop; i < rg.top; i++ {

func (rg *registry) SetTop(topi int) { // +inline-start
// +inline-call rg.checkSize topi
oldtopi := rg.top
rg.top = topi
for i := oldtopi; i < rg.top; i++ {
rg.array[i] = LNil
}
// values beyond top don't need to be valid LValues, so setting them to nil is fine
// setting them to nil rather than LNil lets us invoke the golang memclr opto
if rg.top < oldtop {
nilRange := rg.array[rg.top:oldtop]
if rg.top < oldtopi {
nilRange := rg.array[rg.top:oldtopi]
for i := range nilRange {
nilRange[i] = nil
}
}
//for i := rg.top; i < oldtop; i++ {
// rg.array[i] = LNil
//}
}
} // +inline-end

func (rg *registry) Top() int {
return rg.top
Expand Down Expand Up @@ -498,34 +499,34 @@ func (rg *registry) FillNil(regm, n int) { // +inline-start
func (rg *registry) Insert(value LValue, reg int) {
top := rg.Top()
if reg >= top {
rg.Set(reg, value)
// +inline-call rg.Set reg value
return
}
top--
for ; top >= reg; top-- {
// FIXME consider using copy() here if Insert() is called enough
rg.Set(top+1, rg.Get(top))
// +inline-call rg.Set top+1 rg.Get(top)
}
rg.Set(reg, value)
// +inline-call rg.Set reg value
}

func (rg *registry) Set(reg int, val LValue) {
newSize := reg + 1
func (rg *registry) Set(regi int, vali LValue) { // +inline-start
newSize := regi + 1
// +inline-call rg.checkSize newSize
rg.array[reg] = val
if reg >= rg.top {
rg.top = reg + 1
rg.array[regi] = vali
if regi >= rg.top {
rg.top = regi + 1
}
}
} // +inline-end

func (rg *registry) SetNumber(reg int, val LNumber) {
newSize := reg + 1
func (rg *registry) SetNumber(regi int, vali LNumber) { // +inline-start
newSize := regi + 1
// +inline-call rg.checkSize newSize
rg.array[reg] = rg.alloc.LNumber2I(val)
if reg >= rg.top {
rg.top = reg + 1
rg.array[regi] = rg.alloc.LNumber2I(vali)
if regi >= rg.top {
rg.top = regi + 1
}
}
} // +inline-end

func (rg *registry) IsFull() bool {
return rg.top >= cap(rg.array)
Expand Down Expand Up @@ -769,6 +770,9 @@ func (ls *LState) isStarted() bool {

func (ls *LState) kill() {
ls.Dead = true
if ls.ctxCancelFn != nil {
ls.ctxCancelFn()
}
}

func (ls *LState) indexToReg(idx int) int {
Expand Down Expand Up @@ -1406,6 +1410,7 @@ func (ls *LState) NewThread() (*LState, context.CancelFunc) {
if ls.ctx != nil {
thread.mainLoop = mainLoopWithContext
thread.ctx, f = context.WithCancel(ls.ctx)
thread.ctxCancelFn = f
}
return thread, f
}
Expand Down Expand Up @@ -1855,6 +1860,9 @@ func (ls *LState) PCall(nargs, nret int, errfunc *LFunction) (err error) {
err = rcv.(*ApiError)
err.(*ApiError).StackTrace = ls.stackTrace(0)
}
ls.stack.SetSp(sp)
ls.currentFrame = ls.stack.Last()
ls.reg.SetTop(base)
}
}()
ls.Call(1, 1)
Expand Down
Loading

0 comments on commit 0a199db

Please sign in to comment.