aboutsummaryrefslogtreecommitdiff
path: root/src/ir.cpp
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2020-06-10 15:37:50 +0100
committergingerBill <bill@gingerbill.org>2020-06-10 15:37:50 +0100
commit57b09b2ffbd1021d29e43fdc1f27da43f1b4ed23 (patch)
treeace60d87ae2fc67f35267ac954a58f1b2b91b711 /src/ir.cpp
parente86fde3cb16d2977054aa727c32cd4efcb1bd8a7 (diff)
Fix #439
Diffstat (limited to 'src/ir.cpp')
-rw-r--r--src/ir.cpp29
1 files changed, 27 insertions, 2 deletions
diff --git a/src/ir.cpp b/src/ir.cpp
index 1c2f8df37..9ded36ca4 100644
--- a/src/ir.cpp
+++ b/src/ir.cpp
@@ -523,6 +523,7 @@ struct irAddr {
};
Type *ir_type(irValue *value);
+irValue *ir_gen_anonymous_proc_lit(irModule *m, String prefix_name, Ast *expr, irProcedure *proc = nullptr);
irAddr ir_addr(irValue *addr) {
irAddr v = {irAddr_Default, addr};
@@ -1614,7 +1615,27 @@ irDefer ir_add_defer_proc(irProcedure *proc, isize scope_index, irValue *deferre
}
-
+void ir_check_compound_lit_constant(irModule *m, Ast *expr) {
+ expr = unparen_expr(expr);
+ if (expr == nullptr) {
+ return;
+ }
+ if (expr->kind == Ast_CompoundLit) {
+ ast_node(cl, CompoundLit, expr);
+ for_array(i, cl->elems) {
+ Ast *elem = cl->elems[i];
+ if (elem->kind == Ast_FieldValue) {
+ ast_node(fv, FieldValue, elem);
+ ir_check_compound_lit_constant(m, fv->value);
+ } else {
+ ir_check_compound_lit_constant(m, elem);
+ }
+ }
+ }
+ if (expr->kind == Ast_ProcLit) {
+ ir_gen_anonymous_proc_lit(m, str_lit("_proclit"), expr);
+ }
+}
irValue *ir_add_module_constant(irModule *m, Type *type, ExactValue value) {
gbAllocator a = ir_allocator();
@@ -1652,6 +1673,10 @@ irValue *ir_add_module_constant(irModule *m, Type *type, ExactValue value) {
}
}
+ if (value.kind == ExactValue_Compound) {
+ ir_check_compound_lit_constant(m, value.value_compound);
+ }
+
return ir_value_constant(type, value);
}
@@ -6504,7 +6529,7 @@ void ir_pop_target_list(irProcedure *proc) {
-irValue *ir_gen_anonymous_proc_lit(irModule *m, String prefix_name, Ast *expr, irProcedure *proc = nullptr) {
+irValue *ir_gen_anonymous_proc_lit(irModule *m, String prefix_name, Ast *expr, irProcedure *proc) {
ast_node(pl, ProcLit, expr);
// NOTE(bill): Generate a new name