From 5be1b523a5ad8bf993d9970773bb26e36e3f62d2 Mon Sep 17 00:00:00 2001 From: Ramsey Nasser Date: Tue, 28 Jul 2020 16:05:56 -0400 Subject: [PATCH] Refactor instance field compilation Avoids deftype/closure problems but will not emit volatile. anymore. Tracked in #191. --- src/magic/core.clj | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/src/magic/core.clj b/src/magic/core.clj index 4cbc664..808de2a 100644 --- a/src/magic/core.clj +++ b/src/magic/core.clj @@ -564,13 +564,18 @@ (il/ldsfld field))) (defn field-volatile? [f] - (let [modifiers (into #{} (.GetRequiredCustomModifiers f))] - (modifiers IsVolatile))) + (if (instance? System.Reflection.Emit.FieldBuilder f) + (println (str "cannot look up required custom modifiers on FieldBuilder" f ", skipping")) + (let [modifiers (into #{} (.GetRequiredCustomModifiers f))] + (modifiers IsVolatile)))) (defn instance-field-compiler "Symbolic bytecode for instance fields" - [{:keys [field target]} compilers] - [(compile target compilers) + [{:keys [field target] :as ast} compilers] + (println "[instance-field-compiler]" (:form ast) (:op target) (:local compilers)) + [(if (= target :deftype-this) + (il/ldarg-0) + (compile target compilers)) (when (field-volatile? field) (il/volatile)) (il/ldfld field)]) @@ -1834,17 +1839,6 @@ (il/newobj (ctors arg-count))]) (compile ast (assoc local-compilers :new (:new compilers))))) - :instance-field - (fn deftype-instance-field-compiler - [{:keys [field target] :as ast} local-compilers] - (if (fieldinfos-set field) - [(if (= target :deftype-this) - (il/ldarg-0) - (compile target local-compilers)) - (when (volatile? field) - (il/volatile)) - (il/ldfld field)] - (compile ast compilers))) :local (fn deftype-local-compiler [{:keys [local name] :as ast} inner-compilers]