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/lower.c | |
parent | d922c61db5a4eacf9c4c0a6ec5ed7647d000171a (diff) | |
download | fwd-199d1342d76b5cae6503fa0a97322d2658d43b5f.tar.gz fwd-199d1342d76b5cae6503fa0a97322d2658d43b5f.zip |
improve printing
Diffstat (limited to 'src/lower.c')
-rw-r--r-- | src/lower.c | 22 |
1 files changed, 18 insertions, 4 deletions
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); |