diff options
Diffstat (limited to 'script/vm')
-rw-r--r-- | script/vm/compiler.lua | 3 | ||||
-rw-r--r-- | script/vm/node.lua | 27 |
2 files changed, 29 insertions, 1 deletions
diff --git a/script/vm/compiler.lua b/script/vm/compiler.lua index e361d706..1936fc75 100644 --- a/script/vm/compiler.lua +++ b/script/vm/compiler.lua @@ -1309,7 +1309,8 @@ local compilerSwitch = util.switch() end if src.value then if src.value.type == 'table' then - vm.setNode(src, vm.createNode(src.value), true) + vm.setNode(src, vm.createNode(src.value)) + vm.setNode(src, node:copy():asTable()) else vm.setNode(src, vm.compileNode(src.value), true) end diff --git a/script/vm/node.lua b/script/vm/node.lua index 45e5e6c4..f0d0b0ba 100644 --- a/script/vm/node.lua +++ b/script/vm/node.lua @@ -227,6 +227,7 @@ function mt:remove(name) or (c.type == 'doc.type.boolean' and name == 'false' and c[1] == false) or (c.type == 'doc.type.table' and name == 'table') or (c.type == 'doc.type.array' and name == 'table') + or (c.type == 'doc.type.sign' and name == 'table') or (c.type == 'doc.type.function' and name == 'function') then table.remove(self, index) self[c] = nil @@ -247,6 +248,7 @@ function mt:narrow(name) or (c.type == 'doc.type.boolean' and name == 'boolean') or (c.type == 'doc.type.table' and name == 'table') or (c.type == 'doc.type.array' and name == 'table') + or (c.type == 'doc.type.sign' and name == 'table') or (c.type == 'doc.type.function' and name == 'function') then goto CONTINUE end @@ -328,6 +330,31 @@ function mt:hasName(name) return false end +---@return vm.node +function mt:asTable() + self.optional = nil + for index = #self, 1, -1 do + local c = self[index] + if c.type == 'table' + or c.type == 'doc.type.table' + or c.type == 'doc.type.array' + or c.type == 'doc.type.sign' then + goto CONTINUE + end + if c.type == 'global' and c.cate == 'type' then + ---@cast c vm.global + if c.name == 'table' + or not guide.isBasicType(c.name) then + goto CONTINUE + end + end + table.remove(self, index) + self[c] = nil + ::CONTINUE:: + end + return self +end + ---@return fun():vm.node.object function mt:eachObject() local i = 0 |