From 01fa5dfdb75eda79ddae546e1e5ffc631342b501 Mon Sep 17 00:00:00 2001 From: hanez Date: Sun, 14 Sep 2025 15:48:28 +0200 Subject: [PATCH] Added -DFUN_DEBUG=ON flag as cmake option to enable debug messages. Default is -DFUN_DEBUG=off. --- CMakeLists.txt | 7 +++++++ src/parser.c | 4 ++++ 2 files changed, 11 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index ee4cd91..1ed8b6a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,6 +17,13 @@ target_include_directories(fun_core PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/src ) +# Debug option to enable verbose parser/VM logging +option(FUN_DEBUG "Enable extra debug logging in Fun" OFF) +if(FUN_DEBUG) + message(STATUS "FUN_DEBUG enabled: building with verbose debug logging") + target_compile_definitions(fun_core PUBLIC FUN_DEBUG=1) +endif() + # Playground / interpreter (future /usr/bin/fun) add_executable(fun src/fun.c diff --git a/src/parser.c b/src/parser.c index 813aa54..3688ed9 100644 --- a/src/parser.c +++ b/src/parser.c @@ -328,8 +328,10 @@ static int emit_primary(Bytecode *bc, const char *src, size_t len, size_t *pos) free(name); return 0; } +#ifdef FUN_DEBUG /* DEBUG: show compiled call */ printf("compile: CALL %s with %d arg(s)\n", name, argc); +#endif bytecode_add_instruction(bc, OP_CALL, argc); free(name); return 1; @@ -845,10 +847,12 @@ static void parse_block(Bytecode *bc, const char *src, size_t len, size_t *pos, /* ensure function returns */ bytecode_add_instruction(fn_bc, OP_RETURN, 0); +#ifdef FUN_DEBUG /* DEBUG: dump compiled function bytecode */ printf("=== compiled function %s (%d params) ===\n", fname, env.count); bytecode_dump(fn_bc); printf("=== end function %s ===\n", fname); +#endif /* bind function to global: LOAD_CONST ; STORE_GLOBAL fgi */ int fci = bytecode_add_constant(bc, make_function(fn_bc));