Fix argument ordering bug (#58)

This commit is contained in:
Patrick Stevens
2025-06-20 12:40:45 +01:00
committed by GitHub
parent 71b12b5684
commit 5a7cf11a5f
11 changed files with 221 additions and 47 deletions

View File

@@ -244,6 +244,7 @@ type DumpedAssembly =
interface IDisposable with
member this.Dispose () = this.PeReader.Dispose ()
type TypeResolutionResult =
| FirstLoadAssy of WoofWare.PawPrint.AssemblyReference
| Resolved of DumpedAssembly * TypeInfo<TypeDefn>
@@ -516,3 +517,46 @@ module Assembly =
match assemblies.TryGetValue assy.Name.FullName with
| false, _ -> TypeResolutionResult.FirstLoadAssy assy
| true, toAssy -> resolveTypeFromName toAssy assemblies ty.Namespace ty.Name genericArgs
[<RequireQualifiedAccess>]
module DumpedAssembly =
let resolveBaseType
(bct : BaseClassTypes<DumpedAssembly>)
(loadedAssemblies : ImmutableDictionary<string, DumpedAssembly>)
(source : AssemblyName)
(baseTypeInfo : BaseTypeInfo option)
: ResolvedBaseType
=
let rec go (baseType : BaseTypeInfo option) =
match baseType with
| Some (BaseTypeInfo.TypeRef r) ->
let assy = loadedAssemblies.[source.FullName]
// TODO: generics
match Assembly.resolveTypeRef loadedAssemblies assy assy.TypeRefs.[r] None with
| TypeResolutionResult.FirstLoadAssy _ ->
failwith
"seems pretty unlikely that we could have constructed this object without loading its base type"
| TypeResolutionResult.Resolved (assy, typeInfo) ->
match TypeInfo.isBaseType bct _.Name assy.Name typeInfo.TypeDefHandle with
| Some v -> v
| None -> go typeInfo.BaseType
| Some (BaseTypeInfo.ForeignAssemblyType (assy, ty)) ->
let assy = loadedAssemblies.[assy.FullName]
match TypeInfo.isBaseType bct _.Name assy.Name ty with
| Some v -> v
| None ->
let ty = assy.TypeDefs.[ty]
go ty.BaseType
| Some (BaseTypeInfo.TypeSpec _) -> failwith "TODO"
| Some (BaseTypeInfo.TypeDef h) ->
let assy = loadedAssemblies.[source.FullName]
match TypeInfo.isBaseType bct _.Name assy.Name h with
| Some v -> v
| None ->
let ty = assy.TypeDefs.[h]
go ty.BaseType
| None -> ResolvedBaseType.Object
go baseTypeInfo

View File

@@ -132,6 +132,7 @@ type NullaryIlOp =
| Ldind_i
| Ldind_i1
| Ldind_i2
/// Loads a value of type int32 as an int32 onto the evaluation stack indirectly from the specified address.
| Ldind_i4
| Ldind_i8
| Ldind_u1

View File

@@ -90,6 +90,8 @@ type TypeInfoEval<'ret> =
type TypeInfoCrate =
abstract Apply<'ret> : TypeInfoEval<'ret> -> 'ret
abstract ToString : unit -> string
abstract BaseType : BaseTypeInfo option
abstract Assembly : AssemblyName
[<RequireQualifiedAccess>]
module TypeInfoCrate =
@@ -102,6 +104,10 @@ module TypeInfoCrate =
member _.Eval this = string<TypeInfo<_>> this
}
|> this.Apply
member this.BaseType = t.BaseType
member this.Assembly = t.Assembly
}
type BaseClassTypes<'corelib> =
@@ -242,10 +248,32 @@ module TypeInfo =
Events = events
}
let isBaseType<'corelib>
(baseClassTypes : BaseClassTypes<'corelib>)
(getName : 'corelib -> AssemblyName)
(typeAssy : AssemblyName)
(typeDefinitionHandle : TypeDefinitionHandle)
: ResolvedBaseType option
=
if typeAssy = getName baseClassTypes.Corelib then
if typeDefinitionHandle = baseClassTypes.Enum.TypeDefHandle then
Some ResolvedBaseType.Enum
elif typeDefinitionHandle = baseClassTypes.ValueType.TypeDefHandle then
Some ResolvedBaseType.ValueType
elif typeDefinitionHandle = baseClassTypes.DelegateType.TypeDefHandle then
Some ResolvedBaseType.Delegate
elif typeDefinitionHandle = baseClassTypes.Object.TypeDefHandle then
Some ResolvedBaseType.Object
else
None
else
None
let rec resolveBaseType<'corelib, 'generic>
(baseClassTypes : BaseClassTypes<'corelib>)
(getName : 'corelib -> AssemblyName)
(getType : 'corelib -> TypeDefinitionHandle -> TypeInfo<'generic>)
(getTypeDef : 'corelib -> TypeDefinitionHandle -> TypeInfo<'generic>)
(getTypeRef : 'corelib -> TypeReferenceHandle -> TypeInfo<'generic>)
(sourceAssembly : AssemblyName)
(value : BaseTypeInfo option)
: ResolvedBaseType
@@ -256,37 +284,34 @@ module TypeInfo =
match value with
| BaseTypeInfo.TypeDef typeDefinitionHandle ->
if sourceAssembly = getName baseClassTypes.Corelib then
if typeDefinitionHandle = baseClassTypes.Enum.TypeDefHandle then
ResolvedBaseType.Enum
elif typeDefinitionHandle = baseClassTypes.ValueType.TypeDefHandle then
ResolvedBaseType.ValueType
elif typeDefinitionHandle = baseClassTypes.DelegateType.TypeDefHandle then
ResolvedBaseType.Delegate
else
let baseType = getType baseClassTypes.Corelib typeDefinitionHandle
resolveBaseType baseClassTypes getName getType sourceAssembly baseType.BaseType
else
failwith "unexpected base type not in corelib"
| BaseTypeInfo.TypeRef typeReferenceHandle -> failwith "todo"
match isBaseType baseClassTypes getName sourceAssembly typeDefinitionHandle with
| Some x -> x
| None ->
let baseType = getTypeDef baseClassTypes.Corelib typeDefinitionHandle
resolveBaseType baseClassTypes getName getTypeDef getTypeRef sourceAssembly baseType.BaseType
| BaseTypeInfo.TypeRef typeReferenceHandle ->
let typeRef = getTypeRef baseClassTypes.Corelib typeReferenceHandle
failwith $"{typeRef}"
| BaseTypeInfo.TypeSpec typeSpecificationHandle -> failwith "todo"
| BaseTypeInfo.ForeignAssemblyType (assemblyName, typeDefinitionHandle) ->
resolveBaseType
baseClassTypes
getName
getType
getTypeDef
getTypeRef
assemblyName
(Some (BaseTypeInfo.TypeDef typeDefinitionHandle))
let toTypeDefn
(corelib : BaseClassTypes<'corelib>)
(getName : 'corelib -> AssemblyName)
(getType : 'corelib -> TypeDefinitionHandle -> TypeInfo<'generic>)
(getTypeDef : 'corelib -> TypeDefinitionHandle -> TypeInfo<'generic>)
(getTypeRef : 'corelib -> TypeReferenceHandle -> TypeInfo<'generic>)
(ty : TypeInfo<'generic>)
: TypeDefn
=
let stk =
match resolveBaseType corelib getName getType ty.Assembly ty.BaseType with
match resolveBaseType corelib getName getTypeDef getTypeRef ty.Assembly ty.BaseType with
| ResolvedBaseType.Enum
| ResolvedBaseType.ValueType -> SignatureTypeKind.ValueType
| ResolvedBaseType.Object -> SignatureTypeKind.Class