From 9883349c70ded355cbee0cb0ecfd823bcf7af2c3 Mon Sep 17 00:00:00 2001 From: zhangrengao Date: Mon, 28 Feb 2022 11:58:19 +0800 Subject: [PATCH] disable callOpt --- ts2panda/src/base/builtIn.ts | 11 +-- ts2panda/src/base/vregisterCache.ts | 5 +- ts2panda/src/compiler.ts | 72 +------------------ ts2panda/src/expression/metaProperty.ts | 2 - .../src/function/generatorFunctionBuilder.ts | 5 +- ts2panda/src/lexenv.ts | 6 +- ts2panda/src/pandagen.ts | 20 ------ ts2panda/src/pandasm.ts | 3 - ts2panda/src/scope.ts | 16 ----- ts2panda/src/statement/classStatement.ts | 8 +-- ts2panda/src/ts2panda.ts | 2 - ts2panda/ts2abc/ts2abc.cpp | 34 --------- 12 files changed, 7 insertions(+), 177 deletions(-) diff --git a/ts2panda/src/base/builtIn.ts b/ts2panda/src/base/builtIn.ts index 160b5f9d2a..61afcb3ecd 100755 --- a/ts2panda/src/base/builtIn.ts +++ b/ts2panda/src/base/builtIn.ts @@ -25,8 +25,7 @@ import { EcmaLdsymbol, EcmaLdtrue, EcmaLdundefined, - StaDyn, - EcmaLdfunction + StaDyn } from "../irnodes"; import { CacheList, getVregisterCache } from "./vregisterCache"; @@ -100,12 +99,4 @@ export function expandFalse(pandaGen: PandaGen): IRNode[] { new EcmaLdfalse(), new StaDyn(vreg) ]; -} - -export function expandFunc(pandaGen: PandaGen): IRNode[] { - let vreg = getVregisterCache(pandaGen, CacheList.FUNC); - return [ - new EcmaLdfunction(), - new StaDyn(vreg) - ]; } \ No newline at end of file diff --git a/ts2panda/src/base/vregisterCache.ts b/ts2panda/src/base/vregisterCache.ts index e4b3082acf..c293a8286e 100755 --- a/ts2panda/src/base/vregisterCache.ts +++ b/ts2panda/src/base/vregisterCache.ts @@ -33,15 +33,13 @@ import { // expandString, expandSymbol, expandTrue, - expandUndefined, - expandFunc + expandUndefined } from "./builtIn"; import { expandLexEnv } from "./lexEnv"; export enum CacheList { MIN, NaN = MIN, HOLE, - FUNC, // load function Infinity, undefined, // Boolean, @@ -77,7 +75,6 @@ let cacheExpandHandlers = new Map([ [CacheList.LexEnv, expandLexEnv], [CacheList.True, expandTrue], [CacheList.False, expandFalse], - [CacheList.FUNC, expandFunc], ]); class CacheItem { diff --git a/ts2panda/src/compiler.ts b/ts2panda/src/compiler.ts index b323fc7b57..bfdc5bad5d 100644 --- a/ts2panda/src/compiler.ts +++ b/ts2panda/src/compiler.ts @@ -74,7 +74,6 @@ import { } from "./pandagen"; import { Recorder } from "./recorder"; import { - FunctionScope, GlobalScope, LoopScope, ModuleScope, @@ -159,7 +158,6 @@ export class Compiler { this.compileSourceFileOrBlock(this.rootNode); } else { this.compileFunctionLikeDeclaration(this.rootNode); - this.callOpt(); } } @@ -175,52 +173,6 @@ export class Compiler { return this.envUnion[this.envUnion.length - 1]; } - private callOpt() { - let CallMap: Map = new Map([ - ["this", 1], - ["4newTarget", 2], - ["0newTarget", 2], - ["argumentsOrRestargs", 4] - ]); - let callType = 0; - let scope = this.pandaGen.getScope(); - - if (scope instanceof FunctionScope) { - let tempLocals: VReg[] = []; - let tempNames: Set = new Set(); - let count = 0; - // 4funcObj/newTarget/this - for (let i = 0; i < 3; i++) { - if (scope.getCallOpt().has(scope.getParameters()[i].getName())) { - tempLocals.push(this.pandaGen.getLocals()[i]); - callType += CallMap.get(scope.getParameters()[i].getName()) ?? 0; - } else { - tempNames.add(scope.getParameters()[i].getName()); - count++; - } - } - // acutal parameters - for (let i = 3; i < this.pandaGen.getLocals().length; i++) { - tempLocals.push(this.pandaGen.getLocals()[i]); - } - let name2variable = scope.getName2variable(); - name2variable.forEach((value, key) => { - if (tempNames.has(key)) { - name2variable.delete(key) - } - }) - - this.pandaGen.setLocals(tempLocals); - this.pandaGen.setParametersCount(this.pandaGen.getParametersCount()-count); - - if (scope.getArgumentsOrRestargs()) { - callType += CallMap.get("argumentsOrRestargs") ?? 0; - } - - this.pandaGen.setCallType(callType); - } - } - private compileLexicalBindingForArrowFunction() { let rootNode = this.rootNode; @@ -255,14 +207,8 @@ export class Compiler { let v = variableInfo.v; if (v && v.isLexVar) { - if ((arg === "this" || arg === "4newTarget") && variableInfo.scope instanceof FunctionScope) { - variableInfo.scope.setCallOpt(arg); - } - if (arg === "arguments" && variableInfo.scope instanceof FunctionScope) { - variableInfo.scope.setArgumentsOrRestargs(); - } let pandaGen = this.pandaGen; - let vreg = "4funcObj" === arg ? getVregisterCache(pandaGen, CacheList.FUNC) : pandaGen.getVregForVariable(variableInfo.v); + let vreg = pandaGen.getVregForVariable(variableInfo.v); let slot = (variableInfo.v).idxLex; pandaGen.storeLexicalVar(this.rootNode, variableInfo.level, slot, vreg); } @@ -343,10 +289,6 @@ export class Compiler { let paramReg = pandaGen.getVregForVariable(variable!); if (param.dotDotDotToken) { - let scope = this.pandaGen.getScope(); - if (scope instanceof FunctionScope) { - scope.setArgumentsOrRestargs(); - } pandaGen.copyRestArgs(param, index); pandaGen.storeAccumulator(param, paramReg); } @@ -958,8 +900,6 @@ export class Compiler { let { scope, level, v } = this.scope.find("this"); - this.setCallOpt(scope, "this") - if (!v) { throw new Error("\"this\" not found"); } @@ -1368,8 +1308,6 @@ export class Compiler { let level = thisInfo.level; let v = thisInfo.v; - this.setCallOpt(scope, "this") - if (scope && level >= 0) { let needSetLexVar: boolean = false; while (curScope != scope) { @@ -1398,8 +1336,6 @@ export class Compiler { let pandaGen = this.pandaGen; let thisInfo = this.getCurrentScope().find("this"); - this.setCallOpt(thisInfo.scope, "this") - if (thisInfo.v!.isLexVar) { let slot = (thisInfo.v).idxLex; let value = pandaGen.getTemp(); @@ -1411,12 +1347,6 @@ export class Compiler { } } - setCallOpt(scope: Scope | undefined, callOptStr: String) { - if (scope instanceof FunctionScope) { - scope.setCallOpt(callOptStr); - } - } - getPandaGen() { return this.pandaGen; } diff --git a/ts2panda/src/expression/metaProperty.ts b/ts2panda/src/expression/metaProperty.ts index eadef5cdee..de0500b305 100644 --- a/ts2panda/src/expression/metaProperty.ts +++ b/ts2panda/src/expression/metaProperty.ts @@ -23,8 +23,6 @@ export function compileMetaProperty(expr: ts.MetaProperty, compiler: Compiler) { if (id == "target") { let { scope, level, v } = curScope.find("4newTarget"); - compiler.setCallOpt(scope, "4newTarget"); - if (!v) { throw new Error("fail to access new.target"); } else { diff --git a/ts2panda/src/function/generatorFunctionBuilder.ts b/ts2panda/src/function/generatorFunctionBuilder.ts index 73a26c6be4..a7d780fca7 100755 --- a/ts2panda/src/function/generatorFunctionBuilder.ts +++ b/ts2panda/src/function/generatorFunctionBuilder.ts @@ -48,10 +48,9 @@ export class GeneratorFunctionBuilder { prepare(node: ts.Node, recorder: Recorder) { let pandaGen = this.pandaGen; let scope = recorder.getScopeOfNode(node); - let funcObj = scope.getName2variable().get("4funcObj")!.getVreg(); - + let funcObj = scope.getName2variable().get("4funcObj")!.getVreg(); + pandaGen.createGeneratorObj(node, funcObj); // backend handle funcobj, frontend set undefined - pandaGen.createGeneratorObj(node, getVregisterCache(pandaGen, CacheList.FUNC)); pandaGen.storeAccumulator(node, this.genObj); pandaGen.suspendGenerator(node, this.genObj, getVregisterCache(pandaGen, CacheList.undefined)); pandaGen.resumeGenerator(node, this.genObj); diff --git a/ts2panda/src/lexenv.ts b/ts2panda/src/lexenv.ts index d4c1cc7776..eec0a29046 100644 --- a/ts2panda/src/lexenv.ts +++ b/ts2panda/src/lexenv.ts @@ -92,11 +92,7 @@ export class VariableAccessLoad extends VariableAccessBase { pandaGen.freeTemps(holeReg); return insns; } - if (v.getName() === "4funcObj") { - insns.push(loadAccumulator(getVregisterCache(pandaGen, CacheList.FUNC))); - } else { - insns.push(loadAccumulator(bindVreg)); - } + insns.push(loadAccumulator(bindVreg)); return insns; } diff --git a/ts2panda/src/pandagen.ts b/ts2panda/src/pandagen.ts index d7b0bfceb7..a76191b934 100644 --- a/ts2panda/src/pandagen.ts +++ b/ts2panda/src/pandagen.ts @@ -203,7 +203,6 @@ export class PandaGen { private sourceFileDebugInfo: string = ""; private sourceCodeDebugInfo: string | undefined; private icSize: number = 0; - private callType: number = 0; private static literalArrayBuffer: Array = new Array(); @@ -213,14 +212,6 @@ export class PandaGen { this.scope = scope; this.vregisterCache = new VregisterCache(); } - - public setCallType(callType: number) { - this.callType = callType; - } - - public getCallType(): number { - return this.callType; - } static getExportedTypes() { if (TypeRecorder.getInstance()) { @@ -385,18 +376,10 @@ export class PandaGen { return this.totalRegsNum; } - setParametersCount(count: number) { - this.parametersCount = count; - } - getParametersCount(): number { return this.parametersCount; } - setLocals(locals: VReg[]) { - this.locals = locals; - } - getLocals(): VReg[] { return this.locals; } @@ -412,9 +395,6 @@ export class PandaGen { loadAccFromArgs(node: ts.Node) { if ((this.scope).getUseArgs()) { let v = this.scope!.findLocal("arguments"); - if (this.scope instanceof FunctionScope) { - this.scope.setArgumentsOrRestargs(); - } if (v) { let paramVreg = this.getVregForVariable(v); this.getUnmappedArgs(node); diff --git a/ts2panda/src/pandasm.ts b/ts2panda/src/pandasm.ts index 565615a2f5..1d5e1c02f9 100644 --- a/ts2panda/src/pandasm.ts +++ b/ts2panda/src/pandasm.ts @@ -72,7 +72,6 @@ export class Function { public variables: Array | undefined; public sourceFile: string; public sourceCode: string | undefined; - public callType: number; public typeInfo: Array; public exportedSymbol2Types: Array | undefined; public declaredSymbol2Types: Array | undefined; @@ -86,7 +85,6 @@ export class Function { variables: Array | undefined = undefined, sourceFile: string = "", sourceCode: string | undefined = undefined, - callType: number = 0, typeInfo: Array, exportedSymbol2Types: Array | undefined = undefined, declaredSymbol2Types: Array | undefined = undefined @@ -101,7 +99,6 @@ export class Function { this.variables = variables; this.sourceFile = sourceFile; this.sourceCode = sourceCode; - this.callType = callType; this.typeInfo = typeInfo; this.exportedSymbol2Types = exportedSymbol2Types; this.declaredSymbol2Types = declaredSymbol2Types; diff --git a/ts2panda/src/scope.ts b/ts2panda/src/scope.ts index 79a59c0486..ac81b6c974 100644 --- a/ts2panda/src/scope.ts +++ b/ts2panda/src/scope.ts @@ -418,22 +418,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; } diff --git a/ts2panda/src/statement/classStatement.ts b/ts2panda/src/statement/classStatement.ts index 982d1ab35d..daf4576066 100644 --- a/ts2panda/src/statement/classStatement.ts +++ b/ts2panda/src/statement/classStatement.ts @@ -342,9 +342,6 @@ export function compileSuperCall(compiler: Compiler, node: ts.CallExpression, ar let curScope = compiler.getCurrentScope(); let { scope, level, v } = curScope.find("this"); - compiler.setCallOpt(scope, "this"); - compiler.setCallOpt(scope, "4newTarget"); - if (scope && level >= 0) { let tmpScope = curScope; let needSetLexVar: boolean = false; @@ -359,9 +356,6 @@ export function compileSuperCall(compiler: Compiler, node: ts.CallExpression, ar if (needSetLexVar) { scope.setLexVar(v, curScope); } - if (needSetLexVar && curScope instanceof FunctionScope) { - curScope.setCallOpt("0newTarget"); - } } if (hasSpread) { @@ -403,7 +397,7 @@ function loadCtorObj(node: ts.CallExpression, compiler: Compiler) { if (ts.isConstructorDeclaration(nearestFunc)) { let funcObj = nearestFuncScope.findLocal("4funcObj"); - pandaGen.loadAccumulator(node, getVregisterCache(pandaGen, CacheList.FUNC)); + pandaGen.loadAccumulator(node, pandaGen.getVregForVariable(funcObj)); } else { let outerFunc = jshelpers.getContainingFunctionDeclaration(nearestFunc); let outerFuncScope = recorder.getScopeOfNode(outerFunc!); diff --git a/ts2panda/src/ts2panda.ts b/ts2panda/src/ts2panda.ts index 6e0d6e7cd9..55707b9108 100644 --- a/ts2panda/src/ts2panda.ts +++ b/ts2panda/src/ts2panda.ts @@ -202,7 +202,6 @@ export class Ts2Panda { let funcSignature = Ts2Panda.getFuncSignature(pg); let funcInsnsAndRegsNum = Ts2Panda.getFuncInsnsAndRegsNum(pg); let sourceFile = pg.getSourceFileDebugInfo(); - let callType = pg.getCallType(); let typeRecord = pg.getLocals(); let typeInfo = new Array(); typeRecord.forEach((vreg) => { @@ -252,7 +251,6 @@ export class Ts2Panda { variables, sourceFile, sourceCode, - callType, typeInfo, exportedSymbol2Types, declaredSymbol2Types diff --git a/ts2panda/ts2abc/ts2abc.cpp b/ts2panda/ts2abc/ts2abc.cpp index 6d5e7b14a7..d2fef36bc0 100644 --- a/ts2panda/ts2abc/ts2abc.cpp +++ b/ts2panda/ts2abc/ts2abc.cpp @@ -610,30 +610,6 @@ static void ParseFunctionCatchTables(const Json::Value &function, panda::pandasm } } -static void ParseFunctionCallType(const Json::Value &function, panda::pandasm::Function &pandaFunc) -{ - std::string funcName = ""; - if (function.isMember("name") && function["name"].isString()) { - funcName = function["name"].asString(); - } - if (funcName == "func_main_0") { - return ; - } - - uint32_t callType = 0; - if (function.isMember("callType") && function["callType"].isInt()) { - callType = function["callType"].asUInt(); - } - panda::pandasm::AnnotationData callTypeAnnotation("_ESCallTypeAnnotation"); - std::string annotationName = "callType"; - panda::pandasm::AnnotationElement callTypeAnnotationElement( - annotationName, std::make_unique( - panda::pandasm::ScalarValue::Create(callType))); - callTypeAnnotation.AddElement(std::move(callTypeAnnotationElement)); - const_cast&>( - pandaFunc.metadata->GetAnnotations()).push_back(std::move(callTypeAnnotation)); -} - static void ParseFunctionTypeInfo(const Json::Value &function, panda::pandasm::Function &pandaFunc) { if (function.isMember("typeInfo") && function["typeInfo"].isArray()) { @@ -795,8 +771,6 @@ static panda::pandasm::Function ParseFunction(const Json::Value &function) ParseSourceFileDebugInfo(function, pandaFunc); ParseFunctionLabels(function, pandaFunc); ParseFunctionCatchTables(function, pandaFunc); - // parsing call opt type - ParseFunctionCallType(function, pandaFunc); ParseFunctionTypeInfo(function, pandaFunc); ParseFunctionExportedType(function, pandaFunc); ParseFunctionDeclaredType(function, pandaFunc); @@ -804,13 +778,6 @@ static panda::pandasm::Function ParseFunction(const Json::Value &function) return pandaFunc; } -static void GenerateESCallTypeAnnotationRecord(panda::pandasm::Program &prog) -{ - auto callTypeAnnotationRecord = panda::pandasm::Record("_ESCallTypeAnnotation", LANG_EXT); - callTypeAnnotationRecord.metadata->SetAttribute("external"); - callTypeAnnotationRecord.metadata->SetAccessFlags(panda::ACC_ANNOTATION); - prog.record_table.emplace(callTypeAnnotationRecord.name, std::move(callTypeAnnotationRecord)); -} static void GenerateESTypeAnnotationRecord(panda::pandasm::Program &prog) { auto tsTypeAnnotationRecord = panda::pandasm::Record("_ESTypeAnnotation", LANG_EXT); @@ -913,7 +880,6 @@ static void ReplaceAllDistinct(std::string &str, const std::string &oldValue, co static void ParseOptions(const Json::Value &rootValue, panda::pandasm::Program &prog) { - GenerateESCallTypeAnnotationRecord(prog); GenerateESTypeAnnotationRecord(prog); ParseModuleMode(rootValue, prog); ParseLogEnable(rootValue); -- Gitee