From 48c9818af45cfc923a006a7026e12e035ecf2b26 Mon Sep 17 00:00:00 2001 From: Un1q32 Date: Tue, 16 Jun 2026 14:50:43 -0400 Subject: [PATCH 1/9] gate typeof --- src/utils.h | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/utils.h b/src/utils.h index 56503aebd..d61c27434 100644 --- a/src/utils.h +++ b/src/utils.h @@ -10,15 +10,22 @@ #include "real_type.h" +#if (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 202311L)) \ + || defined(__GNUC__) || defined(__clang__) || defined(__TINYC__) + #define TYPEOF(x) typeof(x) +#else + #define TYPEOF(x) long long +#endif + #define forEach(type, item, array, count) \ - for (typeof(count) item##_i_ = 0; item##_i_ < (count); item##_i_++) \ + for (TYPEOF(count) item##_i_ = 0; item##_i_ < (count); ++item##_i_) \ for (type* item = &(array)[item##_i_]; item; item = NULL) #define forEachIndexed(type, item, index, array, count) \ - for (typeof(count) index = 0; index < (count); index++) \ + for (TYPEOF(count) index = 0; index < (count); ++index) \ for (type* item = &(array)[index]; item; item = NULL) -#define repeat(n, it) for (typeof(n) it = 0; it < (n); ++it) +#define repeat(n, it) for (TYPEOF(n) it = 0; it < (n); ++it) #define require(condition) \ do { \ @@ -48,17 +55,8 @@ static inline void requireMessageFormatted(const char *file, int line, bool cond abort(); } -#define requireNotNull(ptr) ({ \ -typeof(ptr) _val = (ptr); \ -if (_val == NULL) { \ -fprintf(stderr, "%s:%d: requireNotNull failed: '%s'\n", __FILE__, __LINE__, #ptr); \ -abort(); \ -} \ -_val; \ -}) - #define requireNotNullMessage(ptr, msg) ({ \ -typeof(ptr) _val = (ptr); \ +void *_val = (ptr); \ if (_val == NULL) { \ fprintf(stderr, "%s:%d: requireNotNull failed: %s\n", __FILE__, __LINE__, (msg)); \ abort(); \ @@ -66,6 +64,8 @@ abort(); \ _val; \ }) +#define requireNotNull(ptr) requireNotNullMessage(ptr, #ptr) + // Safe allocation macros - check for nullptr and abort with file/line info #define safeMalloc(size) ({ \ void* _ptr = malloc(size); \ From 63ea1d5ce0b186d25a15092fe936b7b90f3109a8 Mon Sep 17 00:00:00 2001 From: Un1q32 Date: Tue, 16 Jun 2026 14:54:29 -0400 Subject: [PATCH 2/9] gate noinline Co-authored-by: Serg One Zero --- src/common.h | 8 ++++++++ src/vm.c | 6 +++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/common.h b/src/common.h index 9c5949bf2..9f3c17ae7 100644 --- a/src/common.h +++ b/src/common.h @@ -42,6 +42,14 @@ #define ALIGN(x) #endif +#if defined(__GNUC__) || defined(__TINYC__) + #define NOINLINE __attribute__((noinline)) +#elif defined(_MSC_VER) && _MSC_VER >= 1400 // VS2005 or later + #define NOINLINE __declspec(noinline) +#else + #define NOINLINE +#endif + #if defined(__GNUC__) || defined(__clang__) #if defined(__x86_64__) || defined(__i386__) #define YIELD() __asm__ volatile("rep; nop" : : : "memory") diff --git a/src/vm.c b/src/vm.c index 5bd3c9f5f..ed6583b4e 100644 --- a/src/vm.c +++ b/src/vm.c @@ -850,7 +850,7 @@ static void writeSingleInstanceVariable(VMContext* ctx, Instance* inst, Variable } // Force out-of-line so the OP_POP fast path in executeLoop doesn't inline this, because we already have an "optimized" version for common writes -__attribute__((noinline)) +NOINLINE static void resolveVariableWrite(VMContext* ctx, int32_t instanceType, uint32_t varRef, RValue val) { Variable* varDef = resolveVarDef(ctx, varRef); @@ -1468,7 +1468,7 @@ static void handlePopz(VMContext* ctx) { RValue_free(&val); } -__attribute__((noinline)) +NOINLINE static void handleAddString(VMContext* ctx, RValue a, RValue b, uint8_t resultType) { if (a.type == RVALUE_STRING && b.type == RVALUE_STRING) { // String concatenation @@ -1509,7 +1509,7 @@ static void handleAddString(VMContext* ctx, RValue a, RValue b, uint8_t resultTy } } -__attribute__((noinline)) +NOINLINE static void handleMulString(VMContext* ctx, RValue a, RValue b, uint8_t resultType) { // a.type == RVALUE_STRING; b is the repetition count. int count = RValue_toInt32(b); From 28342d4dae03b728a22f34ee00401861944eaff5 Mon Sep 17 00:00:00 2001 From: Un1q32 Date: Tue, 16 Jun 2026 14:55:59 -0400 Subject: [PATCH 3/9] use macro --- src/ps2/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ps2/main.c b/src/ps2/main.c index 2adff1285..158baee5e 100644 --- a/src/ps2/main.c +++ b/src/ps2/main.c @@ -63,7 +63,7 @@ static int MAX_MEMORY_BYTES = 0; static int heapCeilingBytes = 0; // 256-byte aligned buffers for libpad (one per port) -static char padBuf[2][256] __attribute__((aligned(64))); +static char padBuf[2][256] ALIGN(64); // Controller button to GML key mapping typedef struct { From 8f1114483d371daf021705f33a4dd2c61c2ae433 Mon Sep 17 00:00:00 2001 From: Un1q32 Date: Tue, 16 Jun 2026 14:56:45 -0400 Subject: [PATCH 4/9] what about now --- src/utils.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils.h b/src/utils.h index d61c27434..6e227ab87 100644 --- a/src/utils.h +++ b/src/utils.h @@ -56,7 +56,7 @@ static inline void requireMessageFormatted(const char *file, int line, bool cond } #define requireNotNullMessage(ptr, msg) ({ \ -void *_val = (ptr); \ +const void *_val = (ptr); \ if (_val == NULL) { \ fprintf(stderr, "%s:%d: requireNotNull failed: %s\n", __FILE__, __LINE__, (msg)); \ abort(); \ From a689b13ad162125a3a7687acfee73a46c9991dcb Mon Sep 17 00:00:00 2001 From: Un1q32 Date: Tue, 16 Jun 2026 14:58:48 -0400 Subject: [PATCH 5/9] fix --- src/utils.h | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/utils.h b/src/utils.h index 6e227ab87..81fd307da 100644 --- a/src/utils.h +++ b/src/utils.h @@ -55,16 +55,15 @@ static inline void requireMessageFormatted(const char *file, int line, bool cond abort(); } -#define requireNotNullMessage(ptr, msg) ({ \ -const void *_val = (ptr); \ -if (_val == NULL) { \ -fprintf(stderr, "%s:%d: requireNotNull failed: %s\n", __FILE__, __LINE__, (msg)); \ -abort(); \ -} \ -_val; \ -}) - -#define requireNotNull(ptr) requireNotNullMessage(ptr, #ptr) +static inline void* requireNotNullFunction(void* ptr, char* file, int line, char* name) { + if (ptr == nullptr) { + fprintf(stderr, "%s:%d: requireNotNull failed: '%s'\n", file, line, name); + abort(); + } + return ptr; +} +#define requireNotNull(ptr) requireNotNullFunction((void*)ptr, __FILE__, __LINE__, #ptr) +#define requireNotNullMessage(ptr, msg) requireNotNullFunction((void*)ptr, __FILE__, __LINE__, msg) // Safe allocation macros - check for nullptr and abort with file/line info #define safeMalloc(size) ({ \ From b8e74da7d8ae6e5250af22ac260cf385654a1dfd Mon Sep 17 00:00:00 2001 From: Un1q32 Date: Tue, 16 Jun 2026 15:00:57 -0400 Subject: [PATCH 6/9] nit --- src/utils.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils.h b/src/utils.h index 81fd307da..d2aa286cf 100644 --- a/src/utils.h +++ b/src/utils.h @@ -56,7 +56,7 @@ static inline void requireMessageFormatted(const char *file, int line, bool cond } static inline void* requireNotNullFunction(void* ptr, char* file, int line, char* name) { - if (ptr == nullptr) { + if (!ptr) { fprintf(stderr, "%s:%d: requireNotNull failed: '%s'\n", file, line, name); abort(); } From 64eeb8c56f881891a29a597b1cc83b58e6e6702e Mon Sep 17 00:00:00 2001 From: Un1q32 Date: Tue, 16 Jun 2026 15:08:54 -0400 Subject: [PATCH 7/9] fixes --- src/math_compat.h | 4 ++++ src/utils.h | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/math_compat.h b/src/math_compat.h index 24b9deb38..f2db92807 100644 --- a/src/math_compat.h +++ b/src/math_compat.h @@ -108,3 +108,7 @@ static float roundf(float x) { #ifndef INFINITY #define INFINITY (1.0f / 0.0f) #endif + +#ifndef M_PI +#define M_PI 3.14159265358979323846 +#endif diff --git a/src/utils.h b/src/utils.h index d2aa286cf..8060ebcee 100644 --- a/src/utils.h +++ b/src/utils.h @@ -6,13 +6,14 @@ #include #include #include +#include #include "math_compat.h" #include "real_type.h" #if (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 202311L)) \ || defined(__GNUC__) || defined(__clang__) || defined(__TINYC__) - #define TYPEOF(x) typeof(x) + #define TYPEOF(x) __typeof__(x) #else #define TYPEOF(x) long long #endif From 5ab5fd5bf841f1dc7b75d06a6f75b93269c4ace6 Mon Sep 17 00:00:00 2001 From: Un1q32 Date: Fri, 19 Jun 2026 08:03:39 -0400 Subject: [PATCH 8/9] fix --- src/vm_builtins.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/vm_builtins.c b/src/vm_builtins.c index c26ab7e34..3418aa6c9 100644 --- a/src/vm_builtins.c +++ b/src/vm_builtins.c @@ -3960,7 +3960,7 @@ static RValue builtin_method(VMContext* ctx, MAYBE_UNUSED RValue* args, int32_t } if (instanceToBeBound == INSTANCE_SELF) { - instanceToBeBound = requireNotNullMessage(ctx->currentInstance, "Trying to bind method to INSTANCE_SELF while there isn't a instance in the current context!")->instanceId; + instanceToBeBound = ((Instance *)requireNotNullMessage(ctx->currentInstance, "Trying to bind method to INSTANCE_SELF while there isn't a instance in the current context!"))->instanceId; } return RValue_makeMethodFromCodeIndexAndInstanceId(codeIndex, instanceToBeBound); From 6e7dd9eab3c435136a4ac1b9524eac0a6548274e Mon Sep 17 00:00:00 2001 From: Un1q32 Date: Fri, 19 Jun 2026 10:59:51 -0400 Subject: [PATCH 9/9] fix --- src/utils.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils.h b/src/utils.h index 8060ebcee..c91bec695 100644 --- a/src/utils.h +++ b/src/utils.h @@ -56,7 +56,7 @@ static inline void requireMessageFormatted(const char *file, int line, bool cond abort(); } -static inline void* requireNotNullFunction(void* ptr, char* file, int line, char* name) { +static inline void* requireNotNullFunction(void* ptr, const char* file, int line, const char* name) { if (!ptr) { fprintf(stderr, "%s:%d: requireNotNull failed: '%s'\n", file, line, name); abort();