From 9e0a8d51b780b1b10e63095db38cde20a6d30d69 Mon Sep 17 00:00:00 2001 From: mcgirjau Date: Thu, 25 Jun 2020 09:40:29 -0400 Subject: [PATCH] Remove symbols from instruction names, and use 1 instead of NOOP for division --- src/propeller/push/core.clj | 14 ++++---- src/propeller/push/instructions/numeric.clj | 36 +++++++------------ .../push/instructions/polymorphic.clj | 4 +-- 3 files changed, 22 insertions(+), 32 deletions(-) diff --git a/src/propeller/push/core.clj b/src/propeller/push/core.clj index aad92c2..c0b54d2 100644 --- a/src/propeller/push/core.clj +++ b/src/propeller/push/core.clj @@ -16,18 +16,18 @@ ;; Set of original propel instructions (def default-instructions (list :in1 - :integer_+ - :integer_- - :integer_* - :integer_% - :integer_= + :integer_add + :integer_subtract + :integer_mult + :integer_quot + :integer_eq :exec_dup :exec_if :boolean_and :boolean_or :boolean_not - :boolean_= - :string_= + :boolean_eq + :string_eq :string_take :string_drop :string_reverse diff --git a/src/propeller/push/instructions/numeric.clj b/src/propeller/push/instructions/numeric.clj index cd7db7c..6610487 100644 --- a/src/propeller/push/instructions/numeric.clj +++ b/src/propeller/push/instructions/numeric.clj @@ -10,67 +10,57 @@ ;; Pushes TRUE onto the BOOLEAN stack if the second item is greater than the top ;; item, and FALSE otherwise -(defn- _> +(defn- _gt [stack state] (make-instruction state > [stack stack] :boolean)) ;; Pushes TRUE onto the BOOLEAN stack if the second item is greater than or ;; equal to the top item, and FALSE otherwise -(defn- _>= +(defn- _gte [stack state] (make-instruction state >= [stack stack] :boolean)) ;; Pushes TRUE onto the BOOLEAN stack if the second item is less than the top ;; item, and FALSE otherwise -(defn- _< +(defn- _lt [stack state] (make-instruction state < [stack stack] :boolean)) ;; Pushes TRUE onto the BOOLEAN stack if the second item is less than or equal ;; to the top item, and FALSE otherwise -(defn- _<= +(defn- _lte [stack state] (make-instruction state <= [stack stack] :boolean)) ;; Pushes the sum of the top two items onto the same stack -(defn- _+ +(defn- _add [stack state] (make-instruction state +' [stack stack] stack)) ;; Pushes the difference of the top two items (i.e. the second item minus the ;; top item) onto the same stack -(defn- _- +(defn- _subtract [stack state] (make-instruction state -' [stack stack] stack)) ;; Pushes the product of the top two items onto the same stack -(defn- _* +(defn- _mult [stack state] (make-instruction state *' [stack stack] stack)) ;; Pushes the quotient of the top two items (i.e. the second item divided by the -;; top item) onto the same stack. If the top item is zero, acts as a NOOP +;; top item) onto the same stack. If the top item is zero, pushes 1 (defn- _quot [stack state] - (make-instruction state - #(if (zero? %2) - (list %1 %2) ; push both items back (NOOP) - (quot %1 %2)) - [stack stack] - stack)) + (make-instruction state #(if (zero? %2) 1 (quot %1 %2)) [stack stack] stack)) ;; Pushes the second item modulo the top item onto the same stack. If the top -;; item is zero, acts as a NOOP. The modulus is computed as the remainder of the +;; item is zero, pushes 1. The modulus is computed as the remainder of the ;; quotient, where the quotient has first been truncated towards negative ;; infinity. -(defn- _% +(defn- _mod [stack state] - (make-instruction state - #(if (zero? %2) - (list %1 %2) ; push both items back (NOOP) - (mod %1 %2)) - [stack stack] - stack)) + (make-instruction state #(if (zero? %2) 1 (mod %1 %2)) [stack stack] stack)) ;; Pushes the maximum of the top two items (defn- _max @@ -118,7 +108,7 @@ ;; 2 types x 16 functions = 32 instructions (generate-functions [:float :integer] - [_> _>= _< _<= _+ _- _* _quot _% _max _min _inc _dec + [_gt _gte _lt _lte _add _subtract _mult _quot _mod _max _min _inc _dec _fromboolean _fromchar _fromstring]) ;; ============================================================================= diff --git a/src/propeller/push/instructions/polymorphic.clj b/src/propeller/push/instructions/polymorphic.clj index 999a315..b19d5b0 100644 --- a/src/propeller/push/instructions/polymorphic.clj +++ b/src/propeller/push/instructions/polymorphic.clj @@ -16,7 +16,7 @@ ;; Pushes TRUE onto the BOOLEAN stack if the top two items are equal. ;; Otherwise FALSE -(defn- _= +(defn- _eq [stack state] (make-instruction state = [stack stack] :boolean)) @@ -101,7 +101,7 @@ ()) ;; 5 types x 1 function = 5 instructions -(generate-functions [:boolean :char :float :integer :string] [_=]) +(generate-functions [:boolean :char :float :integer :string] [_eq]) ;; 8 types x 12 function = 96 instructions (generate-functions