diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2022-03-08 20:40:35 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2022-03-08 20:40:35 +0800 |
commit | 429a75cb3564b3a9a612fde78aeb7aa937f4a683 (patch) | |
tree | 72e24007af8fb31ea81dfe43bc4f0f60d10bba80 | |
parent | 6ef8cb96f7834c99e998b49a4b8632a784b67e89 (diff) | |
download | lua-language-server-429a75cb3564b3a9a612fde78aeb7aa937f4a683.zip |
stash
-rw-r--r-- | script/vm/compiler.lua | 37 | ||||
-rw-r--r-- | script/vm/value.lua | 45 |
2 files changed, 82 insertions, 0 deletions
diff --git a/script/vm/compiler.lua b/script/vm/compiler.lua index 9e804dfb..ec2834bd 100644 --- a/script/vm/compiler.lua +++ b/script/vm/compiler.lua @@ -553,6 +553,7 @@ local compilerMap = util.switch() local result = valueMgr.test(source[1]) if result == nil then nodeMgr.setNode(source, globalMgr.getGlobal('type', 'boolean')) + return else nodeMgr.setNode(source, { type = 'boolean', @@ -561,16 +562,52 @@ local compilerMap = util.switch() parent = source, [1] = not result, }) + return end end if source.op.type == '#' then nodeMgr.setNode(source, globalMgr.getGlobal('type', 'integer')) + return end if source.op.type == '-' then nodeMgr.setNode(source, globalMgr.getGlobal('type', 'number')) + return end if source.op.type == '~' then nodeMgr.setNode(source, globalMgr.getGlobal('type', 'integer')) + return + end + end) + : case 'binary' + : call(function (source) + if source.op.type == 'and' then + local r1 = valueMgr.test(source[1]) + if r1 == true then + nodeMgr.setNode(source, m.compileNode(source[2])) + return + end + if r1 == false then + nodeMgr.setNode(source, m.compileNode(source[1])) + return + end + nodeMgr.setNode(source, globalMgr.getGlobal('type', 'boolean')) + return + end + if source.op.type == 'or' then + local r1 = valueMgr.test(source[1]) + if r1 == true then + nodeMgr.setNode(source, m.compileNode(source[1])) + return + end + if r1 == false then + nodeMgr.setNode(source, m.compileNode(source[2])) + return + end + nodeMgr.setNode(source, globalMgr.getGlobal('type', 'boolean')) + return + end + if source.op.type == '==' then + end end) : getMap() diff --git a/script/vm/value.lua b/script/vm/value.lua index f2708de1..259dc56a 100644 --- a/script/vm/value.lua +++ b/script/vm/value.lua @@ -1,4 +1,5 @@ local nodeMgr = require 'vm.node' +local guide = require 'parser.guide' ---@class vm.value-manager local m = {} @@ -39,4 +40,48 @@ function m.test(source) end end +---@param v vm.node +---@return string +local function getUnique(v) + if v.type == 'local' then + return ('loc:%s@%d'):format(guide.getUri(v), v.start) + end + if v.type == 'global' then + return ('%s:%s'):format(v.cate, v.name) + end + if v.type == 'boolean' then + return ('bool:%s'):format(v[1]) + end + if v.type == 'number' then + return ('num:%s'):format(v[1]) + end + if v.type == 'integer' then + return ('num:%s'):format(v[1]) + end +end + +local function nodeToMap(node) + local map = {} + for n in nodeMgr.eachNode(node) do + if n.type == 'local' then + map[n] = true + end + if n.type == 'global' then + + end + end + return map +end + +---@param a vm.node +---@param b vm.node +---@return boolean|nil +function m.equal(a, b) + local compiler = require 'vm.compiler' + local nodeA = compiler.compileNode(a) + local nodeB = compiler.compileNode(b) + local mapA = {} + local mapB = {} +end + return m |