diff --git a/es2panda/compiler/core/function.cpp b/es2panda/compiler/core/function.cpp index b51e0521b0efb3693c04da2619154d35e0f320e6..57676ef6233872ae4ebccd027f7b95a0f478d04d 100644 --- a/es2panda/compiler/core/function.cpp +++ b/es2panda/compiler/core/function.cpp @@ -215,7 +215,6 @@ static void CompileFunction(PandaGen *pg) const auto *classDef = util::Helpers::GetClassDefiniton(decl); if (classDef->Super() == nullptr && classDef->NeedInstanceInitializer()) { RegScope rs(pg); - auto callee = pg->AllocReg(); auto thisReg = pg->AllocReg(); pg->GetThis(decl); @@ -223,9 +222,7 @@ static void CompileFunction(PandaGen *pg) auto [level, slot] = pg->Scope()->Find(classDef->InstanceInitializer()->Key()); pg->LoadLexicalVar(decl, level, slot); - pg->StoreAccumulator(decl, callee); - - pg->CallThis(decl, callee, 1); + pg->CallInit(decl, thisReg); } } diff --git a/es2panda/compiler/core/pandagen.cpp b/es2panda/compiler/core/pandagen.cpp index 5f7527ddbce7c3c9aac4a3b611d506c5efab882b..b2cb94055d80c7e48e5568e82cf2ff8c2a44cb17 100644 --- a/es2panda/compiler/core/pandagen.cpp +++ b/es2panda/compiler/core/pandagen.cpp @@ -475,7 +475,7 @@ void PandaGen::DefineClassField(const ir::AstNode *node, VReg obj, const Operand void PandaGen::DefineClassPrivateField(const ir::AstNode *node, uint32_t level, uint32_t slot, VReg obj) { - ra_.Emit(node, level, slot, obj); + ra_.Emit(node, 0, level, slot, obj); } void PandaGen::StoreOwnProperty(const ir::AstNode *node, VReg obj, const Operand &prop, bool nameSetting) @@ -577,7 +577,7 @@ void PandaGen::StoreObjByName(const ir::AstNode *node, VReg obj, const util::Str void PandaGen::DefineFieldByName(const ir::AstNode *node, VReg obj, const util::StringView &prop) { - ra_.Emit(node, prop, obj); + ra_.Emit(node, 0, prop, obj); strings_.insert(prop); } @@ -614,12 +614,12 @@ void PandaGen::StoreObjByIndex(const ir::AstNode *node, VReg obj, int64_t index) void PandaGen::DefineFieldByValue(const ir::AstNode *node, VReg obj, VReg prop) { - ra_.Emit(node, prop, obj); + ra_.Emit(node, 0, prop, obj); } void PandaGen::DefineFieldByIndex(const ir::AstNode *node, VReg obj, int64_t index) { - ra_.Emit(node, index, obj); + ra_.Emit(node, 0, index, obj); } void PandaGen::StOwnByName(const ir::AstNode *node, VReg obj, const util::StringView &prop, bool nameSetting) @@ -1357,6 +1357,12 @@ void PandaGen::NotifyConcurrentResult(const ir::AstNode *node) } } +void PandaGen::CallInit(const ir::AstNode *node, VReg thisReg) +{ + // callee is in acc + ra_.Emit(node, 0, thisReg); +} + void PandaGen::NewObject(const ir::AstNode *node, VReg startReg, size_t argCount) { if (argCount <= util::Helpers::MAX_INT8) { diff --git a/es2panda/compiler/core/pandagen.h b/es2panda/compiler/core/pandagen.h index 7d76bda3acfe83e49885c57e1f9228e719160544..f8028ba21c65774bf63842d007876ee70ebb8b43 100644 --- a/es2panda/compiler/core/pandagen.h +++ b/es2panda/compiler/core/pandagen.h @@ -378,6 +378,7 @@ public: void SuperCall(const ir::AstNode *node, VReg startReg, size_t argCount); void SuperCallSpread(const ir::AstNode *node, VReg vs); void NotifyConcurrentResult(const ir::AstNode *node); + void CallInit(const ir::AstNode *node, VReg thisReg); void NewObject(const ir::AstNode *node, VReg startReg, size_t argCount); void DefineFunction(const ir::AstNode *node, const ir::ScriptFunction *realNode, const util::StringView &name); diff --git a/es2panda/ir/expressions/callExpression.cpp b/es2panda/ir/expressions/callExpression.cpp index e09d1f989a81031abb887059074654208d4646fc..0956850bfca8c928745a350df25ba39bc51f39cd 100644 --- a/es2panda/ir/expressions/callExpression.cpp +++ b/es2panda/ir/expressions/callExpression.cpp @@ -124,16 +124,13 @@ void CallExpression::Compile(compiler::PandaGen *pg) const const auto *classDef = util::Helpers::GetClassDefiniton(util::Helpers::GetContainingConstructor(this)); if (classDef->NeedInstanceInitializer()) { - auto callee = pg->AllocReg(); auto thisReg = pg->AllocReg(); + pg->MoveVreg(this, thisReg, newThis); auto [level, slot] = pg->Scope()->Find(classDef->InstanceInitializer()->Key()); pg->LoadLexicalVar(this, level, slot); - pg->StoreAccumulator(this, callee); - - pg->MoveVreg(this, thisReg, newThis); - pg->CallThis(this, callee, 1); + pg->CallInit(this, thisReg); } return; }