Skip to content

Commit

Permalink
added :vector-refilter and :vector-refilterall
Browse files Browse the repository at this point in the history
  • Loading branch information
Vaguery committed Nov 27, 2015
1 parent 9ec8b5e commit bc00115
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/push/types/extra/vector.clj
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,26 @@



(def vector-refilter
(core/build-instruction
vector-refilter
"`:vector-refilter` pops the top `:vector` value, and sends it to the `:exec` stack"
:tags #{:conversion :vector}
(d/consume-top-of :vector :as :arg)
(d/push-onto :exec :arg)))


(def vector-refilterall
(core/build-instruction
vector-refilterall
"`:vector-refilterall` puts the entire `:vector` stack on top of the `:exec` stack"
:tags #{:conversion :vector}
(d/consume-stack :vector :as :stack)
(d/consume-stack :exec :as :old-exec)
(d/calculate [:stack :old-exec]
#(into '() (reverse (concat %1 %2))) :as :new-exec)
(d/replace-stack :exec :new-exec)))


(def standard-vector-type
"builds the basic `:vector` type, which can hold arbitrary and mixed contents"
Expand All @@ -25,6 +45,8 @@
make-movable
make-printable
make-returnable
(t/attach-instruction , vector-refilter)
(t/attach-instruction , vector-refilterall)
(t/attach-instruction , (v/x-butlast-instruction typename))
(t/attach-instruction , (v/x-concat-instruction typename))
(t/attach-instruction , (v/x-conj-instruction typename componentname))
Expand Down
48 changes: 48 additions & 0 deletions test/push/instructions/standard/vector_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,54 @@
)


(tabular
(fact "`vector-refilter` pushes the first :vector onto :exec"
(check-instruction-with-all-kinds-of-stack-stuff
?new-stacks standard-vector-type ?instruction) =>
(contains ?expected))

?new-stacks ?instruction ?expected

{:vector '([1 2 3])
:exec '()} :vector-refilter {:vector '()
:exec '([1 2 3])}
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
{:vector '([1 2 3] [4 5])
:exec '(6)} :vector-refilter {:vector '([4 5])
:exec '([1 2 3] 6)}
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
{:vector '()
:exec '(9 99)} :vector-refilter {:vector '()
:exec '(9 99)}
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
)


(tabular
(fact "`vector-refilterall` pushes the entire :vector stack onto :exec"
(check-instruction-with-all-kinds-of-stack-stuff
?new-stacks standard-vector-type ?instruction) =>
(contains ?expected))

?new-stacks ?instruction ?expected

{:vector '([1 2 3] [4 5])
:exec '(6 7 8)} :vector-refilterall {:vector '()
:exec '([1 2 3]
[4 5] 6 7 8)}
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
{:vector '([])
:exec '(6 7 8)} :vector-refilterall {:vector '()
:exec '([] 6 7 8)}
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
{:vector '()
:exec '(6 7 8)} :vector-refilterall {:vector '()
:exec '(6 7 8)}
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
)



(tabular
(fact "`vector-shatter` pushes the items from the first :vector onto :code"
(check-instruction-with-all-kinds-of-stack-stuff
Expand Down
2 changes: 2 additions & 0 deletions test/push/instructions/standard/vectorized_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,8 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
)



(tabular
(fact "`foos-indexof` pushes an :integer indicating where :foo is in :foos (or -1)"
(check-instruction-with-all-kinds-of-stack-stuff
Expand Down

0 comments on commit bc00115

Please sign in to comment.