From 66856cf99f3b8c2cb5331acd944eb609d58477fa Mon Sep 17 00:00:00 2001 From: mcgirjau Date: Fri, 26 Jun 2020 10:34:04 -0400 Subject: [PATCH] Remove some stacks --- .../push/instructions/polymorphic.clj | 2 +- src/propeller/push/state.clj | 48 +++++++------------ src/propeller/push/utils.clj | 2 +- 3 files changed, 20 insertions(+), 32 deletions(-) diff --git a/src/propeller/push/instructions/polymorphic.clj b/src/propeller/push/instructions/polymorphic.clj index 4cad5bc..0fd207b 100644 --- a/src/propeller/push/instructions/polymorphic.clj +++ b/src/propeller/push/instructions/polymorphic.clj @@ -100,7 +100,7 @@ ;; 5 types x 1 function = 5 instructions (generate-functions [:boolean :char :float :integer :string] [_eq]) -;; 8 types x 12 function = 96 instructions +;; 7 types x 12 function = 84 instructions (generate-functions [:boolean :char :code :exec :float :integer :string] [_dup _duptimes _dupitems _empty _flush _pop _rot _shove _stackdepth diff --git a/src/propeller/push/state.clj b/src/propeller/push/state.clj index f1849c4..95876cf 100644 --- a/src/propeller/push/state.clj +++ b/src/propeller/push/state.clj @@ -1,35 +1,23 @@ (ns propeller.push.state) -;; Set of all stacks used by the Push interpreter -(defonce stacks #{:auxiliary - :boolean - :char - :code - :environment - :exec - :float - :genome - :gtm - :input - :integer - :output - :return - :string - :tag - :vector_boolean - :vector_float - :vector_integer - :vector_string - :zip}) - -;; Record-based states for performance -(defmacro define-push-state [] - `(defrecord ~'State [~@(map #(symbol (name %)) stacks)])) - -(define-push-state) - -;; Empty push state - each stack type is nil -(defonce empty-state (map->State {})) +;; Empty push state - all available stacks are empty +(defonce empty-state {:auxiliary '() + :boolean '() + :char '() + :code '() + :environment '() + :exec '() + :float '() + :genome '() + :input {} + :integer '() + :return '() + :string '() + :tag '() + :vector_boolean '() + :vector_float '() + :vector_integer '() + :vector_string '()}) (def example-push-state {:exec '() diff --git a/src/propeller/push/utils.clj b/src/propeller/push/utils.clj index 78ae855..edc378a 100644 --- a/src/propeller/push/utils.clj +++ b/src/propeller/push/utils.clj @@ -32,7 +32,7 @@ ;; Pretty-prints a Push state, for logging or debugging purposes (defn print-state [state] - (doseq [stack state/stacks] + (doseq [stack (keys state/empty-state)] (printf "%-15s = " stack) (prn (if (get state stack) (get state stack) '())) (flush)))