This commit is contained in:
nub31
2025-07-03 17:55:48 +02:00
parent a5099b921b
commit 4357eef438
2 changed files with 66 additions and 82 deletions

View File

@@ -195,105 +195,86 @@ public static class QBEGenerator
return size;
}
private static void EmitCopyInto(NubType type, string source, string destination)
private static void EmitCopyInto(NubType type, string source, string destinationPointer)
{
switch (type)
{
case NubArrayType nubArrayType:
case NubComplexType complexType:
{
var size = EmitArraySizeInBytes(nubArrayType, source);
var buffer = VarName();
_builder.AppendLine($" {buffer} =l alloc8 {size}");
EmitMemcpy(source, buffer, size);
EmitStore(type, buffer, destination);
break;
var size = complexType switch
{
NubArrayType nubArrayType => EmitArraySizeInBytes(nubArrayType, source),
NubCStringType => EmitCStringSizeInBytes(source),
NubStringType => EmitStringSizeInBytes(source),
NubStructType nubStructType => SizeOf(nubStructType).ToString(),
_ => throw new ArgumentOutOfRangeException(nameof(complexType))
};
switch (complexType)
{
case NubArrayType:
case NubCStringType:
case NubStringType:
{
var buffer = VarName();
_builder.AppendLine($" {buffer} =l alloc8 {size}");
EmitMemcpy(source, buffer, size);
EmitStore(type, buffer, destinationPointer);
return;
}
case NubStructType:
{
EmitMemcpy(source, destinationPointer, size);
return;
}
default:
{
throw new ArgumentOutOfRangeException(nameof(complexType));
}
}
}
case NubCStringType:
case NubSimpleType simpleType:
{
var size = EmitCStringSizeInBytes(source);
var buffer = VarName();
_builder.AppendLine($" {buffer} =l alloc8 {size}");
EmitMemcpy(source, buffer, size);
EmitStore(type, buffer, destination);
break;
EmitStore(simpleType, source, destinationPointer);
return;
}
case NubStringType:
{
var size = EmitStringSizeInBytes(source);
var buffer = VarName();
_builder.AppendLine($" {buffer} =l alloc8 {size}");
EmitMemcpy(source, buffer, size);
EmitStore(type, buffer, destination);
break;
}
case NubStructType nubStructType:
{
var size = SizeOf(nubStructType);
EmitMemcpy(source, destination, size.ToString());
break;
}
case NubPointerType:
case NubPrimitiveType:
{
EmitStore(type, source, destination);
break;
}
case NubVoidType:
case NubFuncType:
case NubAnyType:
throw new NotSupportedException($"Cannot copy type '{type}'");
default:
{
throw new ArgumentOutOfRangeException(nameof(type));
}
}
}
private static string EmitCopy(NubType type, string source)
{
var destination = VarName();
switch (type)
{
case NubArrayType nubArrayType:
case NubComplexType complexType:
{
var size = EmitArraySizeInBytes(nubArrayType, source);
var destination = VarName();
var size = complexType switch
{
NubArrayType nubArrayType => EmitArraySizeInBytes(nubArrayType, source),
NubCStringType => EmitCStringSizeInBytes(source),
NubStringType => EmitStringSizeInBytes(source),
NubStructType nubStructType => SizeOf(nubStructType).ToString(),
_ => throw new ArgumentOutOfRangeException(nameof(complexType))
};
_builder.AppendLine($" {destination} =l alloc8 {size}");
EmitMemcpy(source, destination, size);
break;
return destination;
}
case NubCStringType:
{
var size = EmitCStringSizeInBytes(source);
_builder.AppendLine($" {destination} =l alloc8 {size}");
EmitMemcpy(source, destination, size);
break;
}
case NubStringType:
{
var size = EmitStringSizeInBytes(source);
_builder.AppendLine($" {destination} =l alloc8 {size}");
EmitMemcpy(source, destination, size);
break;
}
case NubStructType nubStructType:
{
var size = SizeOf(nubStructType);
_builder.AppendLine($" {destination} =l alloc8 {size}");
EmitMemcpy(source, destination, size.ToString());
break;
}
case NubPointerType:
case NubPrimitiveType:
case NubSimpleType:
{
return source;
}
case NubVoidType:
case NubFuncType:
case NubAnyType:
throw new NotSupportedException($"Cannot copy type '{type}'");
default:
{
throw new ArgumentOutOfRangeException(nameof(type));
}
}
return destination;
}
private static string QBEAssign(NubType type)