union definitions

This commit is contained in:
nub31
2026-02-15 04:23:36 +01:00
parent cbe27c0ae8
commit caa3b378b3
7 changed files with 239 additions and 17 deletions

View File

@@ -99,6 +99,7 @@ public record Manifest(Dictionary<string, Manifest.Module> Modules)
return typeInfo switch
{
Compiler.Module.TypeInfoStruct s => new Module.TypeInfoStruct(s.Packed, s.Fields.Select(x => new Module.TypeInfoStruct.Field(x.Name, x.Type)).ToList()),
Compiler.Module.TypeInfoEnum e => new Module.TypeInfoEnum(e.Variants.Select(v => new Module.TypeInfoEnum.Variant(v.Name, v.Fields.Select(x => new Module.TypeInfoEnum.Variant.Field(x.Name, x.Type)).ToList())).ToList()),
_ => throw new ArgumentOutOfRangeException(nameof(typeInfo))
};
}
@@ -110,11 +111,20 @@ public record Manifest(Dictionary<string, Manifest.Module> Modules)
public record IdentifierInfo(NubType Type, string MangledName);
[JsonDerivedType(typeof(TypeInfoStruct), "struct")]
[JsonDerivedType(typeof(TypeInfoEnum), "enum")]
public abstract record TypeInfo;
public record TypeInfoStruct(bool Packed, IReadOnlyList<TypeInfoStruct.Field> Fields) : TypeInfo
{
public record Field(string Name, NubType Type);
}
public record TypeInfoEnum(IReadOnlyList<TypeInfoEnum.Variant> Variants) : TypeInfo
{
public record Variant(string Name, List<Variant.Field> Fields)
{
public record Field(string Name, NubType Type);
}
}
}
}