From 18ef2f600c3f389e6984e2366e8b0c93d30d5792 Mon Sep 17 00:00:00 2001 From: sumneko Date: Fri, 11 Mar 2022 23:26:01 +0800 Subject: update --- script/vm/node.lua | 3 +++ script/vm/type.lua | 34 ++++++++++++++++++++++++++++++---- 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/script/vm/node.lua b/script/vm/node.lua index 082a5e87..b8b7917d 100644 --- a/script/vm/node.lua +++ b/script/vm/node.lua @@ -16,6 +16,9 @@ function m.mergeNode(a, b) if not b then return a end + if not a then + return b + end if a.type == 'union' then a:merge(b) return a diff --git a/script/vm/type.lua b/script/vm/type.lua index 5bdc975b..8b80d4f3 100644 --- a/script/vm/type.lua +++ b/script/vm/type.lua @@ -78,13 +78,26 @@ function m.getTableValue(tnode, knode) if tn.type == 'doc.type.table' then for _, field in ipairs(tn.fields) do if m.isSubType(field.name, knode) then - result = nodeMgr.mergeNode(compiler.compileNode(field.extends), result) + result = nodeMgr.mergeNode(result, compiler.compileNode(field.extends)) end end end if tn.type == 'doc.type.array' then if m.isSubType(globalMgr.getGlobal('type', 'integer'), knode) then - result = nodeMgr.mergeNode(compiler.compileNode(tn.node), result) + result = nodeMgr.mergeNode(result, compiler.compileNode(tn.node)) + end + end + if tn.type == 'table' then + for _, field in ipairs(tn) do + if field.type == 'tableindex' then + result = nodeMgr.mergeNode(result, compiler.compileNode(field.value)) + end + if field.type == 'tablefield' then + result = nodeMgr.mergeNode(result, compiler.compileNode(field.value)) + end + if field.type == 'tableexp' then + result = nodeMgr.mergeNode(result, compiler.compileNode(field.value)) + end end end end @@ -99,13 +112,26 @@ function m.getTableKey(tnode, vnode) if tn.type == 'doc.type.table' then for _, field in ipairs(tn.fields) do if m.isSubType(field.extends, vnode) then - result = nodeMgr.mergeNode(compiler.compileNode(field.name), result) + result = nodeMgr.mergeNode(result, compiler.compileNode(field.name)) end end end if tn.type == 'doc.type.array' then if m.isSubType(tn.node, vnode) then - result = nodeMgr.mergeNode(globalMgr.getGlobal('type', 'integer'), result) + result = nodeMgr.mergeNode(result, globalMgr.getGlobal('type', 'integer')) + end + end + if tn.type == 'table' then + for _, field in ipairs(tn) do + if field.type == 'tableindex' then + result = nodeMgr.mergeNode(result, compiler.compileNode(field.index)) + end + if field.type == 'tablefield' then + result = nodeMgr.mergeNode(result, globalMgr.getGlobal('type', 'string')) + end + if field.type == 'tableexp' then + result = nodeMgr.mergeNode(result, globalMgr.getGlobal('type', 'integer')) + end end end end -- cgit v1.2.3