From caf058dd55ba9778cea3513b103eb322225c3ae2 Mon Sep 17 00:00:00 2001 From: PuqiAR Date: Mon, 19 Jan 2026 16:10:12 +0800 Subject: [PATCH] =?UTF-8?q?[VER]=20v0.4.1-alpha=20[Fix]=20=E4=BF=AE?= =?UTF-8?q?=E5=A4=8Dstruct=E5=AE=9A=E4=B9=89=E5=88=9B=E5=BB=BAinstanceCtx?= =?UTF-8?q?=E6=97=B6=E6=8B=B7=E8=B4=9D=E7=B1=BB=E6=96=B9=E6=B3=95=E9=94=99?= =?UTF-8?q?=E8=AF=AF=E7=9A=84Bug,=E8=A1=A8=E7=8E=B0=E5=9C=A8=E5=90=8C?= =?UTF-8?q?=E4=B8=80=E7=B1=BB=E7=9A=842=E4=B8=AA=E4=B8=8D=E5=90=8C?= =?UTF-8?q?=E5=AE=9E=E4=BE=8B=E5=86=85=E7=BD=AE=E5=87=BD=E6=95=B0=E4=B8=80?= =?UTF-8?q?=E6=A0=B7=E7=9A=84=E9=97=AE=E9=A2=98=20=20=20=20=20=20=20(?= =?UTF-8?q?=E5=8D=B3=20addr=20A=20!=3D=20addr=20B,=20addr=20A.method=20=3D?= =?UTF-8?q?=3D=20addr=20B.method)=20=20=20=20=20=20=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E5=90=8E=E4=B8=BA=20(addr=20A=20!=3D=20addr=20B,=20addr=20A.me?= =?UTF-8?q?thod=20!=3D=20addr=20B.method)=20=20=20=20=20=20=20=E6=96=B9?= =?UTF-8?q?=E6=B3=95=E7=9A=84closureContext=E6=8C=87=E5=90=91instance?= =?UTF-8?q?=E7=9A=84Context=20=20=20=20=20=20=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E5=90=8E=20std.time=E5=8F=AF=E4=BB=A5=E6=AD=A3=E5=B8=B8?= =?UTF-8?q?=E4=BD=BF=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Core/core.hpp | 2 +- src/Evaluator/evaluator.cpp | 43 +++++++++++++++++++++++++++++-------- 2 files changed, 35 insertions(+), 10 deletions(-) diff --git a/src/Core/core.hpp b/src/Core/core.hpp index d7878b2..769991e 100644 --- a/src/Core/core.hpp +++ b/src/Core/core.hpp @@ -4,7 +4,7 @@ #include #include -#define __FCORE_VERSION "0.4.0-alpha" +#define __FCORE_VERSION "0.4.1-alpha" #if defined(_WIN32) #define __FCORE_PLATFORM "Windows" diff --git a/src/Evaluator/evaluator.cpp b/src/Evaluator/evaluator.cpp index a97a464..e7d6746 100644 --- a/src/Evaluator/evaluator.cpp +++ b/src/Evaluator/evaluator.cpp @@ -984,17 +984,42 @@ namespace Fig } } } - instanceCtx->merge(*structT.defContext); - for (auto &[id, fn] : instanceCtx->getFunctions()) + // instanceCtx->merge(*structT.defContext); + // for (auto &[id, fn] : instanceCtx->getFunctions()) + // { + // instanceCtx->_update(*instanceCtx->getFunctionName(id), + // std::make_shared(Function(fn.paras, + // fn.retType, + // fn.body, + // instanceCtx) // change its closureContext to + // // struct instance's context + // )); + // } + + ContextPtr stDefCtx = structT.defContext; + + // load struct method + for (auto &[id, fn] : stDefCtx->getFunctions()) { - instanceCtx->_update(*instanceCtx->getFunctionName(id), - std::make_shared(Function(fn.paras, - fn.retType, - fn.body, - instanceCtx) // change its closureContext to - // struct instance's context - )); + auto funcNameOpt = stDefCtx->getFunctionName(id); + assert(funcNameOpt.has_value()); + + const FString &funcName = *funcNameOpt; + auto funcSlot = stDefCtx->get(funcName); + + instanceCtx->def( + funcName, + ValueType::Function, + funcSlot->am, + std::make_shared(Function( + fn.paras, + fn.retType, + fn.body, + instanceCtx + )) + ); } + return std::make_shared(StructInstance(structT.type, instanceCtx)); }