From 13fdbec0c4aea9489e3770fd91808b8d99071371 Mon Sep 17 00:00:00 2001 From: PuqiAR Date: Wed, 14 Jan 2026 21:31:11 +0800 Subject: [PATCH] =?UTF-8?q?[VER]=20v0.3.8-alpha=20[Impl][Fix]=20=E6=9B=B4?= =?UTF-8?q?=E6=94=B9resolveModulePath=E5=AE=9E=E7=8E=B0=EF=BC=8C=E4=BD=BF?= =?UTF-8?q?=E7=94=A8=E7=BB=9D=E5=AF=B9=E8=B7=AF=E5=BE=84=E6=9F=A5=E6=89=BE?= =?UTF-8?q?=E5=86=85=E7=BD=AE=E5=BA=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Core/core.hpp | 2 +- src/Core/executablePath.hpp | 22 ++++++++++++++++++++++ src/Evaluator/evaluator.cpp | 15 ++++++++++++--- 3 files changed, 35 insertions(+), 4 deletions(-) create mode 100644 src/Core/executablePath.hpp diff --git a/src/Core/core.hpp b/src/Core/core.hpp index 3ab42ee..566a779 100644 --- a/src/Core/core.hpp +++ b/src/Core/core.hpp @@ -4,7 +4,7 @@ #include #include -#define __FCORE_VERSION "0.3.7-alpha" +#define __FCORE_VERSION "0.3.8-alpha" #if defined(_WIN32) #define __FCORE_PLATFORM "Windows" diff --git a/src/Core/executablePath.hpp b/src/Core/executablePath.hpp new file mode 100644 index 0000000..ee73e4e --- /dev/null +++ b/src/Core/executablePath.hpp @@ -0,0 +1,22 @@ +#pragma once + +#include +#include + +#ifdef _WIN32 + #include +#endif + +namespace Fig +{ + inline std::filesystem::path getExecutablePath() + { +#ifdef _WIN32 + wchar_t buffer[MAX_PATH]; + GetModuleFileNameW(nullptr, buffer, MAX_PATH); + return std::filesystem::path(buffer); +#else + return std::filesystem::canonical("/proc/self/exe"); +#endif + } +}; // namespace Fig \ No newline at end of file diff --git a/src/Evaluator/evaluator.cpp b/src/Evaluator/evaluator.cpp index d4f9f3c..ac13992 100644 --- a/src/Evaluator/evaluator.cpp +++ b/src/Evaluator/evaluator.cpp @@ -1,5 +1,5 @@ #include -#include "Value/VariableSlot.hpp" +#include #include #include #include @@ -17,6 +17,7 @@ #include #include #include +#include #include #include @@ -68,7 +69,7 @@ namespace Fig AccessModifier::PublicConst), ctx); // fake l-value } - + if (ctx->hasMethodImplemented(baseVal->getTypeInfo(), member)) { // builtin type implementation! @@ -985,8 +986,8 @@ namespace Fig } default: assert(false); - return Object::getNullInstance(); // ignore warning } + return Object::getNullInstance(); // ignore warning } StatementResult Evaluator::evalBlockStatement(Ast::BlockStatement block, ContextPtr ctx) { @@ -1481,6 +1482,14 @@ namespace Fig static const std::vector defaultLibraryPath{"Library", "Library/fpm"}; std::vector pathToFind(defaultLibraryPath); + + fs::path interpreterPath = getExecutablePath().parent_path(); + + for (fs::path &p : pathToFind) + { + p = interpreterPath / p; // 相对路径 -> 绝对路径 + } + pathToFind.insert( pathToFind.begin(), fs::path(this->sourcePath.toBasicString()).parent_path()); // first search module at the source file path