]> gitweb.factorcode.org Git - factor.git/commitdiff
huge code cleanup
authorSlava Pestov <slava@factorcode.org>
Sun, 19 Dec 2004 08:04:03 +0000 (08:04 +0000)
committerSlava Pestov <slava@factorcode.org>
Sun, 19 Dec 2004 08:04:03 +0000 (08:04 +0000)
23 files changed:
TODO.FACTOR.txt
examples/timesheet.factor
library/bootstrap/boot-stage2.factor
library/bootstrap/image.factor
library/cli.factor
library/format.factor [deleted file]
library/generic/predicate.factor
library/httpd/file-responder.factor
library/httpd/html-tags.factor
library/httpd/html.factor
library/httpd/http-common.factor
library/httpd/url-encoding.factor
library/io/ansi.factor
library/sbuf.factor
library/strings.factor
library/syntax/prettyprint.factor
library/syntax/unparser.factor
library/test/format.factor [deleted file]
library/test/strings.factor
library/test/test.factor
library/tools/inspector.factor
library/tools/jedit.factor
library/tools/word-tools.factor

index 704879bc5a3af739879e6185d2a54491593aaeb8..1e54cf10d5d3bb00cd3d4e745aefac14c7a2f86c 100644 (file)
@@ -36,6 +36,7 @@
 \r
 + listener/plugin:\r
 \r
+- use decl wrong\r
 - faster completion\r
 - sidekick: still parsing too much\r
 - errors don't always disappear\r
index 3c92fce93225003641645d73bdba810f21139121..cdae6ecefd9936a1b65995b6d75a007abb1cce4c 100644 (file)
@@ -2,7 +2,6 @@
 
 IN: timesheet
 USE: errors
-USE: format
 USE: kernel
 USE: lists
 USE: math
@@ -31,7 +30,7 @@ USE: vectors
 ! Printing the timesheet.
 
 : hh ( duration -- str ) 60 /i ;
-: mm ( duration -- str ) 60 mod unparse 2 digits ;
+: mm ( duration -- str ) 60 mod unparse 2 "0" pad ;
 : hh:mm ( millis -- str ) [ dup hh , ":" , mm , ] make-list ;
 
 : print-entry ( duration description -- )
index 980f27f95ece89661a88614bddbcf31e292dc50f..14aa3b40d0c92d79967bc71b89b49f3537e71b0e 100644 (file)
@@ -74,7 +74,6 @@ USE: stdio
     "/library/syntax/parse-stream.factor"\r
     "/library/bootstrap/init.factor"\r
 \r
-    "/library/format.factor"\r
     "/library/syntax/unparser.factor"\r
     "/library/io/presentation.factor"\r
     "/library/io/vocabulary-style.factor"\r
index 857338c7d18811cbfca54db17d83879f2a16da98..36cf969e36290bace2a161386ce8625d85c9b939 100644 (file)
@@ -137,7 +137,7 @@ GENERIC: ' ( obj -- ptr )
 : here-as ( tag -- pointer )
     here swap bitor ;
 
-: pad ( -- )
+: align-here ( -- )
     here 8 mod 4 = [ 0 emit ] when ;
 
 ( Remember what objects we've compiled )
@@ -162,7 +162,7 @@ M: bignum ' ( bignum -- tagged )
         [ 0  | [ 1 0   ] ]
         [ -1 | [ 2 1 1 ] ]
         [ 1  | [ 2 0 1 ] ]
-    ] assoc [ emit ] each pad r> ;
+    ] assoc [ emit ] each align-here r> ;
 
 ( Special objects )
 
@@ -267,7 +267,7 @@ M: cons ' ( c -- tagged )
     dup str-length emit
     dup hashcode emit
     pack-string
-    pad ;
+    align-here ;
 
 M: string ' ( string -- pointer )
     #! We pool strings so that each string is only written once
@@ -286,7 +286,7 @@ M: string ' ( string -- pointer )
     array-type >header emit
     dup length emit
     ( elements -- ) [ emit ] each
-    pad r> ;
+    align-here r> ;
 
 M: vector ' ( vector -- pointer )
     dup vector>list emit-array swap vector-length
@@ -294,7 +294,7 @@ M: vector ' ( vector -- pointer )
     vector-type >header emit
     emit ( length )
     emit ( array ptr )
-    pad r> ;
+    align-here r> ;
 
 ( End of the image )
 
index 9165d2b142b5e3227263c49a7b8c8fabcff58f4a..8a61dc9c355a584cb0911fb42d68726329347610 100644 (file)
@@ -64,26 +64,16 @@ USE: words
     #!
     #! Arguments containing = are handled differently; they
     #! set the object path.
-    "=" split1 dup [
+    "=" split1 [
         cli-var-param
     ] [
-        drop dup "no-" str-head? dup [
-            f put drop
-        ] [
-            drop t put
-        ] ifte
-    ] ifte ;
+        "no-" ?str-head not put
+    ] ifte* ;
 
 : cli-arg ( argument -- argument )
     #! Handle a command-line argument. If the argument was
     #! consumed, returns f. Otherwise returns the argument.
-    dup f-or-"" [
-        dup "-" str-head? dup [
-            cli-param drop f
-        ] [
-            drop
-        ] ifte
-    ] unless ;
+    dup f-or-"" [ "-" ?str-head [ cli-param f ] when ] unless ;
 
 : parse-switches ( args -- args )
     [ cli-arg ] map ;
diff --git a/library/format.factor b/library/format.factor
deleted file mode 100644 (file)
index 7475325..0000000
+++ /dev/null
@@ -1,69 +0,0 @@
-! :folding=indent:collapseFolds=0:
-
-! $Id$
-!
-! Copyright (C) 2004 Slava Pestov.
-! 
-! Redistribution and use in source and binary forms, with or without
-! modification, are permitted provided that the following conditions are met:
-! 
-! 1. Redistributions of source code must retain the above copyright notice,
-!    this list of conditions and the following disclaimer.
-! 
-! 2. Redistributions in binary form must reproduce the above copyright notice,
-!    this list of conditions and the following disclaimer in the documentation
-!    and/or other materials provided with the distribution.
-! 
-! THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
-! INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
-! FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
-! DEVELOPERS AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-! SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
-! PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
-! OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-! WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
-! OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
-! ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-IN: format
-USE: kernel
-USE: math
-USE: namespaces
-USE: strings
-
-: decimal-split ( string -- string string )
-    #! Split a string before and after the decimal point.
-    dup "." index-of dup -1 = [ drop f ] [ str// ] ifte ;
-
-: decimal-tail ( count str -- string )
-    #! Given a decimal, trims all but a count of decimal places.
-    [ str-length min ] keep str-head ;
-
-: decimal-cat ( before after -- string )
-    #! If after is of zero length, return before, otherwise
-    #! return "before.after".
-    dup str-length 0 = [
-        drop
-    ] [
-        "." swap cat3
-    ] ifte ;
-
-: decimal-places ( num count -- string )
-    #! Trims the number to a count of decimal places.
-    >r decimal-split dup [
-        r> swap decimal-tail decimal-cat
-    ] [
-        r> 2drop
-    ] ifte ;
-
-: digits ( string count -- string )
-    #! Make sure string has at least count digits, padding it
-    #! with zeroes on the left if needed.
-    over str-length - dup 0 <= [
-        drop
-    ] [
-        "0" fill swap cat2
-    ] ifte ;
-
-: pad-string ( len str -- str )
-    str-length - " " fill ;
index 84694e78a0c9cb66fcdf60dcc7c02c4d1073ed70..b08d9d54d14ec1b36ce16cd42f72fb4d60d4a2ab 100644 (file)
@@ -44,7 +44,7 @@ SYMBOL: predicate
         \ dup , "predicate" word-property , , , \ ifte ,
     ] make-list ;
 
-: (predicate-method) ( vtable definition class type# -- )
+: predicate-method ( vtable definition class type# -- )
     >r rot r> swap [
         vector-nth
         ( vtable definition class existing )
@@ -59,7 +59,7 @@ predicate [
     ( vtable definition class -- )
     dup builtin-supertypes [
         ( vtable definition class type# )
-        >r 3dup r> (predicate-method)
+        >r 3dup r> predicate-method
     ] each 3drop
 ] "add-method" set-word-property
 
index 092c84cf096e6240b245e305d1be2b5a5d9f8816..ea4d8c45b36f953879150d571600226ddd7a3419 100644 (file)
@@ -42,7 +42,7 @@ USE: strings
 USE: unparser
 
 : serving-path ( filename -- filename )
-    f>"" "doc-root" get swap cat2 ;
+    [ "" ] unless* "doc-root" get swap cat2 ;
 
 : file-response ( mime-type length -- )
     [
index 31f80e43786821a7b7d8edc27fa16d10247f1b59..c21a16fdc7790c58f52410ed2a442db29c7edab7 100644 (file)
@@ -26,7 +26,6 @@
 IN: html
 USE: strings
 USE: lists
-USE: format
 USE: kernel
 USE: stdio
 USE: namespaces
index 5f2576086c994394491bf7c765c3c7224a2cec7b..d73e3d60c45e1add6c5f7d125ad4305b82e3cd21 100644 (file)
@@ -26,7 +26,6 @@
 ! ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 IN: html
-USE: format
 USE: lists
 USE: kernel
 USE: namespaces
@@ -55,7 +54,7 @@ USE: generic
     [ dup html-entities assoc dup rot ? ] str-map ;
 
 : >hex-color ( triplet -- hex )
-    [ >hex 2 digits ] map "#" swons cat ;
+    [ >hex 2 "0" pad ] map "#" swons cat ;
 
 : fg-css, ( color -- )
     "color: " , >hex-color , "; " , ;
index ccce12bce118f123c07aff1617a06686bb5e8867..afb4b2faf1270f56b7a7bde2fc1107c086880b50 100644 (file)
@@ -27,7 +27,6 @@
 ! ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 IN: httpd
-USE: format
 USE: kernel
 USE: lists
 USE: logging
index 8a9a6d7af5b4602c27a54938e3bbafb61f5efb69..d9936d26aab55e54b9febf3907eacbff5d8ec23d 100644 (file)
@@ -29,7 +29,6 @@ IN: url-encoding
 USE: errors
 USE: kernel
 USE: lists
-USE: format
 USE: math
 USE: parser
 USE: strings
@@ -37,7 +36,9 @@ USE: unparser
 
 : url-encode ( str -- str )
     [
-        dup url-quotable? [ "%" swap >hex 2 digits cat2 ] unless
+        dup url-quotable? [
+            "%" swap >hex 2 "0" pad cat2
+        ] unless
     ] str-map ;
 
 : catch-hex> ( str -- n )
index b980d2b7075f2c0a6da37a4108d499574195ffe0..7e37e1f83203b27c464f6d84ebf7700951901b1e 100644 (file)
@@ -28,7 +28,6 @@
 IN: ansi
 USE: lists
 USE: kernel
-USE: format
 USE: namespaces
 USE: stdio
 USE: streams
index 2b0219f49b6cdf422c56ef9322bf01458d4c53f7..c56f4c506d7fd6971986efa6bdbc6a3712da83b7 100644 (file)
@@ -48,6 +48,13 @@ USE: strings
     #! repeated.
     [ swap [ dup , ] times drop ] make-string ;
 
+: pad ( string count char -- string )
+    >r over str-length - dup 0 <= [
+        r> 2drop
+    ] [
+        r> fill swap cat2
+    ] ifte ;
+
 : str-map ( str code -- str )
     #! Apply a quotation to each character in the string, and
     #! push a new string constructed from return values.
index 2f8f14d2ac2d885d0b026f442fe2a5e418b23a64..6bfaf13a764955a8d34bb6b0e499235784e26d09 100644 (file)
@@ -43,9 +43,6 @@ M: sbuf = sbuf= ;
 : f-or-"" ( obj -- ? )
     dup not swap "" = or ;
 
-: f>"" ( str/f -- str )
-    [ "" ] unless* ;
-
 : str-length< ( str str -- boolean )
     #! Compare string lengths.
     swap str-length swap str-length < ;
@@ -96,31 +93,33 @@ M: sbuf = sbuf= ;
     #! index.
     [ swap str-head ] 2keep succ swap str-tail ;
 
-: str-headcut ( str begin -- str str )
-    str-length str/ ;
-
-: =? ( x y z -- z/f )
-    #! Push z if x = y, otherwise f.
-    >r = r> f ? ;
-
-: str-head? ( str begin -- str )
-    #! If the string starts with begin, return the rest of the
-    #! string after begin. Otherwise, return f.
-    2dup str-length< [ 2drop f ] [ tuck str-headcut =? ] ifte ;
+: str-head? ( str begin -- ? )
+    2dup str-length< [
+        2drop f
+    ] [
+        dup str-length rot str-head =
+    ] ifte ;
 
 : ?str-head ( str begin -- str ? )
-    dupd str-head? dup [ nip t ] [ drop f ] ifte ;
-
-: str-tailcut ( str end -- str str )
-    str-length >r dup str-length r> - str/ swap ;
+    2dup str-head? [
+        str-length swap str-tail t
+    ] [
+        drop f
+    ] ifte ;
 
-: str-tail? ( str end -- str )
-    #! If the string ends with end, return the start of the
-    #! string before end. Otherwise, return f.
-    2dup str-length< [ 2drop f ] [ tuck str-tailcut =? ] ifte ;
+: str-tail? ( str end -- ? )
+    2dup str-length< [
+        2drop f
+    ] [
+        dup str-length pick str-length swap - rot str-tail =
+    ] ifte ;
 
-: ?str-tail ( str end -- str ? )
-    dupd str-tail? dup [ nip t ] [ drop f ] ifte ;
+: ?str-tail ( str end -- ? )
+    2dup str-tail? [
+        str-length swap [ str-length swap - ] keep str-head t
+    ] [
+        drop f
+    ] ifte ;
 
 : split1 ( string split -- before after )
     2dup index-of dup -1 = [
@@ -130,11 +129,6 @@ M: sbuf = sbuf= ;
         rot str-head swap
     ] ifte ;
 
-: max-str-length ( list -- len )
-    #! Returns the length of the longest string in the given
-    #! list.
-    0 swap [ str-length max ] each ;
-
 : str-each ( str [ code ] -- )
     #! Execute the code, with each character of the string
     #! pushed onto the stack.
index d93117058f2d9310e7a9a12513782ab235eee771..b347e261fb73c18865130b96e06b15432bda9fd7 100644 (file)
@@ -27,7 +27,6 @@
 
 IN: prettyprint
 USE: errors
-USE: format
 USE: generic
 USE: kernel
 USE: lists
index e89fa25c93d3477c02d68b4710fafb35719b2033..727e461bd5d293798136576913edd0903081b31b 100644 (file)
@@ -28,7 +28,6 @@
 IN: unparser
 USE: generic
 USE: kernel
-USE: format
 USE: lists
 USE: math
 USE: namespaces
@@ -142,7 +141,7 @@ M: complex unparse ( num -- str )
     ] assoc ;
 
 : ch>unicode-escape ( ch -- esc )
-    >hex 4 digits "\\u" swap cat2 ;
+    >hex 4 "0" pad "\\u" swap cat2 ;
 
 : unparse-ch ( ch -- ch/str )
     dup quotable? [
diff --git a/library/test/format.factor b/library/test/format.factor
deleted file mode 100644 (file)
index 69bf341..0000000
+++ /dev/null
@@ -1,12 +0,0 @@
-IN: scratchpad
-USE: format
-USE: test
-
-[ "123" ] [ 4 "123" decimal-tail ] unit-test
-[ "12" ] [ 2 "123" decimal-tail ] unit-test
-[ "123" ] [ "123" 2 decimal-places ] unit-test
-[ "123.12" ] [ "123.12" 2 decimal-places ] unit-test
-[ "123.123" ] [ "123.123" 5 decimal-places ] unit-test
-[ "123" ] [ "123.123" 0 decimal-places ] unit-test
-[ "05" ] [ "5" 2 digits ] unit-test
-[ "666" ] [ "666" 2 digits ] unit-test
index f5491169917793c6bd895d764ca3098e620ad43b..1e06d37e336e845545cbdc84431bab907970a305 100644 (file)
@@ -43,13 +43,13 @@ USE: test
 [ "goodbye" f ] [ "goodbye" " " split1 ] unit-test
 [ "" "" ] [ "great" "great" split1 ] unit-test
 
-[ "and end" ] [ "Beginning and end" "Beginning " str-head? ] unit-test
-[ f ] [ "Beginning and end" "Beginning x" str-head? ] unit-test
-[ f ] [ "Beginning and end" "eginning " str-head? ] unit-test
+[ "and end" t ] [ "Beginning and end" "Beginning " ?str-head ] unit-test
+[ "Beginning and end" f ] [ "Beginning and end" "Beginning x" ?str-head ] unit-test
+[ "Beginning and end" f ] [ "Beginning and end" "eginning " ?str-head ] unit-test
 
-[ "Beginning" ] [ "Beginning and end" " and end" str-tail? ] unit-test
-[ f ] [ "Beginning and end" "Beginning x" str-tail? ] unit-test
-[ f ] [ "Beginning and end" "eginning " str-tail? ] unit-test
+[ "Beginning" t ] [ "Beginning and end" " and end" ?str-tail ] unit-test
+[ "Beginning and end" f ] [ "Beginning and end" "Beginning x" ?str-tail ] unit-test
+[ "Beginning and end" f ] [ "Beginning and end" "eginning " ?str-tail ] unit-test
 
 [ [ "This" "is" "a" "split" "sentence" ] ]
 [ "This is a split sentence" " " split ]
@@ -62,16 +62,10 @@ unit-test
 [ [ "a" "b" "c" "d" "e" "f" ] ]
 [ "aXXbXXcXXdXXeXXf" "XX" split ] unit-test
 
-[ 6 ]
-[
-    [ "One" "Two" "Little" "Piggy" "Went" "To" "The" "Market" ]
-    max-str-length
-] unit-test
-
-[ "Hello world" ] [ "Hello world\n" "\n" str-tail? ] unit-test
-[ f ] [ "Hello world" "\n" str-tail? ] unit-test
-[ "" ] [ "\n" "\n" str-tail? ] unit-test
-[ f ] [ "" "\n" str-tail? ] unit-test
+[ "Hello world" t ] [ "Hello world\n" "\n" ?str-tail ] unit-test
+[ "Hello world" f ] [ "Hello world" "\n" ?str-tail ] unit-test
+[ "" t ] [ "\n" "\n" ?str-tail ] unit-test
+[ "" f ] [ "" "\n" ?str-tail ] unit-test
 
 [ t ] [ CHAR: a letter? ] unit-test
 [ f ] [ CHAR: A letter? ] unit-test
@@ -101,3 +95,6 @@ unit-test
     [ dup CHAR: \s = [ drop CHAR: + ] when ] str-map
 ]
 unit-test
+
+[ "05" ] [ "5" 2 "0" pad ] unit-test
+[ "666" ] [ "666" 2 "0" pad ] unit-test
index 8fced0fc5e01de67db177e4acfb349191fab0638..9bbd5a4ce5ac30d176a9e98748e7c22e111f6017 100644 (file)
@@ -78,7 +78,6 @@ USE: unparser
         "namespaces"
         "generic"
         "files"
-        "format"
         "parser"
         "parse-number"
         "prettyprint"
index 2e4a833f92fed97eec2c09385f4fbbc8bec44d47..6cfbf989d1555ec3d31f41c7a0c684b43bba3056 100644 (file)
@@ -26,7 +26,6 @@
 ! ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 IN: inspector
-USE: format
 USE: kernel
 USE: hashtables
 USE: lists
@@ -38,6 +37,7 @@ USE: words
 USE: prettyprint
 USE: unparser
 USE: vectors
+USE: math
 
 : relative>absolute-object-path ( string -- string )
     "object-path" get [ "'" rot cat3 ] when* ;
@@ -60,6 +60,9 @@ USE: vectors
     3list
     default-style append ;
 
+: pad-string ( len str -- str )
+    str-length - " " fill ;
+
 : var-name. ( max name -- )
     tuck unparse pad-string write dup link-style
     swap unparse swap write-attr ;
@@ -67,6 +70,11 @@ USE: vectors
 : value. ( max name value -- )
     >r var-name. ": " write r> . ;
 
+: max-str-length ( list -- len )
+    #! Returns the length of the longest string in the given
+    #! list.
+    0 swap [ str-length max ] each ;
+
 : name-padding ( alist -- col )
     [ car unparse ] map max-str-length ;
 
index 1c06d2237f20dfdf77d9dbdc1752e8a2256f06b2..2e5603075e7601f3db47d62f8a2be53573e2c995 100644 (file)
@@ -88,10 +88,10 @@ USE: words
 
 : word-file ( path -- dir file )
     dup [
-        dup "resource:/" str-head? dup [
-            nip resource-path swap
+        "resource:/" ?str-head [
+            resource-path swap
         ] [
-            swap ( f file )
+            f swap
         ] ifte
     ] [
         f
index d99757ab6ebc2c052784758839a26dafd2c863df..0dbb06a6b73a2e480490e93cca6d5a92b9fdd9fd 100644 (file)
@@ -82,7 +82,7 @@ USE: math
 : vocab-completions ( substring vocab -- list )
     #! Used by jEdit plugin. Like vocab-apropos, but only
     #! matches at the start of a word name are considered.
-    words [ word-name over str-head? ] subset nip ;
+    words [ word-name over ?str-head nip ] subset nip ;
 
 : apropos. ( substring -- )
     #! List all words that contain a string.