Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nakoワーカーを名前空間と文字列定数プールへの対応。 #1628

Merged
merged 1 commit into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 39 additions & 2 deletions src/plugin_webworker.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ const PluginWebWorker = {
fn: function (work, data, sys) {
const msg = {
type: 'run',
data: sys.__modName + '__' + data
data: data
}
work.postMessage(msg)
},
Expand Down Expand Up @@ -291,10 +291,25 @@ const PluginWebWorker = {
pure: false,
fn: function (datas, work, sys) {
if (typeof sys === 'undefined') { sys = work; work = self }
const modNameList = []
const obj = []
if (typeof datas === 'string') { datas = [datas] }
datas.forEach(data => {
data = sys.__modName + '__' + data
if (data.indexOf('__') === -1) {
for (const modname of sys.__modList) {
const varname = modname + '__' + data
if (typeof sys.__varslist[2][varname] !== 'undefined' || typeof sys.__varslist[1][varname] !== 'undefined') {
data = varname
break
}
}
}
if (data.indexOf('__') > -1) {
const modname = data.split('__')[0]
if (modNameList.indexOf(modname) === -1) {
modNameList.push(modname)
}
}
if (typeof sys.__varslist[2][data] !== 'undefined') {
obj.push({
type: 'val',
Expand All @@ -317,6 +332,28 @@ const PluginWebWorker = {
}
})
if (obj.length > 0) {
const modInfoList = []
for (const modname of modNameList) {
modInfoList.push({
name: modname,
export: sys.compiler.moduleExport[modname]
})
}
obj.push({
type: 'env',
name: 'modlist',
content: modInfoList
})
obj.push({
type: 'env',
name: 'constPools',
content: sys.constPools
})
obj.push({
type: 'env',
name: 'constPoolsTemplate',
content: sys.constPoolsTemplate
})
const msg = {
type: 'trans',
data: obj
Expand Down
17 changes: 17 additions & 0 deletions src/wnako3webworker.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,23 @@ if (typeof (navigator) === 'object' && self && self instanceof WorkerGlobalScope
nako3Compiler.__varslist[1][o.name] = () => {}
} else if (o.type === 'val') {
nako3Compiler.__varslist[2][o.name] = o.content
} else if (o.type === 'env') {
if (o.name === 'modlist') {
for (const modInfo of o.content) {
if (nako3Compiler.lexer.modList.indexOf(modInfo.name) < 0) {
nako3Compiler.lexer.modList.push(modInfo.name)
}
if (modInfo.export != null && !nako3Compiler.moduleExport.hasOwnProperty(modInfo.name)) {
nako3Compiler.moduleExport[modInfo.name] = modInfo.export
}
}
} else if (o.name === 'constPools') {
nako3Compiler.constPools = o.content
} else if (o.name === 'constPoolsTemplate') {
nako3Compiler.constPoolsTemplate = o.content
} else if (o.name === 'chk') {
nako3Compiler.chk = o.content
}
}
})
break
Expand Down
Loading