summaryrefslogtreecommitdiff
path: root/script
diff options
context:
space:
mode:
Diffstat (limited to 'script')
-rw-r--r--script/brave/work.lua5
-rw-r--r--script/files.lua44
-rw-r--r--script/global.d.lua4
-rw-r--r--script/service/service.lua2
-rw-r--r--script/workspace/loading.lua6
5 files changed, 50 insertions, 11 deletions
diff --git a/script/brave/work.lua b/script/brave/work.lua
index 33172d7e..85aa193c 100644
--- a/script/brave/work.lua
+++ b/script/brave/work.lua
@@ -58,5 +58,8 @@ brave.on('compile', function (param)
, param.version
, param.options
)
- return state, err
+ return {
+ state = state,
+ err = err,
+ }
end)
diff --git a/script/files.lua b/script/files.lua
index 604afa99..3a65e791 100644
--- a/script/files.lua
+++ b/script/files.lua
@@ -16,6 +16,7 @@ local scope = require 'workspace.scope'
local lazy = require 'lazytable'
local cacher = require 'lazy-cacher'
local sp = require 'bee.subprocess'
+local pub = require 'pub'
---@class file
---@field uri uri
@@ -554,10 +555,13 @@ function m.compileStateThen(state, file)
end
---@param uri uri
----@param file file
---@param async boolean?
---@return parser.state?
-function m.compileState(uri, file, async)
+function m.compileState(uri, async)
+ local file = m.fileMap[uri]
+ if not file then
+ return
+ end
if file.state then
return file.state
end
@@ -586,17 +590,41 @@ function m.compileState(uri, file, async)
end
return nil
end
+
+ ---@type brave.param.compile.options
+ local options = {
+ special = config.get(uri, 'Lua.runtime.special'),
+ unicodeName = config.get(uri, 'Lua.runtime.unicodeName'),
+ nonstandardSymbol = util.arrayToHash(config.get(uri, 'Lua.runtime.nonstandardSymbol')),
+ }
+
+ if async then
+ ---@type brave.param.compile
+ local params = {
+ text = file.text,
+ mode = 'Lua',
+ version = config.get(uri, 'Lua.runtime.version'),
+ options = options
+ }
+ pub.task('compile', params, function (result)
+ if file.text ~= params.text then
+ return
+ end
+ if not result.state then
+ log.error('Compile failed:', uri, result.err)
+ return
+ end
+ m.compileStateThen(result.state, file)
+ end)
+ end
+
local prog <close> = progress.create(uri, lang.script.WINDOW_COMPILING, 0.5)
prog:setMessage(ws.getRelativePath(uri))
local clock = os.clock()
local state, err = parser.compile(file.text
, 'Lua'
, config.get(uri, 'Lua.runtime.version')
- , {
- special = config.get(uri, 'Lua.runtime.special'),
- unicodeName = config.get(uri, 'Lua.runtime.unicodeName'),
- nonstandardSymbol = util.arrayToHash(config.get(uri, 'Lua.runtime.nonstandardSymbol')),
- }
+ , options
)
local passed = os.clock() - clock
if passed > 0.1 then
@@ -626,7 +654,7 @@ function m.getState(uri)
if not file then
return nil
end
- local state = m.compileState(uri, file)
+ local state = m.compileState(uri)
file.cacheActiveTime = timer.clock()
return state
end
diff --git a/script/global.d.lua b/script/global.d.lua
index 04b1855b..9065060a 100644
--- a/script/global.d.lua
+++ b/script/global.d.lua
@@ -60,3 +60,7 @@ LAZY = false
-- (experiment) Improve performance, but reduce accuracy
---@type boolean
CACHEALIVE = false
+
+-- (experiment) Compile files in multi cpu cores
+---@type integer
+COMPILECORES = 0
diff --git a/script/service/service.lua b/script/service/service.lua
index 7c6deec2..7e0c48c3 100644
--- a/script/service/service.lua
+++ b/script/service/service.lua
@@ -260,7 +260,7 @@ end
function m.start()
util.enableCloseFunction()
await.setErrorHandle(log.error)
- pub.recruitBraves(8)
+ pub.recruitBraves(4 + (COMPILECORES or 0))
proto.listen()
m.report()
m.testVersion()
diff --git a/script/workspace/loading.lua b/script/workspace/loading.lua
index 9344949c..ff8626ed 100644
--- a/script/workspace/loading.lua
+++ b/script/workspace/loading.lua
@@ -99,7 +99,11 @@ function mt:loadFile(uri, libraryUri)
-- self._sets[#self._sets+1] = waker
--end)
files.setText(uri, content, false)
- files.getState(uri)
+ if COMPILECORES then
+ files.compileState(uri, true)
+ else
+ files.compileState(uri)
+ end
if not self._cache[uri] then
files.addRef(uri)
end