Fix borrow derefs
This commit is contained in:
parent
fe4e41c435
commit
c622d59c93
@ -1,30 +1,24 @@
|
||||
// Arithmetic, function calls and imports!
|
||||
|
||||
struct Test {
|
||||
field: i32,
|
||||
second: [u32; 4]
|
||||
field: i32,
|
||||
second: [u32; 4],
|
||||
}
|
||||
|
||||
fn test() -> Test {
|
||||
let value = Test {
|
||||
field: 5,
|
||||
second: [6, 3, 4, 8],
|
||||
};
|
||||
return value;
|
||||
let value = Test {
|
||||
field: 5,
|
||||
second: [6, 3, 4, 8],
|
||||
};
|
||||
return value;
|
||||
}
|
||||
|
||||
fn main() -> u32 {
|
||||
let mut value = test();
|
||||
let mut value = test();
|
||||
|
||||
let mut a = &mut value;
|
||||
let mut a = &mut value;
|
||||
|
||||
*a.second[2] = 15;
|
||||
let test = *a.field;
|
||||
|
||||
let b = 4;
|
||||
if value.field < b {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
return value.second[2];
|
||||
}
|
||||
|
@ -440,6 +440,7 @@ impl Builder {
|
||||
}
|
||||
Instr::GetStructElemPtr(ptr_val, idx) => {
|
||||
let ptr_ty = ptr_val.get_type(&self)?;
|
||||
dbg!(&ptr_ty);
|
||||
if let Type::Ptr(ty) = ptr_ty {
|
||||
if let Type::CustomType(val) = *ty {
|
||||
match self.type_data(&val).kind {
|
||||
|
@ -256,7 +256,6 @@ impl mir::Module {
|
||||
let mut typedefs = self.typedefs.clone();
|
||||
typedefs.sort_by(|a, b| b.source_module.cmp(&a.source_module));
|
||||
|
||||
dbg!(&self.module_id, &typedefs);
|
||||
for typedef in typedefs {
|
||||
let type_key = CustomTypeKey(typedef.name.clone(), typedef.source_module);
|
||||
let type_value = match &typedef.kind {
|
||||
@ -1001,6 +1000,7 @@ impl mir::Expression {
|
||||
let TypeKind::CodegenPtr(inner) = &struct_val.1 else {
|
||||
panic!("tried accessing non-pointer");
|
||||
};
|
||||
dbg!(&inner);
|
||||
let TypeKind::CustomType(key) = *inner.clone() else {
|
||||
panic!("tried accessing non-custom-type");
|
||||
};
|
||||
@ -1097,9 +1097,14 @@ impl mir::Expression {
|
||||
.stack_values
|
||||
.get(&varref.1)
|
||||
.expect("Variable reference not found?!");
|
||||
|
||||
let TypeKind::CodegenPtr(ptr_inner) = &v.1 else {
|
||||
panic!();
|
||||
};
|
||||
|
||||
Some(StackValue(
|
||||
StackValueKind::mutable(*mutable, v.0.instr()),
|
||||
TypeKind::Borrow(Box::new(v.1.clone()), *mutable),
|
||||
TypeKind::Borrow(Box::new(*ptr_inner.clone()), *mutable),
|
||||
))
|
||||
}
|
||||
mir::ExprKind::Deref(varref) => {
|
||||
|
Loading…
Reference in New Issue
Block a user