Skip to content

Commit

Permalink
Refactor instance field compilation
Browse files Browse the repository at this point in the history
Avoids deftype/closure problems but will not emit volatile. anymore.
Tracked in #191.
  • Loading branch information
nasser committed Jul 28, 2020
1 parent dc0e495 commit 5be1b52
Showing 1 changed file with 9 additions and 15 deletions.
24 changes: 9 additions & 15 deletions src/magic/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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)])
Expand Down Expand Up @@ -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]
Expand Down

0 comments on commit 5be1b52

Please sign in to comment.