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

View File

@@ -13,9 +13,19 @@ struct Human
export func main(args: []cstring): i64
{
let x: cstring = "test"
c::puts(x)
let x = alloc Human
{
name = alloc Name {
first = "john"
last = "doe"
}
age = 23
}
print_name(x&)
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)
{
var result = EmitUnwrap(EmitExpression(dereference.Expression));
return EmitLoad(dereference.Type, result);
var pointerType = (NubPointerType)dereference.Expression.Type;
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)
{
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)