aboutsummaryrefslogtreecommitdiff
path: root/src/compile.c
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2025-08-24 17:19:24 -0400
committerBruce Hill <bruce@bruce-hill.com>2025-08-24 17:19:24 -0400
commit31beca9f417c2c4fd32eaae01b3e855acf892220 (patch)
treea1d3e656b908d6da6cf8887201f2fa89a82b1142 /src/compile.c
parent2245c883680ccfbe545f230d6b68c38ce54bceb6 (diff)
Split out blocks into their own file
Diffstat (limited to 'src/compile.c')
-rw-r--r--src/compile.c27
1 files changed, 2 insertions, 25 deletions
diff --git a/src/compile.c b/src/compile.c
index 6e53acb4..2a33afb3 100644
--- a/src/compile.c
+++ b/src/compile.c
@@ -6,6 +6,7 @@
#include "ast.h"
#include "compile.h"
#include "compile/assignments.h"
+#include "compile/blocks.h"
#include "compile/enums.h"
#include "compile/functions.h"
#include "compile/integers.h"
@@ -514,31 +515,7 @@ Text_t compile(env_t *env, ast_t *ast) {
case Path: {
return Texts("Path(", compile_text_literal(Text$from_str(Match(ast, Path)->path)), ")");
}
- case Block: {
- ast_list_t *stmts = Match(ast, Block)->statements;
- if (stmts && !stmts->next) return compile(env, stmts->ast);
-
- Text_t code = Text("({\n");
- deferral_t *prev_deferred = env->deferred;
- env = fresh_scope(env);
- for (ast_list_t *stmt = stmts; stmt; stmt = stmt->next)
- prebind_statement(env, stmt->ast);
- for (ast_list_t *stmt = stmts; stmt; stmt = stmt->next) {
- if (stmt->next) {
- code = Texts(code, compile_statement(env, stmt->ast), "\n");
- } else {
- // TODO: put defer after evaluating block expression
- for (deferral_t *deferred = env->deferred; deferred && deferred != prev_deferred;
- deferred = deferred->next) {
- code = Texts(code, compile_statement(deferred->defer_env, deferred->block));
- }
- code = Texts(code, compile(env, stmt->ast), ";\n");
- }
- bind_statement(env, stmt->ast);
- }
-
- return Texts(code, "})");
- }
+ case Block: return compile_block_expression(env, ast);
case Min:
case Max: {
type_t *t = get_type(env, ast);