Fix value transfer in structs and arrays

This commit is contained in:
Sofia 2025-07-17 00:32:41 +03:00
parent 9a4f0dc5d8
commit 8abee593f0
3 changed files with 9 additions and 7 deletions

View File

@ -415,12 +415,11 @@ impl mir::Expression {
}
}
mir::ExprKind::Indexed(expression, val_t, idx_expr) => {
dbg!(&expression, &idx_expr);
let array = expression
.codegen(scope, state)
.codegen(scope, &state.load(true))
.expect("array returned none!");
let idx = idx_expr
.codegen(scope, state)
.codegen(scope, &state.load(true))
.expect("index returned none!");
let mut ptr = scope
@ -488,6 +487,8 @@ impl mir::Expression {
let TypeDefinitionKind::Struct(struct_ty) = scope.get_typedef(&name).unwrap();
let idx = struct_ty.find_index(field).unwrap();
dbg!(&scope.context);
dbg!(&struct_val);
let mut value = scope
.block
.build(Instr::GetStructElemPtr(struct_val, idx as u32))

View File

@ -1,13 +1,14 @@
// Arithmetic, function calls and imports!
fn array() -> [u16; 4] {
return [10, 15, 7, 9];
fn array() -> [[[u16; 4];1];1] {
return [[[10, 15, 7, 9]]];
}
fn main() -> u16 {
let mut list = array();
list[0][0][2] = 19;
let a = 1;
return list[a + 1];
return list[0][0][a + 1];
}

View File

@ -19,5 +19,5 @@ fn main() -> u32 {
let mut b = value[val1];
b.second[2] = 99;
return value[0].second[2];
return value[val1].second[2];
}