summaryrefslogtreecommitdiff
path: root/server/src/vm
diff options
context:
space:
mode:
Diffstat (limited to 'server/src/vm')
-rw-r--r--server/src/vm/label.lua28
-rw-r--r--server/src/vm/source.lua4
-rw-r--r--server/src/vm/vm.lua23
3 files changed, 46 insertions, 9 deletions
diff --git a/server/src/vm/label.lua b/server/src/vm/label.lua
index f8f8eb81..b82e98e8 100644
--- a/server/src/vm/label.lua
+++ b/server/src/vm/label.lua
@@ -1,3 +1,11 @@
+local function getDefaultSource()
+ return {
+ start = 0,
+ finish = 0,
+ uri = '',
+ }
+end
+
local mt = {}
mt.__index = mt
mt.type = 'label'
@@ -6,6 +14,26 @@ function mt:getName()
return self.name
end
+function mt:addInfo(tp, source)
+ if source and not source.start then
+ error('Miss start: ' .. table.dump(source))
+ end
+ self[#self+1] = {
+ type = tp,
+ source = source or getDefaultSource(),
+ }
+end
+
+function mt:eachInfo(callback)
+ for _, info in ipairs(self) do
+ local res = callback(info)
+ if res ~= nil then
+ return res
+ end
+ end
+ return nil
+end
+
return function (name, source)
local self = setmetatable({
name = name,
diff --git a/server/src/vm/source.lua b/server/src/vm/source.lua
index a4839c69..5406298b 100644
--- a/server/src/vm/source.lua
+++ b/server/src/vm/source.lua
@@ -10,9 +10,11 @@ function mt:bindLocal(loc)
end
end
-function mt:bindLabel(label)
+function mt:bindLabel(label, action)
if label then
self._bindLabel = label
+ self._action = action
+ label:addInfo(action, self)
else
return self._bindLabel
end
diff --git a/server/src/vm/vm.lua b/server/src/vm/vm.lua
index 3db7900f..eeb08b76 100644
--- a/server/src/vm/vm.lua
+++ b/server/src/vm/vm.lua
@@ -688,10 +688,15 @@ end
function mt:doLabel(source)
local name = source[1]
- self:createLabel(name, source)
+ local label = self:loadLabel(name)
+ if label then
+ self:bindLabel(source, label, 'set')
+ else
+ label = self:createLabel(name, source, 'set')
+ end
end
-function mt:createLabel(name, source)
+function mt:createLabel(name, source, action)
local label = self:bindLabel(source)
if label then
self:saveLabel(label)
@@ -700,15 +705,17 @@ function mt:createLabel(name, source)
label = createLabel(name, source)
self:saveLabel(label)
- self:bindLabel(source, label)
+ self:bindLabel(source, label, action)
return label
end
function mt:doGoTo(source)
local name = source[1]
local label = self:loadLabel(name)
- if not label then
- label = self:createLabel(name, source)
+ if label then
+ self:bindLabel(source, label, 'get')
+ else
+ label = self:createLabel(name, source, 'get')
end
end
@@ -1008,7 +1015,7 @@ function mt:saveLabel(label)
end
function mt:loadLabel(name)
- return self.currentFunction:loadLocal(name)
+ return self.currentFunction:loadLabel(name)
end
function mt:loadDots(expect)
@@ -1038,10 +1045,10 @@ function mt:bindLocal(source, loc)
end
end
-function mt:bindLabel(source, label)
+function mt:bindLabel(source, label, action)
self:instantSource(source)
if label then
- source:bindLabel(label)
+ source:bindLabel(label, action)
else
return source:bindLabel()
end