frontend: implement debug printing for functions
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#ifndef DEBUG_H_
|
||||
#define DEBUG_H_
|
||||
|
||||
#include <bshell/command/function.h>
|
||||
#include <bshell/runtime/opcode.h>
|
||||
#include <bshell/runtime/script-block.h>
|
||||
#include <stdbool.h>
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user