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