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)); }