]> gitweb.factorcode.org Git - factor.git/commitdiff
using if-zero in even more places.
authorJohn Benediktsson <mrjbq7@gmail.com>
Tue, 17 Jul 2012 02:38:49 +0000 (19:38 -0700)
committerJohn Benediktsson <mrjbq7@gmail.com>
Tue, 17 Jul 2012 02:38:49 +0000 (19:38 -0700)
basis/cpu/x86/x86.factor
basis/io/directories/unix/unix.factor
basis/io/launcher/launcher.factor
extra/io/binary/fast/fast.factor
extra/math/text/english/english.factor

index b304a01de856503fb712496f71085057894456a3..292556be9c199a66572022caaf554a79663c6ae4 100644 (file)
@@ -38,10 +38,10 @@ HOOK: reserved-stack-space cpu ( -- n )
 : spill@ ( n -- op ) spill-offset special-offset stack@ ;
 
 : decr-stack-reg ( n -- )
-    dup 0 = [ drop ] [ stack-reg swap SUB ] if ;
+    [ stack-reg swap SUB ] unless-zero ;
 
 : incr-stack-reg ( n -- )
-    dup 0 = [ drop ] [ stack-reg swap ADD ] if ;
+    [ stack-reg swap ADD ] unless-zero ;
 
 : align-stack ( n -- n' ) 16 align ;
 
@@ -61,7 +61,7 @@ M: x86 test-instruction? t ;
 
 M: x86 immediate-store? immediate-comparand? ;
 
-M: x86 %load-immediate dup 0 = [ drop dup XOR ] [ MOV ] if ;
+M: x86 %load-immediate [ dup XOR ] [ MOV ] if-zero ;
 
 M: x86 %load-reference
     [ swap 0 MOV rc-absolute-cell rel-literal ]
index cae5d1fa75a274c8a6b09c8ae5d9731c274486ca..93dcdebdde7902e13fb66a153dacbf43e3c06eae 100644 (file)
@@ -1,7 +1,7 @@
 ! Copyright (C) 2008 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: accessors alien.c-types alien.data alien.strings
-combinators continuations destructors fry io io.backend
+assocs combinators continuations destructors fry io io.backend
 io.directories io.encodings.binary io.files.info.unix
 io.encodings.utf8 io.files io.pathnames io.files.types kernel
 math.bitwise sequences system unix unix.stat vocabs.loader
@@ -31,7 +31,7 @@ M: unix delete-directory ( path -- )
 
 M: unix copy-file ( from to -- )
     [ normalize-path ] bi@
-    [ call-next-method ] 
+    [ call-next-method ]
     [ [ file-permissions ] dip swap set-file-permissions ] 2bi ;
 
 : with-unix-directory ( path quot -- )
@@ -48,17 +48,16 @@ M: unix find-next-file ( DIR* -- byte-array )
     void* deref [ drop f ] unless ;
 
 : dirent-type>file-type ( ch -- type )
-    {
-        { DT_BLK  [ +block-device+ ] }
-        { DT_CHR  [ +character-device+ ] }
-        { DT_DIR  [ +directory+ ] }
-        { DT_LNK  [ +symbolic-link+ ] }
-        { DT_SOCK [ +socket+ ] }
-        { DT_FIFO [ +fifo+ ] }
-        { DT_REG  [ +regular-file+ ] }
-        { DT_WHT  [ +whiteout+ ] }
-        [ drop +unknown+ ]
-    } case ;
+    H{
+        { $ DT_BLK   +block-device+ }
+        { $ DT_CHR  +character-device+ }
+        { $ DT_DIR  +directory+ }
+        { $ DT_LNK  +symbolic-link+ }
+        { $ DT_SOCK +socket+ }
+        { $ DT_FIFO +fifo+ }
+        { $ DT_REG  +regular-file+ }
+        { $ DT_WHT  +whiteout+ }
+    } at* [ drop +unknown+ ] unless ;
 
 M: unix >directory-entry ( byte-array -- directory-entry )
     {
index ec715944f49991809b8abe0e2a5088651b827bdd..06cd72b23ae033edf450495fac16d7317f86a152 100755 (executable)
@@ -159,8 +159,7 @@ M: process-failed error.
     ] [ process>> . ] bi ;
 
 : wait-for-success ( process -- )
-    dup wait-for-process 0 =
-    [ drop ] [ process-failed ] if ;
+    dup wait-for-process [ drop ] [ process-failed ] if-zero ;
 
 : try-process ( desc -- )
     run-process wait-for-success ;
index 47f326f4e0400f8781f123099d100fab356c8f87..07ab1766d459c26417ea8040d42f6e160adfc44d 100644 (file)
@@ -18,7 +18,7 @@ ERROR: bad-length bytes n ;
     1 - 8 * 0 swap 8 <range> ; inline
 
 : reassemble-bytes ( range -- quot )
-    [ dup 0 = [ drop [ ] ] [ '[ _ shift ] ] if ] map
+    [ [ [ ] ] [ '[ _ shift ] ] if-zero ] map
     '[ [ _ spread ] [ bitor ] reduce-outputs ] ; inline
 
 MACRO: reassemble-be ( n -- quot ) be-range reassemble-bytes ;
index 5b2af13489fd7286b01e658fb5edbf59729904fb..6ed17354a44f1e2f0844e1c0b9dce44100dc4627 100644 (file)
@@ -19,7 +19,7 @@ IN: math.text.english
         f f "twenty" "thirty" "forty" "fifty" "sixty"
         "seventy" "eighty" "ninety"
     } nth ;
-    
+
 : scale-numbers ( n -- str )  ! up to 10^99
     {
         f "thousand" "million" "billion" "trillion" "quadrillion"
@@ -51,9 +51,9 @@ SYMBOL: and-needed?
 : tens-place ( n -- str )
     100 mod dup 20 >= [
         10 /mod [ tens ] dip
-        dup 0 = [ drop ] [ small-numbers "-" glue ] if
+        [ small-numbers "-" glue ] unless-zero
     ] [
-        dup 0 = [ drop "" ] [ small-numbers ] if
+        [ "" ] [ small-numbers ] if-zero
     ] if ;
 
 : 3digits>text ( n -- str )