Changed all macros to functions.

This commit is contained in:
Tom Helmuth 2021-11-02 10:35:34 -04:00
parent fcb8bd398b
commit 9507eca041

View File

@ -2,34 +2,36 @@
(:require [propeller.push.core :as push] (:require [propeller.push.core :as push]
[propeller.push.utils.helpers :refer [get-vector-literal-type]])) [propeller.push.utils.helpers :refer [get-vector-literal-type]]))
;; Defines a Push instruction as a keyword-function pair, and adds it to the (defn def-instruction
;; instruction table "Defines a Push instruction as a keyword-function pair, and adds it to the
(defmacro def-instruction instruction table"
[instruction definition] [instruction function]
`(swap! push/instruction-table assoc ~instruction ~definition)) (swap! push/instruction-table assoc instruction function))
;; Given a generic function, e.g. _dup, and a stack type to instantiate it for, (defn make-metadata
;; e.g. :char, returns the appropriate stack metadata for that function instance "Given a generic function, e.g. _dup, and a stack type to instantiate it for,
(defmacro make-metadata e.g. :char, returns the appropriate stack metadata for that function instance"
[function stack] [function stack]
`(->> (:stacks (meta ~function)) (->> (:stacks (meta function))
(replace {:elem (get-vector-literal-type ~stack)}) (replace {:elem (get-vector-literal-type stack)})
(cons ~stack) (cons stack)
set set
(assoc-in (meta ~function) [:stacks]) (assoc-in (meta function) [:stacks])
(#(dissoc % :name)))) (#(dissoc % :name))))
;; Given a sequence of stacks, e.g. [:float :integer], and a sequence of suffix (defn generate-instructions
;; function strings, e.g. [_add, _mult, _eq], automates the generation of all "Given a sequence of stacks, e.g. [:float :integer], and a sequence of suffix
;; possible combination instructions, which here would be :float_add, :float_mult, function strings, e.g. [_add, _mult, _eq], automates the generation of all
;; :float_eq, :integer_add, :integer_mult, and :integer_eq, also transferring possible combination instructions, which here would be :float_add, :float_mult,
;; and updating the generic function's stack-type metadata. For some vector :float_eq, :integer_add, :integer_mult, and :integer_eq, also transferring
;; instructions, the placeholder :elem will be replaced with the stack of the and updating the generic function's stack-type metadata. For some vector
;; corresponding element type (e.g. for :vector_integer, with :integer) instructions, the placeholder :elem will be replaced with the stack of the
(defmacro generate-instructions [stacks functions] corresponding element type (e.g. for :vector_integer, with :integer)"
`(doseq [stack# ~stacks [stacks functions]
func# ~functions (doseq [stack stacks
:let [instruction-name# (keyword (str (name stack#) (:name (meta func#)))) func functions]
metadata# (make-metadata func# stack#) (let [instruction-name (keyword (str (name stack) (:name (meta func))))
new-func# (with-meta (partial func# stack#) metadata#)]] metadata (make-metadata func stack)
(def-instruction instruction-name# new-func#))) new-func (with-meta (partial func stack) metadata)]
(println [instruction-name new-func (meta new-func)])
(def-instruction instruction-name new-func))))