This commit is contained in:
nub31
2025-06-14 18:24:10 +02:00
parent fef54cc538
commit dfb0d4b5f0
2 changed files with 16 additions and 11 deletions

View File

@@ -86,18 +86,23 @@ public static class QBEGenerator
return $"@l{++_labelIndex}";
}
private static string FuncName(IFuncSignature func)
private static string FuncName(IFuncSignature funcDef)
{
return func switch
return funcDef switch
{
ExternFuncDefinitionNode externFuncDefinition => $"${externFuncDefinition.CallName}",
LocalFuncDefinitionNode localFuncDefinition => localFuncDefinition.Exported
? $"${localFuncDefinition.Name}"
: $"${localFuncDefinition.Namespace}_{localFuncDefinition.Name}",
_ => throw new ArgumentOutOfRangeException(nameof(func))
_ => throw new ArgumentOutOfRangeException(nameof(funcDef))
};
}
private static string StructName(StructDefinitionNode structDef)
{
return $":{structDef.Namespace}_{structDef.Name}";
}
private static string QBEStore(NubType type)
{
return type switch
@@ -349,7 +354,7 @@ public static class QBEGenerator
PrimitiveTypeKind.Bool => "w",
_ => throw new UnreachableException()
},
NubStructType structType => $":{structType.Namespace}_{structType.Name}",
NubStructType structType => StructName(_definitionTable.LookupStruct(structType.Namespace, structType.Name).GetValue()),
NubFixedArrayType => "l",
NubFuncType => "l",
_ => throw new NotSupportedException($"'{returnType}' type cannot be used as a function return type")
@@ -380,7 +385,7 @@ public static class QBEGenerator
PrimitiveTypeKind.Bool => "w",
_ => throw new UnreachableException()
},
NubStructType structType => $":{structType.Namespace}_{structType.Name}",
NubStructType structType => StructName(_definitionTable.LookupStruct(structType.Namespace, structType.Name).GetValue()),
NubFixedArrayType => "l",
NubFuncType => "l",
_ => throw new NotSupportedException($"'{parameter.Type}' type cannot be used as a function parameter type")
@@ -439,7 +444,7 @@ public static class QBEGenerator
private static void GenerateStructDefinition(StructDefinitionNode structDefinition)
{
_builder.Append($"type :{structDefinition.Namespace}_{structDefinition.Name} = {{ ");
_builder.Append($"type {StructName(structDefinition)} = {{ ");
foreach (var structDefinitionField in structDefinition.Fields)
{
var qbeType = structDefinitionField.Type switch
@@ -461,7 +466,7 @@ public static class QBEGenerator
PrimitiveTypeKind.Bool => "w",
_ => throw new UnreachableException()
},
NubStructType structType => $":{structType.Namespace}_{structType.Name}",
NubStructType structType => StructName(_definitionTable.LookupStruct(structType.Namespace, structType.Name).GetValue()),
NubFixedArrayType fixedArrayType => $"b {SizeOf(fixedArrayType)}",
NubFuncType => "l",
_ => throw new NotSupportedException($"'{structDefinitionField.Type}' type cannot be used in structs")
@@ -1320,7 +1325,7 @@ public static class QBEGenerator
PrimitiveTypeKind.Bool => "w",
_ => throw new ArgumentOutOfRangeException()
},
NubStructType structType => $":{structType.Namespace}_{structType.Name}",
NubStructType structType => StructName(_definitionTable.LookupStruct(structType.Namespace, structType.Name).GetValue()),
NubFixedArrayType => "l",
NubFuncType => "l",
_ => throw new NotSupportedException($"'{parameter.Type}' type cannot be used in function calls")