summaryrefslogtreecommitdiff
path: root/server
diff options
context:
space:
mode:
Diffstat (limited to 'server')
-rw-r--r--server/src/service.lua15
-rw-r--r--server/src/vm/function.lua16
-rw-r--r--server/src/vm/label.lua8
-rw-r--r--server/src/vm/list.lua23
-rw-r--r--server/src/vm/local.lua8
-rw-r--r--server/src/vm/source.lua14
-rw-r--r--server/src/vm/value.lua26
7 files changed, 66 insertions, 44 deletions
diff --git a/server/src/service.lua b/server/src/service.lua
index 4fdd7f9c..41630d12 100644
--- a/server/src/service.lua
+++ b/server/src/service.lua
@@ -13,6 +13,7 @@ local localMgr = require 'vm.local'
local valueMgr = require 'vm.value'
local chainMgr = require 'vm.chain'
local functionMgr= require 'vm.function'
+local listMgr = require 'vm.list'
local ErrorCodes = {
-- Defined by JSON RPC
@@ -153,7 +154,7 @@ function mt:isWaitingCompile()
end
function mt:saveText(uri, version, text)
- self._lastLoadedVM = nil
+ self._lastLoadedVM = uri
local obj = self._file[uri]
if obj then
obj.version = version
@@ -632,7 +633,7 @@ function mt:_testMemory()
local alivedSource = 0
local deadSource = 0
for _, id in pairs(sourceMgr.watch) do
- if sourceMgr.list[id] then
+ if listMgr.get(id) then
alivedSource = alivedSource + 1
else
deadSource = deadSource + 1
@@ -653,7 +654,7 @@ function mt:_testMemory()
local alivedFunction = 0
local deadFunction = 0
for _, id in pairs(functionMgr.watch) do
- if functionMgr.list[id] then
+ if listMgr.get(id) then
alivedFunction = alivedFunction + 1
else
deadFunction = deadFunction + 1
@@ -664,19 +665,19 @@ function mt:_testMemory()
log.debug(('\n\z
State\n\z
Mem: [%.3f]kb\n\z
- \n\z
+-------------------\n\z
CachedVM: [%d]\n\z
AlivedVM: [%d]\n\z
DeadVM: [%d]\n\z
- \n\z
+-------------------\n\z
CachedSrc: [%d]\n\z
AlivedSrc: [%d]\n\z
DeadSrc: [%d]\n\z
- \n\z
+-------------------\n\z
CachedFunc:[%d]\n\z
AlivedFunc:[%d]\n\z
DeadFunc: [%d]\n\z
- \n\z
+-------------------\n\z
TotalLoc: [%d]\n\z
TotalVal: [%d]\n\z'):format(
mem,
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()