From e7c891175a487497712684ad043baea03b119389 Mon Sep 17 00:00:00 2001 From: jaroslawroszyk Date: Sun, 3 Jul 2022 21:09:59 +0200 Subject: [PATCH 01/13] Creating vector who can handle paths --- VM/src/VM.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/VM/src/VM.cpp b/VM/src/VM.cpp index e8df083..6491571 100644 --- a/VM/src/VM.cpp +++ b/VM/src/VM.cpp @@ -37,11 +37,18 @@ auto Instance::findModulePath(std::string_view name_) const -> fs::path { auto relativeTo = fs::current_path(); auto path = fs::path(std::string(name_)); + auto modulePaths = std::vector{"../lib"}; + auto searchInModulePaths = std::find(modulePaths.begin(),modulePaths.end(), name_); if (currentModule && name_.starts_with("./") || name_.starts_with(".\\")) { relativeTo = currentModule->absolutePath.parent_path(); } + else if(searchInModulePaths != modulePaths.end()) + { + // .....?????? + relativeTo = currentModule->absolutePath.parent_path(); + } path = relativeTo / path; From 1b7c60caccf23e35056ae27206f6157cbe47618a Mon Sep 17 00:00:00 2001 From: jaroslawroszyk Date: Sun, 3 Jul 2022 21:20:39 +0200 Subject: [PATCH 02/13] Creating vector who can handle paths --- VM/src/VM.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/VM/src/VM.cpp b/VM/src/VM.cpp index 6491571..66102d6 100644 --- a/VM/src/VM.cpp +++ b/VM/src/VM.cpp @@ -46,8 +46,8 @@ auto Instance::findModulePath(std::string_view name_) const -> fs::path } else if(searchInModulePaths != modulePaths.end()) { - // .....?????? - relativeTo = currentModule->absolutePath.parent_path(); + // ?????? + relativeTo = currentModule->absolutePath.relative_path(); } path = relativeTo / path; From b62f96c0b1fb99fa6d5008a1b729f0f7f7071613 Mon Sep 17 00:00:00 2001 From: jaroslawroszyk Date: Sun, 3 Jul 2022 21:26:25 +0200 Subject: [PATCH 03/13] Creating vector who can handle paths --- VM/include/RigCVM/TypeSystem/FuncType.hpp | 6 ++++-- VM/src/Executors/All.cpp | 7 +++---- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/VM/include/RigCVM/TypeSystem/FuncType.hpp b/VM/include/RigCVM/TypeSystem/FuncType.hpp index 23aa8a3..eed5c5d 100644 --- a/VM/include/RigCVM/TypeSystem/FuncType.hpp +++ b/VM/include/RigCVM/TypeSystem/FuncType.hpp @@ -7,12 +7,13 @@ namespace rigc::vm { -//todo: refactor maybe use template? struct FuncType : IType { +private: InnerType result; std::vector parameters; +public: bool isVariadic = false; auto name() const -> std::string override; @@ -35,11 +36,12 @@ struct FuncType : IType struct MethodType : IType { +private: InnerType result; InnerType classType; std::vector parameters; - +public: auto name() const -> std::string override; auto symbolName() const -> std::string override { return "Method"; diff --git a/VM/src/Executors/All.cpp b/VM/src/Executors/All.cpp index 9d50659..149cef5 100644 --- a/VM/src/Executors/All.cpp +++ b/VM/src/Executors/All.cpp @@ -99,13 +99,12 @@ auto evaluateExpression(Instance &vm_, rigc::ParserNode const& expr_) -> OptValu return ExpressionExecutor{vm_, expr_}.evaluate(); } -//todo refactor evaluateSymbol and evaluateName //////////////////////////////////////// auto evaluateSymbol(Instance &vm_, rigc::ParserNode const& expr_) -> OptValue { // Either "PossiblyTemplatedSymbol" or "PossiblyTemplatedSymbolNoDisamb" - auto& name = *findElem(expr_, false); - auto opt = vm_.findVariableByName(name.string_view()); + // auto& name = *findElem(expr_, false); + auto opt = vm_.findVariableByName(expr_.string_view()); // if (!opt) { // opt = vm_.findFunctionExpr(actualExpr.string_view()); @@ -113,7 +112,7 @@ auto evaluateSymbol(Instance &vm_, rigc::ParserNode const& expr_) -> OptValue if (!opt) { - throw RigCError("Unrecognized identifier with name \"{}\"", name.string()) + throw RigCError("Unrecognized identifier with name \"{}\"", expr_.string()) .withHelp("Check the spelling of the identifier.") .withLine(vm_.lastEvaluatedLine); } From 8cb69b7204adc8096b7e7d3ef1af5f0c09378d86 Mon Sep 17 00:00:00 2001 From: jaroslawroszyk Date: Sun, 3 Jul 2022 21:42:54 +0200 Subject: [PATCH 04/13] fix(VM): unintended ADL-related error --- VM/include/RigCVM/ErrorHandling/Exceptions.hpp | 1 + VM/include/RigCVM/ErrorHandling/Formatting.hpp | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/VM/include/RigCVM/ErrorHandling/Exceptions.hpp b/VM/include/RigCVM/ErrorHandling/Exceptions.hpp index ddcec1c..3eaeba6 100644 --- a/VM/include/RigCVM/ErrorHandling/Exceptions.hpp +++ b/VM/include/RigCVM/ErrorHandling/Exceptions.hpp @@ -8,6 +8,7 @@ struct RigCError : std::exception { +private: std::string basicMessage; std::string helpMessage; diff --git a/VM/include/RigCVM/ErrorHandling/Formatting.hpp b/VM/include/RigCVM/ErrorHandling/Formatting.hpp index 6186669..b7284b0 100644 --- a/VM/include/RigCVM/ErrorHandling/Formatting.hpp +++ b/VM/include/RigCVM/ErrorHandling/Formatting.hpp @@ -68,7 +68,7 @@ inline auto errorWithLineArgPair(std::size_t line) -> ArgPair auto const value = fmt::format( "{}{}{}{}{}", - format(boldRedFmt, "[Error"), + fmt::format(boldRedFmt, "[Error"), reset, " on line ", format(s().LightBlue, "{}", line), From 2f76d65889250f59f5a8f33bcac14380c8dd0963 Mon Sep 17 00:00:00 2001 From: jaroslawroszyk Date: Wed, 6 Jul 2022 21:41:29 +0200 Subject: [PATCH 05/13] refactor(Parser): delete unused structure --- Parser/include/RigCParser/Grammar/Tokens.hpp | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/Parser/include/RigCParser/Grammar/Tokens.hpp b/Parser/include/RigCParser/Grammar/Tokens.hpp index 74c8bbc..63b7231 100644 --- a/Parser/include/RigCParser/Grammar/Tokens.hpp +++ b/Parser/include/RigCParser/Grammar/Tokens.hpp @@ -11,22 +11,8 @@ namespace rigc struct Name; -struct PackageImportNames - : p::seq< - Name, - p::opt< - p::seq< p::one<'.'>, PackageImportNames> - > - > -{ -}; - struct PackageImportFullName - : - p::sor< - StringLiteral, - PackageImportNames - > + : StringLiteral { }; From cf06db0fefc358ede4826d4772ebdd49b2a2953f Mon Sep 17 00:00:00 2001 From: jaroslawroszyk Date: Wed, 6 Jul 2022 22:40:19 +0200 Subject: [PATCH 06/13] feat(VM): implement path alias system --- VM/src/VM.cpp | 38 +++++++++++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 9 deletions(-) diff --git a/VM/src/VM.cpp b/VM/src/VM.cpp index 66102d6..9feffb6 100644 --- a/VM/src/VM.cpp +++ b/VM/src/VM.cpp @@ -9,7 +9,6 @@ #include #include #include - #include namespace rigc::vm @@ -36,19 +35,40 @@ DEFINE_BUILTIN_CONVERT_OP (double, Float64); auto Instance::findModulePath(std::string_view name_) const -> fs::path { auto relativeTo = fs::current_path(); - auto path = fs::path(std::string(name_)); - auto modulePaths = std::vector{"../lib"}; - auto searchInModulePaths = std::find(modulePaths.begin(),modulePaths.end(), name_); + auto modulePath = fs::path(std::string(name_)); + auto aliasesPaths = std::unordered_map{ + {"root",relativeTo}, + {"std","../lib/std"} + }; if (currentModule && name_.starts_with("./") || name_.starts_with(".\\")) { relativeTo = currentModule->absolutePath.parent_path(); } - else if(searchInModulePaths != modulePaths.end()) - { - // ?????? - relativeTo = currentModule->absolutePath.relative_path(); - } + if(name_.starts_with('@')) { + auto const separatorPos = name_.find(fs::path::preferred_separator); + + if(separatorPos == std::string_view::npos) + { + std::cerr << "Error"; + return 1; + } + else + { + auto const alias = std::string(name_.substr(0, separatorPos)); + auto const mappedPath = aliasesPaths.find(alias); + + if(mappedPath == aliasesPaths.end()) + { + std::cerr << "Error"; + } + else + { + name_.remove_prefix(alias.size() + 1); + relativeTo = mappedPath->second; + } + } + } path = relativeTo / path; From 036fd0a7d5eb9e67330ca20c71ed55911a15c5ee Mon Sep 17 00:00:00 2001 From: jaroslawroszyk Date: Thu, 7 Jul 2022 00:23:00 +0200 Subject: [PATCH 07/13] feat(VM): implement path alias system --- VM/src/VM.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/VM/src/VM.cpp b/VM/src/VM.cpp index 9feffb6..bd08513 100644 --- a/VM/src/VM.cpp +++ b/VM/src/VM.cpp @@ -51,7 +51,7 @@ auto Instance::findModulePath(std::string_view name_) const -> fs::path if(separatorPos == std::string_view::npos) { std::cerr << "Error"; - return 1; + // return 1; } else { @@ -70,20 +70,20 @@ auto Instance::findModulePath(std::string_view name_) const -> fs::path } } - path = relativeTo / path; + modulePath = relativeTo / modulePath; - if (!path.has_extension()) + if (!modulePath.has_extension()) { - path.replace_extension(".rigc"); - if (!fs::exists(path)) + modulePath.replace_extension(".rigc"); + if (!fs::exists(modulePath)) { - path.replace_extension(".rigcz"); - if (!fs::exists(path)) + modulePath.replace_extension(".rigcz"); + if (!fs::exists(modulePath)) return fs::path{}; } } - return path; + return modulePath; } ////////////////////////////////////////// From a857d61f6543ff249ec8e1c2ac95fd0b3100ff2f Mon Sep 17 00:00:00 2001 From: jaroslawroszyk Date: Thu, 7 Jul 2022 18:55:18 +0200 Subject: [PATCH 08/13] feat(VM): implement getting VM path --- VM/include/RigCVM/Enviroment.hpp | 6 ++++++ VM/src/Enviroment.cpp | 24 ++++++++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 VM/include/RigCVM/Enviroment.hpp create mode 100644 VM/src/Enviroment.cpp diff --git a/VM/include/RigCVM/Enviroment.hpp b/VM/include/RigCVM/Enviroment.hpp new file mode 100644 index 0000000..576038a --- /dev/null +++ b/VM/include/RigCVM/Enviroment.hpp @@ -0,0 +1,6 @@ +#include RIGCVM_PCH + +namespace rigc::vm +{ +fs::path getVmAppPath(); +} \ No newline at end of file diff --git a/VM/src/Enviroment.cpp b/VM/src/Enviroment.cpp new file mode 100644 index 0000000..be8f178 --- /dev/null +++ b/VM/src/Enviroment.cpp @@ -0,0 +1,24 @@ +#include "RigCVM/Enviroment.hpp" + +namespace rigc::vm +{ +fs::path getVmAppPath() +{ + std::array buf; + + #ifdef PACC_SYSTEM_WINDOWS + size_t bytes; + #elif defined(PACC_SYSTEM_LINUX) + ssize_t bytes; + #endif + + // Obtain the path in `buf` and length in `bytes` + #ifdef PACC_SYSTEM_WINDOWS + bytes = static_cast( GetModuleFileNameA(nullptr, buf.data(), static_cast(buf.size()) ) ); + #elif defined(PACC_SYSTEM_LINUX) + bytes = std::min(readlink("/proc/self/exe", buf.data(), buf.size()), ssize_t(buf.size() - 1)); + #endif + + return fs::path(std::string(buf.data(), bytes)); +} +} \ No newline at end of file From 506eb1bf37a33126d764d8fac02253f56f540e41 Mon Sep 17 00:00:00 2001 From: jaroslawroszyk Date: Thu, 7 Jul 2022 18:56:58 +0200 Subject: [PATCH 09/13] feat(VM): implement alias path system --- VM/include/RigCVM/VM.hpp | 1 + VM/src/VM.cpp | 68 ++++++++++++++++++++++++---------------- 2 files changed, 42 insertions(+), 27 deletions(-) diff --git a/VM/include/RigCVM/VM.hpp b/VM/include/RigCVM/VM.hpp index 307b65d..2036d30 100644 --- a/VM/include/RigCVM/VM.hpp +++ b/VM/include/RigCVM/VM.hpp @@ -99,6 +99,7 @@ struct Instance auto parseModule(std::string_view name_) -> Module*; + auto getPathFromAlias(std::string_view alias_) const; auto evaluateModule(Module& module_) -> void; auto findModulePath(std::string_view name_) const -> fs::path; diff --git a/VM/src/VM.cpp b/VM/src/VM.cpp index bd08513..493695c 100644 --- a/VM/src/VM.cpp +++ b/VM/src/VM.cpp @@ -2,6 +2,7 @@ #include +#include "RigCVM/Enviroment.hpp" #include #include #include @@ -31,43 +32,56 @@ DEFINE_BUILTIN_CONVERT_OP (double, Float64); #undef DEFINE_BUILTIN_CONVERT_OP +auto Instance::getPathFromAlias(std::string_view alias_) const +{ + auto const relativeStdPath = fs::path("lib/std").make_preferred(); + auto const stdPath = getVmAppPath().parent_path().parent_path() / relativeStdPath; + + auto aliasesPaths = std::unordered_map{ + {"root",fs::current_path()}, + {"std",stdPath} + }; + auto const separatorPos = alias_.find(fs::path::preferred_separator); + + if(separatorPos == std::string_view::npos) + { + throw RigCError("You gave too many characters - end of the string") + .withHelp("Provide less characters") + .withLine(lastEvaluatedLine); + } + else + { + auto const alias = std::string(alias_.substr(0,separatorPos)); + auto const mappedPath = aliasesPaths.find(alias); + if(mappedPath == aliasesPaths.end()) + { + throw RigCError("No suitable path was found") + .withHelp("Provide correct path") + .withLine(lastEvaluatedLine); + } + else + { + alias_.remove_prefix(alias.size() + 1); + return mappedPath->second; + } + } +} + ////////////////////////////////////////// auto Instance::findModulePath(std::string_view name_) const -> fs::path { auto relativeTo = fs::current_path(); auto modulePath = fs::path(std::string(name_)); - auto aliasesPaths = std::unordered_map{ - {"root",relativeTo}, - {"std","../lib/std"} - }; + auto separatorPos = name_.find(fs::path::preferred_separator); + auto alias = std::string(name_.substr(0,separatorPos)); if (currentModule && name_.starts_with("./") || name_.starts_with(".\\")) { relativeTo = currentModule->absolutePath.parent_path(); } - if(name_.starts_with('@')) { - auto const separatorPos = name_.find(fs::path::preferred_separator); - - if(separatorPos == std::string_view::npos) - { - std::cerr << "Error"; - // return 1; - } - else - { - auto const alias = std::string(name_.substr(0, separatorPos)); - auto const mappedPath = aliasesPaths.find(alias); - - if(mappedPath == aliasesPaths.end()) - { - std::cerr << "Error"; - } - else - { - name_.remove_prefix(alias.size() + 1); - relativeTo = mappedPath->second; - } - } + if(name_.starts_with('@')) + { + relativeTo = getPathFromAlias(alias); } modulePath = relativeTo / modulePath; From c2c4fbee0b246efcce377f5dd7332a1497e4d873 Mon Sep 17 00:00:00 2001 From: jaroslawroszyk Date: Thu, 7 Jul 2022 22:58:41 +0200 Subject: [PATCH 10/13] refactor(VM): extract logic into functions --- VM/src/VM.cpp | 43 +++++++++++++++++++++++++++++-------------- 1 file changed, 29 insertions(+), 14 deletions(-) diff --git a/VM/src/VM.cpp b/VM/src/VM.cpp index 493695c..bd64499 100644 --- a/VM/src/VM.cpp +++ b/VM/src/VM.cpp @@ -32,6 +32,17 @@ DEFINE_BUILTIN_CONVERT_OP (double, Float64); #undef DEFINE_BUILTIN_CONVERT_OP +auto getSeparatorPos(std::string_view name_) +{ + return name_.find(fs::path::preferred_separator); +} + +auto getAlias(std::string_view name_) +{ + auto separatorPos = getSeparatorPos(name_); + return std::string(name_.substr(0,separatorPos)); +} + auto Instance::getPathFromAlias(std::string_view alias_) const { auto const relativeStdPath = fs::path("lib/std").make_preferred(); @@ -41,7 +52,7 @@ auto Instance::getPathFromAlias(std::string_view alias_) const {"root",fs::current_path()}, {"std",stdPath} }; - auto const separatorPos = alias_.find(fs::path::preferred_separator); + auto const separatorPos = getSeparatorPos(alias_); if(separatorPos == std::string_view::npos) { @@ -67,13 +78,26 @@ auto Instance::getPathFromAlias(std::string_view alias_) const } } -////////////////////////////////////////// +auto modulePathExtenstionExists(fs::path modulePath) +{ + if (!modulePath.has_extension()) + { + modulePath.replace_extension(".rigc"); + if (!fs::exists(modulePath)) + { + modulePath.replace_extension(".rigcz"); + if (!fs::exists(modulePath)) + return fs::path{}; + } + } + return modulePath; +} + auto Instance::findModulePath(std::string_view name_) const -> fs::path { auto relativeTo = fs::current_path(); auto modulePath = fs::path(std::string(name_)); - auto separatorPos = name_.find(fs::path::preferred_separator); - auto alias = std::string(name_.substr(0,separatorPos)); + auto alias = getAlias(name_); if (currentModule && name_.starts_with("./") || name_.starts_with(".\\")) { @@ -86,16 +110,7 @@ auto Instance::findModulePath(std::string_view name_) const -> fs::path modulePath = relativeTo / modulePath; - if (!modulePath.has_extension()) - { - modulePath.replace_extension(".rigc"); - if (!fs::exists(modulePath)) - { - modulePath.replace_extension(".rigcz"); - if (!fs::exists(modulePath)) - return fs::path{}; - } - } + modulePathExtenstionExists(modulePath); return modulePath; } From fca527e43f88ac003cf79e49157e3d433d0719a8 Mon Sep 17 00:00:00 2001 From: jaroslawroszyk Date: Fri, 8 Jul 2022 21:45:21 +0200 Subject: [PATCH 11/13] refactor(VM): correction of typos --- VM/include/RigCVM/{Enviroment.hpp => Environment.hpp} | 0 VM/src/{Enviroment.cpp => Environment.cpp} | 2 +- VM/src/VM.cpp | 2 +- 3 files changed, 2 insertions(+), 2 deletions(-) rename VM/include/RigCVM/{Enviroment.hpp => Environment.hpp} (100%) rename VM/src/{Enviroment.cpp => Environment.cpp} (94%) diff --git a/VM/include/RigCVM/Enviroment.hpp b/VM/include/RigCVM/Environment.hpp similarity index 100% rename from VM/include/RigCVM/Enviroment.hpp rename to VM/include/RigCVM/Environment.hpp diff --git a/VM/src/Enviroment.cpp b/VM/src/Environment.cpp similarity index 94% rename from VM/src/Enviroment.cpp rename to VM/src/Environment.cpp index be8f178..630cc9d 100644 --- a/VM/src/Enviroment.cpp +++ b/VM/src/Environment.cpp @@ -1,4 +1,4 @@ -#include "RigCVM/Enviroment.hpp" +#include "RigCVM/Environment.hpp" namespace rigc::vm { diff --git a/VM/src/VM.cpp b/VM/src/VM.cpp index bd64499..35d61a5 100644 --- a/VM/src/VM.cpp +++ b/VM/src/VM.cpp @@ -2,7 +2,7 @@ #include -#include "RigCVM/Enviroment.hpp" +#include "RigCVM/Environment.hpp" #include #include #include From 74264301f66d1697b0a0e861a5b6a57e23d8b090 Mon Sep 17 00:00:00 2001 From: jaroslawroszyk Date: Fri, 8 Jul 2022 21:47:20 +0200 Subject: [PATCH 12/13] refactor(VM): resotre bad changes --- VM/src/Executors/All.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/VM/src/Executors/All.cpp b/VM/src/Executors/All.cpp index 149cef5..d4cde12 100644 --- a/VM/src/Executors/All.cpp +++ b/VM/src/Executors/All.cpp @@ -103,8 +103,8 @@ auto evaluateExpression(Instance &vm_, rigc::ParserNode const& expr_) -> OptValu auto evaluateSymbol(Instance &vm_, rigc::ParserNode const& expr_) -> OptValue { // Either "PossiblyTemplatedSymbol" or "PossiblyTemplatedSymbolNoDisamb" - // auto& name = *findElem(expr_, false); - auto opt = vm_.findVariableByName(expr_.string_view()); + auto& name = *findElem(expr_, false); + auto opt = vm_.findVariableByName(name.string_view()); // if (!opt) { // opt = vm_.findFunctionExpr(actualExpr.string_view()); @@ -112,7 +112,7 @@ auto evaluateSymbol(Instance &vm_, rigc::ParserNode const& expr_) -> OptValue if (!opt) { - throw RigCError("Unrecognized identifier with name \"{}\"", expr_.string()) + throw RigCError("Unrecognized identifier with name \"{}\"", name.string()) .withHelp("Check the spelling of the identifier.") .withLine(vm_.lastEvaluatedLine); } From d224d0f69b3ef33a83462c033ed3f8968e6d2a97 Mon Sep 17 00:00:00 2001 From: jaroslawroszyk Date: Fri, 8 Jul 2022 22:00:58 +0200 Subject: [PATCH 13/13] refactor(VM): improve errors message --- VM/src/VM.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/VM/src/VM.cpp b/VM/src/VM.cpp index 35d61a5..f8b8948 100644 --- a/VM/src/VM.cpp +++ b/VM/src/VM.cpp @@ -56,8 +56,8 @@ auto Instance::getPathFromAlias(std::string_view alias_) const if(separatorPos == std::string_view::npos) { - throw RigCError("You gave too many characters - end of the string") - .withHelp("Provide less characters") + throw RigCError("Could not find module {} - only provided a directory alias", alias_) + .withHelp("Provide a module name, example: {}/Module",alias_) .withLine(lastEvaluatedLine); } else @@ -66,8 +66,8 @@ auto Instance::getPathFromAlias(std::string_view alias_) const auto const mappedPath = aliasesPaths.find(alias); if(mappedPath == aliasesPaths.end()) { - throw RigCError("No suitable path was found") - .withHelp("Provide correct path") + throw RigCError("Could not find alias {}",alias_) + .withHelp("Ensure the {} alias is defined within the configuration file", alias_) .withLine(lastEvaluatedLine); } else @@ -616,4 +616,4 @@ auto Instance::popStackFrame() -> void stack.popFrame(); currentScope = stack.frames.back().scope; } -} +} \ No newline at end of file