diff options
author | Kimplul <kimi.h.kuparinen@gmail.com> | 2025-03-22 15:40:15 +0200 |
---|---|---|
committer | Kimplul <kimi.h.kuparinen@gmail.com> | 2025-03-22 15:40:15 +0200 |
commit | 199d1342d76b5cae6503fa0a97322d2658d43b5f (patch) | |
tree | b88b49f7c16d305b76736e34e795e781dac28417 /src | |
parent | d922c61db5a4eacf9c4c0a6ec5ed7647d000171a (diff) | |
download | fwd-199d1342d76b5cae6503fa0a97322d2658d43b5f.tar.gz fwd-199d1342d76b5cae6503fa0a97322d2658d43b5f.zip |
improve printing
Diffstat (limited to 'src')
-rw-r--r-- | src/ast.c | 5 | ||||
-rw-r--r-- | src/lower.c | 22 |
2 files changed, 21 insertions, 6 deletions
@@ -188,8 +188,9 @@ static void dump(int depth, const char *fmt, ...) va_list args; va_start(args, fmt); printf("//"); - for (int i = 0; i < depth; ++i) - printf(" "); + /* indent */ + if (depth != 0) + printf("%*c", 2 * depth, ' '); vprintf(fmt, args); diff --git a/src/lower.c b/src/lower.c index 8849bd1..21844ae 100644 --- a/src/lower.c +++ b/src/lower.c @@ -29,8 +29,8 @@ static void decrease_indent(struct state *state) static void indent(struct state *state) { - for (long i = 0; i < state->indent; ++i) - putchar(' '); + if (state->indent != 0) + printf("%*c", (int)(2 * state->indent), ' '); } static int lower_var(struct ast *expr); @@ -367,8 +367,12 @@ static int lower_call(struct state *state, struct ast *call, bool ret) } printf("\n"); + + increase_indent(state); indent(state); - printf(" return %s;\n", err_str); + decrease_indent(state); + + printf("return %s;\n", err_str); if (ret) { indent(state); @@ -452,7 +456,13 @@ static int lower_statement(struct state *state, struct ast *stmt, bool ret) case AST_LET: return lower_let(state, stmt, ret); case AST_CALL: return lower_call(state, stmt, ret); case AST_IF: return lower_if(state, stmt, ret); - case AST_EMPTY: return 0; + case AST_EMPTY: + if (ret) + printf("return nullptr;\n"); + else + printf("\n"); + + return 0; default: internal_error("missing statement lowering"); return -1; @@ -516,6 +526,10 @@ static int lower_block(struct state *state, struct ast *block, bool ret) if (lower_error(block_error(block))) return -1; } + else if (!block_body(block)) { + indent(state); + printf("return nullptr;\n"); + } decrease_indent(state); indent(state); |