This commit is contained in:
nub31
2025-07-03 20:17:43 +02:00
parent f93ae27437
commit 36cbe3b186
2 changed files with 27 additions and 6 deletions

View File

@@ -13,9 +13,19 @@ struct Human
export func main(args: []cstring): i64 export func main(args: []cstring): i64
{ {
let x: cstring = "test" let x = alloc Human
{
c::puts(x) name = alloc Name {
first = "john"
last = "doe"
}
age = 23
}
print_name(x&)
return 0 return 0
} }
func print_name(human: ^Human) {
c::puts(human^.name.last)
}

View File

@@ -827,13 +827,24 @@ public static class QBEGenerator
private static Val EmitDereference(BoundDereferenceNode dereference) private static Val EmitDereference(BoundDereferenceNode dereference)
{ {
var result = EmitUnwrap(EmitExpression(dereference.Expression)); var pointerType = (NubPointerType)dereference.Expression.Type;
return EmitLoad(dereference.Type, result);
var pointer = EmitExpression(dereference.Expression);
// Complex types are already pointers, so no need to load them
if (pointerType.BaseType is NubComplexType)
{
return pointer;
}
return EmitLoad(dereference.Type, EmitUnwrap(pointer));
} }
private static Val EmitAddressOf(BoundAddressOfNode addressOf) private static Val EmitAddressOf(BoundAddressOfNode addressOf)
{ {
throw new NotImplementedException(); var value = EmitExpression(addressOf.Expression);
Debug.Assert(value.Kind == ValKind.Pointer);
return new Val(value.Name, addressOf.Type, ValKind.Direct);
} }
private static Val EmitBinaryExpression(BoundBinaryExpressionNode binaryExpression) private static Val EmitBinaryExpression(BoundBinaryExpressionNode binaryExpression)