diff options
Diffstat (limited to 'script-beta/vm/getInfer.lua')
-rw-r--r-- | script-beta/vm/getInfer.lua | 310 |
1 files changed, 0 insertions, 310 deletions
diff --git a/script-beta/vm/getInfer.lua b/script-beta/vm/getInfer.lua index e98ac1a0..3357b912 100644 --- a/script-beta/vm/getInfer.lua +++ b/script-beta/vm/getInfer.lua @@ -123,316 +123,6 @@ local function checkLiteral(source) end end -local function checkUnary(source) - if source.type ~= 'unary' then - return - end - local op = source.op - if op.type == 'not' then - local checkTrue = vm.checkTrue(source[1]) - local value = nil - if checkTrue == true then - value = false - elseif checkTrue == false then - value = true - end - return alloc { - type = 'boolean', - value = value, - source = source, - } - elseif op.type == '#' then - return alloc { - type = 'integer', - source = source, - } - elseif op.type == '~' then - local l = vm.getLiteral(source[1], 'integer') - return alloc { - type = 'integer', - value = l and ~l or nil, - source = source, - } - elseif op.type == '-' then - local v = vm.getLiteral(source[1], 'integer') - if v then - return alloc { - type = 'integer', - value = - v, - source = source, - } - end - v = vm.getLiteral(source[1], 'number') - return alloc { - type = 'number', - value = v and -v or nil, - source = source, - } - end -end - -local function mathCheck(a, b) - local v1 = vm.getLiteral(a, 'integer') or vm.getLiteral(a, 'number') - local v2 = vm.getLiteral(b, 'integer') or vm.getLiteral(a, 'number') - local int = vm.hasType(a, 'integer') - and vm.hasType(b, 'integer') - and not vm.hasType(a, 'number') - and not vm.hasType(b, 'number') - return int and 'integer' or 'number', v1, v2 -end - -local function checkBinary(source) - if source.type ~= 'binary' then - return - end - local op = source.op - if op.type == 'and' then - local isTrue = vm.checkTrue(source[1]) - if isTrue == true then - return vm.getInfers(source[2]) - elseif isTrue == false then - return vm.getInfers(source[1]) - else - return merge( - vm.getInfers(source[1]), - vm.getInfers(source[2]) - ) - end - elseif op.type == 'or' then - local isTrue = vm.checkTrue(source[1]) - if isTrue == true then - return vm.getInfers(source[1]) - elseif isTrue == false then - return vm.getInfers(source[2]) - else - return merge( - vm.getInfers(source[1]), - vm.getInfers(source[2]) - ) - end - elseif op.type == '==' then - local value = vm.isSameValue(source[1], source[2]) - if value ~= nil then - return alloc { - type = 'boolean', - value = value, - source = source, - } - end - local isSame = vm.isSameRef(source[1], source[2]) - if isSame == true then - value = true - else - value = nil - end - return alloc { - type = 'boolean', - value = value, - source = source, - } - elseif op.type == '~=' then - local value = vm.isSameValue(source[1], source[2]) - if value ~= nil then - return alloc { - type = 'boolean', - value = not value, - source = source, - } - end - local isSame = vm.isSameRef(source[1], source[2]) - if isSame == true then - value = false - else - value = nil - end - return alloc { - type = 'boolean', - value = value, - source = source, - } - elseif op.type == '<=' then - local v1 = vm.getLiteral(source[1], 'integer') or vm.getLiteral(source[1], 'number') - local v2 = vm.getLiteral(source[2], 'integer') or vm.getLiteral(source[2], 'number') - local v - if v1 and v2 then - v = v1 <= v2 - end - return alloc { - type = 'boolean', - value = v, - source = source, - } - elseif op.type == '>=' then - local v1 = vm.getLiteral(source[1], 'integer') or vm.getLiteral(source[1], 'number') - local v2 = vm.getLiteral(source[2], 'integer') or vm.getLiteral(source[2], 'number') - local v - if v1 and v2 then - v = v1 >= v2 - end - return alloc { - type = 'boolean', - value = v, - source = source, - } - elseif op.type == '<' then - local v1 = vm.getLiteral(source[1], 'integer') or vm.getLiteral(source[1], 'number') - local v2 = vm.getLiteral(source[2], 'integer') or vm.getLiteral(source[2], 'number') - local v - if v1 and v2 then - v = v1 < v2 - end - return alloc { - type = 'boolean', - value = v, - source = source, - } - elseif op.type == '>' then - local v1 = vm.getLiteral(source[1], 'integer') or vm.getLiteral(source[1], 'number') - local v2 = vm.getLiteral(source[2], 'integer') or vm.getLiteral(source[2], 'number') - local v - if v1 and v2 then - v = v1 > v2 - end - return alloc { - type = 'boolean', - value = v, - source = source, - } - elseif op.type == '|' then - local v1 = vm.getLiteral(source[1], 'integer') - local v2 = vm.getLiteral(source[2], 'integer') - local v - if v1 and v2 then - v = v1 | v2 - end - return alloc { - type = 'integer', - value = v, - source = source, - } - elseif op.type == '~' then - local v1 = vm.getLiteral(source[1], 'integer') - local v2 = vm.getLiteral(source[2], 'integer') - local v - if v1 and v2 then - v = v1 ~ v2 - end - return alloc { - type = 'integer', - value = v, - source = source, - } - elseif op.type == '&' then - local v1 = vm.getLiteral(source[1], 'integer') - local v2 = vm.getLiteral(source[2], 'integer') - local v - if v1 and v2 then - v = v1 & v2 - end - return alloc { - type = 'integer', - value = v, - source = source, - } - elseif op.type == '<<' then - local v1 = vm.getLiteral(source[1], 'integer') - local v2 = vm.getLiteral(source[2], 'integer') - local v - if v1 and v2 then - v = v1 << v2 - end - return alloc { - type = 'integer', - value = v, - source = source, - } - elseif op.type == '>>' then - local v1 = vm.getLiteral(source[1], 'integer') - local v2 = vm.getLiteral(source[2], 'integer') - local v - if v1 and v2 then - v = v1 >> v2 - end - return alloc { - type = 'integer', - value = v, - source = source, - } - elseif op.type == '..' then - local v1 = vm.getLiteral(source[1], 'string') - local v2 = vm.getLiteral(source[2], 'string') - local v - if v1 and v2 then - v = v1 .. v2 - end - return alloc { - type = 'string', - value = v, - source = source, - } - elseif op.type == '^' then - local v1 = vm.getLiteral(source[1], 'integer') or vm.getLiteral(source[1], 'number') - local v2 = vm.getLiteral(source[2], 'integer') or vm.getLiteral(source[2], 'number') - local v - if v1 and v2 then - v = v1 ^ v2 - end - return alloc { - type = 'number', - value = v, - source = source, - } - elseif op.type == '/' then - local v1 = vm.getLiteral(source[1], 'integer') or vm.getLiteral(source[1], 'number') - local v2 = vm.getLiteral(source[2], 'integer') or vm.getLiteral(source[2], 'number') - local v - if v1 and v2 then - v = v1 > v2 - end - return alloc { - type = 'number', - value = v, - source = source, - } - -- 其他数学运算根据2侧的值决定,当2侧的值均为整数时返回整数 - elseif op.type == '+' then - local int, v1, v2 = mathCheck(source[1], source[2]) - return alloc { - type = int, - value = (v1 and v2) and (v1 + v2) or nil, - source = source, - } - elseif op.type == '-' then - local int, v1, v2 = mathCheck(source[1], source[2]) - return alloc { - type = int, - value = (v1 and v2) and (v1 - v2) or nil, - source = source, - } - elseif op.type == '*' then - local int, v1, v2 = mathCheck(source[1], source[2]) - return alloc { - type = int, - value = (v1 and v2) and (v1 * v2) or nil, - source = source, - } - elseif op.type == '%' then - local int, v1, v2 = mathCheck(source[1], source[2]) - return alloc { - type = int, - value = (v1 and v2) and (v1 % v2) or nil, - source = source, - } - elseif op.type == '//' then - local int, v1, v2 = mathCheck(source[1], source[2]) - return alloc { - type = int, - value = (v1 and v2) and (v1 // v2) or nil, - source = source, - } - end -end - local function inferByCall(results, source) if #results ~= 0 then return |