diff options
Diffstat (limited to 'script/vm')
-rw-r--r-- | script/vm/compiler.lua | 10 | ||||
-rw-r--r-- | script/vm/value.lua | 18 |
2 files changed, 10 insertions, 18 deletions
diff --git a/script/vm/compiler.lua b/script/vm/compiler.lua index bf0cc44b..1ba20785 100644 --- a/script/vm/compiler.lua +++ b/script/vm/compiler.lua @@ -1033,13 +1033,14 @@ local binarySwich = util.switch() : call(function (source) local node1 = vm.compileNode(source[1]) local node2 = vm.compileNode(source[2]) - local r1 = vm.testCondition(source[1]) + local r1 = vm.testCondition(source[1]) if r1 == true then vm.setNode(source, node2) elseif r1 == false then vm.setNode(source, node1) else - vm.setNode(source, node2) + local node = node1:copy():setFalsy():merge(node2) + vm.setNode(source, node) end end) : case 'or' @@ -1052,9 +1053,8 @@ local binarySwich = util.switch() elseif r1 == false then vm.setNode(source, node2) else - vm.getNode(source):merge(node1) - vm.getNode(source):setTruthy() - vm.getNode(source):merge(node2) + local node = node1:copy():setTruthy():merge(node2) + vm.setNode(source, node) end end) : case '==' diff --git a/script/vm/value.lua b/script/vm/value.lua index 83265603..c4f8e96d 100644 --- a/script/vm/value.lua +++ b/script/vm/value.lua @@ -22,24 +22,16 @@ function vm.testCondition(source) if n[1] == false then hasFalse = true end - end - if n.type == 'global' and n.cate == 'type' then - if n.name == 'true' then - hasTrue = true - end + elseif n.type == 'global' and n.cate == 'type' then if n.name == 'false' or n.name == 'nil' then hasFalse = true + else + hasTrue = true end - end - if n.type == 'nil' then + elseif n.type == 'nil' then hasFalse = true - end - if n.type == 'string' - or n.type == 'number' - or n.type == 'integer' - or n.type == 'table' - or n.type == 'function' then + elseif guide.isLiteral(n) then hasTrue = true end end |