aboutsummaryrefslogtreecommitdiff
path: root/src/llvm_backend.cpp
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2021-07-05 16:23:13 +0100
committergingerBill <bill@gingerbill.org>2021-07-05 16:23:13 +0100
commita98eee145d60a42324835c578d8573675d6fdd49 (patch)
tree2f4824a5812115ff84277d798b7322e97f962811 /src/llvm_backend.cpp
parentc6b9b3b9a41d6e049d39780933067d44cf2b6469 (diff)
Remove `try`; Replace `try x else y` with `or_else(x, y)`
Diffstat (limited to 'src/llvm_backend.cpp')
-rw-r--r--src/llvm_backend.cpp99
1 files changed, 47 insertions, 52 deletions
diff --git a/src/llvm_backend.cpp b/src/llvm_backend.cpp
index 4c4c015ba..1df07f986 100644
--- a/src/llvm_backend.cpp
+++ b/src/llvm_backend.cpp
@@ -9590,50 +9590,50 @@ lbValue lb_emit_try_has_value(lbProcedure *p, lbValue rhs) {
GB_ASSERT(has_value.value != nullptr);
return has_value;
}
-lbValue lb_emit_try(lbProcedure *p, Ast *arg, TypeAndValue const &tv) {
- lbValue lhs = {};
- lbValue rhs = {};
- lb_emit_try_lhs_rhs(p, arg, tv, &lhs, &rhs);
-
- lbBlock *return_block = lb_create_block(p, "try.return", false);
- lbBlock *continue_block = lb_create_block(p, "try.continue", false);
- lb_emit_if(p, lb_emit_try_has_value(p, rhs), continue_block, return_block);
- lb_start_block(p, return_block);
-
- {
- Type *proc_type = base_type(p->type);
- Type *results = proc_type->Proc.results;
- GB_ASSERT(results != nullptr && results->kind == Type_Tuple);
- TypeTuple *tuple = &results->Tuple;
-
- GB_ASSERT(tuple->variables.count != 0);
-
- Entity *end_entity = tuple->variables[tuple->variables.count-1];
- rhs = lb_emit_conv(p, rhs, end_entity->type);
- if (p->type->Proc.has_named_results) {
- GB_ASSERT(end_entity->token.string.len != 0);
-
- // NOTE(bill): store the named values before returning
- lbValue found = map_must_get(&p->module->values, hash_entity(end_entity));
- lb_emit_store(p, found, rhs);
-
- lb_build_return_stmt(p, {});
- } else {
- GB_ASSERT(tuple->variables.count == 1);
- lb_build_return_stmt_internal(p, rhs);
- }
- }
-
- lb_start_block(p, continue_block);
-
- if (tv.type != nullptr) {
- return lb_emit_conv(p, lhs, tv.type);
- }
- return {};
-}
-
-
-lbValue lb_emit_try_else(lbProcedure *p, Ast *arg, Ast *else_expr, TypeAndValue const &tv) {
+// lbValue lb_emit_try(lbProcedure *p, Ast *arg, TypeAndValue const &tv) {
+// lbValue lhs = {};
+// lbValue rhs = {};
+// lb_emit_try_lhs_rhs(p, arg, tv, &lhs, &rhs);
+
+// lbBlock *return_block = lb_create_block(p, "try.return", false);
+// lbBlock *continue_block = lb_create_block(p, "try.continue", false);
+// lb_emit_if(p, lb_emit_try_has_value(p, rhs), continue_block, return_block);
+// lb_start_block(p, return_block);
+
+// {
+// Type *proc_type = base_type(p->type);
+// Type *results = proc_type->Proc.results;
+// GB_ASSERT(results != nullptr && results->kind == Type_Tuple);
+// TypeTuple *tuple = &results->Tuple;
+
+// GB_ASSERT(tuple->variables.count != 0);
+
+// Entity *end_entity = tuple->variables[tuple->variables.count-1];
+// rhs = lb_emit_conv(p, rhs, end_entity->type);
+// if (p->type->Proc.has_named_results) {
+// GB_ASSERT(end_entity->token.string.len != 0);
+
+// // NOTE(bill): store the named values before returning
+// lbValue found = map_must_get(&p->module->values, hash_entity(end_entity));
+// lb_emit_store(p, found, rhs);
+
+// lb_build_return_stmt(p, {});
+// } else {
+// GB_ASSERT(tuple->variables.count == 1);
+// lb_build_return_stmt_internal(p, rhs);
+// }
+// }
+
+// lb_start_block(p, continue_block);
+
+// if (tv.type != nullptr) {
+// return lb_emit_conv(p, lhs, tv.type);
+// }
+// return {};
+// }
+
+
+lbValue lb_emit_or_else(lbProcedure *p, Ast *arg, Ast *else_expr, TypeAndValue const &tv) {
lbValue lhs = {};
lbValue rhs = {};
lb_emit_try_lhs_rhs(p, arg, tv, &lhs, &rhs);
@@ -10064,6 +10064,9 @@ lbValue lb_build_builtin_proc(lbProcedure *p, Ast *expr, TypeAndValue const &tv,
case BuiltinProc_soa_unzip:
return lb_soa_unzip(p, ce, tv);
+ case BuiltinProc_or_else:
+ return lb_emit_or_else(p, ce->args[0], ce->args[1], tv);
+
// "Intrinsics"
case BuiltinProc_alloca:
@@ -12783,14 +12786,6 @@ lbValue lb_build_expr(lbProcedure *p, Ast *expr) {
return lb_build_binary_expr(p, expr);
case_end;
- case_ast_node(te, TryExpr, expr);
- return lb_emit_try(p, te->expr, tv);
- case_end;
-
- case_ast_node(te, TryElseExpr, expr);
- return lb_emit_try_else(p, te->expr, te->else_expr, tv);
- case_end;
-
case_ast_node(pl, ProcLit, expr);
return lb_generate_anonymous_proc_lit(p->module, p->name, expr, p);
case_end;