From 1c1cd8efc57884e3bae72f964584967645e232e3 Mon Sep 17 00:00:00 2001 From: Lance Pollard Date: Sun, 1 Mar 2026 16:51:56 -0800 Subject: [PATCH] Make HEAP_CAP and MAX_THREADS configurable via compile-time defines Wrap HEAP_CAP and MAX_THREADS in #ifndef guards so embedders can tune them at compile time without modifying source. Add a compile-time check that HEAP_CAP_BITS does not exceed VAL_BITS, since heap addresses must fit in the 38-bit VAL field of a term. Usage: clang -O2 -DHEAP_CAP_BITS=28 -DMAX_THREADS=4 -o main main.c Defaults are unchanged. No behavior change on existing platforms. --- clang/hvm.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/clang/hvm.c b/clang/hvm.c index ebf54fe..6d74bfc 100644 --- a/clang/hvm.c +++ b/clang/hvm.c @@ -155,10 +155,18 @@ typedef struct { // Capacities // ========== -#define HEAP_CAP (1ULL << 38) +#ifndef HEAP_CAP_BITS +#define HEAP_CAP_BITS 38 +#endif +#if HEAP_CAP_BITS > VAL_BITS +#error "HEAP_CAP_BITS must be <= VAL_BITS (heap addresses must fit in term VAL field)" +#endif +#define HEAP_CAP (1ULL << HEAP_CAP_BITS) #define BOOK_CAP (1ULL << 24) #define WNF_CAP (1ULL << 32) +#ifndef MAX_THREADS #define MAX_THREADS 64 +#endif // Thread Globals // ==============