From 28abb4d2d3c2148eddeaad472f8f2d4703ce1715 Mon Sep 17 00:00:00 2001 From: Max Wash Date: Sat, 30 May 2026 19:53:39 +0100 Subject: [PATCH] frontend: implement debug printing for functions --- bshell/debug.c | 26 ++++++++++++++++++++++++++ bshell/debug.h | 2 ++ 2 files changed, 28 insertions(+) diff --git a/bshell/debug.c b/bshell/debug.c index aeaf8a8..245d4ea 100644 --- a/bshell/debug.c +++ b/bshell/debug.c @@ -171,6 +171,32 @@ void print_scriptblock(bshell_scriptblock *block, size_t depth) } } +void print_function(bshell_function *func) +{ + const char *name = bshell_function_get_name(func); + const fx_array *params + = bshell_function_get_positional_parameters(func); + bshell_scriptblock *body = bshell_function_get_body(func); + printf("%s(", name); + + size_t i = 0; + const fx_iterator *it = fx_iterator_begin(params); + fx_foreach(v, it) + { + if (i > 0) { + printf(", "); + } + + printf("$"); + fx_value_to_string(v, fx_stdout, NULL); + i++; + } + fx_iterator_unref(it); + + printf("):\n"); + print_scriptblock(body, 1); +} + void print_instruction( size_t offset, bshell_instruction instr, diff --git a/bshell/debug.h b/bshell/debug.h index 0473192..1da74a0 100644 --- a/bshell/debug.h +++ b/bshell/debug.h @@ -1,6 +1,7 @@ #ifndef DEBUG_H_ #define DEBUG_H_ +#include #include #include #include @@ -12,6 +13,7 @@ extern void print_lex_token(struct bshell_lex_token *tok); extern void print_ast_node(struct bshell_ast_node *node); extern void print_ast_node_recursive(struct bshell_ast_node *node); extern void print_scriptblock(bshell_scriptblock *block, size_t depth); +extern void print_function(bshell_function *func); extern void print_instruction( size_t offset, bshell_instruction instr,