summaryrefslogtreecommitdiff
path: root/server/src
diff options
context:
space:
mode:
Diffstat (limited to 'server/src')
-rw-r--r--server/src/vm/function.lua31
-rw-r--r--server/src/vm/vm.lua4
2 files changed, 34 insertions, 1 deletions
diff --git a/server/src/vm/function.lua b/server/src/vm/function.lua
index cb437d9e..2fe1ee41 100644
--- a/server/src/vm/function.lua
+++ b/server/src/vm/function.lua
@@ -21,6 +21,9 @@ function mt:getUri()
end
function mt:push(source)
+ if self._removed then
+ return
+ end
self._top = self._top + 1
self.locals[self._top] = {}
self.finishs[self._top] = source and source.finish or math.maxinteger
@@ -37,6 +40,9 @@ function mt:pop()
end
function mt:saveLocal(name, loc)
+ if self._removed then
+ return
+ end
if loc.type ~= 'local' then
error('saveLocal必须是local')
end
@@ -76,6 +82,9 @@ function mt:eachLocal(callback)
end
function mt:saveLabel(label)
+ if self._removed then
+ return
+ end
if not self._label then
self._label = {}
end
@@ -95,6 +104,9 @@ function mt:loadLabel(name)
end
function mt:setReturn(index, value)
+ if self._removed then
+ return
+ end
self:set('hasReturn', true)
if not self.returns then
self.returns = createMulti()
@@ -105,6 +117,9 @@ function mt:setReturn(index, value)
end
function mt:mergeReturn(index, value)
+ if self._removed then
+ return
+ end
self:set('hasReturn', true)
if not self.returns then
self.returns = createMulti()
@@ -119,6 +134,9 @@ function mt:mergeReturn(index, value)
end
function mt:getReturn(index)
+ if self._removed then
+ return nil
+ end
if self.maxReturns and index and self.maxReturns < index then
return nil
end
@@ -164,11 +182,15 @@ function mt:needSkip()
end
function mt:run(vm)
- self._runed = self._runed + 1
+ if self._removed then
+ return
+ end
if not self:getSource() then
return
end
+ self._runed = self._runed + 1
+
-- 第一次运行函数时,创建函数的参数
if self._runed == 1 then
-- 如果是面向对象形式的函数,创建隐藏的参数self
@@ -267,9 +289,16 @@ function mt:get(name)
end
function mt:getSource()
+ if self._removed then
+ return nil
+ end
return sourceMgr.list[self.source]
end
+function mt:kill()
+ self._removed = true
+end
+
local function create(source)
if not source then
error('Function need source')
diff --git a/server/src/vm/vm.lua b/server/src/vm/vm.lua
index ac642056..4b044916 100644
--- a/server/src/vm/vm.lua
+++ b/server/src/vm/vm.lua
@@ -1148,6 +1148,10 @@ function mt:remove()
source:kill()
end
self.sources = nil
+ for _, func in ipairs(self.funcs) do
+ func:kill()
+ end
+ self.funcs = nil
end
local function compile(vm, ast, lsp, uri)