summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2018-12-24 14:29:35 +0800
committer最萌小汐 <sumneko@hotmail.com>2018-12-24 14:29:35 +0800
commit83b82470f1486493e5373501f1f69d8ca0b6e18f (patch)
tree6472321795e7df7e629f1163e711e2c051e8a523
parent6f09591a6e14b3fbc027c2389ece2803f9e2ffaa (diff)
downloadlua-language-server-83b82470f1486493e5373501f1f69d8ca0b6e18f.zip
进行一些算术运算
-rw-r--r--server/src/matcher/vm.lua44
-rw-r--r--server/test/hover/init.lua5
2 files changed, 48 insertions, 1 deletions
diff --git a/server/src/matcher/vm.lua b/server/src/matcher/vm.lua
index 63bc826e..d80aaba2 100644
--- a/server/src/matcher/vm.lua
+++ b/server/src/matcher/vm.lua
@@ -978,14 +978,29 @@ function mt:getBinary(exp)
or op == '&'
or op == '<<'
or op == '>>'
- or op == '//'
then
self:inference(v1, 'integer')
self:inference(v2, 'integer')
+ if math.type(v1.value) == 'integer' and math.type(v2.value) == 'integer' then
+ if op == '|' then
+ return self:createValue('integer', v1.value | v2.value)
+ elseif op == '~' then
+ return self:createValue('integer', v1.value ~ v2.value)
+ elseif op == '&' then
+ return self:createValue('integer', v1.value &v2.value)
+ elseif op == '<<' then
+ return self:createValue('integer', v1.value << v2.value)
+ elseif op == '>>' then
+ return self:createValue('integer', v1.value >> v2.value)
+ end
+ end
return self:createValue('integer')
elseif op == '..' then
self:inference(v1, 'string')
self:inference(v2, 'string')
+ if type(v1.value) == 'string' and type(v2.value) == 'string' then
+ return self:createValue('string', nil, v1.value .. v2.value)
+ end
return self:createValue('string')
elseif op == '+'
or op == '-'
@@ -993,9 +1008,27 @@ function mt:getBinary(exp)
or op == '/'
or op == '^'
or op == '%'
+ or op == '//'
then
self:inference(v1, 'number')
self:inference(v2, 'number')
+ if type(v1.value) == 'number' and type(v2.value) == 'number' then
+ if op == '+' then
+ return self:createValue('number', nil, v1.value + v2.value)
+ elseif op == '-' then
+ return self:createValue('number', nil, v1.value - v2.value)
+ elseif op == '*' then
+ return self:createValue('number', nil, v1.value * v2.value)
+ elseif op == '/' then
+ return self:createValue('number', nil, v1.value / v2.value)
+ elseif op == '^' then
+ return self:createValue('number', nil, v1.value ^ v2.value)
+ elseif op == '%' then
+ return self:createValue('number', nil, v1.value % v2.value)
+ elseif op == '//' then
+ return self:createValue('number', nil, v1.value // v2.value)
+ end
+ end
return self:createValue('number')
end
return nil
@@ -1009,12 +1042,21 @@ function mt:getUnary(exp)
return self:createValue('boolean')
elseif op == '#' then
self:inference(v1, 'table')
+ if type(v1.value) == 'string' then
+ return self:createValue('integer', nil, #v1.value)
+ end
return self:createValue('integer')
elseif op == '-' then
self:inference(v1, 'number')
+ if type(v1.value) == 'number' then
+ return self:createValue('number', nil, -v1.value)
+ end
return self:createValue('number')
elseif op == '~' then
self:inference(v1, 'integer')
+ if math.type(v1.value) == 'integer' then
+ return self:createValue('integer', nil, ~v1.value)
+ end
return self:createValue('integer')
end
return nil
diff --git a/server/test/hover/init.lua b/server/test/hover/init.lua
index 445e72ba..71e839ae 100644
--- a/server/test/hover/init.lua
+++ b/server/test/hover/init.lua
@@ -216,3 +216,8 @@ t:<?add?>()
[[
function mt:add(a: any, b: any)
]]
+
+TEST [[
+local <?t?> = - 1000
+]]
+[[number t = -1000]]