From 3fb76e148f9596de2fc82df391162f1c32b4d897 Mon Sep 17 00:00:00 2001 From: Patrick Stevens <3138005+Smaug123@users.noreply.github.com> Date: Sun, 1 Jun 2025 15:49:37 +0100 Subject: [PATCH] Allocate statics when they're not allocated (#31) --- WoofWare.PawPrint/UnaryMetadataIlOp.fs | 35 +++++++++++++++----------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/WoofWare.PawPrint/UnaryMetadataIlOp.fs b/WoofWare.PawPrint/UnaryMetadataIlOp.fs index 8737b11..26b78c5 100644 --- a/WoofWare.PawPrint/UnaryMetadataIlOp.fs +++ b/WoofWare.PawPrint/UnaryMetadataIlOp.fs @@ -351,6 +351,7 @@ module internal UnaryMetadataIlOp = state |> IlMachineState.advanceProgramCounter thread |> Tuple.withRight WhatWeDid.Executed + | Stsfld -> let fieldHandle = match metadataToken with @@ -542,7 +543,23 @@ module internal UnaryMetadataIlOp = | NothingToDo state -> if TypeDefn.isManaged field.Signature then - match state.Statics.TryGetValue ((field.DeclaringType, activeAssy.Name)) with + let typeId = field.DeclaringType, activeAssy.Name + + let allocateStatic () = + // TODO: generics + let state, zero = + IlMachineState.cliTypeZeroOf + loggerFactory + activeAssy + field.Signature + ImmutableArray.Empty + state + + state.SetStatic typeId field.Name zero + |> IlMachineState.pushToEvalStack (CliType.ObjectRef None) thread + |> Tuple.withRight WhatWeDid.Executed + + match state.Statics.TryGetValue typeId with | true, v -> match v.TryGetValue field.Name with | true, v -> @@ -550,19 +567,9 @@ module internal UnaryMetadataIlOp = |> IlMachineState.advanceProgramCounter thread |> Tuple.withRight WhatWeDid.Executed | false, _ -> - let allocation, state = - state |> (failwith "TODO: Ldsflda static field allocation unimplemented") - - state - |> IlMachineState.pushToEvalStack (CliType.ObjectRef (Some allocation)) thread - |> Tuple.withRight WhatWeDid.Executed - | false, _ -> - let allocation, state = - state |> (failwith "TODO: Ldsflda static field allocation unimplemented") - - state - |> IlMachineState.pushToEvalStack (CliType.ObjectRef (Some allocation)) thread - |> Tuple.withRight WhatWeDid.Executed + // Field has not yet been initialised. + allocateStatic () + | false, _ -> allocateStatic () else failwith "TODO: Ldsflda - push unmanaged pointer" | Ldftn -> failwith "TODO: Ldftn unimplemented"