]> gitweb.factorcode.org Git - factor.git/blobdiff - basis/shuffle/shuffle.factor
shuffle( -- ) arbitrary stack shuffling word
[factor.git] / basis / shuffle / shuffle.factor
index b195e4abf903bd261d199d61741af8a4577cc9b7..632c09e33840273757d688ca2c2ed620777b284f 100644 (file)
@@ -1,9 +1,28 @@
 ! Copyright (C) 2007 Chris Double, Doug Coleman.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: kernel generalizations ;
-
+USING: accessors assocs effects.parser generalizations
+hashtables kernel locals locals.backend macros make math
+parser sequences ;
 IN: shuffle
 
+<PRIVATE
+
+: >locals-assoc ( sequence -- assoc )
+    dup length dup 1- [ - ] curry map zip >hashtable ;
+
+PRIVATE>
+
+MACRO: shuffle-effect ( effect -- )
+    [ out>> ] [ in>> >locals-assoc ] bi
+    [
+        [ nip assoc-size , \ load-locals , ]
+        [ [ at , \ get-local , ] curry each ]
+        [ nip assoc-size , \ drop-locals , ] 2tri
+    ] [ ] make ;
+
+: shuffle(
+    ")" parse-effect parsed \ shuffle-effect parsed ; parsing
+
 : 2swap ( x y z t -- z t x y ) 2 2 mnswap ; inline
 
 : nipd ( a b c -- b c ) rot drop ; inline