Skip to content

Commit

Permalink
Make the dev output sane
Browse files Browse the repository at this point in the history
  • Loading branch information
viega committed Jul 18, 2024
1 parent afda051 commit 258c1e9
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 55 deletions.
2 changes: 0 additions & 2 deletions src/compiler/lex.c
Original file line number Diff line number Diff line change
Expand Up @@ -1222,8 +1222,6 @@ c4m_format_tokens(c4m_file_compile_ctx *ctx)
c4m_ka(5),
"header_rows",
c4m_ka(1),
"container_tag",
c4m_ka("table2"),
"stripe",
c4m_ka(true)));

Expand Down
11 changes: 8 additions & 3 deletions src/compiler/scope.c
Original file line number Diff line number Diff line change
Expand Up @@ -381,13 +381,15 @@ c4m_symbol_lookup(c4m_scope_t *local_scope,
c4m_grid_t *
c4m_format_scope(c4m_scope_t *scope)
{
uint64_t len;
uint64_t len = 0;
hatrack_dict_value_t *values;
c4m_grid_t *grid = c4m_new(c4m_type_grid(),
c4m_kw("start_cols",
c4m_ka(6),
"header_rows",
c4m_ka(1),
"container_tag",
c4m_ka("table2"),
"stripe",
c4m_ka(true)));
c4m_list_t *row = c4m_new_table_row();
Expand All @@ -397,10 +399,13 @@ c4m_format_scope(c4m_scope_t *scope)
c4m_type_utf8());
int64_t nexttid = 0;

values = hatrack_dict_values_sort(scope->symbols,
&len);
if (scope != NULL) {
values = hatrack_dict_values_sort(scope->symbols,
&len);
}

if (len == 0) {
empty_scope:
grid = c4m_new(c4m_type_grid(), c4m_kw("start_cols", c4m_ka(1)));
c4m_list_append(row, c4m_new_utf8("Scope is empty"));
c4m_grid_add_row(grid, row);
Expand Down
81 changes: 31 additions & 50 deletions src/tests/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -722,53 +722,38 @@ next_comparison:;
static void
show_dev_compile_info(c4m_compile_ctx *ctx)
{
if (!dev_mode) {
return;
}

c4m_printf("[h2]Module Source Code for {}", ctx->entry_point->path);
c4m_print(ctx->entry_point->raw);
c4m_printf("[h2]Module Source Code for {}", ctx->entry_point->path);
c4m_print(c4m_format_tokens(ctx->entry_point));
if (ctx->entry_point->parse_tree) {
c4m_print(c4m_format_parse_tree(ctx->entry_point));
}
if (ctx->entry_point->cfg) {
c4m_print(c4m_cstr_format("[h1]Toplevel CFG for {}",
ctx->entry_point->path));
c4m_print(c4m_cfg_repr(ctx->entry_point->cfg));
}

for (int i = 0; i < c4m_list_len(ctx->module_ordering); i++) {
c4m_file_compile_ctx *f = c4m_list_get(ctx->module_ordering,
i,
NULL);

c4m_print(c4m_cstr_format("[h1]Processing module {}", f->path));
if (ctx->entry_point->parse_tree) {
c4m_print(c4m_format_parse_tree(ctx->entry_point));
}
else {
continue;
}

if (ctx->entry_point->cfg) {
c4m_print(c4m_cstr_format("[h1]Toplevel CFG for {}", f->path));
c4m_print(c4m_cfg_repr(ctx->entry_point->cfg));
}
else {
continue;
}

for (int j = 0; j < c4m_list_len(f->fn_def_syms); j++) {
c4m_symbol_t *sym = c4m_list_get(f->fn_def_syms,
j,
NULL);
c4m_fn_decl_t *decl = sym->value;
c4m_print(c4m_cstr_format("[h1]CFG for Function {}{}",
sym->name,
sym->type));
c4m_print(c4m_cfg_repr(decl->cfg));
c4m_print(c4m_cstr_format("[h2]Function Scope for {}{}",
sym->name,
sym->type));
c4m_print(c4m_format_scope(decl->signature_info->fn_scope));
}

c4m_print(c4m_rich_lit("[h2]Global Scope"));
c4m_print(c4m_format_scope(ctx->final_globals));
c4m_print(c4m_rich_lit("[h2]Module Scope"));
c4m_print(c4m_format_scope(ctx->entry_point->module_scope));
for (int j = 0; j < c4m_list_len(ctx->entry_point->fn_def_syms); j++) {
c4m_symbol_t *sym = c4m_list_get(ctx->entry_point->fn_def_syms,
j,
NULL);
c4m_fn_decl_t *decl = sym->value;
c4m_print(c4m_cstr_format("[h1]CFG for Function {}{}",
sym->name,
sym->type));
c4m_print(c4m_cfg_repr(decl->cfg));
c4m_print(c4m_cstr_format("[h2]Function Scope for {}{}",
sym->name,
sym->type));
c4m_print(c4m_format_scope(decl->signature_info->fn_scope));
}

c4m_print(c4m_rich_lit("[h2]Module Scope"));
c4m_print(c4m_format_scope(ctx->entry_point->module_scope));
c4m_print(c4m_rich_lit("[h2]Global Scope"));
c4m_print(c4m_format_scope(ctx->final_globals));
}

static void
Expand All @@ -785,16 +770,12 @@ execute_test(c4m_test_kat *kat)
{
c4m_compile_ctx *ctx;
c4m_gc_show_heap_stats_on();
c4m_printf("[atomic lime]info:[/] Compiling: {}", kat->path);
c4m_print(c4m_cstr_format("[h1]Processing module {}", kat->path));

ctx = c4m_compile_from_entry_point(kat->path);

show_dev_compile_info(ctx);

if (dev_mode) {
c4m_file_compile_ctx *f = ctx->entry_point;
c4m_print(c4m_rich_lit("[h2]Module Source Code"));
c4m_print(f->raw);
show_dev_compile_info(ctx);
}

c4m_grid_t *err_output = c4m_format_errors(ctx);
Expand Down

0 comments on commit 258c1e9

Please sign in to comment.