summaryrefslogtreecommitdiff
path: root/script/vm/def.lua
diff options
context:
space:
mode:
Diffstat (limited to 'script/vm/def.lua')
-rw-r--r--script/vm/def.lua33
1 files changed, 10 insertions, 23 deletions
diff --git a/script/vm/def.lua b/script/vm/def.lua
index 22c52be1..98d41fbd 100644
--- a/script/vm/def.lua
+++ b/script/vm/def.lua
@@ -7,7 +7,7 @@ local localID = require 'vm.local-id'
local globalMgr = require 'vm.global-manager'
local nodeMgr = require 'vm.node'
-local simpleMap
+local simpleSwitch
local function searchGetLocal(source, node, pushResult)
local key = guide.getKeyName(source)
@@ -21,7 +21,7 @@ local function searchGetLocal(source, node, pushResult)
end
end
-simpleMap = util.switch()
+simpleSwitch = util.switch()
: case 'local'
: call(function (source, pushResult)
pushResult(source)
@@ -42,13 +42,13 @@ simpleMap = util.switch()
: case 'getlocal'
: case 'setlocal'
: call(function (source, pushResult)
- simpleMap['local'](source.node, pushResult)
+ simpleSwitch('local', source.node, pushResult)
end)
: case 'field'
: call(function (source, pushResult)
local parent = source.parent
if parent.type ~= 'tablefield' then
- simpleMap[parent.type](parent, pushResult)
+ simpleSwitch(parent.type, parent, pushResult)
end
end)
: case 'setfield'
@@ -74,9 +74,8 @@ simpleMap = util.switch()
pushResult(source.node)
end
end)
- : getMap()
-local searchFieldMap = util.switch()
+local searchFieldSwitch = util.switch()
: case 'table'
: call(function (node, key, pushResult)
for _, field in ipairs(node) do
@@ -126,10 +125,9 @@ local searchFieldMap = util.switch()
end
end
end)
- : getMap()
local searchByParentNode
-local nodeMap = util.switch()
+local nodeSwitch = util.switch()
: case 'field'
: case 'method'
: call(function (source, pushResult)
@@ -148,9 +146,7 @@ local nodeMap = util.switch()
end
local key = guide.getKeyName(source)
for pn in nodeMgr.eachNode(parentNode) do
- if searchFieldMap[pn.type] then
- searchFieldMap[pn.type](pn, key, pushResult)
- end
+ searchFieldSwitch(pn.type, pn, key, pushResult)
end
end)
: case 'doc.see.field'
@@ -160,20 +156,14 @@ local nodeMap = util.switch()
return
end
for pn in nodeMgr.eachNode(parentNode) do
- if searchFieldMap[pn.type] then
- searchFieldMap[pn.type](pn, source[1], pushResult)
- end
+ searchFieldSwitch(pn.type, pn, source[1], pushResult)
end
end)
- : getMap()
---@param source parser.object
---@param pushResult fun(src: parser.object)
local function searchBySimple(source, pushResult)
- local simple = simpleMap[source.type]
- if simple then
- simple(source, pushResult)
- end
+ simpleSwitch(source.type, source, pushResult)
end
---@param source parser.object
@@ -193,10 +183,7 @@ end
---@param source parser.object
---@param pushResult fun(src: parser.object)
function searchByParentNode(source, pushResult)
- local node = nodeMap[source.type]
- if node then
- node(source, pushResult)
- end
+ nodeSwitch(source.type, source, pushResult)
end
local function searchByNode(source, pushResult)