]> gitweb.factorcode.org Git - factor.git/commitdiff
more cleanups; split up huge gadgets vocabulary
authorSlava Pestov <slava@factorcode.org>
Thu, 1 Sep 2005 01:06:13 +0000 (01:06 +0000)
committerSlava Pestov <slava@factorcode.org>
Thu, 1 Sep 2005 01:06:13 +0000 (01:06 +0000)
50 files changed:
CHANGES.html
TODO.FACTOR.txt
doc/handbook.tex
library/alien/compiler.factor
library/bootstrap/boot-stage1.factor
library/bootstrap/primitives.factor
library/collections/namespaces.factor
library/compiler/compiler.factor
library/generic/generic.factor
library/help/tutorial.factor
library/httpd/file-responder.factor
library/httpd/html.factor
library/httpd/http-client.factor
library/httpd/httpd.factor
library/httpd/responder.factor
library/inference/known-words.factor
library/io/logging.factor
library/math/math.factor
library/math/parse-numbers.factor [new file with mode: 0644]
library/sdl/sdl-video.factor
library/syntax/parse-numbers.factor [deleted file]
library/syntax/parse-stream.factor
library/syntax/prettyprint.factor
library/syntax/see.factor
library/test/test.factor
library/tools/gensym.factor [deleted file]
library/tools/jedit.factor
library/tools/telnetd.factor
library/tools/word-tools.factor [deleted file]
library/ui/books.factor
library/ui/borders.factor
library/ui/buttons.factor
library/ui/editors.factor
library/ui/frames.factor
library/ui/incremental.factor
library/ui/labels.factor
library/ui/layouts.factor
library/ui/listener.factor
library/ui/menus.factor
library/ui/panes.factor
library/ui/presentations.factor
library/ui/scrolling.factor
library/ui/sliders.factor
library/ui/splitters.factor
library/ui/text.factor
library/ui/ui.factor
library/ui/world.factor
library/unix/io.factor
library/unix/sockets.factor
library/words.factor

index e791a6a0b0cc1aeab3f3c0f7363e14ee25c03c19..54b562662a2d04d776f235caa40714ca7ddddd68 100644 (file)
@@ -65,6 +65,7 @@ make-sbuf    ==&gt; SBUF" " make
 <li>New <code>sleep ( ms -- )</code> word pauses current thread for a number of milliseconds.</li>
 <li>New <code>with-datastack ( stack word -- stack )</code> combinator.</li>
 <li>New <code>cond ( conditions -- )</code> combinator. It behaves like a set of nested <code>ifte</code>s, and compiles if each branch has the same stack effect. See its documentation comment for details.</li>
+<li>Formally documented method combination (<code>G:</code> syntax) in handbook.
 <li>Erlang/Termite-style concurrency library in <code>contrib/concurrency</code> (Chris Double).</li>
 <li>Completely redid infix algebra in <code>conrib/algebra/</code>. Now, vector operations are possible
 and the syntax doesn't use so many spaces. New way to write the quadratic formula:
index 5aa9266a9e6f226cc7a80228b8200c000fe6288f..a1833a2579b417cb70a103a0264a12a4f149102b 100644 (file)
@@ -2,13 +2,14 @@
 - out of memory error when printing global namespace\r
 - removing unneeded #label\r
 - pprint trailing space regression\r
+- finish scrollbars\r
+- fix up the min thumb size hack\r
 \r
 + ui:\r
 \r
-- fix up the min thumb size hack\r
+- long lines of text fail in draw-surface\r
 - only redraw dirty gadgets\r
 - faster mouse tracking\r
-\r
 - off-by-one error in pick-up?\r
 - closing ui does not stop timers\r
 - adding/removing timers automatically for animated gadgets\r
@@ -66,8 +67,8 @@
 - the invalid recursion form case needs to be fixed, for inlines too\r
 - #jump-f #jump-f-label\r
 - re-introduce #target-label => #target optimization\r
-- recursion is iffy; no base case needs to throw an error, and if the\r
-  stack at the recursive call doesn't match up, throw an error\r
+- recursion is iffy; if the stack at the recursive call doesn't match\r
+  up, throw an error\r
 \r
 + kernel:\r
 \r
index d9d5f97cf725883ed1190f712675469bedbc539c..2e3a3486a1cde1c7a6c15bb501a00ad2321cd9c3 100644 (file)
@@ -2543,21 +2543,6 @@ Outputs a new sequence with the reverse element order.
 }
 Tests if \texttt{s1} starts or ends with \texttt{s1}. If \texttt{s1} is longer than \texttt{s2}, outputs \texttt{f}.
 
-\wordtable{
-\vocabulary{sequences}
-\ordinaryword{cut}{cut ( seq n -- s1 s2 )}
-}
-Outputs a pair of sequences that equal the original sequence when appended. The first sequence has length $n$, the second has length $l-n$ where $l$ is the length of the input.
-\begin{alltt}
-  "Hello world" 5 cut .s
-\textbf{" world"
-"Hello"}
-\end{alltt}
-This word has a simple definition:
-\begin{verbatim}
-: cut ( n seq -- seq seq )
-    [ head ] 2keep tail ;
-\end{verbatim}
 \wordtable{
 \vocabulary{sequences}
 \ordinaryword{?head}{?head~( s1 s2 -- seq ?~)}
index 065bfb208b8117dd8af7571f390c0cf2dd4f730d..9a033101613520f9527a52cf56c7538fed96c3f6 100644 (file)
@@ -167,5 +167,5 @@ M: compound (uncrossref)
         drop
     ] [
         dup { "infer-effect" "base-case" "no-effect" }
-        reset-props decompile
+        reset-props update-xt
     ] ifte ;
index c11a3ed8f2e30b1512d9d486a2fa6ccf82b08ef4..74ff9842ad71d7aaca805a1b54209823ae5b1757 100644 (file)
@@ -54,6 +54,7 @@ sequences io vectors words ;
         "/library/collections/queues.factor"
 
         "/library/math/matrices.factor"
+        "/library/math/parse-numbers.factor"
 
         "/library/words.factor"
         "/library/vocabularies.factor"
@@ -71,7 +72,6 @@ sequences io vectors words ;
         "/library/io/directories.factor"
         "/library/io/binary.factor"
 
-        "/library/syntax/parse-numbers.factor"
         "/library/syntax/parse-words.factor"
         "/library/syntax/parse-errors.factor"
         "/library/syntax/parser.factor"
@@ -95,20 +95,17 @@ sequences io vectors words ;
 
         "/library/io/logging.factor"
 
-        "/library/tools/gensym.factor"
         "/library/tools/interpreter.factor"
         "/library/tools/debugger.factor"
         "/library/tools/memory.factor"
         "/library/tools/listener.factor"
-        "/library/tools/word-tools.factor"
         "/library/tools/walker.factor"
         "/library/tools/jedit.factor"
-
-        "/library/test/test.factor"
-
         "/library/tools/annotations.factor"
         "/library/tools/inspector.factor"
 
+        "/library/test/test.factor"
+        
         "/library/syntax/see.factor"
 
         "/library/threads.factor"
index 78d4c52e27be78f706643232093c2a5cae65fbea..0e02885e543132cdddfae591748e745a561b59a9 100644 (file)
@@ -38,8 +38,8 @@ vocabularies get [ "syntax" set [ reveal ] each ] bind
     { ">bignum" "math"                      }
     { ">float" "math"                       }
     { "(fraction>)" "math-internals"        }
-    { "str>float" "parser"                  }
-    { "(unparse-float)" "parser"            }
+    { "string>float" "math-internals"       }
+    { "float>string" "math-internals"       }
     { "float>bits" "math"                   }
     { "double>bits" "math"                  }
     { "bits>float" "math"                   }
index ff7dc680951fbe0f3e285b9637afc8300be8ff43..78a875244a9dc4ea90a0662d52f7036c11238146 100644 (file)
@@ -106,6 +106,10 @@ SYMBOL: building
     #! Append to the sequence being built with make-seq.
     building get swap nappend ;
 
+: # ( n -- )
+    #! Only useful with "" make.
+    number>string % ;
+
 ! Building hashtables, and computing a transitive closure.
 SYMBOL: hash-buffer
 
index e5f6fc447ee1223100ef9f143b69acf413262012..989a5e67881b78b2f4ba38253de6e235d932a8b1 100644 (file)
@@ -48,15 +48,8 @@ M: compound (compile) ( word -- )
 
 : compile-all ( -- ) [ try-compile ] each-word ;
 
-: decompile ( word -- )
-    dup compiled? [
-        "Decompiling " write dup . update-xt
-    ] [
-        drop
-    ] ifte ;
-
 : recompile ( word -- )
-    dup decompile compile ;
+    dup update-xt compile ;
 
 : compile-1 ( quot -- word )
     #! Compute a quotation into an uninterned word, for testing
index cc1dd2d667bc5c185f779d25ff0d6b2ca6f4127b..39bc1ec7bfaa0f03c869597d6040f89f49f9be90 100644 (file)
@@ -140,3 +140,12 @@ M: generic definer drop \ G: ;
 : define-class ( class metaclass -- )
     dupd "metaclass" set-word-prop
     dup types number-sort typemap get set-hash ;
+
+: implementors ( class -- list )
+    #! Find a list of generics that implement a method
+    #! specializing on this class.
+    [ "methods" word-prop ?hash ] word-subset-with ;
+
+: classes ( -- list )
+    #! Output a list of all defined classes.
+    [ metaclass ] word-subset ;
index f69946bab2d0ef4dab485201a64f210d99a453cd..4f684955336c810ea4c81cfa58c7bf67cc7a3cfe 100644 (file)
@@ -30,7 +30,7 @@ M: general-list tutorial-line
 \r
 : <page> ( list -- gadget )\r
     [ tutorial-line ] map\r
-    1 <pile> [ add-gadgets ] keep\r
+    <pile> dup 1 over set-pack-fill [ add-gadgets ] keep\r
     empty-border ;\r
 \r
 : tutorial-pages\r
index 04f3fc08ccb56c4a01f546c4b3a6e62b8cf3b8ad..e909a28185199b373b46eb2fffcf2313148bfe31 100644 (file)
@@ -1,7 +1,7 @@
 ! Copyright (C) 2004,2005 Slava Pestov.
 ! See http://factor.sf.net/license.txt for BSD license.
 IN: file-responder
-USING: html httpd kernel lists namespaces parser sequences
+USING: html httpd kernel lists math namespaces parser sequences
 io strings ;
 
 : serving-path ( filename -- filename )
index 93b630dc66e3b25a43a2e81fd4bb9d8ba498cfbc..8afe197d4336f7fa2b76d80c519547a2dc93dfff 100644 (file)
@@ -1,7 +1,7 @@
 ! Copyright (C) 2004, 2005 Slava Pestov.
 ! See http://factor.sf.net/license.txt for BSD license.
 IN: html
-USING: generic http io kernel lists namespaces parser
+USING: generic http io kernel lists math namespaces parser
 presentation sequences strings styles words ;
 
 : html-entities ( -- alist )
@@ -35,7 +35,7 @@ presentation sequences strings styles words ;
     [ "text-decoration: underline; " % ] when ;
 
 : size-css, ( size -- )
-    "font-size: " % number>string % "; " % ;
+    "font-size: " % # "; " % ;
 
 : font-css, ( font -- )
     "font-family: " % % "; " % ;
index acdcc317d1fc55c58c78312dbb98fdf29a2bede5..de92da80ce1afebc9da3798da923ecb243c40f72 100644 (file)
@@ -1,7 +1,7 @@
 ! Copyright (C) 2005 Slava Pestov.
 ! See http://factor.sf.net/license.txt for BSD license.
 IN: http-client
-USING: errors http kernel lists namespaces parser sequences
+USING: errors http kernel lists math namespaces parser sequences
 io strings ;
 
 : parse-host ( url -- host port )
index 1a9ceb1c869ff073cae59aaf8948fa160addddf0..1e3a35f40467681aa8d48b3f02e475783bc82b88 100644 (file)
@@ -38,7 +38,7 @@ sequences ;
     [ (handle-request) serve-responder ] with-scope ;
 
 : parse-request ( request -- )
-    dup log
+    dup log-message
     " " split1 dup [
         " HTTP" split1 drop url>path secure-path dup [
             swap handle-request
index 6c8e01e365adf25db1322a9574249091c3387fd0..3873b1e26eb5892396c688f4031a5d2f30d6aeca 100644 (file)
@@ -1,8 +1,8 @@
 ! Copyright (C) 2004, 2005 Slava Pestov.
 ! See http://factor.sf.net/license.txt for BSD license.
 IN: httpd
-USING: hashtables http kernel lists namespaces parser sequences
-io strings ;
+USING: hashtables http kernel lists math namespaces parser
+sequences io strings ;
 
 ! Variables
 SYMBOL: vhosts
@@ -66,7 +66,7 @@ SYMBOL: responders
 
 : log-user-agent ( alist -- )
     "User-Agent" swap assoc* [
-        unswons [ % ": " % % ] "" make log
+        unswons [ % ": " % % ] "" make log-message
     ] when* ;
 
 : prepare-url ( url -- url )
@@ -138,7 +138,7 @@ SYMBOL: responders
     "default" responder call-responder ;
 
 : log-responder ( path -- )
-    "Calling responder " swap append log ;
+    "Calling responder " swap append log-message ;
 
 : trim-/ ( url -- url )
     #! Trim a leading /, if there is one.
index 3fbeb9293521ee36d811c7723daaf28f697f1d0e..3d1c5d8a78f30248c62caf93f92b6b0e31bd6ce1 100644 (file)
@@ -113,13 +113,13 @@ memory parser sequences strings vectors words prettyprint ;
 \ (fraction>) t "flushable" set-word-prop
 \ (fraction>) t "foldable" set-word-prop
 
-\ str>float [ [ string ] [ float ] ] "infer-effect" set-word-prop
-\ str>float t "flushable" set-word-prop
-\ str>float t "foldable" set-word-prop
+\ string>float [ [ string ] [ float ] ] "infer-effect" set-word-prop
+\ string>float t "flushable" set-word-prop
+\ string>float t "foldable" set-word-prop
 
-\ (unparse-float) [ [ float ] [ string ] ] "infer-effect" set-word-prop
-\ (unparse-float) t "flushable" set-word-prop
-\ (unparse-float) t "foldable" set-word-prop
+\ float>string [ [ float ] [ string ] ] "infer-effect" set-word-prop
+\ float>string t "flushable" set-word-prop
+\ float>string t "foldable" set-word-prop
 
 \ float>bits [ [ real ] [ integer ] ] "infer-effect" set-word-prop
 \ float>bits t "flushable" set-word-prop
index 62abfa755d0e7add172022ea494c081950163680..efe44653d9775cfa14821982731b61fd0115ce72 100644 (file)
@@ -1,28 +1,25 @@
 ! Copyright (C) 2003, 2005 Slava Pestov.
 ! See http://factor.sf.net/license.txt for BSD license.
 IN: io
-USING: io kernel namespaces parser sequences strings ;
+USING: io kernel math namespaces parser sequences strings ;
 
 ! A simple logging framework.
 SYMBOL: log-stream
 
-: log ( msg -- )
+: log-message ( msg -- )
     #! Log a message to the log stream, either stdio or a file.
-    log-stream get [
-        [ stream-print ] keep stream-flush
-    ] [
-        print flush
-    ] ifte* ;
+    log-stream get [ stdio get ] unless*
+    [ stream-print ] keep stream-flush ;
 
-: log-error ( error -- ) "Error: " swap append log ;
+: log-error ( error -- ) "Error: " swap append log-message ;
 
 : log-client ( client-stream -- )
     [
         "Accepted connection from " %
         dup client-stream-host %
         CHAR: : ,
-        client-stream-port number>string % 
-    ] "" make log ;
+        client-stream-port # 
+    ] "" make log-message ;
 
 : with-log-file ( file quot -- )
     #! Calls to log inside quot will output to a file.
index 6ea8dec95ee49a18dca54769b8c2887bb5782879..79f7ac0d163f261b5adf9f6fa5fcdfcabf42ed5a 100644 (file)
@@ -86,3 +86,6 @@ GENERIC: abs ( z -- |z| )
     ] [
         dup 1 = [ drop 0 ] [ 2 /i log2 1 + ] ifte
     ] ifte ; foldable
+
+GENERIC: string>number ( str -- num ) foldable
+GENERIC: number>string ( str -- num ) foldable
diff --git a/library/math/parse-numbers.factor b/library/math/parse-numbers.factor
new file mode 100644 (file)
index 0000000..a955370
--- /dev/null
@@ -0,0 +1,74 @@
+! Copyright (C) 2004, 2005 Slava Pestov.
+! See http://factor.sf.net/license.txt for BSD license.
+IN: math
+USING: errors generic kernel math-internals namespaces sequences
+strings ;
+
+! Number parsing
+
+: not-a-number "Not a number" throw ; inline
+
+GENERIC: digit> ( ch -- n )
+M: digit  digit> CHAR: 0 - ;
+M: letter digit> CHAR: a - 10 + ;
+M: LETTER digit> CHAR: A - 10 + ;
+M: object digit> not-a-number ;
+
+: digit+ ( num digit base -- num )
+    2dup < [ rot * + ] [ not-a-number ] ifte ;
+
+: (base>) ( base str -- num )
+    dup empty? [
+        not-a-number
+    ] [
+        0 [ digit> pick digit+ ] reduce nip
+    ] ifte ;
+
+: base> ( str base -- num )
+    #! Convert a string to an integer. Throw an error if
+    #! conversion fails.
+    swap "-" ?head >r (base>) r> [ neg ] when ;
+
+M: string string>number 10 base> ;
+
+PREDICATE: string potential-ratio CHAR: / swap member? ;
+M: potential-ratio string>number ( str -- num )
+    "/" split1 >r 10 base> r> 10 base> / ;
+
+PREDICATE: string potential-float CHAR: . swap member? ;
+M: potential-float string>number ( str -- num ) string>float ;
+
+: bin> 2 base> ;
+: oct> 8 base> ;
+: hex> 16 base> ;
+
+: >digit ( n -- ch )
+    dup 10 < [ CHAR: 0 + ] [ 10 - CHAR: a + ] ifte ;
+
+: integer, ( num radix -- )
+    dup >r /mod >digit , dup 0 >
+    [ r> integer, ] [ r> 2drop ] ifte ;
+
+: >base ( num radix -- string )
+    #! Convert a number to a string in a certain base.
+    [
+        over 0 < [
+            swap neg swap integer, CHAR: - ,
+        ] [
+            integer,
+        ] ifte
+    ] "" make reverse ;
+
+: >bin ( num -- string ) 2 >base ;
+: >oct ( num -- string ) 8 >base ;
+: >hex ( num -- string ) 16 >base ;
+
+M: integer number>string ( obj -- str ) 10 >base ;
+
+M: ratio number>string ( num -- str )
+    [ dup numerator # CHAR: / , denominator # ] "" make ;
+
+M: float number>string ( float -- str )
+    #! This is terrible. Will go away when we do our own float
+    #! output.
+    float>string CHAR: . over member? [ ".0" append ] unless ;
index ec10633516a5926cb5cfe48575c0742ea4d76568..0c71978499c3af9cbb494a7ecefe2e41e7738f76 100644 (file)
@@ -69,8 +69,8 @@ BEGIN-STRUCT: surface
     FIELD: void*       hwdata
     FIELD: short       clip-x
     FIELD: short       clip-y
-    FIELD: ushort       clip-w
-    FIELD: ushort       clip-h
+    FIELD: ushort      clip-w
+    FIELD: ushort      clip-h
     FIELD: uint        unused1
     FIELD: uint        locked
     FIELD: int         map
diff --git a/library/syntax/parse-numbers.factor b/library/syntax/parse-numbers.factor
deleted file mode 100644 (file)
index 91d19cf..0000000
+++ /dev/null
@@ -1,89 +0,0 @@
-! Copyright (C) 2004, 2005 Slava Pestov.
-! See http://factor.sf.net/license.txt for BSD license.
-IN: parser
-USING: errors generic kernel math namespaces sequences strings ;
-
-! Number parsing
-
-: not-a-number "Not a number" throw ; inline
-
-GENERIC: digit> ( ch -- n )
-M: digit  digit> CHAR: 0 - ;
-M: letter digit> CHAR: a - 10 + ;
-M: LETTER digit> CHAR: A - 10 + ;
-M: object digit> not-a-number ;
-
-: digit+ ( num digit base -- num )
-    2dup < [ rot * + ] [ not-a-number ] ifte ;
-
-: (base>) ( base str -- num )
-    dup empty? [
-        not-a-number
-    ] [
-        0 [ digit> pick digit+ ] reduce nip
-    ] ifte ;
-
-: base> ( str base -- num )
-    #! Convert a string to an integer. Throw an error if
-    #! conversion fails.
-    swap "-" ?head [ (base>) neg ] [ (base>) ] ifte ;
-
-GENERIC: string>number ( str -- num )
-
-M: string string>number 10 base> ;
-
-PREDICATE: string potential-ratio CHAR: / swap member? ;
-M: potential-ratio string>number ( str -- num )
-    "/" split1 >r 10 base> r> 10 base> / ;
-
-PREDICATE: string potential-float CHAR: . swap member? ;
-M: potential-float string>number ( str -- num )
-    str>float ;
-
-: bin> 2 base> ;
-: oct> 8 base> ;
-: hex> 16 base> ;
-
-GENERIC: number>string ( str -- num )
-
-: >digit ( n -- ch )
-    dup 10 < [ CHAR: 0 + ] [ 10 - CHAR: a + ] ifte ;
-
-: integer, ( num radix -- )
-    dup >r /mod >digit , dup 0 > [
-        r> integer,
-    ] [
-        r> 2drop
-    ] ifte ;
-
-: >base ( num radix -- string )
-    #! Convert a number to a string in a certain base.
-    [
-        over 0 < [
-            swap neg swap integer, CHAR: - ,
-        ] [
-            integer,
-        ] ifte
-    ] "" make reverse ;
-
-: >bin ( num -- string ) 2 >base ;
-: >oct ( num -- string ) 8 >base ;
-: >hex ( num -- string ) 16 >base ;
-
-M: integer number>string ( obj -- str ) 10 >base ;
-
-M: ratio number>string ( num -- str )
-    [
-        dup
-        numerator number>string %
-        CHAR: / ,
-        denominator number>string %
-    ] "" make ;
-
-: fix-float ( str -- str )
-    #! This is terrible. Will go away when we do our own float
-    #! output.
-    CHAR: . over member? [ ".0" append ] unless ;
-
-M: float number>string ( float -- str )
-    (unparse-float) fix-float ;
index 2981e1e563e739d06d4301f3545a5e5792fb3aee..ee45a7299c03eaa2653512ca7dffb871bc0f713a 100644 (file)
@@ -1,7 +1,7 @@
 ! Copyright (C) 2004, 2005 Slava Pestov.\r
 ! See http://factor.sf.net/license.txt for BSD license.\r
 IN: parser\r
-USING: kernel lists namespaces sequences io ;\r
+USING: kernel lists namespaces sequences io words ;\r
 \r
 : file-vocabs ( -- )\r
     "scratchpad" "in" set\r
@@ -38,3 +38,12 @@ USING: kernel lists namespaces sequences io ;
 \r
 : run-resource ( file -- )\r
     parse-resource call ;\r
+\r
+: word-file ( word -- file )\r
+    "file" word-prop dup [\r
+        "resource:/" ?head [ resource-path swap path+ ] when\r
+    ] when ;\r
+\r
+: reload ( word -- )\r
+    #! Reload the source file the word originated from.\r
+    word-file run-file ;\r
index 41fa8d6d87401a2690ee7f9f02d40e7ea38a7c67..9e766b20b63164071a434c6b5839443cb6431356 100644 (file)
@@ -11,7 +11,6 @@ SYMBOL: last-newline
 SYMBOL: recursion-check
 SYMBOL: line-count
 SYMBOL: end-printing
-SYMBOL: newline-ok?
 
 ! Configuration
 SYMBOL: tab-size
@@ -30,7 +29,6 @@ global [
     0 last-newline set
     0 line-count set
     string-limit off
-    newline-ok? off
 ] bind
 
 TUPLE: pprinter stack ;
@@ -48,9 +46,6 @@ C: section ( length -- section )
 : section-fits? ( section -- ? )
     section-end last-newline get - indent get + margin get <= ;
 
-: insert-newline? ( section -- ? )
-    section-fits? not newline-ok? and ;
-
 : line-limit? ( -- ? )
     line-limit get dup [ line-count get <= ] when ;
 
@@ -58,10 +53,14 @@ C: section ( length -- section )
 
 : fresh-line ( n -- )
     #! n is current column position.
-    last-newline set
-    line-count inc
-    line-limit? [ "..." write end-printing get call ] when
-    "\n" write do-indent ;
+    dup last-newline get = [
+        drop
+    ] [
+        last-newline set
+        line-count inc
+        line-limit? [ "..." write end-printing get call ] when
+        "\n" write do-indent
+    ] ifte ;
 
 TUPLE: text string style ;
 
@@ -71,7 +70,7 @@ C: text ( string style -- section )
     [ set-text-string ] keep ;
 
 M: text pprint-section*
-    dup text-string swap text-style format  " " write ;
+    dup text-string swap text-style format " " write ;
 
 TUPLE: block sections ;
 
@@ -107,8 +106,8 @@ C: block ( -- block )
     [ section-end fresh-line ] [ drop ] ifte ;
 
 : pprint-section ( section -- )
-    dup insert-newline? newline-ok? on
-    [ inset-section ] [ pprint-section* ] ifte ;
+    dup section-fits?
+    [ pprint-section* ] [ inset-section ] ifte ;
 
 TUPLE: newline ;
 
@@ -116,7 +115,7 @@ C: newline ( -- section )
     0 <section> over set-delegate ;
 
 M: newline pprint-section* ( newline -- )
-    section-start fresh-line newline-ok? off ;
+    section-start fresh-line ;
 
 M: block pprint-section* ( block -- )
     block-sections [ pprint-section ] each ;
index 1b4e14dc045f1bcc3c402753499a1f863ab1ac40..fc1dbb645be2406e078642a8339efaa41fe0b249 100644 (file)
@@ -118,3 +118,14 @@ M: word class. drop ;
 
 : see ( word -- )
     [ dup in. dup (see) dup class. methods. ] with-pprint ;
+
+: (apropos) ( substring -- seq )
+    vocabs [
+        words [ word-name subseq? ] subset-with
+    ] map-with concat ;
+
+: apropos ( substring -- )
+    #! List all words that contain a string.
+    (apropos) [
+        "IN: " write dup word-vocabulary write " " write .
+    ] each ;
index 9d6c571bbb698c14db3e4ff55d436769cd30fcc1..4f732c67aad29542fffe04001211513448aec994 100644 (file)
@@ -21,10 +21,7 @@ M: assert error.
     #! Evaluates the given code and prints the time taken to
     #! execute it.
     millis >r gc-time >r call gc-time r> - millis r> -
-    [
-        number>string % " ms run / " %
-        number>string % " ms GC time" %
-    ] "" make print ;
+    [ # " ms run / " % # " ms GC time" % ] "" make print ;
 
 : unit-test ( output input -- )
     [
diff --git a/library/tools/gensym.factor b/library/tools/gensym.factor
deleted file mode 100644 (file)
index ce7cdb8..0000000
+++ /dev/null
@@ -1,14 +0,0 @@
-! Copyright (C) 2004, 2005 Slava Pestov.
-! See http://factor.sf.net/license.txt for BSD license.
-IN: words
-USING: hashtables kernel math namespaces parser sequences
-strings ;
-
-: gensym ( -- word )
-    #! Return a word that is distinct from every other word, and
-    #! is not contained in any vocabulary.
-    "G:"
-    global [ \ gensym dup inc get ] bind
-    number>string append f <word> ;
-
-0 \ gensym global set-hash
index 033d95b297cd7ed3f0fdc4e45a3702c5d978e4c1..1123aa5fb54447ac27f8777a817cd1bc0edc337a 100644 (file)
@@ -1,7 +1,7 @@
 ! Copyright (C) 2004, 2005 Slava Pestov.
 ! See http://factor.sf.net/license.txt for BSD license.
 IN: jedit
-USING: errors io kernel lists namespaces parser prettyprint
+USING: errors io kernel lists math namespaces parser prettyprint
 sequences strings unparser vectors words ;
 
 ! Some words to send requests to a running jEdit instance to
index a56fe13a64ec9b7bf3aed81617facec3bdd21d25..f61ca9f5472976a73959d1059d079ad5616d2eb0 100644 (file)
@@ -1,7 +1,7 @@
 ! Copyright (C) 2003, 2005 Slava Pestov.
 ! See http://factor.sf.net/license.txt for BSD license.
 IN: telnetd
-USING: errors listener kernel namespaces io threads parser ;
+USING: errors listener kernel math namespaces io threads parser ;
 
 : telnet-client ( socket -- )
     dup [ log-client print-banner listener ] with-stream ;
diff --git a/library/tools/word-tools.factor b/library/tools/word-tools.factor
deleted file mode 100644 (file)
index af10d0d..0000000
+++ /dev/null
@@ -1,43 +0,0 @@
-! Copyright (C) 2003, 2005 Slava Pestov.
-! See http://factor.sf.net/license.txt for BSD license.
-IN: words
-USING: generic inspector lists kernel namespaces
-prettyprint io strings sequences math hashtables parser ;
-
-: vocab-apropos ( substring vocab -- list )
-    #! Push a list of all words in a vocabulary whose names
-    #! contain a string.
-    words [ word-name subseq? ] subset-with ;
-
-: vocab-apropos. ( substring vocab -- )
-    #! List all words in a vocabulary that contain a string.
-    tuck vocab-apropos dup [
-        "IN: " write swap print sequence.
-    ] [
-        2drop
-    ] ifte ;
-
-: apropos. ( substring -- )
-    #! List all words that contain a string.
-    vocabs [ vocab-apropos. ] each-with ;
-
-: word-file ( word -- file )
-    "file" word-prop dup [
-        "resource:/" ?head [
-            resource-path swap path+
-        ] when
-    ] when ;
-
-: reload ( word -- )
-    #! Reload the source file the word originated from.
-    word-file run-file ;
-
-: implementors ( class -- list )
-    #! Find a list of generics that implement a method
-    #! specializing on this class.
-    [
-        "methods" word-prop [ dupd hash ] [ f ] ifte*
-    ] word-subset nip ;
-
-: classes ( -- list )
-    [ metaclass ] word-subset ;
index 877f7315fb01d6c235df67b34e419a12dadad29f..eddf33b62b2772701ec6363baebe582444d3e357 100644 (file)
@@ -1,7 +1,8 @@
 ! Copyright (C) 2005 Slava Pestov.
 ! See http://factor.sf.net/license.txt for BSD license.
-IN: gadgets
-USING: generic kernel lists math matrices sequences ;
+IN: gadgets-books
+USING: gadgets gadgets-buttons gadgets-labels gadgets-layouts
+generic kernel lists math matrices sequences ;
 
 TUPLE: book page ;
 
@@ -46,7 +47,7 @@ TUPLE: book-browser book ;
         { ">"  [ find-book next-page  ] }
         { ">|" [ find-book last-page  ] }
     ] [ 2unseq >r <label> r> <button> ] map
-    <shelf> [ add-gadgets ] keep ;
+    <shelf> [ add-gadgets ] keep ;
 
 C: book-browser ( book -- gadget )
     <frame> over set-delegate
index 065a960bf29a3c20d53b09acc6be3a54982c97aa..4b0c7e74cfa83b7c885092d08f5a658508b9dbfe 100644 (file)
@@ -1,7 +1,7 @@
 ! Copyright (C) 2005 Slava Pestov.
 ! See http://factor.sf.net/license.txt for BSD license.
-IN: gadgets
-USING: errors generic hashtables kernel lists math matrices
+IN: gadgets-borders
+USING: errors gadgets generic hashtables kernel lists math
 namespaces sdl vectors ;
 
 TUPLE: border size ;
index 5ad822c78763eae971debeee28ef2fdf32ce0442..10cdcc6664a1e0628fb916f02a9160a6ee718de6 100644 (file)
@@ -1,8 +1,8 @@
 ! Copyright (C) 2005 Slava Pestov.
 ! See http://factor.sf.net/license.txt for BSD license.
-IN: gadgets
-USING: generic io kernel lists math namespaces prettyprint sdl
-sequences sequences styles threads ;
+IN: gadgets-buttons
+USING: gadgets gadgets-borders generic io kernel lists math
+namespaces sdl sequences sequences styles threads ;
 
 : button-down? ( n -- ? ) hand hand-buttons member? ;
 
index f65290b4ee62102d3e1cda45bd75c500cc1c1430..8878f0c3b08ee5d26c50bb3767df59242c19e429 100644 (file)
@@ -1,8 +1,8 @@
 ! Copyright (C) 2005 Slava Pestov.
 ! See http://factor.sf.net/license.txt for BSD license.
-IN: gadgets
-USING: generic kernel math matrices namespaces sdl sequences
-strings styles threads vectors ;
+IN: gadgets-editors
+USING: gadgets gadgets-labels gadgets-scrolling generic kernel
+math namespaces sdl sequences strings styles threads vectors ;
 
 ! A blinking caret
 TUPLE: caret ;
index 90e12be8281144887f333faa8e83e17340e91d4b..ee56172ec25025fe9ab17b1185056ced68926f24 100644 (file)
@@ -1,7 +1,8 @@
 ! Copyright (C) 2005 Slava Pestov.
 ! See http://factor.sf.net/license.txt for BSD license.
-IN: gadgets
-USING: generic kernel lists math namespaces sequences vectors ;
+IN: gadgets-layouts
+USING: gadgets generic kernel lists math namespaces sequences
+vectors ;
 
 ! A frame arranges gadgets in a 3x3 grid, where the center
 ! gadgets gets left-over space.
index b1711ef8149297c427d1fcfbdfacf4c6536ad136..fd28854d411a3e268ff8d6b20b6a488a74d51b7b 100644 (file)
@@ -1,7 +1,7 @@
 ! Copyright (C) 2005 Slava Pestov.
 ! See http://factor.sf.net/license.txt for BSD license.
-IN: gadgets
-USING: generic kernel math ;
+IN: gadgets-layouts
+USING: gadgets generic kernel math ;
 
 ! Incremental layout allows adding lines to panes to be O(1).
 ! Note that incremental packs are distinct from ordinary packs
index 3df6de128af58a00d0af07089ec1bc1b3aa4995b..999cf9aaef6966b4f658fab767c4fd1a290913bd 100644 (file)
@@ -1,8 +1,8 @@
 ! Copyright (C) 2005 Slava Pestov.
 ! See http://factor.sf.net/license.txt for BSD license.
-IN: gadgets
-USING: generic hashtables io kernel lists math namespaces sdl
-sequences styles vectors ;
+IN: gadgets-labels
+USING: gadgets generic hashtables io kernel lists math
+namespaces sdl sequences styles vectors ;
 
 ! A label gadget draws a string.
 TUPLE: label text ;
index 599454b93459f23c1f1eb81495a5a58bcfdefc14..e402a7c1dc2c043e1c0cdad3d9d8a48149583d78 100644 (file)
@@ -1,8 +1,8 @@
 ! Copyright (C) 2005 Slava Pestov.
 ! See http://factor.sf.net/license.txt for BSD license.
-IN: gadgets
-USING: errors generic hashtables kernel lists math matrices
-namespaces sdl sequences ;
+IN: gadgets-layouts
+USING: errors gadgets generic hashtables kernel lists math
+matrices namespaces sdl sequences ;
 
 : layout ( gadget -- )
     #! Set the gadget's width and height to its preferred width
@@ -26,36 +26,24 @@ TUPLE: pack align fill vector ;
     >r >r pack-vector r> r> [ pick set-axis ] 2map nip ;
 
 : packed-dim-2 ( gadget sizes -- list )
-    [
-        over rect-dim { 1 1 1 } vmax over v-
-        rot pack-fill v*n v+
-    ] map-with ;
-
-: (packed-dims) ( gadget sizes -- seq )
-    2dup packed-dim-2 swap orient ;
+    [ over rect-dim over v- rot pack-fill v*n v+ ] map-with ;
 
 : packed-dims ( gadget sizes -- seq )
-    over gadget-children >r (packed-dims) r>
-    [ set-gadget-dim ] 2each ;
+    2dup packed-dim-2 swap orient ;
 
 : packed-loc-1 ( sizes -- seq )
     { 0 0 0 } [ v+ ] accumulate ;
 
 : packed-loc-2 ( gadget sizes -- seq )
-    >r dup rect-dim { 1 1 1 } vmax over r>
-    packed-dim-2 [ v- ] map-with
-    >r dup pack-align swap rect-dim { 1 1 1 } vmax r>
-    [ >r 2dup r> v- n*v ] map 2nip ;
+    [ >r dup pack-align swap rect-dim r> v- n*v ] map-with ;
 
-: (packed-locs) ( gadget sizes -- seq )
+: packed-locs ( gadget sizes -- seq )
     dup packed-loc-1 >r dupd packed-loc-2 r> orient ;
 
-: packed-locs ( gadget sizes -- )
-    over gadget-children >r (packed-locs) r>
-    [ set-rect-loc ] 2each ;
-
 : packed-layout ( gadget sizes -- )
-    2dup packed-locs packed-dims ;
+    over gadget-children
+    >r dupd packed-dims r> 2dup [ set-gadget-dim ] 2each
+    >r packed-locs r> [ set-rect-loc ] 2each ;
 
 C: pack ( fill vector -- pack )
     #! gap: between each child.
@@ -65,9 +53,9 @@ C: pack ( fill vector -- pack )
     [ set-pack-fill ] keep
     0 over set-pack-align ;
 
-: <pile> ( fill -- pack ) { 0 1 0 } <pack> ;
+: <pile> ( -- pack ) { 0 1 0 } <pack> ;
 
-: <shelf> ( fill -- pack ) { 1 0 0 } <pack> ;
+: <shelf> ( -- pack ) { 1 0 0 } <pack> ;
 
 M: pack pref-dim ( pack -- dim )
     [
@@ -94,7 +82,8 @@ TUPLE: stack ;
 
 C: stack ( -- gadget )
     #! A stack lays out all its children on top of each other.
-    1 { 0 0 1 } <pack> over set-delegate ;
+    { 0 0 1 } <pack> over set-delegate
+    1 over set-pack-fill ;
 
 M: stack children-on ( point stack -- gadget )
     nip gadget-children ;
index 07640efb70c2fc569e2ee8a83f89f9c32a485f91..25fc0b864afa19c0aee36bcfca03b5d164c0100b 100644 (file)
@@ -3,8 +3,10 @@
 IN: help
 DEFER: <tutorial-button>
 
-IN: gadgets
-USING: generic help io kernel listener lists math namespaces
+IN: gadgets-listener
+USING: gadgets gadgets-labels gadgets-layouts gadgets-panes
+gadgets-presentations gadgets-scrolling gadgets-splitters
+generic help io kernel listener lists math namespaces
 prettyprint sdl sequences shells styles threads words ;
 
 SYMBOL: datastack-display
@@ -25,14 +27,11 @@ TUPLE: display title pane ;
 C: display ( -- display )
     <frame> over set-delegate
     "" <display-title> over add-display-title
-    <pile> 2dup swap set-display-pane
+    <pile> 2dup swap set-display-pane
     <scroller> over add-center ;
 
 : make-presentations ( seq -- seq )
-    [
-        dup presented swons unit swap unparse-short
-        <presentation>
-    ] map ;
+    [ <object-presentation> ] map ;
 
 : present-stack ( seq title display -- )
     [ display-title set-label-text ] keep
index f4f8cd5cc0249c9e75b8d5053a5bf6ade981bd26..7a3a4fcefa6587d7c1bd250364044568c9cedcc3 100644 (file)
@@ -1,7 +1,8 @@
 ! Copyright (C) 2005 Slava Pestov.
 ! See http://factor.sf.net/license.txt for BSD license.
-IN: gadgets
-USING: generic kernel lists math namespaces sequences ;
+IN: gadgets-menus
+USING: gadgets gadgets-borders gadgets-buttons gadgets-layouts
+gadgets-labels generic kernel lists math namespaces sequences ;
 
 : menu-actions ( glass -- )
     [ drop hide-glass ] [ button-down 1 ] set-action ;
@@ -22,7 +23,7 @@ USING: generic kernel lists math namespaces sequences ;
     #! Given an association list mapping labels to quotations.
     #! Prepend a call to hide-menu to each quotation.
     [ uncons \ hide-glass swons >r <label> r> <roll-button> ] map
-    1 <pile> [ add-gadgets ] keep ;
+    <pile> 1 over set-pack-fill [ add-gadgets ] keep ;
 
 : menu-theme ( menu -- )
     << solid f >> interior set-paint-prop ;
index 65a50983625bff0dab98de9ad44eddd1c896a67e..85666035703d46f2e53a5cc90c0399608099a902 100644 (file)
@@ -1,7 +1,8 @@
 ! Copyright (C) 2005 Slava Pestov.
 ! See http://factor.sf.net/license.txt for BSD license.
-IN: gadgets
-USING: generic hashtables io kernel line-editor listener lists
+IN: gadgets-panes
+USING: gadgets gadgets-editors gadgets-labels gadgets-layouts
+gadgets-scrolling generic hashtables io kernel line-editor lists
 math namespaces prettyprint sequences strings styles threads
 vectors ;
 
@@ -19,7 +20,7 @@ TUPLE: pane output active current input continuation ;
 : add-input 2dup set-pane-input add-gadget ;
 
 : <active-line> ( input current -- line )
-    2vector <shelf> [ add-gadgets ] keep ;
+    2vector <shelf> [ add-gadgets ] keep ;
 
 : init-active-line ( pane -- )
     dup pane-active unparent
@@ -53,6 +54,9 @@ SYMBOL: structured-input
 : pane-return ( pane -- )
     [ pane-input editor-commit ] keep
     2dup stream-print pane-eval ;
+
+: pane-clear ( pane -- )
+    dup pane-output clear-incremental pane-current clear-gadget ;
  
 : pane-actions ( line -- )
     [
@@ -60,12 +64,13 @@ SYMBOL: structured-input
         [[ [ "RETURN" ] [ pane-return ] ]]
         [[ [ "UP" ] [ pane-input [ history-prev ] with-editor ] ]]
         [[ [ "DOWN" ] [ pane-input [ history-next ] with-editor ] ]]
+        [[ [ "CTRL" "l" ] [ pane get pane-clear ] ]]
     ] swap add-actions ;
 
 C: pane ( -- pane )
-    <pile> over set-delegate
-    <pile> <incremental> over add-output
-    <shelf> over set-pane-current
+    <pile> over set-delegate
+    <pile> <incremental> over add-output
+    <shelf> over set-pane-current
     "" <editor> over set-pane-input
     dup init-active-line
     dup pane-actions ;
@@ -73,9 +78,6 @@ C: pane ( -- pane )
 M: pane focusable-child* ( pane -- editor )
     pane-input ;
 
-: pane-clear ( pane -- )
-    dup pane-output clear-incremental pane-current clear-gadget ;
-
 : pane-write-1 ( style text pane -- )
     pick not pick empty? and [
         3drop
@@ -96,7 +98,7 @@ M: pane focusable-child* ( pane -- editor )
 
 : pane-terpri ( pane -- )
     dup pane-current over pane-print-1
-    <shelf> over set-pane-current init-active-line ;
+    <shelf> over set-pane-current init-active-line ;
 
 : pane-write ( style pane list -- )
     3dup car swap pane-write-1 cdr dup
index 2d12b6e797a46c6b168d4cf6cca44362e609ec1a..75b4d6ae33edb7000bbe1cf614aa7030c79fd41f 100644 (file)
@@ -1,9 +1,10 @@
 ! Copyright (C) 2005 Slava Pestov.
 ! See http://factor.sf.net/license.txt for BSD license.
-IN: gadgets
-USING: compiler generic hashtables inference inspector io jedit
-kernel lists memory namespaces parser prettyprint sequences
-styles vectors words ;
+IN: gadgets-presentations
+USING: compiler gadgets gadgets-buttons gadgets-labels
+gadgets-menus gadgets-panes generic hashtables inference
+inspector io jedit kernel lists memory namespaces parser
+prettyprint sequences styles vectors words ;
 
 SYMBOL: commands
 
@@ -43,6 +44,9 @@ SYMBOL: commands
     gadget pick assoc dup
     [ 2nip ] [ drop <styled-label> init-commands ] ifte ;
 
+: <object-presentation> ( object -- gadget )
+    dup presented swons unit swap unparse-short <presentation> ;
+
 : gadget. ( gadget -- )
     gadget swons unit
     "This stream does not support live gadgets"
@@ -62,7 +66,6 @@ SYMBOL: commands
 [ compound? ] "Annotate with breakpoint" [ break ] define-command
 [ compound? ] "Annotate with profiling" [ profile ] define-command
 [ word? ] "Compile" [ recompile ] define-command
-[ word? ] "Decompile" [ decompile ] define-command
 [ word? ] "Show stack effect" [ unit infer . ] define-command
 [ word? ] "Show dataflow IR" [ word-def t dataflow. ] define-command
 [ word? ] "Show linear IR" [ precompile ] define-command
index 40244d86df4c362652ef692d1ce64d17bfa48dfe..29c1c9d574caf98dc8db4401a9f399a32c3f6e07 100644 (file)
@@ -1,8 +1,8 @@
 ! Copyright (C) 2005 Slava Pestov.
 ! See http://factor.sf.net/license.txt for BSD license.
-IN: gadgets
-USING: generic kernel lists math matrices namespaces sequences
-threads vectors styles ;
+IN: gadgets-scrolling
+USING: gadgets gadgets-layouts generic kernel lists math
+namespaces sequences threads vectors styles ;
 
 ! A viewport can be scrolled.
 TUPLE: viewport ;
@@ -83,5 +83,6 @@ M: scroller focusable-child* ( scroller -- viewport )
 M: scroller layout* ( scroller -- )
     dup scroller-bottom? [
         f over set-scroller-bottom?
-        dup dup scroller-viewport viewport-dim scroll
+        dup dup scroller-viewport viewport-dim
+        { 0 1 0 } v* scroll
     ] when delegate layout* ;
index 46903c850348a23afcea4e36b56b39922dfcec49..c31eca3798c2708fb20456579804fe8583c1b50c 100644 (file)
@@ -1,8 +1,8 @@
 ! Copyright (C) 2005 Slava Pestov.
 ! See http://factor.sf.net/license.txt for BSD license.
-IN: gadgets
-USING: generic kernel lists math matrices namespaces sequences
-threads vectors styles ;
+IN: gadgets-scrolling
+USING: gadgets gadgets-buttons gadgets-layouts generic kernel
+lists math namespaces sequences threads vectors styles ;
 
 ! An elevator has a thumb that may be moved up and down.
 TUPLE: elevator ;
index 1debe28244c7f3adaab4749472ec4e2b6c63da7f..0aa4417e875bb5a50acad1a2aaf4f03673b4a2a7 100644 (file)
@@ -1,8 +1,8 @@
 ! Copyright (C) 2005 Slava Pestov.
 ! See http://factor.sf.net/license.txt for BSD license.
-IN: gadgets
-USING: generic kernel lists math matrices namespaces sequences
-styles vectors ;
+IN: gadgets-splitters
+USING: gadgets gadgets-layouts generic kernel lists math
+namespaces sequences styles vectors ;
 
 TUPLE: divider splitter ;
 
@@ -31,9 +31,10 @@ C: divider ( -- divider )
     dup divider-actions ;
 
 C: splitter ( first second split vector -- splitter )
-    [ >r 1 swap <pack> r> set-delegate ] keep
+    [ >r <pack> r> set-delegate ] keep
     [ set-splitter-split ] keep
-    [ >r >r <divider> r> 3vector r> add-gadgets ] keep ;
+    [ >r >r <divider> r> 3vector r> add-gadgets ] keep
+    1 over set-pack-fill ;
 
 : <x-splitter> ( first second split -- splitter )
     { 0 1 0 } <splitter> ;
index 86652fc24847d01a2e7a8b0ec5a4984880a2aca5..d47c6188699856ba4f4d53b82045ae3ed87499d7 100644 (file)
@@ -6,12 +6,10 @@ sequences strings styles ;
 
 : draw-surface ( x y surface -- )
     surface get SDL_UnlockSurface
-    [
-        [ surface-rect ] keep swap surface get 0 0
-    ] keep surface-rect swap rot SDL_UpperBlit drop
-    surface get dup must-lock-surface? [
-        SDL_LockSurface
-    ] when drop ;
+    [ [ surface-rect ] keep swap surface get 0 0 ] keep
+    surface-rect swap rot SDL_UpperBlit drop
+    surface get dup must-lock-surface?
+    [ SDL_LockSurface ] when drop ;
 
 : filter-nulls ( str -- str )
     [ dup 0 = [ drop CHAR: \s ] when ] map ;
index 4ed7a747af9683f1a5e4304c9266563227d4982f..54a74e3eb605fda00aa2cbbb22872a6938a20919 100644 (file)
@@ -1,8 +1,9 @@
 ! Copyright (C) 2005 Slava Pestov.
 ! See http://factor.sf.net/license.txt for BSD license.
 IN: gadgets
-USING: generic help io kernel listener lists math namespaces
-prettyprint sdl sequences shells styles threads words ;
+USING: gadgets-listener generic help io kernel listener lists
+math namespaces prettyprint sdl sequences shells styles threads
+words ;
 
 : init-world
     global [
index 59994f971afa5b742628500831fafcae63476c2c..f95aa2c86847a8ca2c9d92cbc7ee79df95cea3f3 100644 (file)
@@ -1,9 +1,9 @@
 ! Copyright (C) 2005 Slava Pestov.
 ! See http://factor.sf.net/license.txt for BSD license.
 IN: gadgets
-USING: alien errors generic io kernel lists math memory
-namespaces prettyprint sdl sequences sequences strings threads
-vectors ;
+USING: alien errors gadgets-layouts generic io kernel lists math
+memory namespaces prettyprint sdl sequences sequences strings
+threads vectors ;
 
 ! The world gadget is the top level gadget that all (visible)
 ! gadgets are contained in. The current world is stored in the
index ac330735d90f71f280a2e1d4282b0578bbb01e54..fd9f500b623e23381626d729617bfc87061b230e 100644 (file)
@@ -77,11 +77,8 @@ M: port set-timeout ( timeout port -- )
     dup port-error f rot set-port-error throw ;
 
 : report-error ( error port -- )
-    [
-        "Error on fd " %
-        dup port-handle number>string %
-        ": " % swap %
-    ] "" make swap set-port-error ;
+    [ "Error on fd " % dup port-handle # ": " % swap % ] "" make
+    swap set-port-error ;
 
 : defer-error ( port -- ? )
     #! Return t if it is an unrecoverable error.
index e6a41b3d71c49b070d80f7dc0058219e194da60a..0c472b2035a73087400bd68992466bbd0794328b 100644 (file)
@@ -81,10 +81,10 @@ C: accept-task ( port -- task )
 
 : inet-ntoa ( n -- str )
     ntohl [
-        dup -24 shift HEX: ff bitand number>string % CHAR: . ,
-        dup -16 shift HEX: ff bitand number>string % CHAR: . ,
-        dup -8  shift HEX: ff bitand number>string % CHAR: . ,
-                      HEX: ff bitand number>string %
+        dup -24 shift HEX: ff bitand # CHAR: . ,
+        dup -16 shift HEX: ff bitand # CHAR: . ,
+        dup -8  shift HEX: ff bitand # CHAR: . ,
+                      HEX: ff bitand #
     ] "" make ;
 
 : do-accept ( port sockaddr fd -- )
index eca4bb80bc1b5933e9e9fb745c9e6b1bc13d524b..2819dc23fc02159cc7be8ff1c26096f8547015db 100644 (file)
@@ -20,38 +20,36 @@ M: word set-word-xt ( xt w -- ) 7 set-integer-slot ;
     #! Sort a list of words by name.
     [ swap word-name swap word-name lexi ] sort ;
 
+: uses ( word -- uses )
+    #! Outputs a list of words that this word directly calls.
+    [
+        dup word-def [
+            dup word? [ 2dup eq? [ dup , ] unless ] when 2drop
+        ] tree-each-with
+    ] { } make prune ;
+
 ! The cross-referencer keeps track of word dependencies, so that
 ! words can be recompiled when redefined.
 SYMBOL: crossref
 
-: (add-crossref)
-    dup word? [
-        crossref get [ dupd nest set-hash ] bind
-    ] [
-        2drop
-    ] ifte ;
+: (add-crossref) crossref get [ dupd nest set-hash ] bind ;
 
 : add-crossref ( word -- )
     #! Marks each word in the quotation as being a dependency
     #! of the word.
     crossref get [
-        dup word-def [ (add-crossref) ] tree-each-with
+        dup uses [ (add-crossref) ] each-with
     ] [
         drop
     ] ifte ;
 
-: (remove-crossref)
-    dup word? [
-        crossref get [ nest remove-hash ] bind
-    ] [
-        2drop
-    ] ifte ;
+: (remove-crossref) crossref get [ nest remove-hash ] bind ;
 
 : remove-crossref ( word -- )
     #! Marks each word in the quotation as not being a
     #! dependency of the word.
     crossref get [
-        dup word-def [ (remove-crossref) ] tree-each-with
+        dup uses [ (remove-crossref) ] each-with
     ] [
         drop
     ] ifte ;
@@ -126,3 +124,12 @@ M: object literalize ;
 M: word literalize <wrapper> ;
 
 M: wrapper literalize <wrapper> ;
+
+: gensym ( -- word )
+    #! Return a word that is distinct from every other word, and
+    #! is not contained in any vocabulary.
+    "G:"
+    global [ \ gensym dup inc get ] bind
+    number>string append f <word> ;
+
+0 \ gensym global set-hash