From 94d45b606068f9739540b3a39359f91e79e887ef Mon Sep 17 00:00:00 2001 From: zhangrengao Date: Fri, 4 Mar 2022 19:13:21 +0800 Subject: [PATCH] fix callopt of store funcobj Signed-off-by: zhangrengao Change-Id: Ic3bc41896f8ee8bca3b0b803bd7f99871dc39613 --- ts2panda/src/compiler.ts | 3 ++- ts2panda/src/lexenv.ts | 10 ++++---- ts2panda/src/scope.ts | 49 +++++++++++++++++++++++++--------------- 3 files changed, 39 insertions(+), 23 deletions(-) diff --git a/ts2panda/src/compiler.ts b/ts2panda/src/compiler.ts index a8057b1eca..48cd427aec 100644 --- a/ts2panda/src/compiler.ts +++ b/ts2panda/src/compiler.ts @@ -183,7 +183,8 @@ export class Compiler { ["this", 1], ["4newTarget", 2], ["0newTarget", 2], - ["argumentsOrRestargs", 4] + ["argumentsOrRestargs", 4], + ["4funcObj", 8] ]); let callType = 0; let scope = this.pandaGen.getScope(); diff --git a/ts2panda/src/lexenv.ts b/ts2panda/src/lexenv.ts index 5259296302..e45d72cf0f 100644 --- a/ts2panda/src/lexenv.ts +++ b/ts2panda/src/lexenv.ts @@ -93,10 +93,9 @@ export class VariableAccessLoad extends VariableAccessBase { return insns; } if (v.getName() === "4funcObj") { - insns.push(loadAccumulator(getVregisterCache(pandaGen, CacheList.FUNC))); - } else { - insns.push(loadAccumulator(bindVreg)); + this.scope.setCallOpt("4funcObj") } + insns.push(loadAccumulator(bindVreg)); return insns; } @@ -162,6 +161,9 @@ export class VariableAcessStore extends VariableAccessBase { checkConstAssignment(pandaGen, v, insns, this.node); } + if (v.getName() === "4funcObj") { + this.scope.setCallOpt("4funcObj") + } insns.push(storeAccumulator(bindVreg)); if (v.isExportVar()) { @@ -246,4 +248,4 @@ function checkConstAssignment(pg: PandaGen, v: Variable, expansion: IRNode[], no } pg.freeTemps(nameReg); -} \ No newline at end of file +} diff --git a/ts2panda/src/scope.ts b/ts2panda/src/scope.ts index 79a59c0486..e21fa01c20 100644 --- a/ts2panda/src/scope.ts +++ b/ts2panda/src/scope.ts @@ -88,6 +88,9 @@ export abstract class Scope { // for debuginfo protected startIns: DebugInsPlaceHolder = new DebugInsPlaceHolder(); protected endIns: DebugInsPlaceHolder = new DebugInsPlaceHolder(); + private callOpt: Set = new Set(); + private isArgumentsOrRestargs: boolean = false; + constructor() { } abstract add(name: string, declKind: VarDeclarationKind, status?: InitStatus): Variable | undefined; @@ -249,6 +252,34 @@ export abstract class Scope { getDecls() { return this.decls; } + + public getCallOpt() { + return this.callOpt; + } + + public setCallOpt(key: String) { + if (this instanceof FunctionScope) { + this.callOpt.add(key); + } else { + let parent = this.parent; + while (parent != undefined) { + if (parent instanceof FunctionScope) { + parent.callOpt.add(key); + break; + } else { + parent = parent.parent; + } + } + } + } + + public setArgumentsOrRestargs() { + this.isArgumentsOrRestargs = true; + } + + public getArgumentsOrRestargs() { + return this.isArgumentsOrRestargs; + } } export abstract class VariableScope extends Scope { @@ -394,8 +425,6 @@ export class ModuleScope extends VariableScope { export class FunctionScope extends VariableScope { private parameterLength: number = 0; private funcName: string = ""; - private callOpt: Set = new Set(); - private isArgumentsOrRestargs: boolean = false; constructor(parent?: Scope, node?: ts.FunctionLikeDeclaration) { super(); this.parent = parent ? parent : undefined; @@ -418,22 +447,6 @@ export class FunctionScope extends VariableScope { return this.funcName; } - public getCallOpt() { - return this.callOpt; - } - - public setCallOpt(key: String) { - this.callOpt.add(key); - } - - public setArgumentsOrRestargs() { - this.isArgumentsOrRestargs = true; - } - - public getArgumentsOrRestargs() { - return this.isArgumentsOrRestargs; - } - getParent(): Scope | undefined { return this.parent; } -- Gitee