From 92e859742812006db40f4013699b579a4658a8b4 Mon Sep 17 00:00:00 2001 From: chris cerne Date: Wed, 18 Dec 2024 00:06:23 -0500 Subject: [PATCH 01/21] Bump version number --- Cargo.lock | 2 +- Cargo.toml | 2 +- package.json | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index caafe12..fd9011f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -19,7 +19,7 @@ dependencies = [ [[package]] name = "gs2compiler" -version = "0.1.0" +version = "0.2.0" dependencies = [ "cmake", "libc", diff --git a/Cargo.toml b/Cargo.toml index f4417ba..c324f81 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "gs2compiler" -version = "0.1.0" +version = "0.2.0" edition = "2021" build = "build.rs" diff --git a/package.json b/package.json index d92005f..88ba7dd 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@xtjoeytx/gs2-parser", - "version": "0.0.2", + "version": "0.2.0", "description": "This is a compiler for the Graal Script 2 (GS2) language.", "main": "dist/gs2test.js", "types": "dist/gs2test.d.ts", From fb9866de595705b63dd5f5de3fa9d16b33befbb1 Mon Sep 17 00:00:00 2001 From: chris cerne Date: Wed, 18 Dec 2024 00:34:52 -0500 Subject: [PATCH 02/21] Cleaned CMakeLists file & build.rs, remove building files to lib/ directory, bump version numbers, update deps --- CMakeLists.txt | 98 ++++++++++++++++++++++++++++++++++---------------- Cargo.lock | 23 ++++++++---- Cargo.toml | 2 +- build.rs | 23 +++++++----- package.json | 2 +- 5 files changed, 100 insertions(+), 48 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1b11e05..c0114ac 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,27 +1,30 @@ cmake_minimum_required(VERSION 3.10) project(gs2test VERSION 1.0) +set(CMAKE_VERBOSE_MAKEFILE ON) set(CMAKE_DEBUG_POSTFIX _d) set(BIN_DIR "bin" CACHE STRING "Binary output directory") # specify the C++ standard -set(CMAKE_CXX_STANDARD 23) -set(CMAKE_CXX_STANDARD_REQUIRED True) +set(CMAKE_CXX_STANDARD 20) +set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_POSITION_INDEPENDENT_CODE ON) -# Set up output directories -set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/lib) -set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/lib) -set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/${BIN_DIR}) - -# Second, for multi-config builds (e.g. msvc) -foreach( OUTPUTCONFIG ${CMAKE_CONFIGURATION_TYPES} ) - string( TOUPPER ${OUTPUTCONFIG} OUTPUTCONFIG ) - set( CMAKE_ARCHIVE_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${PROJECT_SOURCE_DIR}/lib ) - set( CMAKE_LIBRARY_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${PROJECT_SOURCE_DIR}/lib ) - set( CMAKE_RUNTIME_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${PROJECT_SOURCE_DIR}/${BIN_DIR} ) -endforeach( OUTPUTCONFIG CMAKE_CONFIGURATION_TYPES ) +# TODO: @xtjoeytx, do we need this? It breaks the rust build. I think we should leave it +# up to the user of the library to specify how the output should be built. +# Set up output ditrectories +# set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/lib) +# set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/lib) +# set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/${BIN_DIR}) + +# # Second, for multi-config builds (e.g. msvc) +# foreach( OUTPUTCONFIG ${CMAKE_CONFIGURATION_TYPES} ) +# string( TOUPPER ${OUTPUTCONFIG} OUTPUTCONFIG ) +# set( CMAKE_ARCHIVE_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${PROJECT_SOURCE_DIR}/lib ) +# set( CMAKE_LIBRARY_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${PROJECT_SOURCE_DIR}/lib ) +# set( CMAKE_RUNTIME_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${PROJECT_SOURCE_DIR}/${BIN_DIR} ) +# endforeach( OUTPUTCONFIG CMAKE_CONFIGURATION_TYPES ) link_directories(${PROJECT_SOURCE_DIR}/lib) @@ -30,16 +33,43 @@ if(WIN32 OR APPLE) set(CMAKE_STATIC_LIBRARY_PREFIX "lib") endif() +# Attempt to find Bison and Flex first +find_package(BISON 3.4 QUIET) +find_package(FLEX QUIET) + +# If still not found, fail +if(NOT BISON_FOUND) + message(FATAL_ERROR "Bison not found. Please install Bison.") +endif() +if(NOT FLEX_FOUND) + message(FATAL_ERROR "Flex not found. Please install Flex.") +endif() + if(WIN32 AND NOT MINGW) - execute_process(COMMAND ${CMAKE_COMMAND} -S${CMAKE_CURRENT_SOURCE_DIR}/dependencies/winflexbison -B${CMAKE_CURRENT_SOURCE_DIR}/dependencies/winflexbison/build-winflex-bison -GNinja -DCMAKE_BUILD_TYPE=Release) - execute_process(COMMAND ${CMAKE_COMMAND} --build ${CMAKE_CURRENT_SOURCE_DIR}/dependencies/winflexbison/build-winflex-bison --parallel 8) - LIST(APPEND CMAKE_PROGRAM_PATH ${CMAKE_CURRENT_SOURCE_DIR}/dependencies/winflexbison/bin/Release) set(FLEX_FLAGS "--wincompat") -endif(WIN32 AND NOT MINGW) +endif() + +# Check for std::format support +include(CheckCXXSourceCompiles) -find_package(BISON 3.4 REQUIRED) -find_package(FLEX REQUIRED) +set(TEST_CODE " +#include +#include +int main() { + std::string s = std::format(\"Hello, {}!\", \"World\"); + return s.empty() ? 1 : 0; +} +") +check_cxx_source_compiles("${TEST_CODE}" HAS_STD_FORMAT) + +if(HAS_STD_FORMAT) + message(STATUS "std::format is available and works.") +else() + message(FATAL_ERROR "std::format not available or not functional, fallback needed.") +endif() + +# Generate parser and scanner with Bison / Flex BISON_TARGET(GS2Parser generator/gs2parser.y ${CMAKE_CURRENT_BINARY_DIR}/gs2parser.tab.cc) FLEX_TARGET(GS2Scanner generator/gs2scanner.l ${CMAKE_CURRENT_BINARY_DIR}/lex.yy.cc DEFINES_FILE ${CMAKE_CURRENT_BINARY_DIR}/lex.yy.h COMPILE_FLAGS "${FLEX_FLAGS}") ADD_FLEX_BISON_DEPENDENCY(GS2Scanner GS2Parser) @@ -81,35 +111,41 @@ set(SOURCES_ALL ${BISON_GS2Parser_INPUT} ${FLEX_GS2Scanner_INPUT} ${BISON_GS2Parser_OUTPUTS} - ${FLEX_GS2Scanner_OUTPUTS}) + ${FLEX_GS2Scanner_OUTPUTS} +) -add_subdirectory(${PROJECT_SOURCE_DIR}/dependencies/fmtlib EXCLUDE_FROM_ALL) +# Add fmtlib dependency +# add_subdirectory(${PROJECT_SOURCE_DIR}/dependencies/fmtlib EXCLUDE_FROM_ALL) -if (DEFINED EMSCRIPTEN) +# If building for Emscripten, build a JS/WASM target +if(DEFINED EMSCRIPTEN) add_executable(gs2test ${SOURCES_ALL} src/js_interface.cpp) - set_target_properties(gs2test PROPERTIES LINK_FLAGS "--embind-emit-tsd gs2test.d.ts -s ENVIRONMENT=web -s DYNAMIC_EXECUTION=0 -s SINGLE_FILE=1 -s MODULARIZE -s 'EXPORT_NAME=GS2Compiler' --bind") + set_target_properties(gs2test PROPERTIES + LINK_FLAGS "--embind-emit-tsd gs2test.d.ts -s ENVIRONMENT=web -s DYNAMIC_EXECUTION=0 -s SINGLE_FILE=1 -s MODULARIZE -s 'EXPORT_NAME=GS2Compiler' --bind") else() add_executable(gs2test ${SOURCES_ALL} src/main.cpp) endif() -if (STATIC) +# Add library (static or shared) +if(STATIC) add_library(gs2compiler STATIC ${SOURCES_ALL}) else() add_library(gs2compiler SHARED ${SOURCES_ALL}) endif() +# On Windows + MinGW, ensure -fno-rtti is set +# TODO: Why is this necessary? Is it for performance / compatibility reasons? if(WIN32 AND MINGW) target_compile_options(gs2compiler PRIVATE "-fno-rtti") endif() -set_property(TARGET gs2test PROPERTY CXX_STANDARD 23) -set_property(TARGET gs2compiler PROPERTY CXX_STANDARD 23) - -target_link_libraries(gs2test fmt::fmt) -target_link_libraries(gs2compiler fmt::fmt) +# Link fmtlib +#target_link_libraries(gs2test fmt::fmt) +#target_link_libraries(gs2compiler fmt::fmt) set(GS2COMPILER_INCLUDE_DIRECTORY "${PROJECT_SOURCE_DIR}/include" "${PROJECT_BINARY_DIR}/include" "${PROJECT_SOURCE_DIR}/src" - PARENT_SCOPE) + PARENT_SCOPE +) diff --git a/Cargo.lock b/Cargo.lock index fd9011f..bc89e1b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,22 +4,25 @@ version = 3 [[package]] name = "cc" -version = "1.1.7" +version = "1.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26a5c3fd7bfa1ce3897a3a3501d362b2d87b7f2583ebcb4a949ec25911025cbc" +checksum = "9157bbaa6b165880c27a4293a474c91cdcf265cc68cc829bf10be0964a391caf" +dependencies = [ + "shlex", +] [[package]] name = "cmake" -version = "0.1.50" +version = "0.1.52" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a31c789563b815f77f4250caee12365734369f942439b7defd71e18a48197130" +checksum = "c682c223677e0e5b6b7f63a64b9351844c3f1b1678a68b7ee617e30fb082620e" dependencies = [ "cc", ] [[package]] name = "gs2compiler" -version = "0.2.0" +version = "0.2.1" dependencies = [ "cmake", "libc", @@ -27,6 +30,12 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.155" +version = "0.2.168" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5aaeb2981e0606ca11d79718f8bb01164f1d6ed75080182d3abf017e6d244b6d" + +[[package]] +name = "shlex" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" diff --git a/Cargo.toml b/Cargo.toml index c324f81..0955c2b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "gs2compiler" -version = "0.2.0" +version = "0.2.1" edition = "2021" build = "build.rs" diff --git a/build.rs b/build.rs index bba0957..de21c96 100644 --- a/build.rs +++ b/build.rs @@ -4,8 +4,6 @@ use cmake::Config; // Constants for common library names const DEBUG_SUFFIX_GS2: &str = "_d"; -const DEBUG_SUFFIX_FMT: &str = "d"; -const STATIC_LIB_DIR: &str = "lib"; fn main() { let profile = env::var("PROFILE").unwrap_or_else(|_| "release".to_string()); @@ -13,14 +11,24 @@ fn main() { // Determine the appropriate library names based on the profile and platform let gs2_compiler_lib = library_name("gs2compiler", &profile, DEBUG_SUFFIX_GS2, &target); - let fmt_lib = library_name("fmt", &profile, DEBUG_SUFFIX_FMT, &target); let mut cmake_config = Config::new("."); cmake_config.build_target("gs2compiler").define("STATIC", "ON"); let cpp_lib = configure_platform_specifics(&target, &mut cmake_config); - link_libraries(cmake_config.build(), cpp_lib, &gs2_compiler_lib, &fmt_lib); + let lib_path = cmake_config.build(); + + // Add the appropriate subdirectory (e.g., Debug or Release) + let build_subdir = if profile == "debug" { + "build/Debug" + } else { + "build/Release" + }; + + let full_lib_path = lib_path.join(build_subdir); + + link_libraries(full_lib_path, cpp_lib, &gs2_compiler_lib); } fn library_name(base: &str, profile: &str, debug_suffix: &str, target: &str) -> String { @@ -49,13 +57,12 @@ fn configure_platform_specifics(target: &str, cmake_config: &mut Config) -> &'st } } -fn link_libraries(lib_path: PathBuf, cpp_lib: &str, gs2_lib: &str, fmt_lib: &str) { - let lib_dir = env::current_dir().unwrap().join(STATIC_LIB_DIR); +fn link_libraries(lib_path: PathBuf, cpp_lib: &str, gs2_lib: &str) { + // let lib_dir = env::current_dir().unwrap().join(STATIC_LIB_DIR); println!("cargo:rustc-link-lib=dylib={}", cpp_lib); println!("cargo:rustc-link-search=native={}", lib_path.display()); - println!("cargo:rustc-link-search=native={}", lib_dir.display()); + // println!("cargo:rustc-link-search=native={}", lib_dir.display()); println!("cargo:rustc-link-lib=static={}", gs2_lib); - println!("cargo:rustc-link-lib=static={}", fmt_lib); } diff --git a/package.json b/package.json index 88ba7dd..d07c7ea 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@xtjoeytx/gs2-parser", - "version": "0.2.0", + "version": "0.2.1", "description": "This is a compiler for the Graal Script 2 (GS2) language.", "main": "dist/gs2test.js", "types": "dist/gs2test.d.ts", From cb9d119e0a42688ca0f083ed0951e407d21377b3 Mon Sep 17 00:00:00 2001 From: chris cerne Date: Wed, 18 Dec 2024 00:38:14 -0500 Subject: [PATCH 03/21] Added Cargo.toml license & description, bumped version --- Cargo.lock | 2 +- Cargo.toml | 4 +++- package.json | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index bc89e1b..d5d121d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -22,7 +22,7 @@ dependencies = [ [[package]] name = "gs2compiler" -version = "0.2.1" +version = "0.2.2" dependencies = [ "cmake", "libc", diff --git a/Cargo.toml b/Cargo.toml index 0955c2b..ad40d3b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,8 +1,10 @@ [package] name = "gs2compiler" -version = "0.2.1" +version = "0.2.2" edition = "2021" build = "build.rs" +description = "Compiles GS2 source code into GS2 bytecode." +license = "GPL-3.0-only" [dependencies] libc = "0.2.155" diff --git a/package.json b/package.json index d07c7ea..4052975 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@xtjoeytx/gs2-parser", - "version": "0.2.1", + "version": "0.2.2", "description": "This is a compiler for the Graal Script 2 (GS2) language.", "main": "dist/gs2test.js", "types": "dist/gs2test.d.ts", From 612f27a3720ae88d56093d7be38ff9a532204157 Mon Sep 17 00:00:00 2001 From: chris cerne Date: Wed, 18 Dec 2024 00:04:59 -0500 Subject: [PATCH 04/21] Removed fmtlib dependency. Removed winflexbison dependency & require user to have flex and bison installed as part of a build requirement --- .gitignore | 5 ++++- .gitmodules | 6 ------ CMakeLists.txt | 25 +++++++++++-------------- build.rs | 18 ++++-------------- dependencies/fmtlib | 1 - dependencies/winflexbison | 1 - src/GS2Context.cpp | 2 +- src/Parser.cpp | 12 ++++++------ src/Parser.h | 2 +- src/main.cpp | 2 +- src/visitors/GS2CompilerVisitor.cpp | 10 +++++----- src/visitors/GS2CompilerVisitor.h | 1 + 12 files changed, 34 insertions(+), 51 deletions(-) delete mode 160000 dependencies/fmtlib delete mode 160000 dependencies/winflexbison diff --git a/.gitignore b/.gitignore index dc30f00..4e5f91c 100644 --- a/.gitignore +++ b/.gitignore @@ -57,5 +57,8 @@ cmake-build-*/ # Added by cargo - /target +/lib + +# Ignore dependencies +/dependencies \ No newline at end of file diff --git a/.gitmodules b/.gitmodules index 5c96a90..a7a569e 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,9 +1,3 @@ -[submodule "dependencies/fmtlib"] - path = dependencies/fmtlib - url = https://github.com/fmtlib/fmt.git -[submodule "dependencies/winflexbison"] - path = dependencies/winflexbison - url = https://github.com/lexxmark/winflexbison.git [submodule "dependencies/emsdk"] path = dependencies/emsdk url = https://github.com/emscripten-core/emsdk.git diff --git a/CMakeLists.txt b/CMakeLists.txt index c0114ac..e4d0003 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,5 @@ cmake_minimum_required(VERSION 3.10) project(gs2test VERSION 1.0) -set(CMAKE_VERBOSE_MAKEFILE ON) set(CMAKE_DEBUG_POSTFIX _d) @@ -11,20 +10,18 @@ set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_POSITION_INDEPENDENT_CODE ON) -# TODO: @xtjoeytx, do we need this? It breaks the rust build. I think we should leave it -# up to the user of the library to specify how the output should be built. # Set up output ditrectories -# set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/lib) -# set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/lib) -# set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/${BIN_DIR}) - -# # Second, for multi-config builds (e.g. msvc) -# foreach( OUTPUTCONFIG ${CMAKE_CONFIGURATION_TYPES} ) -# string( TOUPPER ${OUTPUTCONFIG} OUTPUTCONFIG ) -# set( CMAKE_ARCHIVE_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${PROJECT_SOURCE_DIR}/lib ) -# set( CMAKE_LIBRARY_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${PROJECT_SOURCE_DIR}/lib ) -# set( CMAKE_RUNTIME_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${PROJECT_SOURCE_DIR}/${BIN_DIR} ) -# endforeach( OUTPUTCONFIG CMAKE_CONFIGURATION_TYPES ) +set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/lib) +set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/lib) +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/${BIN_DIR}) + +# Second, for multi-config builds (e.g. msvc) +foreach( OUTPUTCONFIG ${CMAKE_CONFIGURATION_TYPES} ) + string( TOUPPER ${OUTPUTCONFIG} OUTPUTCONFIG ) + set( CMAKE_ARCHIVE_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${PROJECT_SOURCE_DIR}/lib ) + set( CMAKE_LIBRARY_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${PROJECT_SOURCE_DIR}/lib ) + set( CMAKE_RUNTIME_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${PROJECT_SOURCE_DIR}/${BIN_DIR} ) +endforeach( OUTPUTCONFIG CMAKE_CONFIGURATION_TYPES ) link_directories(${PROJECT_SOURCE_DIR}/lib) diff --git a/build.rs b/build.rs index de21c96..b541d0d 100644 --- a/build.rs +++ b/build.rs @@ -4,6 +4,7 @@ use cmake::Config; // Constants for common library names const DEBUG_SUFFIX_GS2: &str = "_d"; +const STATIC_LIB_DIR: &str = "lib"; fn main() { let profile = env::var("PROFILE").unwrap_or_else(|_| "release".to_string()); @@ -17,18 +18,7 @@ fn main() { let cpp_lib = configure_platform_specifics(&target, &mut cmake_config); - let lib_path = cmake_config.build(); - - // Add the appropriate subdirectory (e.g., Debug or Release) - let build_subdir = if profile == "debug" { - "build/Debug" - } else { - "build/Release" - }; - - let full_lib_path = lib_path.join(build_subdir); - - link_libraries(full_lib_path, cpp_lib, &gs2_compiler_lib); + link_libraries(cmake_config.build(), cpp_lib, &gs2_compiler_lib); } fn library_name(base: &str, profile: &str, debug_suffix: &str, target: &str) -> String { @@ -58,11 +48,11 @@ fn configure_platform_specifics(target: &str, cmake_config: &mut Config) -> &'st } fn link_libraries(lib_path: PathBuf, cpp_lib: &str, gs2_lib: &str) { - // let lib_dir = env::current_dir().unwrap().join(STATIC_LIB_DIR); + let lib_dir = env::current_dir().unwrap().join(STATIC_LIB_DIR); println!("cargo:rustc-link-lib=dylib={}", cpp_lib); println!("cargo:rustc-link-search=native={}", lib_path.display()); - // println!("cargo:rustc-link-search=native={}", lib_dir.display()); + println!("cargo:rustc-link-search=native={}", lib_dir.display()); println!("cargo:rustc-link-lib=static={}", gs2_lib); } diff --git a/dependencies/fmtlib b/dependencies/fmtlib deleted file mode 160000 index 34caecd..0000000 --- a/dependencies/fmtlib +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 34caecd6b6850adb3e57218dc28f14eaafd5cf0e diff --git a/dependencies/winflexbison b/dependencies/winflexbison deleted file mode 160000 index 9118533..0000000 --- a/dependencies/winflexbison +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 911853359017d3e817d638a0de18881eb7960de9 diff --git a/src/GS2Context.cpp b/src/GS2Context.cpp index 5d201cb..a863a6a 100644 --- a/src/GS2Context.cpp +++ b/src/GS2Context.cpp @@ -1,4 +1,4 @@ -#include +#include #include "GS2Context.h" #include "encoding/graalencoding.h" #include "visitors/GS2CompilerVisitor.h" diff --git a/src/Parser.cpp b/src/Parser.cpp index 26ac66f..91b53e9 100644 --- a/src/Parser.cpp +++ b/src/Parser.cpp @@ -106,7 +106,7 @@ std::string* ParserContext::saveString(const char* str, int length, bool unquote std::string * ParserContext::generateLambdaFuncName() { - std::string fnName = fmt::format("function_{}_1", 100 + lambdaFunctionCount); + std::string fnName = std::format("function_{}_1", 100 + lambdaFunctionCount); lambdaFunctionCount++; return saveString(fnName.c_str(), int(fnName.length())); } @@ -139,7 +139,7 @@ void ParserContext::addConstant(const std::string& ident, ExpressionIdentifierNo if (constant) { // report error - redefining constant - addParserError(fmt::format("redefinition of constant {}", ident)); + addParserError(std::format("redefinition of constant {}", ident)); return; } @@ -168,7 +168,7 @@ void ParserContext::addConstant(const std::string& ident, ExpressionIdentifierNo else { // report error - constant does not exist - addParserError(fmt::format("constant {} is undefined", ident)); + addParserError(std::format("constant {} is undefined", ident)); return; } } @@ -187,7 +187,7 @@ void ParserContext::addConstant(const std::string& ident, ExpressionNode *node) auto constant = getConstant(ident); if (constant) { - addParserError(fmt::format("redefinition of constant {}", ident)); + addParserError(std::format("redefinition of constant {}", ident)); return; } @@ -205,11 +205,11 @@ void ParserContext::addParserError(const std::string& errmsg) std::string msg; if (lineText.empty()) { - msg = fmt::format("parser error occurred near line {}: {}", lineNumber, errmsg); + msg = std::format("parser error occurred near line {}: {}", lineNumber, errmsg); } else { - msg = fmt::format("{} at line {}: {}", errmsg, lineNumber, lineText); + msg = std::format("{} at line {}: {}", errmsg, lineNumber, lineText); } addError({ ErrorLevel::E_ERROR, GS2CompilerError::ErrorCategory::Parser, std::move(msg) }); diff --git a/src/Parser.h b/src/Parser.h index c9d08fc..4c4f6de 100644 --- a/src/Parser.h +++ b/src/Parser.h @@ -12,7 +12,7 @@ #include #include -#include +#include #include "ast/ast.h" #include "exceptions/GS2CompilerError.h" diff --git a/src/main.cpp b/src/main.cpp index edddeaa..6adef3d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -87,7 +87,7 @@ int main(int argc, const char *argv[]) { // yydebug = 1; #endif -// auto ret = fmt::format("Test {}", 42); +// auto ret = std::format("Test {}", 42); // printf("Test: %s\n", ret.c_str()); //auto ret = std::format("test {}", 3); //printf("Test: %s\n", ret.c_str()); diff --git a/src/visitors/GS2CompilerVisitor.cpp b/src/visitors/GS2CompilerVisitor.cpp index f471614..6e6b5c6 100644 --- a/src/visitors/GS2CompilerVisitor.cpp +++ b/src/visitors/GS2CompilerVisitor.cpp @@ -86,7 +86,7 @@ void GS2CompilerVisitor::writeLabels() void GS2CompilerVisitor::Visit(Node *node) { - std::string errorMsg = fmt::format("unimplemented node type {}", node->NodeType()); + std::string errorMsg = std::format("unimplemented node type {}", node->NodeType()); parserContext.addError({ ErrorLevel::E_ERROR, GS2CompilerError::ErrorCategory::Compiler, errorMsg }); #ifdef DBGEMITTERS @@ -470,7 +470,7 @@ void GS2CompilerVisitor::Visit(ExpressionBinaryOpNode *node) } } - std::string errorMsg = fmt::format("Undefined opcode in BinaryExpression {}: {} {}", node->op, ExpressionOpToString(node->op), node->toString()); + std::string errorMsg = std::format("Undefined opcode in BinaryExpression {}: {} {}", static_cast(node->op), ExpressionOpToString(node->op), node->toString()); parserContext.addError({ ErrorLevel::E_ERROR, GS2CompilerError::ErrorCategory::Compiler, std::move(errorMsg) }); } @@ -599,7 +599,7 @@ void GS2CompilerVisitor::Visit(ExpressionUnaryOpNode* node) } } - std::string errorMsg = fmt::format("Undefined opcode in UnaryExpression {}: {}", node->op, ExpressionOpToString(node->op)); + std::string errorMsg = std::format("Undefined opcode in UnaryExpression {}: {}", static_cast(node->op), ExpressionOpToString(node->op)); parserContext.addError({ ErrorLevel::E_ERROR, GS2CompilerError::ErrorCategory::Compiler, std::move(errorMsg) }); } @@ -1172,7 +1172,7 @@ void GS2CompilerVisitor::Visit(StatementBreakNode* node) { if (break_label <= 0) { - std::string errorMsg = fmt::format("`break` outside loop detected"); + std::string errorMsg = std::format("`break` outside loop detected"); parserContext.addError({ ErrorLevel::E_WARNING, GS2CompilerError::ErrorCategory::Compiler, std::move(errorMsg) }); return; } @@ -1188,7 +1188,7 @@ void GS2CompilerVisitor::Visit(StatementContinueNode* node) { if (continue_label <= 0) { - std::string errorMsg = fmt::format("`continue` outside loop detected"); + std::string errorMsg = std::format("`continue` outside loop detected"); parserContext.addError({ ErrorLevel::E_WARNING, GS2CompilerError::ErrorCategory::Compiler, std::move(errorMsg) }); return; } diff --git a/src/visitors/GS2CompilerVisitor.h b/src/visitors/GS2CompilerVisitor.h index efd9eb4..4a15e60 100644 --- a/src/visitors/GS2CompilerVisitor.h +++ b/src/visitors/GS2CompilerVisitor.h @@ -7,6 +7,7 @@ #include #include #include +#include #include "ast/astvisitor.h" #include "GS2Bytecode.h" #include "GS2BuiltInFunctions.h" From 5c6a7d62870b3128c489824a0520bef4be8c9eef Mon Sep 17 00:00:00 2001 From: chris cerne Date: Wed, 18 Dec 2024 00:06:23 -0500 Subject: [PATCH 05/21] Bump version number --- Cargo.lock | 23 +++++++---------------- Cargo.toml | 4 +--- package.json | 2 +- 3 files changed, 9 insertions(+), 20 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d5d121d..fd9011f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,25 +4,22 @@ version = 3 [[package]] name = "cc" -version = "1.2.4" +version = "1.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9157bbaa6b165880c27a4293a474c91cdcf265cc68cc829bf10be0964a391caf" -dependencies = [ - "shlex", -] +checksum = "26a5c3fd7bfa1ce3897a3a3501d362b2d87b7f2583ebcb4a949ec25911025cbc" [[package]] name = "cmake" -version = "0.1.52" +version = "0.1.50" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c682c223677e0e5b6b7f63a64b9351844c3f1b1678a68b7ee617e30fb082620e" +checksum = "a31c789563b815f77f4250caee12365734369f942439b7defd71e18a48197130" dependencies = [ "cc", ] [[package]] name = "gs2compiler" -version = "0.2.2" +version = "0.2.0" dependencies = [ "cmake", "libc", @@ -30,12 +27,6 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.168" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5aaeb2981e0606ca11d79718f8bb01164f1d6ed75080182d3abf017e6d244b6d" - -[[package]] -name = "shlex" -version = "1.3.0" +version = "0.2.155" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" +checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" diff --git a/Cargo.toml b/Cargo.toml index ad40d3b..c324f81 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,10 +1,8 @@ [package] name = "gs2compiler" -version = "0.2.2" +version = "0.2.0" edition = "2021" build = "build.rs" -description = "Compiles GS2 source code into GS2 bytecode." -license = "GPL-3.0-only" [dependencies] libc = "0.2.155" diff --git a/package.json b/package.json index 4052975..88ba7dd 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@xtjoeytx/gs2-parser", - "version": "0.2.2", + "version": "0.2.0", "description": "This is a compiler for the Graal Script 2 (GS2) language.", "main": "dist/gs2test.js", "types": "dist/gs2test.d.ts", From 613284ac041f54b9b6b7be24baf06e5485a7f76f Mon Sep 17 00:00:00 2001 From: chris cerne Date: Wed, 18 Dec 2024 00:34:52 -0500 Subject: [PATCH 06/21] Cleaned CMakeLists file & build.rs, remove building files to lib/ directory, bump version numbers, update deps --- CMakeLists.txt | 25 ++++++++++++++----------- Cargo.lock | 23 ++++++++++++++++------- Cargo.toml | 2 +- build.rs | 18 ++++++++++++++---- package.json | 2 +- 5 files changed, 46 insertions(+), 24 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e4d0003..c0114ac 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,6 @@ cmake_minimum_required(VERSION 3.10) project(gs2test VERSION 1.0) +set(CMAKE_VERBOSE_MAKEFILE ON) set(CMAKE_DEBUG_POSTFIX _d) @@ -10,18 +11,20 @@ set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_POSITION_INDEPENDENT_CODE ON) +# TODO: @xtjoeytx, do we need this? It breaks the rust build. I think we should leave it +# up to the user of the library to specify how the output should be built. # Set up output ditrectories -set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/lib) -set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/lib) -set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/${BIN_DIR}) - -# Second, for multi-config builds (e.g. msvc) -foreach( OUTPUTCONFIG ${CMAKE_CONFIGURATION_TYPES} ) - string( TOUPPER ${OUTPUTCONFIG} OUTPUTCONFIG ) - set( CMAKE_ARCHIVE_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${PROJECT_SOURCE_DIR}/lib ) - set( CMAKE_LIBRARY_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${PROJECT_SOURCE_DIR}/lib ) - set( CMAKE_RUNTIME_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${PROJECT_SOURCE_DIR}/${BIN_DIR} ) -endforeach( OUTPUTCONFIG CMAKE_CONFIGURATION_TYPES ) +# set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/lib) +# set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/lib) +# set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/${BIN_DIR}) + +# # Second, for multi-config builds (e.g. msvc) +# foreach( OUTPUTCONFIG ${CMAKE_CONFIGURATION_TYPES} ) +# string( TOUPPER ${OUTPUTCONFIG} OUTPUTCONFIG ) +# set( CMAKE_ARCHIVE_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${PROJECT_SOURCE_DIR}/lib ) +# set( CMAKE_LIBRARY_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${PROJECT_SOURCE_DIR}/lib ) +# set( CMAKE_RUNTIME_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${PROJECT_SOURCE_DIR}/${BIN_DIR} ) +# endforeach( OUTPUTCONFIG CMAKE_CONFIGURATION_TYPES ) link_directories(${PROJECT_SOURCE_DIR}/lib) diff --git a/Cargo.lock b/Cargo.lock index fd9011f..bc89e1b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,22 +4,25 @@ version = 3 [[package]] name = "cc" -version = "1.1.7" +version = "1.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26a5c3fd7bfa1ce3897a3a3501d362b2d87b7f2583ebcb4a949ec25911025cbc" +checksum = "9157bbaa6b165880c27a4293a474c91cdcf265cc68cc829bf10be0964a391caf" +dependencies = [ + "shlex", +] [[package]] name = "cmake" -version = "0.1.50" +version = "0.1.52" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a31c789563b815f77f4250caee12365734369f942439b7defd71e18a48197130" +checksum = "c682c223677e0e5b6b7f63a64b9351844c3f1b1678a68b7ee617e30fb082620e" dependencies = [ "cc", ] [[package]] name = "gs2compiler" -version = "0.2.0" +version = "0.2.1" dependencies = [ "cmake", "libc", @@ -27,6 +30,12 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.155" +version = "0.2.168" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5aaeb2981e0606ca11d79718f8bb01164f1d6ed75080182d3abf017e6d244b6d" + +[[package]] +name = "shlex" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" diff --git a/Cargo.toml b/Cargo.toml index c324f81..0955c2b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "gs2compiler" -version = "0.2.0" +version = "0.2.1" edition = "2021" build = "build.rs" diff --git a/build.rs b/build.rs index b541d0d..de21c96 100644 --- a/build.rs +++ b/build.rs @@ -4,7 +4,6 @@ use cmake::Config; // Constants for common library names const DEBUG_SUFFIX_GS2: &str = "_d"; -const STATIC_LIB_DIR: &str = "lib"; fn main() { let profile = env::var("PROFILE").unwrap_or_else(|_| "release".to_string()); @@ -18,7 +17,18 @@ fn main() { let cpp_lib = configure_platform_specifics(&target, &mut cmake_config); - link_libraries(cmake_config.build(), cpp_lib, &gs2_compiler_lib); + let lib_path = cmake_config.build(); + + // Add the appropriate subdirectory (e.g., Debug or Release) + let build_subdir = if profile == "debug" { + "build/Debug" + } else { + "build/Release" + }; + + let full_lib_path = lib_path.join(build_subdir); + + link_libraries(full_lib_path, cpp_lib, &gs2_compiler_lib); } fn library_name(base: &str, profile: &str, debug_suffix: &str, target: &str) -> String { @@ -48,11 +58,11 @@ fn configure_platform_specifics(target: &str, cmake_config: &mut Config) -> &'st } fn link_libraries(lib_path: PathBuf, cpp_lib: &str, gs2_lib: &str) { - let lib_dir = env::current_dir().unwrap().join(STATIC_LIB_DIR); + // let lib_dir = env::current_dir().unwrap().join(STATIC_LIB_DIR); println!("cargo:rustc-link-lib=dylib={}", cpp_lib); println!("cargo:rustc-link-search=native={}", lib_path.display()); - println!("cargo:rustc-link-search=native={}", lib_dir.display()); + // println!("cargo:rustc-link-search=native={}", lib_dir.display()); println!("cargo:rustc-link-lib=static={}", gs2_lib); } diff --git a/package.json b/package.json index 88ba7dd..d07c7ea 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@xtjoeytx/gs2-parser", - "version": "0.2.0", + "version": "0.2.1", "description": "This is a compiler for the Graal Script 2 (GS2) language.", "main": "dist/gs2test.js", "types": "dist/gs2test.d.ts", From bf5173e912ebeb183f044298d95caf781c73a991 Mon Sep 17 00:00:00 2001 From: chris cerne Date: Wed, 18 Dec 2024 00:38:14 -0500 Subject: [PATCH 07/21] Added Cargo.toml license & description, bumped version --- Cargo.lock | 2 +- Cargo.toml | 4 +++- package.json | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index bc89e1b..d5d121d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -22,7 +22,7 @@ dependencies = [ [[package]] name = "gs2compiler" -version = "0.2.1" +version = "0.2.2" dependencies = [ "cmake", "libc", diff --git a/Cargo.toml b/Cargo.toml index 0955c2b..ad40d3b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,8 +1,10 @@ [package] name = "gs2compiler" -version = "0.2.1" +version = "0.2.2" edition = "2021" build = "build.rs" +description = "Compiles GS2 source code into GS2 bytecode." +license = "GPL-3.0-only" [dependencies] libc = "0.2.155" diff --git a/package.json b/package.json index d07c7ea..4052975 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@xtjoeytx/gs2-parser", - "version": "0.2.1", + "version": "0.2.2", "description": "This is a compiler for the Graal Script 2 (GS2) language.", "main": "dist/gs2test.js", "types": "dist/gs2test.d.ts", From 21efa320369b34257167e118a93e1e4c5635b8b4 Mon Sep 17 00:00:00 2001 From: chris cerne Date: Wed, 18 Dec 2024 09:16:08 -0500 Subject: [PATCH 08/21] Upgrade actions --- .github/workflows/release-package.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release-package.yml b/.github/workflows/release-package.yml index 01b82f6..ed7ef40 100644 --- a/.github/workflows/release-package.yml +++ b/.github/workflows/release-package.yml @@ -29,7 +29,7 @@ jobs: # Upload build artifacts - name: Upload build artifacts - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v4 with: name: build-artifacts path: dist From f23d8cb2193cd8e4d3e4a248cce840651944913d Mon Sep 17 00:00:00 2001 From: chris cerne Date: Wed, 18 Dec 2024 09:22:22 -0500 Subject: [PATCH 09/21] Removed emscripten --- .github/workflows/release-package.yml | 58 --------------------------- .gitmodules | 3 -- .npmrc | 3 -- CMakeLists.txt | 15 +++---- README.md | 15 +------ dependencies/emsdk | 1 - package-lock.json | 13 ------ package.json | 16 -------- src/js_interface.cpp | 37 ----------------- 9 files changed, 9 insertions(+), 152 deletions(-) delete mode 100644 .github/workflows/release-package.yml delete mode 100644 .npmrc delete mode 160000 dependencies/emsdk delete mode 100644 package-lock.json delete mode 100644 package.json delete mode 100644 src/js_interface.cpp diff --git a/.github/workflows/release-package.yml b/.github/workflows/release-package.yml deleted file mode 100644 index ed7ef40..0000000 --- a/.github/workflows/release-package.yml +++ /dev/null @@ -1,58 +0,0 @@ -name: Build - -on: - push: - branches: - - feature/* - - dev - - main - tags: - - '[0-9]+.[0-9]+.[0-9]+' - -jobs: - build: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v4 - with: - submodules: recursive - - # Set up Emscripten - - name: Set up Emscripten - uses: mymindstorm/setup-emsdk@v14 - - # Build your project with CMake - - name: Build - run: | - npm run build - - # Upload build artifacts - - name: Upload build artifacts - uses: actions/upload-artifact@v4 - with: - name: build-artifacts - path: dist - - publish: - needs: build - if: github.ref_type == 'tag' - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - name: Download build artifacts - uses: actions/download-artifact@v2 - with: - name: build-artifacts - path: dist - - # Publish to GitHub Packages (adjust for your packaging tool) - - name: Publish - run: | - # Assuming you're generating a npm package - git config --global user.name "${{ github.actor }}" - git config --global user.email "github-action-${{ github.actor }}@users.noreply.github.com" - npm version ${{ github.ref_name }} - npm publish --access public - env: - NPM_CONFIG_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.gitmodules b/.gitmodules index a7a569e..e69de29 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +0,0 @@ -[submodule "dependencies/emsdk"] - path = dependencies/emsdk - url = https://github.com/emscripten-core/emsdk.git diff --git a/.npmrc b/.npmrc deleted file mode 100644 index b9eae83..0000000 --- a/.npmrc +++ /dev/null @@ -1,3 +0,0 @@ -//npm.pkg.github.com/:_authToken=${NPM_CONFIG_TOKEN} -@xtjoeytx:registry=https://npm.pkg.github.com -always-auth=true \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index c0114ac..463d24d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -118,13 +118,14 @@ set(SOURCES_ALL # add_subdirectory(${PROJECT_SOURCE_DIR}/dependencies/fmtlib EXCLUDE_FROM_ALL) # If building for Emscripten, build a JS/WASM target -if(DEFINED EMSCRIPTEN) - add_executable(gs2test ${SOURCES_ALL} src/js_interface.cpp) - set_target_properties(gs2test PROPERTIES - LINK_FLAGS "--embind-emit-tsd gs2test.d.ts -s ENVIRONMENT=web -s DYNAMIC_EXECUTION=0 -s SINGLE_FILE=1 -s MODULARIZE -s 'EXPORT_NAME=GS2Compiler' --bind") -else() - add_executable(gs2test ${SOURCES_ALL} src/main.cpp) -endif() +# if(DEFINED EMSCRIPTEN) +# add_executable(gs2test ${SOURCES_ALL} src/js_interface.cpp) +# set_target_properties(gs2test PROPERTIES +# LINK_FLAGS "--embind-emit-tsd gs2test.d.ts -s ENVIRONMENT=web -s DYNAMIC_EXECUTION=0 -s SINGLE_FILE=1 -s MODULARIZE -s 'EXPORT_NAME=GS2Compiler' --bind") +# else() +# add_executable(gs2test ${SOURCES_ALL} src/main.cpp) +# endif() +add_executable(gs2test ${SOURCES_ALL} src/main.cpp) # Add library (static or shared) if(STATIC) diff --git a/README.md b/README.md index 2169018..7b500ec 100644 --- a/README.md +++ b/README.md @@ -21,22 +21,9 @@ cmake .. make -j $(nproc) ``` -# Building (Wasm) - -First, ensure you have Emscripten installed. Then, you can build the project using CMake: - -```sh -mkdir build -cd build -emcmake cmake .. -make -j $(nproc) -``` - -The resulting `gs2test.js` file can be imported into a webpage. - # Running -The non-wasm build can be run using the following command: +You can use the following command: ```sh $ ./gs2test ../scripts/asd2.txt diff --git a/dependencies/emsdk b/dependencies/emsdk deleted file mode 160000 index 476dc4e..0000000 --- a/dependencies/emsdk +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 476dc4e01fce997b540d9a507241f136256344e3 diff --git a/package-lock.json b/package-lock.json deleted file mode 100644 index 28094aa..0000000 --- a/package-lock.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "name": "@xtjoeytx/gs2-parser", - "version": "0.0.2", - "lockfileVersion": 3, - "requires": true, - "packages": { - "": { - "name": "@xtjoeytx/gs2-parser", - "version": "0.0.2", - "license": "GPL-3.0-only" - } - } -} diff --git a/package.json b/package.json deleted file mode 100644 index 4052975..0000000 --- a/package.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "name": "@xtjoeytx/gs2-parser", - "version": "0.2.2", - "description": "This is a compiler for the Graal Script 2 (GS2) language.", - "main": "dist/gs2test.js", - "types": "dist/gs2test.d.ts", - "scripts": { - "build": "mkdir -p dist && emcmake cmake -S. -Bbuild/ && cmake --build build/ -j$(nproc) && mv -fv ./bin/* ./dist/" - }, - "keywords": [], - "author": "xtjoeytx", - "license": "GPL-3.0-only", - "publishConfig": { - "registry": "https://npm.pkg.github.com" - } -} diff --git a/src/js_interface.cpp b/src/js_interface.cpp deleted file mode 100644 index 2fa39b8..0000000 --- a/src/js_interface.cpp +++ /dev/null @@ -1,37 +0,0 @@ -#include -#include "GS2Context.h" -using namespace emscripten; - -EMSCRIPTEN_BINDINGS(module) { - register_vector("VectorString"); -} - -EMSCRIPTEN_BINDINGS(GS2Context_bindings) { - class_("GS2Context") - .constructor<>() - .function("compile", select_overload(&GS2Context::compile), emscripten::return_value_policy::take_ownership()) - .function("compile", select_overload(&GS2Context::compile), emscripten::return_value_policy::take_ownership()); -} - -emscripten::val getBytecodeFromBuffer(const CompilerResponse &response) { - const Buffer &buf = response.bytecode; - return emscripten::val(emscripten::typed_memory_view(buf.size(), buf.buffer())); -} - -/* getErrors is simply a list of strings for now */ -std::vector getErrors(const CompilerResponse &response) { - std::vector errors; - for (const GS2CompilerError &error : response.errors) { - errors.push_back(error.msg()); - } - - return errors; -} - -EMSCRIPTEN_BINDINGS(CompilerResponse_bindings) { - /* For now, let's just have a test property set to 1 */ - class_("CompilerResponse") - .property("success", &CompilerResponse::success) - .function("getBytecode", &getBytecodeFromBuffer, emscripten::return_value_policy::take_ownership()) - .function("getErrors", &getErrors, emscripten::return_value_policy::take_ownership()); -} \ No newline at end of file From a6a98b2e14724c21336a4a1567b95ee1248f7708 Mon Sep 17 00:00:00 2001 From: chris cerne Date: Wed, 18 Dec 2024 09:33:08 -0500 Subject: [PATCH 10/21] Bump minimum C++ version --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 463d24d..800eee0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,7 +7,7 @@ set(CMAKE_DEBUG_POSTFIX _d) set(BIN_DIR "bin" CACHE STRING "Binary output directory") # specify the C++ standard -set(CMAKE_CXX_STANDARD 20) +set(CMAKE_CXX_STANDARD 23) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_POSITION_INDEPENDENT_CODE ON) From 9f13abd233772e38a9a85e6602c1ad9c52b32c32 Mon Sep 17 00:00:00 2001 From: chris cerne Date: Wed, 18 Dec 2024 10:00:13 -0500 Subject: [PATCH 11/21] Revert to legacy string format due to external dependency bullshit --- CMakeLists.txt | 36 ++----------------- src/GS2Context.cpp | 1 - src/Parser.cpp | 12 +++---- src/Parser.h | 2 +- src/utils/format_string.h | 55 +++++++++++++++++++++++++++++ src/visitors/GS2CompilerVisitor.cpp | 10 +++--- src/visitors/GS2CompilerVisitor.h | 1 - 7 files changed, 70 insertions(+), 47 deletions(-) create mode 100644 src/utils/format_string.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 800eee0..bf60497 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,11 +4,11 @@ set(CMAKE_VERBOSE_MAKEFILE ON) set(CMAKE_DEBUG_POSTFIX _d) -set(BIN_DIR "bin" CACHE STRING "Binary output directory") +# set(BIN_DIR "bin" CACHE STRING "Binary output directory") # specify the C++ standard set(CMAKE_CXX_STANDARD 23) -set(CMAKE_CXX_STANDARD_REQUIRED ON) +# set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_POSITION_INDEPENDENT_CODE ON) # TODO: @xtjoeytx, do we need this? It breaks the rust build. I think we should leave it @@ -49,26 +49,6 @@ if(WIN32 AND NOT MINGW) set(FLEX_FLAGS "--wincompat") endif() -# Check for std::format support -include(CheckCXXSourceCompiles) - -set(TEST_CODE " -#include -#include -int main() { - std::string s = std::format(\"Hello, {}!\", \"World\"); - return s.empty() ? 1 : 0; -} -") - -check_cxx_source_compiles("${TEST_CODE}" HAS_STD_FORMAT) - -if(HAS_STD_FORMAT) - message(STATUS "std::format is available and works.") -else() - message(FATAL_ERROR "std::format not available or not functional, fallback needed.") -endif() - # Generate parser and scanner with Bison / Flex BISON_TARGET(GS2Parser generator/gs2parser.y ${CMAKE_CURRENT_BINARY_DIR}/gs2parser.tab.cc) FLEX_TARGET(GS2Scanner generator/gs2scanner.l ${CMAKE_CURRENT_BINARY_DIR}/lex.yy.cc DEFINES_FILE ${CMAKE_CURRENT_BINARY_DIR}/lex.yy.h COMPILE_FLAGS "${FLEX_FLAGS}") @@ -98,6 +78,7 @@ set(SOURCES_ALL src/utils/EventHandler.h src/exceptions/GS2CompilerError.h src/utils/ContextThreadPool.h + src/utils/format_string.h src/visitors/FunctionInspectVisitor.h src/visitors/GS2CompilerVisitor.h src/visitors/GS2SourceVisitor.h @@ -114,17 +95,6 @@ set(SOURCES_ALL ${FLEX_GS2Scanner_OUTPUTS} ) -# Add fmtlib dependency -# add_subdirectory(${PROJECT_SOURCE_DIR}/dependencies/fmtlib EXCLUDE_FROM_ALL) - -# If building for Emscripten, build a JS/WASM target -# if(DEFINED EMSCRIPTEN) -# add_executable(gs2test ${SOURCES_ALL} src/js_interface.cpp) -# set_target_properties(gs2test PROPERTIES -# LINK_FLAGS "--embind-emit-tsd gs2test.d.ts -s ENVIRONMENT=web -s DYNAMIC_EXECUTION=0 -s SINGLE_FILE=1 -s MODULARIZE -s 'EXPORT_NAME=GS2Compiler' --bind") -# else() -# add_executable(gs2test ${SOURCES_ALL} src/main.cpp) -# endif() add_executable(gs2test ${SOURCES_ALL} src/main.cpp) # Add library (static or shared) diff --git a/src/GS2Context.cpp b/src/GS2Context.cpp index a863a6a..1033cfc 100644 --- a/src/GS2Context.cpp +++ b/src/GS2Context.cpp @@ -1,4 +1,3 @@ -#include #include "GS2Context.h" #include "encoding/graalencoding.h" #include "visitors/GS2CompilerVisitor.h" diff --git a/src/Parser.cpp b/src/Parser.cpp index 91b53e9..ee9df53 100644 --- a/src/Parser.cpp +++ b/src/Parser.cpp @@ -106,7 +106,7 @@ std::string* ParserContext::saveString(const char* str, int length, bool unquote std::string * ParserContext::generateLambdaFuncName() { - std::string fnName = std::format("function_{}_1", 100 + lambdaFunctionCount); + std::string fnName = format_string("function_%d_1", 100 + lambdaFunctionCount); lambdaFunctionCount++; return saveString(fnName.c_str(), int(fnName.length())); } @@ -139,7 +139,7 @@ void ParserContext::addConstant(const std::string& ident, ExpressionIdentifierNo if (constant) { // report error - redefining constant - addParserError(std::format("redefinition of constant {}", ident)); + addParserError(format_string("redefinition of constant %s", ident.c_str())); return; } @@ -168,7 +168,7 @@ void ParserContext::addConstant(const std::string& ident, ExpressionIdentifierNo else { // report error - constant does not exist - addParserError(std::format("constant {} is undefined", ident)); + addParserError(format_string("constant %s is undefined", ident.c_str())); return; } } @@ -187,7 +187,7 @@ void ParserContext::addConstant(const std::string& ident, ExpressionNode *node) auto constant = getConstant(ident); if (constant) { - addParserError(std::format("redefinition of constant {}", ident)); + addParserError(format_string("redefinition of constant %s", ident.c_str())); return; } @@ -205,11 +205,11 @@ void ParserContext::addParserError(const std::string& errmsg) std::string msg; if (lineText.empty()) { - msg = std::format("parser error occurred near line {}: {}", lineNumber, errmsg); + msg = format_string("parser error occurred near line %d: %s", lineNumber, errmsg.c_str()); } else { - msg = std::format("{} at line {}: {}", errmsg, lineNumber, lineText); + msg = format_string("%s at line %d: %s", errmsg.c_str(), lineNumber, lineText.c_str()); } addError({ ErrorLevel::E_ERROR, GS2CompilerError::ErrorCategory::Parser, std::move(msg) }); diff --git a/src/Parser.h b/src/Parser.h index 4c4f6de..f2715d8 100644 --- a/src/Parser.h +++ b/src/Parser.h @@ -12,8 +12,8 @@ #include #include -#include #include "ast/ast.h" +#include "utils/format_string.h" #include "exceptions/GS2CompilerError.h" typedef void* yyscan_t; diff --git a/src/utils/format_string.h b/src/utils/format_string.h new file mode 100644 index 0000000..b3c112d --- /dev/null +++ b/src/utils/format_string.h @@ -0,0 +1,55 @@ +#ifndef FORMAT_STRING_H +#define FORMAT_STRING_H + +#include +#include +#include +#include +#include // for std::vsnprintf + +/** + * @brief Formats a string using a printf-style format string and variadic arguments. + * + * Remove the dependency on std::format by using std::vsnprintf to format a string + * + * @param fmt The printf-style format string. + * @param ... Variadic arguments matching the format string specifiers. + * @return A formatted std::string. + * @throws std::runtime_error If an error occurs during formatting. + * + * @note This function supports standard printf-style formatting specifiers (e.g., + * `%d`, `%s`, `%f`, etc.). Ensure that the number and types of arguments match + * the format specifiers to avoid undefined behavior. + * + * @example + * ```cpp + * std::string result = format_string("Hello, %s! You have %d new messages.", "Alice", 5); + * std::cout << result; // Output: Hello, Alice! You have 5 new messages. + * ``` + */ +std::string format_string(const char* fmt, ...) { + // Start variable arguments processing + va_list args; + va_start(args, fmt); + + // Estimate required buffer size + size_t size = std::vsnprintf(nullptr, 0, fmt, args) + 1; // +1 for null terminator + va_end(args); + + if (size <= 0) { + throw std::runtime_error("Error during formatting."); + } + + // Allocate the required size + std::vector buffer(size); + + // Format the string + va_start(args, fmt); + std::vsnprintf(buffer.data(), size, fmt, args); + va_end(args); + + // Return the formatted string + return std::string(buffer.data()); +} + +#endif // FORMAT_STRING_H diff --git a/src/visitors/GS2CompilerVisitor.cpp b/src/visitors/GS2CompilerVisitor.cpp index 6e6b5c6..47e9b04 100644 --- a/src/visitors/GS2CompilerVisitor.cpp +++ b/src/visitors/GS2CompilerVisitor.cpp @@ -86,7 +86,7 @@ void GS2CompilerVisitor::writeLabels() void GS2CompilerVisitor::Visit(Node *node) { - std::string errorMsg = std::format("unimplemented node type {}", node->NodeType()); + std::string errorMsg = format_string("unimplemented node type %s", node->NodeType()); parserContext.addError({ ErrorLevel::E_ERROR, GS2CompilerError::ErrorCategory::Compiler, errorMsg }); #ifdef DBGEMITTERS @@ -470,7 +470,7 @@ void GS2CompilerVisitor::Visit(ExpressionBinaryOpNode *node) } } - std::string errorMsg = std::format("Undefined opcode in BinaryExpression {}: {} {}", static_cast(node->op), ExpressionOpToString(node->op), node->toString()); + std::string errorMsg = format_string("Undefined opcode in BinaryExpression %d: %s %s", static_cast(node->op), ExpressionOpToString(node->op), node->toString().c_str()); parserContext.addError({ ErrorLevel::E_ERROR, GS2CompilerError::ErrorCategory::Compiler, std::move(errorMsg) }); } @@ -599,7 +599,7 @@ void GS2CompilerVisitor::Visit(ExpressionUnaryOpNode* node) } } - std::string errorMsg = std::format("Undefined opcode in UnaryExpression {}: {}", static_cast(node->op), ExpressionOpToString(node->op)); + std::string errorMsg = format_string("Undefined opcode in UnaryExpression %d: %s", static_cast(node->op), ExpressionOpToString(node->op)); parserContext.addError({ ErrorLevel::E_ERROR, GS2CompilerError::ErrorCategory::Compiler, std::move(errorMsg) }); } @@ -1172,7 +1172,7 @@ void GS2CompilerVisitor::Visit(StatementBreakNode* node) { if (break_label <= 0) { - std::string errorMsg = std::format("`break` outside loop detected"); + std::string errorMsg = format_string("`break` outside loop detected"); parserContext.addError({ ErrorLevel::E_WARNING, GS2CompilerError::ErrorCategory::Compiler, std::move(errorMsg) }); return; } @@ -1188,7 +1188,7 @@ void GS2CompilerVisitor::Visit(StatementContinueNode* node) { if (continue_label <= 0) { - std::string errorMsg = std::format("`continue` outside loop detected"); + std::string errorMsg = format_string("`continue` outside loop detected"); parserContext.addError({ ErrorLevel::E_WARNING, GS2CompilerError::ErrorCategory::Compiler, std::move(errorMsg) }); return; } diff --git a/src/visitors/GS2CompilerVisitor.h b/src/visitors/GS2CompilerVisitor.h index 4a15e60..efd9eb4 100644 --- a/src/visitors/GS2CompilerVisitor.h +++ b/src/visitors/GS2CompilerVisitor.h @@ -7,7 +7,6 @@ #include #include #include -#include #include "ast/astvisitor.h" #include "GS2Bytecode.h" #include "GS2BuiltInFunctions.h" From 945da94d2c5fe27f96f0bbdb00b1624f9ca420e5 Mon Sep 17 00:00:00 2001 From: chris cerne Date: Wed, 18 Dec 2024 10:02:52 -0500 Subject: [PATCH 12/21] rename func --- src/Parser.cpp | 12 ++++++------ src/utils/format_string.h | 4 ++-- src/visitors/GS2CompilerVisitor.cpp | 10 +++++----- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/Parser.cpp b/src/Parser.cpp index ee9df53..d0a7dc8 100644 --- a/src/Parser.cpp +++ b/src/Parser.cpp @@ -106,7 +106,7 @@ std::string* ParserContext::saveString(const char* str, int length, bool unquote std::string * ParserContext::generateLambdaFuncName() { - std::string fnName = format_string("function_%d_1", 100 + lambdaFunctionCount); + std::string fnName = printf_format_string("function_%d_1", 100 + lambdaFunctionCount); lambdaFunctionCount++; return saveString(fnName.c_str(), int(fnName.length())); } @@ -139,7 +139,7 @@ void ParserContext::addConstant(const std::string& ident, ExpressionIdentifierNo if (constant) { // report error - redefining constant - addParserError(format_string("redefinition of constant %s", ident.c_str())); + addParserError(printf_format_string("redefinition of constant %s", ident.c_str())); return; } @@ -168,7 +168,7 @@ void ParserContext::addConstant(const std::string& ident, ExpressionIdentifierNo else { // report error - constant does not exist - addParserError(format_string("constant %s is undefined", ident.c_str())); + addParserError(printf_format_string("constant %s is undefined", ident.c_str())); return; } } @@ -187,7 +187,7 @@ void ParserContext::addConstant(const std::string& ident, ExpressionNode *node) auto constant = getConstant(ident); if (constant) { - addParserError(format_string("redefinition of constant %s", ident.c_str())); + addParserError(printf_format_string("redefinition of constant %s", ident.c_str())); return; } @@ -205,11 +205,11 @@ void ParserContext::addParserError(const std::string& errmsg) std::string msg; if (lineText.empty()) { - msg = format_string("parser error occurred near line %d: %s", lineNumber, errmsg.c_str()); + msg = printf_format_string("parser error occurred near line %d: %s", lineNumber, errmsg.c_str()); } else { - msg = format_string("%s at line %d: %s", errmsg.c_str(), lineNumber, lineText.c_str()); + msg = printf_format_string("%s at line %d: %s", errmsg.c_str(), lineNumber, lineText.c_str()); } addError({ ErrorLevel::E_ERROR, GS2CompilerError::ErrorCategory::Parser, std::move(msg) }); diff --git a/src/utils/format_string.h b/src/utils/format_string.h index b3c112d..2a98fd4 100644 --- a/src/utils/format_string.h +++ b/src/utils/format_string.h @@ -23,11 +23,11 @@ * * @example * ```cpp - * std::string result = format_string("Hello, %s! You have %d new messages.", "Alice", 5); + * std::string result = printf_format_string("Hello, %s! You have %d new messages.", "Alice", 5); * std::cout << result; // Output: Hello, Alice! You have 5 new messages. * ``` */ -std::string format_string(const char* fmt, ...) { +std::string printf_format_string(const char* fmt, ...) { // Start variable arguments processing va_list args; va_start(args, fmt); diff --git a/src/visitors/GS2CompilerVisitor.cpp b/src/visitors/GS2CompilerVisitor.cpp index 47e9b04..11f8b3e 100644 --- a/src/visitors/GS2CompilerVisitor.cpp +++ b/src/visitors/GS2CompilerVisitor.cpp @@ -86,7 +86,7 @@ void GS2CompilerVisitor::writeLabels() void GS2CompilerVisitor::Visit(Node *node) { - std::string errorMsg = format_string("unimplemented node type %s", node->NodeType()); + std::string errorMsg = printf_format_string("unimplemented node type %s", node->NodeType()); parserContext.addError({ ErrorLevel::E_ERROR, GS2CompilerError::ErrorCategory::Compiler, errorMsg }); #ifdef DBGEMITTERS @@ -470,7 +470,7 @@ void GS2CompilerVisitor::Visit(ExpressionBinaryOpNode *node) } } - std::string errorMsg = format_string("Undefined opcode in BinaryExpression %d: %s %s", static_cast(node->op), ExpressionOpToString(node->op), node->toString().c_str()); + std::string errorMsg = printf_format_string("Undefined opcode in BinaryExpression %d: %s %s", static_cast(node->op), ExpressionOpToString(node->op), node->toString().c_str()); parserContext.addError({ ErrorLevel::E_ERROR, GS2CompilerError::ErrorCategory::Compiler, std::move(errorMsg) }); } @@ -599,7 +599,7 @@ void GS2CompilerVisitor::Visit(ExpressionUnaryOpNode* node) } } - std::string errorMsg = format_string("Undefined opcode in UnaryExpression %d: %s", static_cast(node->op), ExpressionOpToString(node->op)); + std::string errorMsg = printf_format_string("Undefined opcode in UnaryExpression %d: %s", static_cast(node->op), ExpressionOpToString(node->op)); parserContext.addError({ ErrorLevel::E_ERROR, GS2CompilerError::ErrorCategory::Compiler, std::move(errorMsg) }); } @@ -1172,7 +1172,7 @@ void GS2CompilerVisitor::Visit(StatementBreakNode* node) { if (break_label <= 0) { - std::string errorMsg = format_string("`break` outside loop detected"); + std::string errorMsg = printf_format_string("`break` outside loop detected"); parserContext.addError({ ErrorLevel::E_WARNING, GS2CompilerError::ErrorCategory::Compiler, std::move(errorMsg) }); return; } @@ -1188,7 +1188,7 @@ void GS2CompilerVisitor::Visit(StatementContinueNode* node) { if (continue_label <= 0) { - std::string errorMsg = format_string("`continue` outside loop detected"); + std::string errorMsg = printf_format_string("`continue` outside loop detected"); parserContext.addError({ ErrorLevel::E_WARNING, GS2CompilerError::ErrorCategory::Compiler, std::move(errorMsg) }); return; } From 928d6d2153ea7aedb8e6e9ba3e263575a4058f05 Mon Sep 17 00:00:00 2001 From: chris cerne Date: Wed, 18 Dec 2024 10:09:47 -0500 Subject: [PATCH 13/21] inline printf to prevent linker errors --- src/utils/format_string.h | 2 +- src/visitors/GS2CompilerVisitor.h | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/utils/format_string.h b/src/utils/format_string.h index 2a98fd4..7d17580 100644 --- a/src/utils/format_string.h +++ b/src/utils/format_string.h @@ -27,7 +27,7 @@ * std::cout << result; // Output: Hello, Alice! You have 5 new messages. * ``` */ -std::string printf_format_string(const char* fmt, ...) { +inline std::string printf_format_string(const char* fmt, ...) { // Start variable arguments processing va_list args; va_start(args, fmt); diff --git a/src/visitors/GS2CompilerVisitor.h b/src/visitors/GS2CompilerVisitor.h index efd9eb4..1eab0c3 100644 --- a/src/visitors/GS2CompilerVisitor.h +++ b/src/visitors/GS2CompilerVisitor.h @@ -9,6 +9,7 @@ #include #include "ast/astvisitor.h" #include "GS2Bytecode.h" +#include "utils/format_string.h" #include "GS2BuiltInFunctions.h" class ParserContext; From fdbf7c47c77a4847f7a7818bf72d01a42106a8c5 Mon Sep 17 00:00:00 2001 From: chris cerne Date: Wed, 18 Dec 2024 10:24:13 -0500 Subject: [PATCH 14/21] resolving node issue with CI/CD pipeline --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 90dcdc4..f106be2 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -256,7 +256,7 @@ killall_jobs(); project.builds.each { v -> branches["Build ${v.DockerRoot}/${v.DockerImage}:${v.DockerTag}"] = { - node { + node("amd64") { buildStep(v.DockerImage, v.Generator, v.OS, v.OSDir, v.Defines); } } From 5b895d475878c6762d6768e94d0f6042664f551d Mon Sep 17 00:00:00 2001 From: chris cerne Date: Wed, 18 Dec 2024 10:45:19 -0500 Subject: [PATCH 15/21] Specify lib in cmake command instead of CMakeLists --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index f106be2..a90cc29 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -70,7 +70,7 @@ def buildStep(dockerImage, generator, os, osdir, defines) { discordSend(description: "", footer: "", link: env.BUILD_URL, result: currentBuild.currentResult, title: "[${split_job_name[0]}] Starting ${os} build target...", webhookURL: env.GS2EMU_WEBHOOK); dir("build") { - sh("cmake -G\"${generator}\" -DCMAKE_BUILD_TYPE=Release ${defines} -DVER_EXTRA=\"-${fixed_os}-${fixed_job_name}\" .. || true"); // Temporary fix for Windows MingW builds + sh("cmake -G\"${generator}\" -DCMAKE_RUNTIME_OUTPUT_DIRECTORY=bin -DCMAKE_LIBRARY_OUTPUT_DIRECTORY=lib -DCMAKE_ARCHIVE_OUTPUT_DIRECTORY=lib -DCMAKE_BUILD_TYPE=Release ${defines} -DVER_EXTRA=\"-${fixed_os}-${fixed_job_name}\" .. || true"); // Temporary fix for Windows MingW builds sh("cmake --build . --config Release --target all -- -j `nproc`"); } From 7b5aafacea96edf919c11d6ee9ad3d54b5763a7d Mon Sep 17 00:00:00 2001 From: chris cerne Date: Wed, 18 Dec 2024 10:53:47 -0500 Subject: [PATCH 16/21] output files are now going to build/lib --- Jenkinsfile | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index a90cc29..353e54a 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -63,9 +63,9 @@ def buildStep(dockerImage, generator, os, osdir, defines) { } sh("mkdir -p build/"); - sh("mkdir -p lib/"); + // sh("mkdir -p lib/"); sh("rm -rfv build/*"); - sh("rm -rfv lib/*"); + // sh("rm -rfv lib/*"); discordSend(description: "", footer: "", link: env.BUILD_URL, result: currentBuild.currentResult, title: "[${split_job_name[0]}] Starting ${os} build target...", webhookURL: env.GS2EMU_WEBHOOK); @@ -74,8 +74,8 @@ def buildStep(dockerImage, generator, os, osdir, defines) { sh("cmake --build . --config Release --target all -- -j `nproc`"); } - archiveArtifacts(artifacts: 'lib/*.dylib,lib/*.so,bin/*.dll', allowEmptyArchive: true); - stash(name: osdir, includes: 'lib/*.dylib,lib/*.so,bin/*.dll', allowEmpty: true); + archiveArtifacts(artifacts: 'build/lib/*.dylib,build/lib/*.so,build/bin/*.dll', allowEmptyArchive: true); + stash(name: osdir, includes: 'build/lib/*.dylib,build/lib/*.so,build/bin/*.dll', allowEmpty: true); discordSend(description: "", footer: "", link: env.BUILD_URL, result: currentBuild.currentResult, title: "[${split_job_name[0]}] Build ${fixed_job_name} #${env.BUILD_NUMBER} Target: ${os} successful!", webhookURL: env.GS2EMU_WEBHOOK); } @@ -273,12 +273,12 @@ killall_jobs(); dir("bindings/dotnet/cross-compile/${v.OSDir}/") { unstash(name: v.OSDir); try { - sh("mv -fv bin/* ."); - sh("rm -rf bin") + sh("mv -fv build/bin/* ."); + sh("rm -rf build/bin") } catch(err) { } try { - sh("mv -fv lib/* ."); - sh("rm -rf lib") + sh("mv -fv build/lib/* ."); + sh("rm -rf build/lib") } catch(err) { } } } From 0794c406c5275be4f2665ac77e467e1c665afce3 Mon Sep 17 00:00:00 2001 From: chris cerne Date: Wed, 18 Dec 2024 12:07:07 -0500 Subject: [PATCH 17/21] Resolve feedback on PR --- CMakeLists.txt | 20 -------------------- Jenkinsfile | 3 +-- build.rs | 4 ---- 3 files changed, 1 insertion(+), 26 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index bf60497..c358340 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,24 +8,8 @@ set(CMAKE_DEBUG_POSTFIX _d) # specify the C++ standard set(CMAKE_CXX_STANDARD 23) -# set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_POSITION_INDEPENDENT_CODE ON) -# TODO: @xtjoeytx, do we need this? It breaks the rust build. I think we should leave it -# up to the user of the library to specify how the output should be built. -# Set up output ditrectories -# set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/lib) -# set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/lib) -# set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/${BIN_DIR}) - -# # Second, for multi-config builds (e.g. msvc) -# foreach( OUTPUTCONFIG ${CMAKE_CONFIGURATION_TYPES} ) -# string( TOUPPER ${OUTPUTCONFIG} OUTPUTCONFIG ) -# set( CMAKE_ARCHIVE_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${PROJECT_SOURCE_DIR}/lib ) -# set( CMAKE_LIBRARY_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${PROJECT_SOURCE_DIR}/lib ) -# set( CMAKE_RUNTIME_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${PROJECT_SOURCE_DIR}/${BIN_DIR} ) -# endforeach( OUTPUTCONFIG CMAKE_CONFIGURATION_TYPES ) - link_directories(${PROJECT_SOURCE_DIR}/lib) if(WIN32 OR APPLE) @@ -110,10 +94,6 @@ if(WIN32 AND MINGW) target_compile_options(gs2compiler PRIVATE "-fno-rtti") endif() -# Link fmtlib -#target_link_libraries(gs2test fmt::fmt) -#target_link_libraries(gs2compiler fmt::fmt) - set(GS2COMPILER_INCLUDE_DIRECTORY "${PROJECT_SOURCE_DIR}/include" "${PROJECT_BINARY_DIR}/include" diff --git a/Jenkinsfile b/Jenkinsfile index 353e54a..cd8f370 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -63,9 +63,8 @@ def buildStep(dockerImage, generator, os, osdir, defines) { } sh("mkdir -p build/"); - // sh("mkdir -p lib/"); sh("rm -rfv build/*"); - // sh("rm -rfv lib/*"); + sh("rm -rfv build/lib/*"); discordSend(description: "", footer: "", link: env.BUILD_URL, result: currentBuild.currentResult, title: "[${split_job_name[0]}] Starting ${os} build target...", webhookURL: env.GS2EMU_WEBHOOK); diff --git a/build.rs b/build.rs index de21c96..54dc3d6 100644 --- a/build.rs +++ b/build.rs @@ -58,11 +58,7 @@ fn configure_platform_specifics(target: &str, cmake_config: &mut Config) -> &'st } fn link_libraries(lib_path: PathBuf, cpp_lib: &str, gs2_lib: &str) { - // let lib_dir = env::current_dir().unwrap().join(STATIC_LIB_DIR); - println!("cargo:rustc-link-lib=dylib={}", cpp_lib); println!("cargo:rustc-link-search=native={}", lib_path.display()); - // println!("cargo:rustc-link-search=native={}", lib_dir.display()); - println!("cargo:rustc-link-lib=static={}", gs2_lib); } From 7cff8c83dbfa059a5582749f331911eadf9c4df1 Mon Sep 17 00:00:00 2001 From: chris cerne Date: Wed, 18 Dec 2024 15:20:54 -0500 Subject: [PATCH 18/21] re-introduce winflexbison --- .gitignore | 3 - .gitmodules | 3 + CMakeLists.txt | 144 +++++++++++++++++++++----------------- dependencies/winflexbison | 1 + 4 files changed, 83 insertions(+), 68 deletions(-) create mode 160000 dependencies/winflexbison diff --git a/.gitignore b/.gitignore index 4e5f91c..16c5d53 100644 --- a/.gitignore +++ b/.gitignore @@ -59,6 +59,3 @@ cmake-build-*/ # Added by cargo /target /lib - -# Ignore dependencies -/dependencies \ No newline at end of file diff --git a/.gitmodules b/.gitmodules index e69de29..90b410e 100644 --- a/.gitmodules +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "dependencies/winflexbison"] + path = dependencies/winflexbison + url = git@github.com:lexxmark/winflexbison.git diff --git a/CMakeLists.txt b/CMakeLists.txt index c358340..07807ba 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,102 +1,116 @@ cmake_minimum_required(VERSION 3.10) project(gs2test VERSION 1.0) + +# Enable verbose makefile for debugging purposes set(CMAKE_VERBOSE_MAKEFILE ON) +# Set debug postfix for binaries set(CMAKE_DEBUG_POSTFIX _d) -# set(BIN_DIR "bin" CACHE STRING "Binary output directory") - -# specify the C++ standard +# Specify the C++ standard set(CMAKE_CXX_STANDARD 23) set(CMAKE_POSITION_INDEPENDENT_CODE ON) -link_directories(${PROJECT_SOURCE_DIR}/lib) +# Include necessary directories +include_directories( + ${CMAKE_CURRENT_BINARY_DIR} + src +) +# Adjust library prefixes for specific platforms if(WIN32 OR APPLE) - set(CMAKE_SHARED_LIBRARY_PREFIX "") - set(CMAKE_STATIC_LIBRARY_PREFIX "lib") + set(CMAKE_SHARED_LIBRARY_PREFIX "") + set(CMAKE_STATIC_LIBRARY_PREFIX "lib") endif() -# Attempt to find Bison and Flex first -find_package(BISON 3.4 QUIET) -find_package(FLEX QUIET) +# Handle winflexbison setup on Windows (not MinGW) +if(WIN32 AND NOT MINGW) + execute_process(COMMAND ${CMAKE_COMMAND} -S${CMAKE_CURRENT_SOURCE_DIR}/dependencies/winflexbison -B${CMAKE_CURRENT_SOURCE_DIR}/dependencies/winflexbison/build-winflex-bison -GNinja -DCMAKE_BUILD_TYPE=Release) + execute_process(COMMAND ${CMAKE_COMMAND} --build ${CMAKE_CURRENT_SOURCE_DIR}/dependencies/winflexbison/build-winflex-bison --parallel 8) + LIST(APPEND CMAKE_PROGRAM_PATH ${CMAKE_CURRENT_SOURCE_DIR}/dependencies/winflexbison/bin/Release) + set(FLEX_FLAGS "--wincompat") +endif(WIN32 AND NOT MINGW) + +find_package(BISON 3.4 REQUIRED) +find_package(FLEX REQUIRED) -# If still not found, fail -if(NOT BISON_FOUND) - message(FATAL_ERROR "Bison not found. Please install Bison.") +# Check for Bison and Flex availability +if(NOT BISON_EXECUTABLE) + message(FATAL_ERROR "Bison not found. Please ensure winflexbison is available.") endif() -if(NOT FLEX_FOUND) - message(FATAL_ERROR "Flex not found. Please install Flex.") + +if(NOT FLEX_EXECUTABLE) + message(FATAL_ERROR "Flex not found. Please ensure winflexbison is available.") endif() +# Add Flex compatibility flags for Windows if(WIN32 AND NOT MINGW) - set(FLEX_FLAGS "--wincompat") + set(FLEX_FLAGS "--wincompat") endif() -# Generate parser and scanner with Bison / Flex +# Generate parser and scanner with Bison/Flex BISON_TARGET(GS2Parser generator/gs2parser.y ${CMAKE_CURRENT_BINARY_DIR}/gs2parser.tab.cc) -FLEX_TARGET(GS2Scanner generator/gs2scanner.l ${CMAKE_CURRENT_BINARY_DIR}/lex.yy.cc DEFINES_FILE ${CMAKE_CURRENT_BINARY_DIR}/lex.yy.h COMPILE_FLAGS "${FLEX_FLAGS}") +FLEX_TARGET(GS2Scanner generator/gs2scanner.l ${CMAKE_CURRENT_BINARY_DIR}/lex.yy.cc + DEFINES_FILE ${CMAKE_CURRENT_BINARY_DIR}/lex.yy.h + COMPILE_FLAGS "${FLEX_FLAGS}") ADD_FLEX_BISON_DEPENDENCY(GS2Scanner GS2Parser) -include_directories( - ${CMAKE_CURRENT_BINARY_DIR} - src -) - +# List source files set(SOURCES_ALL - src/ast/ast.cpp - src/encoding/buffer.cpp - src/visitors/GS2CompilerVisitor.cpp - src/GS2BuiltInFunctions.cpp - src/GS2Bytecode.cpp - src/GS2Context.cpp - src/Parser.cpp - src/c_interface.cpp - - src/ast/ast.h - src/ast/astvisitor.h - src/ast/astnodevisitor.h - src/ast/expressiontypes.h - src/encoding/buffer.h - src/encoding/graalencoding.h - src/utils/EventHandler.h - src/exceptions/GS2CompilerError.h - src/utils/ContextThreadPool.h - src/utils/format_string.h - src/visitors/FunctionInspectVisitor.h - src/visitors/GS2CompilerVisitor.h - src/visitors/GS2SourceVisitor.h - src/CompilerThreadJob.h - src/GS2BuiltInFunctions.h - src/GS2Bytecode.h - src/GS2Context.h - src/opcodes.h - src/Parser.h - - ${BISON_GS2Parser_INPUT} - ${FLEX_GS2Scanner_INPUT} - ${BISON_GS2Parser_OUTPUTS} - ${FLEX_GS2Scanner_OUTPUTS} + src/ast/ast.cpp + src/encoding/buffer.cpp + src/visitors/GS2CompilerVisitor.cpp + src/GS2BuiltInFunctions.cpp + src/GS2Bytecode.cpp + src/GS2Context.cpp + src/Parser.cpp + src/c_interface.cpp + + src/ast/ast.h + src/ast/astvisitor.h + src/ast/astnodevisitor.h + src/ast/expressiontypes.h + src/encoding/buffer.h + src/encoding/graalencoding.h + src/utils/EventHandler.h + src/exceptions/GS2CompilerError.h + src/utils/ContextThreadPool.h + src/utils/format_string.h + src/visitors/FunctionInspectVisitor.h + src/visitors/GS2CompilerVisitor.h + src/visitors/GS2SourceVisitor.h + src/CompilerThreadJob.h + src/GS2BuiltInFunctions.h + src/GS2Bytecode.h + src/GS2Context.h + src/opcodes.h + src/Parser.h + + ${BISON_GS2Parser_INPUT} + ${FLEX_GS2Scanner_INPUT} + ${BISON_GS2Parser_OUTPUTS} + ${FLEX_GS2Scanner_OUTPUTS} ) +# Create executable target add_executable(gs2test ${SOURCES_ALL} src/main.cpp) -# Add library (static or shared) +# Add library target if(STATIC) - add_library(gs2compiler STATIC ${SOURCES_ALL}) + add_library(gs2compiler STATIC ${SOURCES_ALL}) else() - add_library(gs2compiler SHARED ${SOURCES_ALL}) + add_library(gs2compiler SHARED ${SOURCES_ALL}) endif() -# On Windows + MinGW, ensure -fno-rtti is set -# TODO: Why is this necessary? Is it for performance / compatibility reasons? +# Set special compile options for MinGW if(WIN32 AND MINGW) - target_compile_options(gs2compiler PRIVATE "-fno-rtti") + target_compile_options(gs2compiler PRIVATE "-fno-rtti") endif() +# Export include directory for use by other projects set(GS2COMPILER_INCLUDE_DIRECTORY - "${PROJECT_SOURCE_DIR}/include" - "${PROJECT_BINARY_DIR}/include" - "${PROJECT_SOURCE_DIR}/src" - PARENT_SCOPE + "${PROJECT_SOURCE_DIR}/include" + "${PROJECT_BINARY_DIR}/include" + "${PROJECT_SOURCE_DIR}/src" + PARENT_SCOPE ) diff --git a/dependencies/winflexbison b/dependencies/winflexbison new file mode 160000 index 0000000..9118533 --- /dev/null +++ b/dependencies/winflexbison @@ -0,0 +1 @@ +Subproject commit 911853359017d3e817d638a0de18881eb7960de9 From ae2ed56f916d1efab319ac7d8db5d171a89406f0 Mon Sep 17 00:00:00 2001 From: chris cerne Date: Wed, 18 Dec 2024 15:24:47 -0500 Subject: [PATCH 19/21] last CR suggestion --- Jenkinsfile | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index cd8f370..94a8f39 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -62,9 +62,8 @@ def buildStep(dockerImage, generator, os, osdir, defines) { } + sh("rm -rf build"); sh("mkdir -p build/"); - sh("rm -rfv build/*"); - sh("rm -rfv build/lib/*"); discordSend(description: "", footer: "", link: env.BUILD_URL, result: currentBuild.currentResult, title: "[${split_job_name[0]}] Starting ${os} build target...", webhookURL: env.GS2EMU_WEBHOOK); From a6dd8798bc323ca5f0b11fffed0c894910c881f6 Mon Sep 17 00:00:00 2001 From: chris cerne Date: Wed, 18 Dec 2024 15:27:46 -0500 Subject: [PATCH 20/21] changed submodule to https variant --- .gitmodules | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitmodules b/.gitmodules index 90b410e..7f610be 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,3 @@ [submodule "dependencies/winflexbison"] path = dependencies/winflexbison - url = git@github.com:lexxmark/winflexbison.git + url = https://github.com/lexxmark/winflexbison.git From 0dfd7cf68aa897672e9bab743c090110f6535966 Mon Sep 17 00:00:00 2001 From: chris cerne Date: Sun, 19 Jan 2025 19:30:20 -0500 Subject: [PATCH 21/21] fix build for windows --- CMakeLists.txt | 4 ++-- Cargo.lock | 4 ++-- Cargo.toml | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 07807ba..48ac233 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -35,11 +35,11 @@ find_package(BISON 3.4 REQUIRED) find_package(FLEX REQUIRED) # Check for Bison and Flex availability -if(NOT BISON_EXECUTABLE) +if(NOT BISON_EXECUTABLE AND (WIN32 AND NOT MINGW)) message(FATAL_ERROR "Bison not found. Please ensure winflexbison is available.") endif() -if(NOT FLEX_EXECUTABLE) +if(NOT FLEX_EXECUTABLE AND (WIN32 AND NOT MINGW)) message(FATAL_ERROR "Flex not found. Please ensure winflexbison is available.") endif() diff --git a/Cargo.lock b/Cargo.lock index d5d121d..74b18bf 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,6 +1,6 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -version = 3 +version = 4 [[package]] name = "cc" @@ -22,7 +22,7 @@ dependencies = [ [[package]] name = "gs2compiler" -version = "0.2.2" +version = "0.2.3" dependencies = [ "cmake", "libc", diff --git a/Cargo.toml b/Cargo.toml index ad40d3b..a012cad 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "gs2compiler" -version = "0.2.2" +version = "0.2.3" edition = "2021" build = "build.rs" description = "Compiles GS2 source code into GS2 bytecode."