1
0
Fork 0
forked from fun/fun

Added -DFUN_DEBUG=ON flag as cmake option to enable debug messages. Default is -DFUN_DEBUG=off.

This commit is contained in:
Johannes Findeisen 2025-09-14 15:48:28 +02:00
commit 01fa5dfdb7
2 changed files with 11 additions and 0 deletions

View file

@ -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

View file

@ -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 <fn> ; STORE_GLOBAL fgi */
int fci = bytecode_add_constant(bc, make_function(fn_bc));