diff options
Diffstat (limited to 'server/src/vm')
-rw-r--r-- | server/src/vm/function.lua | 16 | ||||
-rw-r--r-- | server/src/vm/label.lua | 8 | ||||
-rw-r--r-- | server/src/vm/list.lua | 23 | ||||
-rw-r--r-- | server/src/vm/local.lua | 8 | ||||
-rw-r--r-- | server/src/vm/source.lua | 14 | ||||
-rw-r--r-- | server/src/vm/value.lua | 26 |
6 files changed, 58 insertions, 37 deletions
diff --git a/server/src/vm/function.lua b/server/src/vm/function.lua index c6915f25..2db056c4 100644 --- a/server/src/vm/function.lua +++ b/server/src/vm/function.lua @@ -2,9 +2,8 @@ local createMulti = require 'vm.multi' local valueMgr = require 'vm.value' local localMgr = require 'vm.local' local sourceMgr = require 'vm.source' +local listMgr = require 'vm.list' -local Id = 0 -local List = {} local Watch = setmetatable({}, {__mode = 'kv'}) local mt = {} @@ -14,7 +13,7 @@ mt._runed = 0 mt._top = 0 function mt:getSource() - return sourceMgr.list[self.source] + return listMgr.get(self.source) end function mt:getUri() @@ -294,7 +293,7 @@ function mt:getSource() if self._removed then return nil end - return sourceMgr.list[self.source] + return listMgr.get(self.source) end function mt:kill() @@ -302,7 +301,7 @@ function mt:kill() return end self._removed = true - List[self.id] = nil + listMgr.clear(self.id) end local function create(source) @@ -313,23 +312,22 @@ local function create(source) if not id then error('Not instanted source') end - Id = Id + 1 local self = setmetatable({ source = id, - id = id, locals = {}, finishs = {}, args = {}, argValues = {}, }, mt) self:push(source) + + local id = listMgr.add(self) + self.id = id Watch[self] = id - List[id] = self return self end return { create = create, watch = Watch, - list = List, } diff --git a/server/src/vm/label.lua b/server/src/vm/label.lua index 9ed62ca3..c0e0dfb8 100644 --- a/server/src/vm/label.lua +++ b/server/src/vm/label.lua @@ -1,4 +1,4 @@ -local sourceMgr = require 'vm.source' +local listMgr = require 'vm.list' local Sort = 0 @@ -34,7 +34,7 @@ end function mt:eachInfo(callback) local list = {} for srcId, info in pairs(self._info) do - local src = sourceMgr.list[srcId] + local src = listMgr.get(srcId) if src then list[#list+1] = info else @@ -46,7 +46,7 @@ function mt:eachInfo(callback) end) for i = 1, #list do local info = list[i] - local res = callback(info, sourceMgr.list[info.source]) + local res = callback(info, listMgr.get(info.source)) if res ~= nil then return res end @@ -55,7 +55,7 @@ function mt:eachInfo(callback) end function mt:getSource() - return sourceMgr.list[self.source] + return listMgr.get(self.source) end return function (name, source) diff --git a/server/src/vm/list.lua b/server/src/vm/list.lua new file mode 100644 index 00000000..f0f2bd3e --- /dev/null +++ b/server/src/vm/list.lua @@ -0,0 +1,23 @@ +local Id = 0 +local List = {} + +local function get(id) + return List[id] +end + +local function add(obj) + Id = Id + 1 + List[Id] = obj + return Id +end + +local function clear(id) + List[id] = nil +end + +return { + get = get, + add = add, + clear = clear, + list = List, +} diff --git a/server/src/vm/local.lua b/server/src/vm/local.lua index 9b981c1d..b8a387fe 100644 --- a/server/src/vm/local.lua +++ b/server/src/vm/local.lua @@ -1,4 +1,4 @@ -local sourceMgr = require 'vm.source' +local listMgr = require 'vm.list' local Sort = 0 local Watch = setmetatable({}, {__mode = 'kv'}) @@ -44,7 +44,7 @@ end function mt:eachInfo(callback) local list = {} for srcId, info in pairs(self._info) do - local src = sourceMgr.list[srcId] + local src = listMgr.get(srcId) if src then list[#list+1] = info else @@ -56,7 +56,7 @@ function mt:eachInfo(callback) end) for i = 1, #list do local info = list[i] - local res = callback(info, sourceMgr.list[info.source]) + local res = callback(info, listMgr.get(info.source)) if res ~= nil then return res end @@ -117,7 +117,7 @@ function mt:close(pos) end function mt:getSource() - return sourceMgr.list[self.source] + return listMgr.get(self.source) end local function create(name, source, value) diff --git a/server/src/vm/source.lua b/server/src/vm/source.lua index af8b9ab3..8de44b1b 100644 --- a/server/src/vm/source.lua +++ b/server/src/vm/source.lua @@ -1,3 +1,5 @@ +local listMgr = require 'vm.list' + local mt = {} mt.__index = mt mt.uri = '' @@ -5,8 +7,6 @@ mt.start = 0 mt.finish = 0 mt.id = 0 -local Id = 0 -local List = {} local Watch = setmetatable({}, {__mode = 'k'}) function mt:bindLocal(loc, action) @@ -89,7 +89,7 @@ end function mt:kill() self._dead = true - List[self.id] = nil + listMgr.clear(self.id) end function mt:isDead() @@ -100,10 +100,9 @@ local function instant(source) if source.id then return false end - Id = Id + 1 - source.id = Id - List[Id] = source - Watch[source] = Id + local id = listMgr.add(source) + source.id = id + Watch[source] = id setmetatable(source, mt) return true end @@ -116,7 +115,6 @@ end return { instant = instant, - list = List, watch = Watch, dummy = dummy, } diff --git a/server/src/vm/value.lua b/server/src/vm/value.lua index ad1deccf..35f92b5d 100644 --- a/server/src/vm/value.lua +++ b/server/src/vm/value.lua @@ -1,6 +1,6 @@ local libraryBuilder = require 'vm.library' local library = require 'core.library' -local sourceMgr = require 'vm.source' +local listMgr = require 'vm.list' local Sort = 0 local Watch = setmetatable({}, {__mode = 'kv'}) @@ -45,7 +45,7 @@ local function isDeadChild(value, index) return false end for srcId, info in pairs(value._info) do - local src = sourceMgr.list[srcId] + local src = listMgr.get(srcId) if src and (info.type == 'set child' or info.type == 'get child') and info[1] == index @@ -207,7 +207,7 @@ function mt:rawEach(callback, foundIndex) local infos = self._info local count = 0 for srcId, info in pairs(infos) do - local src = sourceMgr.list[srcId] + local src = listMgr.get(srcId) if src and (info.type == 'set child' or info.type == 'get child') then @@ -288,7 +288,7 @@ function mt:mergeValue(value) local infos = self._info for srcId, info in pairs(value._info) do - local src = sourceMgr.list[srcId] + local src = listMgr.get(srcId) if src and not infos[srcId] then infos[srcId] = info infos._count = (infos._count or 0) + 1 @@ -342,7 +342,7 @@ function mt:addInfo(tp, source, ...) if self._global and infos._count > (infos._limit or 10) then local count = 0 for srcId in pairs(infos) do - local src = sourceMgr.list[srcId] + local src = listMgr.get(srcId) if src then count = count + 1 else @@ -358,7 +358,7 @@ function mt:eachInfo(callback) local infos = self._info local list = {} for srcId, info in pairs(infos) do - local src = sourceMgr.list[srcId] + local src = listMgr.get(srcId) if src then list[#list+1] = info else @@ -372,7 +372,7 @@ function mt:eachInfo(callback) end) for i = 1, #list do local info = list[i] - local res = callback(info, sourceMgr.list[info.source]) + local res = callback(info, listMgr.get(info.source)) if res ~= nil then return res end @@ -381,11 +381,12 @@ function mt:eachInfo(callback) end function mt:setFunction(func) - self._func = func + self._func = func.id end function mt:getFunction() - local func = self._func + local id = self._func + local func = listMgr.get(id) if not func then return nil end @@ -393,9 +394,10 @@ function mt:getFunction() return nil end if not func:getSource() then - self._func = nil + func = nil + listMgr.clear(id) end - return self._func + return func end function mt:setLib(lib) @@ -425,7 +427,7 @@ function mt:get(name) end function mt:getSource() - return sourceMgr.list[self.source] + return listMgr.get(self.source) end function mt:markGlobal() |