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 (ns propeller.genome
(:require [propeller.push.core :as push] (:require [propeller.push.instructions :as instructions]
[propeller.utils :as utils])) [propeller.utils :as utils]))
(defn make-random-plushy (defn make-random-plushy
@ -16,7 +16,7 @@
(let [plushy (if (:diploid argmap) (map first (partition 2 plushy)) plushy) (let [plushy (if (:diploid argmap) (map first (partition 2 plushy)) plushy)
opener? #(and (vector? %) (= (first %) 'open))] ;; [open <n>] marks opens opener? #(and (vector? %) (= (first %) 'open))] ;; [open <n>] marks opens
(loop [push () ;; iteratively build the Push program from the plushy (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 (empty? plushy) ;; maybe we're done?
(if (some opener? push) ;; done with plushy, but unclosed open (if (some opener? push) ;; done with plushy, but unclosed open
(recur push '(close)) ;; recur with one more close (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 ;; 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 ;; can be either constant literals or functions that take and return a Push state

View File

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

View File

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

View File

@ -1,12 +1,12 @@
(ns propeller.push.utils.macros (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]])) [propeller.push.utils.helpers :refer [get-vector-literal-type]]))
(defn def-instruction (defn def-instruction
"Defines a Push instruction as a keyword-function pair, and adds it to the "Defines a Push instruction as a keyword-function pair, and adds it to the
instruction table" instruction table"
[instruction function] [instruction function]
(swap! push/instruction-table assoc instruction function)) (swap! instructions/instruction-table assoc instruction function))
(defn make-metadata (defn make-metadata
"Given a generic function, e.g. _dup, and a stack type to instantiate it for, "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.variation :as variation]
[propeller.problems.simple-regression :as regression] [propeller.problems.simple-regression :as regression]
[propeller.problems.string-classification :as string-classif] [propeller.problems.string-classification :as string-classif]
[propeller.push.core :as push] [propeller.push.instructions :as instructions]
[propeller.push.interpreter :as interpreter] [propeller.push.interpreter :as interpreter]
[propeller.push.state :as state] [propeller.push.state :as state]
[propeller.push.utils.helpers :refer [get-stack-instructions]])) [propeller.push.utils.helpers :refer [get-stack-instructions]]))