From ad67266047d84323d355249f7ee42f90a3027fae Mon Sep 17 00:00:00 2001 From: Sodgerel Mandakhnaran Date: Fri, 8 Aug 2025 17:16:41 +0900 Subject: [PATCH] Make handle stack size configurable like memory --- runtime.c | 10 ++++++---- scrapscript.py | 3 +++ 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/runtime.c b/runtime.c index 29af2a16..099d3f56 100644 --- a/runtime.c +++ b/runtime.c @@ -680,17 +680,19 @@ void variant_set(struct object* variant, struct object* value) { as_variant(variant)->value = value; } -#define MAX_HANDLES 4096 - struct handle_scope { struct object*** base; }; -static struct object** handle_stack[MAX_HANDLES]; +#ifndef HANDLE_STACK_SIZE +#define HANDLE_STACK_SIZE 4096 +#endif + +static struct object** handle_stack[HANDLE_STACK_SIZE]; static struct object*** handles = handle_stack; #ifndef NDEBUG // Only used to check for handle stack overflow. -static struct object*** handles_end = &handle_stack[MAX_HANDLES]; +static struct object*** handles_end = &handle_stack[HANDLE_STACK_SIZE]; #endif void pop_handles(void* local_handles) { diff --git a/scrapscript.py b/scrapscript.py index 895aa34d..421d5084 100755 --- a/scrapscript.py +++ b/scrapscript.py @@ -2478,6 +2478,8 @@ def compile_command(args: argparse.Namespace) -> None: cflags = discover_cflags(cc, args.debug) if args.memory: cflags += [f"-DMEMORY_SIZE={args.memory}"] + if args.handle_stack_size: + cflags += [f"-DHANDLE_STACK_SIZE={args.handle_stack_size}"] ldflags = env_get_split("LDFLAGS") subprocess.run([*cc, "-o", "a.out", *cflags, args.output, *ldflags], check=True) @@ -2590,6 +2592,7 @@ def main() -> None: comp.add_argument("--format", action="store_true") comp.add_argument("--compile", action="store_true") comp.add_argument("--memory", type=int) + comp.add_argument("--handle-stack-size", type=int) comp.add_argument("--run", action="store_true") comp.add_argument("--debug", action="store_true", default=False) comp.add_argument("--check", action="store_true", default=False)