Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
4 changes: 4 additions & 0 deletions src/math_compat.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion src/ps2/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
40 changes: 20 additions & 20 deletions src/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,27 @@
#include <stdlib.h>
#include <stddef.h>
#include <stdint.h>
#include <string.h>
#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)
#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 { \
Expand Down Expand Up @@ -48,23 +56,15 @@ 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); \
if (_val == NULL) { \
fprintf(stderr, "%s:%d: requireNotNull failed: %s\n", __FILE__, __LINE__, (msg)); \
abort(); \
} \
_val; \
})
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();
}
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) ({ \
Expand Down
6 changes: 3 additions & 3 deletions src/vm.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/vm_builtins.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Loading