This commit is contained in:
nub31
2025-09-08 17:41:08 +02:00
parent 6216fdb68c
commit edccffd618
2 changed files with 11 additions and 11 deletions

View File

@@ -22,7 +22,7 @@ func main(args: []cstring): i64
let x: Printable = struct Human { let x: Printable = struct Human {
name = "Oliver" name = "Oliver"
age = 23 age = 23
} }
x.print() x.print()

View File

@@ -197,28 +197,28 @@ public class QBEGenerator
return size; return size;
} }
private bool EmitTryMoveInto(ExpressionNode source, string destinationPointer) private bool EmitTryMoveInto(ExpressionNode source, string destinationLValue)
{ {
switch (source) switch (source)
{ {
case ArrayInitializerNode arrayInitializer: case ArrayInitializerNode arrayInitializer:
{ {
EmitStore(source.Type, EmitArrayInitializer(arrayInitializer), destinationPointer); EmitStore(source.Type, EmitArrayInitializer(arrayInitializer), destinationLValue);
return true; return true;
} }
case StructInitializerNode structInitializer: case StructInitializerNode structInitializer:
{ {
EmitStructInitializer(structInitializer, destinationPointer); EmitStructInitializer(structInitializer, destinationLValue);
return true; return true;
} }
case InterfaceInitializerNode interfaceInitializer: case InterfaceInitializerNode interfaceInitializer:
{ {
EmitInterfaceInitializer(interfaceInitializer, destinationPointer); EmitInterfaceInitializer(interfaceInitializer, destinationLValue);
return true; return true;
} }
case LiteralNode { Kind: LiteralKind.String } literal: case LiteralNode { Kind: LiteralKind.String } literal:
{ {
EmitStore(source.Type, EmitLiteral(literal), destinationPointer); EmitStore(source.Type, EmitLiteral(literal), destinationLValue);
return true; return true;
} }
} }
@@ -226,10 +226,10 @@ public class QBEGenerator
return false; return false;
} }
private void EmitCopyIntoOrInitialize(ExpressionNode source, string destinationPointer) private void EmitCopyIntoOrInitialize(ExpressionNode source, string destinationLValue)
{ {
// If the source is a value which is not used yet such as an array/struct initializer or literal, we can skip copying // If the source is a value which is not used yet such as an array/struct initializer or literal, we can skip copying
if (EmitTryMoveInto(source, destinationPointer)) if (EmitTryMoveInto(source, destinationLValue))
{ {
return; return;
} }
@@ -238,13 +238,13 @@ public class QBEGenerator
if (source.Type.IsSimpleType(out var simpleType, out var complexType)) if (source.Type.IsSimpleType(out var simpleType, out var complexType))
{ {
EmitStore(simpleType, value, destinationPointer); EmitStore(simpleType, value, destinationLValue);
} }
else else
{ {
if (complexType is StructTypeNode or InterfaceTypeNode) if (complexType is StructTypeNode or InterfaceTypeNode)
{ {
EmitMemcpy(value, destinationPointer, SizeOf(complexType).ToString()); EmitMemcpy(value, destinationLValue, SizeOf(complexType).ToString());
} }
else else
{ {
@@ -259,7 +259,7 @@ public class QBEGenerator
var buffer = TmpName(); var buffer = TmpName();
_writer.Indented($"{buffer} =l alloc8 {size}"); _writer.Indented($"{buffer} =l alloc8 {size}");
EmitMemcpy(value, buffer, size); EmitMemcpy(value, buffer, size);
EmitStore(complexType, buffer, destinationPointer); EmitStore(complexType, buffer, destinationLValue);
} }
} }
} }