summaryrefslogtreecommitdiff
path: root/script/vm/compiler.lua
diff options
context:
space:
mode:
Diffstat (limited to 'script/vm/compiler.lua')
-rw-r--r--script/vm/compiler.lua30
1 files changed, 30 insertions, 0 deletions
diff --git a/script/vm/compiler.lua b/script/vm/compiler.lua
index 6f542367..1473b985 100644
--- a/script/vm/compiler.lua
+++ b/script/vm/compiler.lua
@@ -7,6 +7,8 @@ local signMgr = require 'vm.sign'
local config = require 'config'
local union = require 'vm.union'
local genericMgr = require 'vm.generic'
+local rpath = require 'workspace.require-path'
+local files = require 'files'
---@class parser.object
---@field _compiledNodes boolean
@@ -275,6 +277,26 @@ local function getReturn(func, index, args)
end
return getReturn(args[1], index - 1, newArgs)
end
+ if func.special == 'require' then
+ local nameArg = args[1]
+ if not nameArg or nameArg.type ~= 'string' then
+ return nil
+ end
+ local name = nameArg[1]
+ if not name or type(name) ~= 'string' then
+ return nil
+ end
+ local uri = rpath.findUrisByRequirePath(guide.getUri(func), name)[1]
+ if not uri then
+ return nil
+ end
+ local state = files.getState(uri)
+ local ast = state and state.ast
+ if not ast then
+ return nil
+ end
+ return m.compileNode(ast)
+ end
local node = m.compileNode(func)
---@type vm.node.union
local result, hasCalled
@@ -674,6 +696,14 @@ local compilerSwitch = util.switch()
end
end
end)
+ : case 'main'
+ : call(function (source)
+ if source.returns then
+ for _, rtn in ipairs(source.returns) do
+ nodeMgr.setNode(source, m.compileNode(rtn[1]))
+ end
+ end
+ end)
: case 'select'
: call(function (source)
local vararg = source.vararg