diff options
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); |