Clean up macros
This commit is contained in:
parent
3f5c2fd8a7
commit
7820d5529b
@ -1,13 +1,22 @@
|
||||
(ns propeller.push.utils.macros
|
||||
(:require [propeller.push.core :as push]
|
||||
[propeller.push.state :as state]
|
||||
[propeller.push.utils.helpers :refer [get-vector-literal-type]]))
|
||||
|
||||
;; Defines a Push instruction as a keyword-function pair, and adds it to the
|
||||
;; instruction table
|
||||
(defmacro def-instruction
|
||||
[instruction definition]
|
||||
`(swap! push/instruction-table assoc '~instruction ~definition))
|
||||
`(swap! push/instruction-table assoc ~instruction ~definition))
|
||||
|
||||
;; Given a generic function, e.g. _dup, and a stack type to instantiate it for,
|
||||
;; e.g. :char, returns the appropriate stack metadata for that function instance
|
||||
(defmacro make-metadata
|
||||
[function stack]
|
||||
`(->> (:stacks (meta ~function))
|
||||
(replace {:elem (get-vector-literal-type ~stack)})
|
||||
(cons ~stack)
|
||||
set
|
||||
(assoc-in (meta ~function) [:stacks])))
|
||||
|
||||
;; Given a sequence of stacks, e.g. [:float :integer], and a sequence of suffix
|
||||
;; function strings, e.g. [_add, _mult, _eq], automates the generation of all
|
||||
@ -17,15 +26,10 @@
|
||||
;; instructions, the placeholder :elem will be replaced with the stack of the
|
||||
;; corresponding element type (e.g. for :vector_integer, with :integer)
|
||||
(defmacro generate-instructions [stacks functions]
|
||||
`(do ~@(for [stack stacks
|
||||
`(do
|
||||
~@(for [stack stacks
|
||||
func functions
|
||||
:let [instruction-name (keyword (str (name stack) func))
|
||||
old-stack-data `(:stacks (meta ~func))
|
||||
vec-stack-data `(set
|
||||
(replace
|
||||
{:elem (get-vector-literal-type ~stack)}
|
||||
~old-stack-data))
|
||||
new-stack-data `(conj ~vec-stack-data ~stack)
|
||||
metadata `(assoc-in (meta ~func) [:stacks] ~new-stack-data)
|
||||
metadata (make-metadata func stack)
|
||||
new-func `(with-meta (partial ~func ~stack) ~metadata)]]
|
||||
`(def-instruction ~instruction-name ~new-func))))
|
||||
|
Loading…
x
Reference in New Issue
Block a user