Skip to content

Commit 572632f

Browse files
committed
[compiler] Add missing implementation for runtime compound value nested in another compound value.
1 parent d46d4d5 commit 572632f

3 files changed

Lines changed: 25 additions & 6 deletions

File tree

CHANGELOG.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ master
5858
- LD is invoked with all dependencies in --start-group --end-group block on Linux.
5959
- DLib now use correct dynamic runtime on Windows.
6060
- Fix copying of system libraries to the output location in case no custom module directory was set on Windows.
61+
- Add missing implementation for runtime compound value nested in another compound value.
6162

6263
[Modules]
6364

src/vm.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1634,9 +1634,7 @@ void interp_instr_decl_direct_ref(struct virtual_machine *vm, struct mir_instr_d
16341634
stack_push(vm, &real_ptr, ref->base.value.type);
16351635
}
16361636

1637-
void interp_instr_compound(struct virtual_machine *vm,
1638-
vm_stack_ptr_t tmp_ptr,
1639-
struct mir_instr_compound *cmp) {
1637+
void interp_instr_compound(struct virtual_machine *vm, vm_stack_ptr_t tmp_ptr, struct mir_instr_compound *cmp) {
16401638
bassert(!mir_is_comptime(&cmp->base));
16411639
const bool will_push = tmp_ptr == NULL;
16421640
if (will_push) {
@@ -1656,7 +1654,6 @@ void interp_instr_compound(struct virtual_machine *vm,
16561654
struct mir_instr *value = sarrpeek(values, i);
16571655
elem_type = value->value.type;
16581656
switch (type->kind) {
1659-
16601657
case MIR_TYPE_STRING:
16611658
case MIR_TYPE_DYNARR:
16621659
case MIR_TYPE_SLICE:
@@ -1675,8 +1672,14 @@ void interp_instr_compound(struct virtual_machine *vm,
16751672
bassert(i == 0 && "Invalid elem count for non-agregate type!!!");
16761673
}
16771674

1678-
vm_stack_ptr_t value_ptr = fetch_value(vm, &value->value);
1679-
memcpy(elem_ptr, value_ptr, elem_type->store_size_bytes);
1675+
if (!mir_is_comptime(value) && value->kind == MIR_INSTR_COMPOUND) {
1676+
struct mir_instr_compound *nested_cmp = (struct mir_instr_compound *)value;
1677+
bassert(!nested_cmp->is_naked);
1678+
interp_instr_compound(vm, elem_ptr, nested_cmp);
1679+
} else {
1680+
vm_stack_ptr_t value_ptr = fetch_value(vm, &value->value);
1681+
memcpy(elem_ptr, value_ptr, elem_type->store_size_bytes);
1682+
}
16801683
}
16811684

16821685
if (will_push) stack_push(vm, tmp_ptr, cmp->base.value.type);

tests/src/compounds.test.bl

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,3 +493,18 @@ anonymous_compound_assignment_propagation :: fn () #test {
493493
b : s32 = .{ 10 };
494494
test_true(b == 10);
495495
}
496+
497+
nested_compound_mixed_runtime_comptime :: fn () #test {
498+
i := 30;
499+
j := 40;
500+
501+
v :: T2.{
502+
.{ 10, 20 },
503+
.{ i, j },
504+
};
505+
506+
test_eq(v.a.i, 10);
507+
test_eq(v.a.j, 20);
508+
test_eq(v.b.i, i);
509+
test_eq(v.b.j, j);
510+
}

0 commit comments

Comments
 (0)