Moved push/core.cljc to push/instructions.cljc

This commit is contained in:
Tom Helmuth 2021-11-02 11:18:29 -04:00
parent 6b39e078ee
commit a42d23bf7a
6 changed files with 11 additions and 11 deletions

View File

@ -1,5 +1,5 @@
(ns propeller.genome
(:require [propeller.push.core :as push]
(:require [propeller.push.instructions :as instructions]
[propeller.utils :as utils]))
(defn make-random-plushy
@ -16,7 +16,7 @@
(let [plushy (if (:diploid argmap) (map first (partition 2 plushy)) plushy)
opener? #(and (vector? %) (= (first %) 'open))] ;; [open <n>] marks opens
(loop [push () ;; iteratively build the Push program from the plushy
plushy (mapcat #(if-let [n (get push/opens %)] [% ['open n]] [%]) plushy)]
plushy (mapcat #(if-let [n (get instructions/opens %)] [% ['open n]] [%]) plushy)]
(if (empty? plushy) ;; maybe we're done?
(if (some opener? push) ;; done with plushy, but unclosed open
(recur push '(close)) ;; recur with one more close

View File

@ -1,4 +1,4 @@
(ns propeller.push.core)
(ns propeller.push.instructions)
;; PushGP instructions are represented as keywords, and stored in an atom. They
;; can be either constant literals or functions that take and return a Push state

View File

@ -1,5 +1,5 @@
(ns propeller.push.interpreter
(:require [propeller.push.core :as push]
(:require [propeller.push.instructions :as instructions]
[propeller.push.state :as state]
[propeller.push.instructions.input-output :as io]
[propeller.push.utils.helpers :refer [get-literal-type]]))
@ -14,7 +14,7 @@
;;
;; Recognize functional instruction or input instruction
(keyword? instruction)
(if-let [function (instruction @push/instruction-table)]
(if-let [function (instruction @instructions/instruction-table)]
(function popped-state)
(io/handle-input-instruction popped-state instruction))
;;

View File

@ -1,6 +1,6 @@
(ns propeller.push.utils.helpers
(:require [clojure.set]
[propeller.push.core :as push]
[propeller.push.instructions :as instructions]
[propeller.push.state :as state]
[propeller.utils :as u]
#?(:cljs [goog.string :as gstring])
@ -29,7 +29,7 @@
;; only. Won't include random instructions unless :random is in the set as well
(defn get-stack-instructions
[stacks]
(doseq [[instruction-name function] @push/instruction-table]
(doseq [[instruction-name function] @instructions/instruction-table]
(assert
(:stacks (meta function))
#?(:clj (format
@ -38,7 +38,7 @@
:cljs (gstring/format
"ERROR: Instruction %s does not have :stacks defined in metadata."
(name instruction-name)))))
(for [[instruction-name function] @push/instruction-table
(for [[instruction-name function] @instructions/instruction-table
:when (clojure.set/subset? (:stacks (meta function)) stacks)]
instruction-name))

View File

@ -1,12 +1,12 @@
(ns propeller.push.utils.macros
(:require [propeller.push.core :as push]
(:require [propeller.push.instructions :as instructions]
[propeller.push.utils.helpers :refer [get-vector-literal-type]]))
(defn def-instruction
"Defines a Push instruction as a keyword-function pair, and adds it to the
instruction table"
[instruction function]
(swap! push/instruction-table assoc instruction function))
(swap! instructions/instruction-table assoc instruction function))
(defn make-metadata
"Given a generic function, e.g. _dup, and a stack type to instantiate it for,

View File

@ -5,7 +5,7 @@
[propeller.variation :as variation]
[propeller.problems.simple-regression :as regression]
[propeller.problems.string-classification :as string-classif]
[propeller.push.core :as push]
[propeller.push.instructions :as instructions]
[propeller.push.interpreter :as interpreter]
[propeller.push.state :as state]
[propeller.push.utils.helpers :refer [get-stack-instructions]]))