...
This commit is contained in:
@@ -264,6 +264,56 @@ public static class QBEGenerator
|
||||
throw new ArgumentOutOfRangeException(nameof(type));
|
||||
}
|
||||
}
|
||||
|
||||
private static string EmitCopy(NubType type, string source)
|
||||
{
|
||||
var destination = VarName();
|
||||
switch (type)
|
||||
{
|
||||
case NubArrayType nubArrayType:
|
||||
{
|
||||
var size = EmitArraySizeInBytes(nubArrayType, source);
|
||||
_builder.AppendLine($" {destination} =l alloc8 {size}");
|
||||
EmitMemcpy(source, destination, size);
|
||||
break;
|
||||
}
|
||||
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:
|
||||
{
|
||||
_builder.AppendLine($" {destination} {QBEAssign(type)} {source}");
|
||||
break;
|
||||
}
|
||||
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)
|
||||
{
|
||||
@@ -1248,6 +1298,7 @@ public static class QBEGenerator
|
||||
foreach (var parameter in funcCall.Parameters)
|
||||
{
|
||||
var result = EmitUnwrap(EmitExpression(parameter));
|
||||
var copy = EmitCopy(parameter.Type, result);
|
||||
|
||||
var qbeType = parameter.Type switch
|
||||
{
|
||||
@@ -1274,7 +1325,8 @@ public static class QBEGenerator
|
||||
NubStringType => "l",
|
||||
_ => throw new NotSupportedException($"'{parameter.Type}' type cannot be used in function calls")
|
||||
};
|
||||
parameterStrings.Add($"{qbeType} {result}");
|
||||
|
||||
parameterStrings.Add($"{qbeType} {copy}");
|
||||
}
|
||||
|
||||
var funcPointer = EmitUnwrap(EmitExpression(funcCall.Expression));
|
||||
|
||||
Reference in New Issue
Block a user