Skip to content

Commit

Permalink
Merge pull request #1845 from weyk/fix_asyncfn
Browse files Browse the repository at this point in the history
asyncFn=true周りが連携するよう修正
  • Loading branch information
kujirahand authored Nov 24, 2024
2 parents 99c6cb3 + ab61656 commit 55ccb52
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
7 changes: 4 additions & 3 deletions core/src/nako_gen.mts
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ export class NakoGen {
// eslint-disable-next-line @typescript-eslint/no-empty-function
fn: () => {},
type: 'func',
asyncFn: false,
asyncFn: t.asyncFn ? true : false,
isExport: t.isExport
})
funcList.push({ name, node: t })
Expand Down Expand Up @@ -1467,7 +1467,7 @@ export class NakoGen {
} else {
func = this.nakoFuncList.get(funcName)
// 無名関数の可能性
if (func === undefined) { func = { return_none: false } }
if (func === undefined) { func = { return_none: false, asyncFn: node.asyncFn ? true : false } }
}
// 関数の参照渡しか?
if (node.type === 'func_pointer') {
Expand Down Expand Up @@ -1643,14 +1643,15 @@ export class NakoGen {
indent(funcBegin, 1) + '\n' +
indent('try {', 1) + '\n' +
indent(`let ${varI} = ${funcCall};`, 2) + '\n' +
indent(`return ${sorePrefex}${varI}${sorePostfix};`, 2) + '\n' +
indent(`return ${varI};`, 2) + '\n' +
indent('} finally {', 2) + '\n' +
indent(funcEnd, 1) + '\n' +
indent('}', 1) + '\n' +
'}).call(this)'
if (func.asyncFn) {
code = `await (${code})`
}
code = `${sorePrefex}${code}${sorePostfix}`
}
}
// ...して
Expand Down
5 changes: 4 additions & 1 deletion core/src/nako_parser3.mts
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,10 @@ export class NakoParser extends NakoParserBase {
throw NakoSyntaxError.fromNode(this.nodeToStr(funcName, { depth: 0, typeName: '関数' }, false) +
'の定義で以下のエラーがありました。\n' + err.message, def)
}

const func = this.funclist.get(funcName.value)
if (func && !func.asyncFn && asyncFn) {
func.asyncFn = asyncFn
}
return {
type,
name: funcName.value,
Expand Down

0 comments on commit 55ccb52

Please sign in to comment.