diff --git a/CMakeLists.txt b/CMakeLists.txt index 76530f2..b27ead4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -175,7 +175,7 @@ set(CPACK_PACKAGE_INSTALL_DIRECTORY "${PROJECT_NAME} ${CMAKE_PROJECT_VERSION_MAJ set(CPACK_PACKAGE_FILE_NAME "${LOWERCASE_PROJECT_NAME}-${PROJECT_VERSION}-${TIME}.${CMAKE_SYSTEM_PROCESSOR}") include_directories(${CMAKE_CURRENT_LIST_DIR}) -add_executable(${EXENAME} src/main.cpp ${CMAKE_CURRENT_BINARY_DIR}/processed/${PROJECT_NAME}.rc src/etc/filefuncs.cpp src/etc/lexer.cpp src/headers/lex.hpp src/headers/misc.hpp src/headers/parsing/ParseComponents.hpp src/headers/transpiler/Target.hpp src/headers/transpiler/implementations/Lua.hpp src/headers/transpiler/implementations/Js.hpp src/headers/transpiler/implementations/Py.hpp src/headers/parsing/Parser.hpp src/headers/arguments.hpp src/headers/parsing/ReservedIdentifiers.hpp) +add_executable(${EXENAME} src/main.cpp ${CMAKE_CURRENT_BINARY_DIR}/processed/${PROJECT_NAME}.rc src/etc/filefuncs.cpp src/etc/lexer.cpp src/headers/lex.hpp src/headers/misc.hpp src/headers/parsing/ParseComponents.hpp src/headers/transpiler/Target.hpp src/headers/transpiler/implementations/Lua.hpp src/headers/transpiler/implementations/Js.hpp src/headers/transpiler/implementations/Py.hpp src/headers/parsing/Parser.hpp src/headers/arguments.hpp src/headers/parsing/ReservedIdentifiers.hpp src/headers/emscripten_compatibility.h) target_compile_definitions(${EXENAME} PRIVATE YBCON_VERSION="${CODENAME} ${PROJECT_VERSION}") target_precompile_headers(${EXENAME} PRIVATE src/headers/Yerbacon.hpp) if (Threads_FOUND) diff --git a/src/headers/emscripten_compatibility.h b/src/headers/emscripten_compatibility.h new file mode 100644 index 0000000..9b78d94 --- /dev/null +++ b/src/headers/emscripten_compatibility.h @@ -0,0 +1,36 @@ +#ifndef YERBACON_EMSCRIPTEN_COMPATIBILITY_H +#define YERBACON_EMSCRIPTEN_COMPATIBILITY_H + +#include +#include +#include + +filesystem::path mount(const std::string_view& element_path) { + filesystem::path file_path = element_path; +#ifdef EMSCRIPTEN + if (element_path.size() >= 2 and element_path[1] == ':') { + auto path = string(element_path.begin() + 2, element_path.end()); + replace(path.begin(), path.end(), '\\', '/'); + file_path = path; + } + const string directory = filesystem::path(file_path).remove_filename(); + cout << "Directory: " << directory << endl; + for (unsigned int character = 1; character < directory.size(); ++character) { + const string sub_directory = directory.substr(0, character); + if (is_node and (directory[character] == '/') and not filesystem::is_directory(sub_directory)) { + MAIN_THREAD_EM_ASM({ + const sub_directory = UTF8ToString($0); + if (!FS.isMountpoint(sub_directory)) { + try { + FS.mkdir(sub_directory); + FS.mount(NODEFS, {root: sub_directory}, sub_directory); + } catch (exception) {} + }; + }, sub_directory.c_str()); + } + } +#endif + return file_path; +} + +#endif //YERBACON_EMSCRIPTEN_COMPATIBILITY_H \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 0e36ad5..66749d0 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -8,6 +8,7 @@ using namespace std; #include "headers/misc.hpp" #include "headers/arguments.hpp" #include "headers/transpiler/Target.hpp" +#include "headers/emscripten_compatibility.h" int main(int argc, char* argv[]) { setlocale(LC_ALL, ""); @@ -44,38 +45,15 @@ int main(int argc, char* argv[]) { else if (currentArgument == ArgumentShort("text")) printResult = text_provided = true; else if (currentArgument == ArgumentShort("output")) if ((not output_directory.has_value()) and Units.empty() and (i + 1) != argc) { + mount(argv[i + 1]); output_directory = argv[i + 1]; ++i; } else goto invalid_argument; else if (text_provided || currentArgument.ends_with(".ybcon")) { #ifdef _OPENMP if (not parallel) omp_set_num_threads(1); #endif - optional file_path = make_optional(); - if (not text_provided) { - file_path = filesystem::path(currentArgument); - #ifdef EMSCRIPTEN - if (currentArgument.size() >= 2 and currentArgument[1] == ':') { - auto path = string(currentArgument).erase(0, 2); - replace(path.begin(), path.end(), '\\', '/'); - file_path = path; - } - const string directory = filesystem::path(file_path.value()).remove_filename(); - for (unsigned int character = 1; character < directory.size(); ++character) { - const string sub_directory = directory.substr(0, character); - if (is_node and (directory[character] == '/') and not filesystem::is_directory(sub_directory)) { - MAIN_THREAD_EM_ASM({ - const sub_directory = UTF8ToString($0); - if (!FS.isMountpoint(sub_directory)) { - try { - FS.mkdir(sub_directory); - FS.mount(NODEFS, {root: sub_directory}, sub_directory); - } catch (exception) {} - }; - }, sub_directory.c_str()); - } - } - #endif - } + optional file_path; + if (not text_provided) file_path = mount(currentArgument); Units.insert_or_assign(currentArgument, async(not parallel ? launch::deferred : launch::async, [&, currentArgument, file_path, index = Units.size() + 1]() { unit_result resultingPair; try {