diff --git a/CMakeLists.txt b/CMakeLists.txt index cdbcc6e5d4..53707a4370 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,21 +21,25 @@ endif() if(MSVC AND (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")) message(STATUS "Clang on MSVC detected! Adding compile flags") set(CMAKE_CXX_FLAGS - "-Xclang -fcxx-exceptions \ + "${CMAKE_CXX_FLAGS} \ + -Xclang -fcxx-exceptions \ -Xclang -fexceptions \ -Xclang -std=c++17 \ -Xclang -D_CRT_SECURE_NO_WARNINGS \ -mavx \ -Wno-c++11-narrowing -Wno-c++98-compat -W3") - # additional c++ flags for release mode for our projects + # linker flags + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /STACK:16000000,16384") + + # additional c++ and linker flags for release mode for our projects if(CMAKE_BUILD_TYPE MATCHES "Release") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /O2 /Ob2") + elseif(CMAKE_BUILD_TYPE MATCHES "RelWithDebInfo") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /O2 /Ob2") + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /DEBUG") endif() - # linker flags - set(CMAKE_EXE_LINKER_FLAGS "/STACK:16000000,16384") - elseif(UNIX) message(STATUS "GCC detected! Adding compile flags") set(CMAKE_CXX_FLAGS @@ -69,10 +73,18 @@ elseif(MSVC) # set(CMAKE_CXX_FLAGS_DEBUG "/ZI") endif() # c++ flags for all build types - set(CMAKE_CXX_FLAGS "/EHsc /utf-8 /arch:AVX") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc /utf-8 /arch:AVX") # linker flags - set(CMAKE_EXE_LINKER_FLAGS "/STACK:16000000,16384") + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /STACK:16000000,16384") + + # additional c++ and linker flags for specific build types + if(CMAKE_BUILD_TYPE MATCHES "Release") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /O2 /Ob2") + elseif(CMAKE_BUILD_TYPE MATCHES "RelWithDebInfo") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /O2 /Ob2") + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /DEBUG") + endif() endif() if(WIN32) @@ -80,6 +92,9 @@ if(WIN32) set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) + + set(CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION 7.1.7600.0.30514) # win7.1, supports xp + message("Windows SDK version: ${CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION}") endif() if(ASAN_BUILD) diff --git a/CMakePresets.json b/CMakePresets.json index e92107cdad..9dadfa309a 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -54,6 +54,25 @@ }, "vendor": { "microsoft.com/VisualStudioSettings/CMake/1.0": { "hostOS": [ "Windows" ] } } }, + { + "name": "RelWithDebInfo-clang", + "displayName": "Windows RelWithDebInfo (clang-cl)", + "description": "Target Windows with the Visual Studio development environment.", + "generator": "Ninja", + "binaryDir": "${sourceDir}/out/build/Release", + "architecture": { + "value": "x64", + "strategy": "external" + }, + "cacheVariables": { + "CMAKE_BUILD_TYPE": "RelWithDebInfo", + "CMAKE_INSTALL_PREFIX": "${sourceDir}/out/install/${presetName}", + "INSTALL_GTEST": "True", + "CMAKE_C_COMPILER": "clang-cl", + "CMAKE_CXX_COMPILER": "clang-cl" + }, + "vendor": { "microsoft.com/VisualStudioSettings/CMake/1.0": { "hostOS": [ "Windows" ] } } + }, { "name": "Release-clang-static", "displayName": "Windows Release - Static (clang-cl)", diff --git a/common/util/Serializer.h b/common/util/Serializer.h index f49076dfc6..fa410f607b 100644 --- a/common/util/Serializer.h +++ b/common/util/Serializer.h @@ -3,6 +3,7 @@ #include #include #include +#include "common/common_types.h" #include "common/util/Assert.h" /*! @@ -35,7 +36,7 @@ class Serializer { * later be accessed with get_save_result. */ Serializer() : m_writing(true) { - const size_t initial_size = 32; + constexpr size_t initial_size = 32 * 1024 * 1024; m_data = (u8*)malloc(initial_size); m_size = initial_size; } diff --git a/decompiler/ObjectFile/ObjectFileDB.cpp b/decompiler/ObjectFile/ObjectFileDB.cpp index 9ed02e414a..dda918c543 100644 --- a/decompiler/ObjectFile/ObjectFileDB.cpp +++ b/decompiler/ObjectFile/ObjectFileDB.cpp @@ -393,11 +393,14 @@ std::string ObjectFileDB::generate_obj_listing(const std::unordered_set obj buffer i) name part) - (return bc) + (awhen (file-status (-> obj buffer i) name part) + (return it) ) ) #f diff --git a/goal_src/engine/sound/gsound.gc b/goal_src/engine/sound/gsound.gc index b716839840..5a59622e14 100644 --- a/goal_src/engine/sound/gsound.gc +++ b/goal_src/engine/sound/gsound.gc @@ -544,13 +544,13 @@ ) (case (-> src type) ((entity-actor entity-ambient) - (swhen (res-lump-struct-exact (the entity src) 'effect-name symbol) - (set! name (string->sound-name (symbol->string bc))) + (awhen (res-lump-struct-exact (the entity src) 'effect-name symbol) + (set! name (string->sound-name (symbol->string it))) (set! sound-times (res-lump-data (the entity src) 'cycle-speed (pointer float))) (set! spec *ambient-spec*) (let ((tag (new 'static 'res-tag))) - (swhen (res-lump-data-exact (the entity src) 'effect-param sound-play-parms :tag-ptr (& tag)) - (set! params bc) + (awhen (res-lump-data-exact (the entity src) 'effect-param sound-play-parms :tag-ptr (& tag)) + (set! params it) (set! param-count (the int (-> tag elt-count))) ) ) diff --git a/goal_src/goal-lib.gc b/goal_src/goal-lib.gc index cc913939b3..c2ccc6b33a 100644 --- a/goal_src/goal-lib.gc +++ b/goal_src/goal-lib.gc @@ -438,16 +438,23 @@ ) ) -(defmacro swhen (condition &rest body) - "Same as when, but saves the branch condition onto a variable named bc" +(defmacro aif (condition true false) + "Anaphoric if, similar to Common Lisp" - `(let ((bc ,condition)) - (if bc - (begin ,@body) + `(let ((it ,condition)) + (if it + ,true + ,false ) ) ) +(defmacro awhen (condition &rest body) + "Anaphoric when" + + `(aif ,condition (begin ,@body) #f) + ) + (defmacro return (val) `(return-from #f ,val) ) @@ -460,7 +467,8 @@ (defmacro case (switch &key (comp =) &rest cases) "A switch-case construct. switch is saved onto a local variable and compared against each case, sequentially. - else can be used like the 'default' case, but it must be the last one." + else can be used like the 'default' case, but it must be the last one. + comp is the function to use when evaluating the clauses. It can be any valid head of a form (operator or call)." (with-gensyms (sw) ;; save the switch to a variable (only evaluated once)