Remove symbols from instruction names, and use 1 instead of NOOP for division

This commit is contained in:
mcgirjau 2020-06-25 09:40:29 -04:00
parent f04804b00b
commit 9e0a8d51b7
3 changed files with 22 additions and 32 deletions

View File

@ -16,18 +16,18 @@
;; Set of original propel instructions ;; Set of original propel instructions
(def default-instructions (def default-instructions
(list :in1 (list :in1
:integer_+ :integer_add
:integer_- :integer_subtract
:integer_* :integer_mult
:integer_% :integer_quot
:integer_= :integer_eq
:exec_dup :exec_dup
:exec_if :exec_if
:boolean_and :boolean_and
:boolean_or :boolean_or
:boolean_not :boolean_not
:boolean_= :boolean_eq
:string_= :string_eq
:string_take :string_take
:string_drop :string_drop
:string_reverse :string_reverse

View File

@ -10,67 +10,57 @@
;; Pushes TRUE onto the BOOLEAN stack if the second item is greater than the top ;; Pushes TRUE onto the BOOLEAN stack if the second item is greater than the top
;; item, and FALSE otherwise ;; item, and FALSE otherwise
(defn- _> (defn- _gt
[stack state] [stack state]
(make-instruction state > [stack stack] :boolean)) (make-instruction state > [stack stack] :boolean))
;; Pushes TRUE onto the BOOLEAN stack if the second item is greater than or ;; Pushes TRUE onto the BOOLEAN stack if the second item is greater than or
;; equal to the top item, and FALSE otherwise ;; equal to the top item, and FALSE otherwise
(defn- _>= (defn- _gte
[stack state] [stack state]
(make-instruction state >= [stack stack] :boolean)) (make-instruction state >= [stack stack] :boolean))
;; Pushes TRUE onto the BOOLEAN stack if the second item is less than the top ;; Pushes TRUE onto the BOOLEAN stack if the second item is less than the top
;; item, and FALSE otherwise ;; item, and FALSE otherwise
(defn- _< (defn- _lt
[stack state] [stack state]
(make-instruction state < [stack stack] :boolean)) (make-instruction state < [stack stack] :boolean))
;; Pushes TRUE onto the BOOLEAN stack if the second item is less than or equal ;; Pushes TRUE onto the BOOLEAN stack if the second item is less than or equal
;; to the top item, and FALSE otherwise ;; to the top item, and FALSE otherwise
(defn- _<= (defn- _lte
[stack state] [stack state]
(make-instruction state <= [stack stack] :boolean)) (make-instruction state <= [stack stack] :boolean))
;; Pushes the sum of the top two items onto the same stack ;; Pushes the sum of the top two items onto the same stack
(defn- _+ (defn- _add
[stack state] [stack state]
(make-instruction state +' [stack stack] stack)) (make-instruction state +' [stack stack] stack))
;; Pushes the difference of the top two items (i.e. the second item minus the ;; Pushes the difference of the top two items (i.e. the second item minus the
;; top item) onto the same stack ;; top item) onto the same stack
(defn- _- (defn- _subtract
[stack state] [stack state]
(make-instruction state -' [stack stack] stack)) (make-instruction state -' [stack stack] stack))
;; Pushes the product of the top two items onto the same stack ;; Pushes the product of the top two items onto the same stack
(defn- _* (defn- _mult
[stack state] [stack state]
(make-instruction state *' [stack stack] stack)) (make-instruction state *' [stack stack] stack))
;; Pushes the quotient of the top two items (i.e. the second item divided by the ;; 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 (defn- _quot
[stack state] [stack state]
(make-instruction state (make-instruction state #(if (zero? %2) 1 (quot %1 %2)) [stack stack] stack))
#(if (zero? %2)
(list %1 %2) ; push both items back (NOOP)
(quot %1 %2))
[stack stack]
stack))
;; Pushes the second item modulo the top item onto the same stack. If the top ;; 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 ;; quotient, where the quotient has first been truncated towards negative
;; infinity. ;; infinity.
(defn- _% (defn- _mod
[stack state] [stack state]
(make-instruction state (make-instruction state #(if (zero? %2) 1 (mod %1 %2)) [stack stack] stack))
#(if (zero? %2)
(list %1 %2) ; push both items back (NOOP)
(mod %1 %2))
[stack stack]
stack))
;; Pushes the maximum of the top two items ;; Pushes the maximum of the top two items
(defn- _max (defn- _max
@ -118,7 +108,7 @@
;; 2 types x 16 functions = 32 instructions ;; 2 types x 16 functions = 32 instructions
(generate-functions (generate-functions
[:float :integer] [:float :integer]
[_> _>= _< _<= _+ _- _* _quot _% _max _min _inc _dec [_gt _gte _lt _lte _add _subtract _mult _quot _mod _max _min _inc _dec
_fromboolean _fromchar _fromstring]) _fromboolean _fromchar _fromstring])
;; ============================================================================= ;; =============================================================================

View File

@ -16,7 +16,7 @@
;; Pushes TRUE onto the BOOLEAN stack if the top two items are equal. ;; Pushes TRUE onto the BOOLEAN stack if the top two items are equal.
;; Otherwise FALSE ;; Otherwise FALSE
(defn- _= (defn- _eq
[stack state] [stack state]
(make-instruction state = [stack stack] :boolean)) (make-instruction state = [stack stack] :boolean))
@ -101,7 +101,7 @@
()) ())
;; 5 types x 1 function = 5 instructions ;; 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 ;; 8 types x 12 function = 96 instructions
(generate-functions (generate-functions