(defrecord RawCode [ast locals]
IInstruction
(reads-from [this]
(keep (or locals #{})
(map :name (-> ast :env :locals vals))))
(writes-to [this] [(:id this)])
(block-references [this] [])
IEmittableInstruction
(emit-instruction [this state-sym]
(if (not-empty (reads-from this))
`[~@(->> (-> ast :env :locals vals)
(map #(select-keys % [:op :name :form]))
(filter (fn [local]
(when locals
(get locals (:name local)))))
set
(mapcat
(fn [local]
`[~(:form local) ~(get locals (:name local))])))
~(:id this) ~(:form ast)]
`[~(:id this) ~(:form ast)])))