...
This commit is contained in:
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user