summaryrefslogtreecommitdiff
path: root/server/src/vm
diff options
context:
space:
mode:
Diffstat (limited to 'server/src/vm')
-rw-r--r--server/src/vm/emmy.lua27
-rw-r--r--server/src/vm/function.lua12
-rw-r--r--server/src/vm/value.lua1
3 files changed, 30 insertions, 10 deletions
diff --git a/server/src/vm/emmy.lua b/server/src/vm/emmy.lua
index cdbbd3b7..7a82cfcd 100644
--- a/server/src/vm/emmy.lua
+++ b/server/src/vm/emmy.lua
@@ -1,3 +1,5 @@
+local functionMgr = require 'vm.function'
+local library = require 'vm.library'
local mt = require 'vm.manager'
function mt:clearEmmy()
@@ -267,17 +269,30 @@ function mt:doEmmyFunctionType(action)
---@type emmyMgr
local emmyMgr = self.emmyMgr
self:instantSource(action)
- local func = emmyMgr:addFunctionType(action)
+ local funcObj = emmyMgr:addFunctionType(action)
+ ---@type function
+ local func = functionMgr.create(action)
for i = 1, #action // 2 do
local nameSource = action[i*2-1]
local typeSource = action[i*2]
local paramType = self:buildEmmyAnyType(typeSource)
- func:addParam(nameSource[1], paramType)
+ funcObj:addParam(nameSource[1], paramType)
+ local value = self:createValue(paramType:getType(), typeSource)
+ value:setEmmy(paramType)
+ self:instantSource(nameSource)
+ func:addArg(nameSource[1], nameSource, value)
end
- local returnType = self:buildEmmyAnyType(action[#action])
- func:addReturn(returnType)
- self._emmy = func
- return func
+ local returnSource = action[#action]
+ if returnSource then
+ local returnType = self:buildEmmyAnyType(returnSource)
+ funcObj:addReturn(returnType)
+ local value = self:createValue(returnType:getType(), returnSource)
+ value:setEmmy(returnType)
+ func:setReturn(1, value)
+ end
+ funcObj:bindFunction(func)
+ self._emmy = funcObj
+ return funcObj
end
function mt:buildEmmyAnyType(source)
diff --git a/server/src/vm/function.lua b/server/src/vm/function.lua
index 2322fa70..e605e1c9 100644
--- a/server/src/vm/function.lua
+++ b/server/src/vm/function.lua
@@ -349,15 +349,19 @@ function mt:findEmmyParamByName(name)
return nil
end
+function mt:addArg(name, source, value)
+ local loc = localMgr.create(name, source, value)
+ self:saveUpvalue(name, loc)
+ self.args[#self.args+1] = loc
+end
+
function mt:createArg(vm, arg)
vm:instantSource(arg)
arg:set('arg', self)
if arg.type == 'name' then
+ vm:instantSource(arg)
local value = valueMgr.create('nil', arg)
- local loc = localMgr.create(arg[1], arg, value)
- self:saveUpvalue(arg[1], loc)
- self.args[#self.args+1] = loc
-
+ self:addArg(arg[1], arg, value)
elseif arg.type == '...' then
self._dots = createMulti()
end
diff --git a/server/src/vm/value.lua b/server/src/vm/value.lua
index b43530d0..bf20468d 100644
--- a/server/src/vm/value.lua
+++ b/server/src/vm/value.lua
@@ -600,6 +600,7 @@ function mt:setEmmy(emmy)
---@type EmmyFunctionType
local emmyFuncType = emmy
emmyFuncType:setValue(self)
+ self:setFunction(emmyFuncType:bindFunction())
else
return
end