]> gitweb.factorcode.org Git - factor.git/commitdiff
more prettyprinter updates, unparser is gone
authorSlava Pestov <slava@factorcode.org>
Mon, 22 Aug 2005 00:50:14 +0000 (00:50 +0000)
committerSlava Pestov <slava@factorcode.org>
Mon, 22 Aug 2005 00:50:14 +0000 (00:50 +0000)
50 files changed:
CHANGES.html
library/alien/compiler.factor
library/alien/enums.factor
library/bootstrap/boot-stage1.factor
library/bootstrap/boot-stage2.factor
library/bootstrap/boot-stage3.factor
library/bootstrap/boot-stage4.factor
library/bootstrap/primitives.factor
library/collections/namespaces.factor
library/collections/sequences-epilogue.factor
library/httpd/cont-responder.factor
library/httpd/file-responder.factor
library/httpd/html.factor
library/httpd/http-client.factor
library/httpd/http-common.factor
library/httpd/responder.factor
library/inference/branches.factor
library/inference/inference.factor
library/inference/known-words.factor
library/io/directories.factor
library/io/logging.factor
library/io/stdio.factor
library/syntax/parse-numbers.factor
library/syntax/parse-syntax.factor
library/syntax/parse-words.factor
library/syntax/prettyprint.factor
library/syntax/see.factor
library/syntax/unparser.factor [deleted file]
library/test/generic.factor
library/test/inference.factor
library/test/interpreter.factor
library/test/math/integer.factor
library/test/math/rational.factor
library/test/parse-number.factor
library/test/parser.factor
library/test/prettyprint.factor
library/test/test.factor
library/tools/debugger.factor
library/tools/gensym.factor
library/tools/inspector.factor
library/tools/jedit.factor
library/tools/listener.factor
library/tools/memory.factor
library/tools/telnetd.factor
library/tools/word-tools.factor
library/ui/ui.factor
library/unix/io.factor
library/unix/sockets.factor
library/vocabularies.factor
library/win32/win32-server.factor

index 23b73760e57f161dcb3f1fa68d4256533ce474c1..6a6ed71ddf41561324474ecb48f530e58e7abd50 100644 (file)
 
 </li>
 
+<li>Prettyprinter:
+
+<ul>
+<li>The prettyprinter has been merged with the unparser. The <code>unparse ( object -- string )</code> word has been moved to the <code>prettyprint</code> vocabulary, and can now produce a parsable string for any class supported by the prettyprinter.</li>
+<li>New <code>unparse-short ( object -- string )</code> returns a string no longer than a single line.</li>
+<li>The prettyprinter now supports many more configuration variables. See the handbook for details.</li>
+</ul>
+
+</li>
+
 <li>Everything else:
 
 <ul>
index 39032cedf8bdbaa74bd5e24d7da7d0bd47ec0d48..f64a770a98b09fd642cf23135531972faaaa2eba 100644 (file)
@@ -2,8 +2,8 @@
 ! See http://factor.sf.net/license.txt for BSD license.
 IN: alien
 USING: assembler compiler compiler-backend compiler-frontend
-errors generic hashtables inference kernel lists math namespaces
-sequences io strings unparser words ;
+errors generic hashtables inference io kernel lists math
+namespaces prettyprint sequences strings words ;
 
 ! ! ! WARNING ! ! !
 ! Reloading this file into a running Factor instance on Win32
@@ -93,7 +93,7 @@ C: alien-node make-node ;
 
 : incr-param ( reg-class -- )
     #! OS X is so ugly.
-    dup class [ 1 + ] change  dup float-regs? [
+    dup class inc  dup float-regs? [
         os "macosx" = [
             int-regs [ swap float-regs-size 4 / + ] change
         ] [
index dff5314cbed2862145c8ad72683fd4d65ded5f23..03aa175c186368e6c53674a01d66699651cb1b27 100644 (file)
@@ -14,7 +14,7 @@ USING: kernel lists math parser words ;
     #! END-ENUM
     #!
     #! This is the same as : x 0 ; : y 1 ; : z 2 ;.
-    scan str>number ; parsing
+    scan string>number ; parsing
 
 : ENUM:
     dup CREATE swap unit define-compound 1 + ; parsing
index 4a6a4c70e32b594d5515f29e68691b5489447637..8bb76f3a77ecb939f8ad060df540a85f5a37743c 100644 (file)
@@ -73,7 +73,6 @@ parser prettyprint sequences io vectors words ;
         
         "/library/alien/aliens.factor"
         
-        "/library/syntax/unparser.factor"
         "/library/syntax/prettyprint.factor"
 
         "/library/tools/gensym.factor"
index 5d0f3e24cd1779d432a0408b8938f573659b3cff..3727fcc9e795512cdf00276d8719a71eff8dfe2a 100644 (file)
@@ -1,8 +1,7 @@
 ! Copyright (C) 2004, 2005 Slava Pestov.\r
 ! See http://factor.sf.net/license.txt for BSD license.\r
 USING: alien assembler command-line compiler errors generic\r
-hashtables io kernel lists memory namespaces parser sequences\r
-unparser words ;\r
+hashtables io kernel lists memory namespaces parser sequences words ;\r
 \r
 : pull-in ( ? list -- )\r
     swap [\r
index 018e0cc238611cffd7ba8193522dd119cb5d0c9e..ca736560ba54c6ed17381012a01717e3ef6bc134 100644 (file)
@@ -2,7 +2,7 @@
 ! See http://factor.sf.net/license.txt for BSD license.
 USING: alien assembler command-line compiler compiler-backend
 compiler-frontend inference io-internals kernel lists math
-namespaces parser sequences io unparser words ;
+namespaces parser sequences io words ;
 
 "Compiling base..." print
 
@@ -36,7 +36,8 @@ compile? [
     \ car compile
     \ * compile
     \ = compile
-    \ unparse compile
+    \ string>number compile
+    \ number>string compile
     \ scan compile
     \ (generate) compile
 ] when
index 96809a3b1a3dec9a127a43024ff6e92dbbcbc228..5a13a19533c7843a82b9a92a1f50d8cfcd57f126 100644 (file)
@@ -3,8 +3,7 @@
 IN: kernel
 USING: alien assembler command-line compiler console errors
 generic inference kernel-internals listener lists math memory
-namespaces parser presentation prettyprint random io
-unparser words ;
+namespaces parser presentation prettyprint random io words ;
 
 "Bootstrap stage 4..." print
 
@@ -37,12 +36,13 @@ terpri
 terpri
 
 0 [ compiled? [ 1 + ] when ] each-word
-unparse write " words compiled" print
+number>string write " words compiled" print
 
 0 [ drop 1 + ] each-word
-unparse write " words total" print 
+number>string write " words total" print 
 
-"Total bootstrap GC time: " write gc-time unparse write " ms" print
+"Total bootstrap GC time: " write gc-time
+number>string write " ms" print
 
 "Bootstrapping is complete." print
 "Now, you can run ./f factor.image" print
index c8c07dfef28ac95a19968c11c82c0f8c1eaf2ae2..220a5109b303daf1e5f522342132227eb4df821c 100644 (file)
@@ -44,7 +44,7 @@ vocabularies get [
     { ">float" "math"                       }
     { "(fraction>)" "math-internals"        }
     { "str>float" "parser"                  }
-    { "(unparse-float)" "unparser"          }
+    { "(unparse-float)" "parser"            }
     { "float>bits" "math"                   }
     { "double>bits" "math"                  }
     { "bits>float" "math"                   }
index 8e544dbbc9af85e1fac74089555e603c7b703fd9..a401d9cd3c9ccf9bacd1f8478c959bfdf8d82006 100644 (file)
@@ -65,10 +65,6 @@ strings vectors words ;
 
 : set ( value variable -- ) namespace set-hash ;
 
-: on ( var -- ) t swap set ;
-
-: off ( var -- ) f swap set ;
-
 : nest ( variable -- hash )
     #! If the variable is set in the current namespace, return
     #! its value, otherwise set its value to a new namespace.
@@ -80,6 +76,14 @@ strings vectors words ;
     #! quotation.
     >r dup get r> rot slip set ; inline
 
+: on ( var -- ) t swap set ; inline
+
+: off ( var -- ) f swap set ; inline
+
+: inc ( var -- ) [ 1 + ] change ; inline
+
+: dec ( var -- ) [ 1 - ] change ; inline
+
 : bind ( namespace quot -- )
     #! Execute a quotation with a namespace on the namestack.
     swap >n call n> drop ; inline
index c013cfb11ce0fe4746d291f3fbd28452b9a9f4db..65c16585cdba4b300caff5dfcef3602c63fcbdac 100644 (file)
@@ -212,7 +212,7 @@ M: object reverse ( seq -- seq ) [ <reversed> ] keep like ;
 
 : flip ( seq -- seq )
     #! An example illustrates this word best:
-    #! { { 1 2 3 } { 4 5 6 } } ==> { { 1 2 } { 3 4 } { 5 6 } }
+    #! { { 1 2 3 } { 4 5 6 } } ==> { { 1 4 } { 2 5 } { 3 6 } }
     dup empty? [
         dup first length [ swap [ nth ] map-with ] map-with
     ] unless ; flushable
index c4f2f12145a5ebdc445f94278492478df8296b8f..a91a13e90ad2717d93a79dd87b1d0968eddbd7ad 100644 (file)
@@ -22,7 +22,7 @@
 ! ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 IN: cont-responder
 USING: http httpd math random namespaces io
-       lists strings kernel html unparser hashtables
+       lists strings kernel html hashtables
        parser generic sequences ;
 
 #! Used inside the session state of responders to indicate whether the
@@ -40,7 +40,8 @@ SYMBOL: post-refresh-get?
 
 : get-random-id ( -- id ) 
   #! Generate a random id to use for continuation URL's
-  [ 32 [ 0 9 random-int unparse % ] times ] make-string str>number 36 >base ;
+  [ 32 [ 0 9 random-int CHAR: 0 + , ] times ] make-string
+  string>number 36 >base ;
 
 #! Name of variable holding the table of continuations.
 SYMBOL: table 
index b0c171e006110f27f9fe3bf71d16298877cbaac2..7aea901f5b6cd33e15fddbbaccd0217960dd2c88 100644 (file)
@@ -2,14 +2,14 @@
 ! See http://factor.sf.net/license.txt for BSD license.
 IN: file-responder
 USING: html httpd kernel lists namespaces parser sequences
-io strings unparser ;
+io strings ;
 
 : serving-path ( filename -- filename )
     [ "" ] unless* "doc-root" get swap append ;
 
 : file-response ( mime-type length -- )
     [
-        unparse "Content-Length" swons ,
+        number>string "Content-Length" swons ,
         "Content-Type" swons ,
     ] make-list "200 OK" response terpri ;
 
index 65aeb0acecba8654ae58f4e8380758aa5930d122..e20c201c04e0ca544397b17f3d26d6e89236c857 100644 (file)
@@ -1,8 +1,8 @@
 ! Copyright (C) 2004, 2005 Slava Pestov.
 ! See http://factor.sf.net/license.txt for BSD license.
 IN: html
-USING: #<unknown> generic http io kernel lists namespaces
-presentation sequences strings styles unparser words ;
+USING: generic http io kernel lists namespaces parser
+presentation sequences strings styles words ;
 
 : html-entities ( -- alist )
     [
@@ -35,7 +35,7 @@ presentation sequences strings styles unparser words ;
     [ "text-decoration: underline; " % ] when ;
 
 : size-css, ( size -- )
-    "font-size: " % unparse % "; " % ;
+    "font-size: " % number>string % "; " % ;
 
 : font-css, ( font -- )
     "font-family: " % % "; " % ;
index 52193dd995fb3359f359cf9ecce189ebbf4e15b8..acdcc317d1fc55c58c78312dbb98fdf29a2bede5 100644 (file)
@@ -2,11 +2,11 @@
 ! See http://factor.sf.net/license.txt for BSD license.
 IN: http-client
 USING: errors http kernel lists namespaces parser sequences
-io strings unparser ;
+io strings ;
 
 : parse-host ( url -- host port )
     #! Extract the host name and port number from an HTTP URL.
-    ":" split1 [ str>number ] [ 80 ] ifte* ;
+    ":" split1 [ string>number ] [ 80 ] ifte* ;
 
 : parse-url ( url -- host resource )
     "http://" ?head [
@@ -16,13 +16,15 @@ io strings unparser ;
 
 : parse-response ( line -- code )
     "HTTP/" ?head [ " " split1 nip ] when
-    " " split1 drop str>number ;
+    " " split1 drop string>number ;
 
 : read-response ( -- code header )
     #! After sending a GET oR POST we read a response line and
     #! header.
     flush readln parse-response read-header ;
 
+: crlf "\r\n" write ;
+
 : http-request ( host resource method -- )
     write " " write write " HTTP/1.0" write crlf
     "Host: " write write crlf ;
@@ -53,8 +55,8 @@ DEFER: http-get
     #! Note: It is up to the caller to url encode the content if
     #! it is required according to the content-type.
     "POST" http-request [
-        "Content-Length: " write length unparse write crlf
-        "Content-Type: " write write crlf
+        "Content-Length: " write length number>string write crlf
+        "Content-Type: " write url-encode write crlf
         crlf
     ] keep write ;
 
index bc95e66df295e22ac0921b6bef1cca5bfc245336..2c2a4d10bbda887f7bc9e08eef3fa5823d3d7003 100644 (file)
@@ -1,7 +1,7 @@
 ! Copyright (C) 2003, 2005 Slava Pestov
 IN: http
 USING: errors kernel lists math namespaces parser sequences
-io strings unparser ;
+io strings ;
 
 : header-line ( alist line -- alist )
     ": " split1 dup [ cons swons ] [ 2drop ] ifte ;
index 1363a82b86f95c34b60416f25e2d5ead67a400ce..61420248b56de88c54649fba898da6cd0c6f77d2 100644 (file)
@@ -62,7 +62,7 @@ SYMBOL: responders
 
 : read-post-request ( header -- alist )
     "Content-Length" swap assoc dup
-    [ str>number read query>alist ] when ;
+    [ string>number read query>alist ] when ;
 
 : log-user-agent ( alist -- )
     "User-Agent" swap assoc* [
index 60d349c9046e172cf147a76774f2b4f3de1673dc..0b277c039264efa92101f14e8cf13d60e3cce328 100644 (file)
@@ -2,7 +2,7 @@
 ! See http://factor.sf.net/license.txt for BSD license.
 IN: inference
 USING: errors generic hashtables interpreter kernel lists math
-namespaces prettyprint sequences strings unparser vectors words ;
+namespaces parser prettyprint sequences strings vectors words ;
 
 : unify-lengths ( seq -- seq )
     #! Pad all vectors to the same length. If one vector is
@@ -31,7 +31,8 @@ namespaces prettyprint sequences strings unparser vectors words ;
     [ unify-stacks >r unify-stacks r> ]
     [
         { "Unbalanced branches:" } -rot [
-            swap length unparse " " rot length unparse append3
+            swap length number>string
+            " " rot length number>string append3
         ] 2map append "\n" join inference-error
     ] ifte ;
 
index a1a9c163600132266e5a5030f50eaf517fed62d1..2214baaa5665fda8d77f4b75faec1bcd2335fbc8 100644 (file)
@@ -2,7 +2,7 @@
 ! See http://factor.sf.net/license.txt for BSD license.
 IN: inference
 USING: errors generic interpreter io kernel lists math
-namespaces prettyprint sequences strings unparser vectors words ;
+namespaces parser prettyprint sequences strings vectors words ;
 
 ! This variable takes a boolean value.
 SYMBOL: inferring-base-case
@@ -112,7 +112,7 @@ M: wrapper apply-object wrapped apply-literal ;
 : check-return ( -- )
     #! Raise an error if word leaves values on return stack.
     meta-r get empty? [
-        "Word leaves " meta-r get length unparse
+        "Word leaves " meta-r get length number>string
         " element(s) on return stack. Check >r/r> usage." append3
         inference-error
     ] unless ;
index e0970d503a9a1e862249d0d01ca820ec4fe51f54..6ff698eebe155ce8c43ad4098cebc5e53a0ad321 100644 (file)
@@ -1,7 +1,7 @@
 IN: inference
 USING: alien assembler errors generic hashtables interpreter io
 io-internals kernel kernel-internals lists math math-internals
-memory parser sequences strings unparser vectors words ;
+memory parser sequences strings vectors words prettyprint ;
 
 ! Primitive combinators
 \ call [
index b8cb2f71917fd06576da7914a9e8c5a1d7a879af..6e3ad05e668c4ac84753f71abc38b6605acd23f0 100644 (file)
@@ -2,7 +2,7 @@
 ! See http://factor.sf.net/license.txt for BSD license.
 IN: io
 USING: hashtables kernel lists namespaces presentation sequences
-strings styles unparser ;
+strings styles ;
 
 ! Hyperlinked directory listings.
 
index 64e8d7ea790ef36129c0934c6c2065680e00b486..53c7c079046e0fd79911c60e3ffa976520d82b42 100644 (file)
@@ -1,7 +1,7 @@
 ! Copyright (C) 2003, 2005 Slava Pestov.
 ! See http://factor.sf.net/license.txt for BSD license.
 IN: io
-USING: kernel namespaces io sequences strings unparser ;
+USING: io kernel namespaces parser sequences strings ;
 
 ! A simple logging framework.
 SYMBOL: log-stream
@@ -21,7 +21,7 @@ SYMBOL: log-stream
         "Accepted connection from " %
         dup client-stream-host %
         CHAR: : ,
-        client-stream-port unparse % 
+        client-stream-port number>string % 
     ] make-string log ;
 
 : with-log-file ( file quot -- )
index 7912fa633dad0141eb8927ed1c467335ceada38e..6e4842f12b6aa6de92bc59766ee6ee5e9cb04e19 100644 (file)
@@ -14,12 +14,13 @@ USING: errors generic kernel lists namespaces strings styles ;
 : terpri ( -- )              stdio get stream-terpri ;\r
 : close  ( -- )              stdio get stream-close ;\r
 \r
-: crlf   ( -- )              "\r\n" write ;\r
-\r
 : write-icon ( resource -- )\r
     #! Write an icon. Eg, /library/icons/File.png\r
     icon swons unit "" swap format ;\r
 \r
+: write-object ( string object -- )\r
+    presented swons unit format ;\r
+\r
 : with-stream ( stream quot -- )\r
     #! Close the stream no matter what happens.\r
     [ swap stdio set [ close rethrow ] catch ] with-scope ;\r
index fcd665bcf1b7bb2f3f95f6a7da3e1a302987f489..9d39afd3de9540cede598b9c1231e27145b12464 100644 (file)
@@ -1,7 +1,7 @@
 ! Copyright (C) 2004, 2005 Slava Pestov.
 ! See http://factor.sf.net/license.txt for BSD license.
 IN: parser
-USING: errors generic kernel math sequences strings ;
+USING: errors generic kernel math namespaces sequences strings ;
 
 ! Number parsing
 
@@ -28,19 +28,62 @@ M: object digit> not-a-number ;
     #! conversion fails.
     swap "-" ?head [ (base>) neg ] [ (base>) ] ifte ;
 
-GENERIC: str>number ( str -- num )
+GENERIC: string>number ( str -- num )
 
-M: string str>number 10 base> ;
+M: string string>number 10 base> ;
 
 PREDICATE: string potential-ratio CHAR: / swap member? ;
-M: potential-ratio str>number ( str -- num )
+M: potential-ratio string>number ( str -- num )
     "/" split1 >r 10 base> r> 10 base> / ;
 
 PREDICATE: string potential-float CHAR: . swap member? ;
-M: potential-float str>number ( str -- num )
+M: potential-float string>number ( str -- num )
     str>float ;
 
 : bin> 2 base> ;
 : oct> 8 base> ;
-: dec> 10 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-rstring ;
+
+: >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-string ;
+
+: 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 09c16e81477fc1b4f0b96733fa8fa16d82c1b182..7d96e2e06ec234cac019c5b26383d86ee2d26529 100644 (file)
@@ -4,7 +4,7 @@
 ! Bootstrapping trick; see doc/bootstrap.txt.
 IN: !syntax
 USING: alien errors generic hashtables kernel lists math
-namespaces parser sequences strings syntax unparse vectors
+namespaces parser sequences strings syntax vectors
 words ;
 
 : parsing ( -- )
index 9e2891ffbf5e112e5fd96162314b3ccc60dca030..7b00564ab37a55aed63d73422af646cbf53a9eb5 100644 (file)
@@ -2,7 +2,7 @@
 ! See http://factor.sf.net/license.txt for BSD license.
 IN: parser
 USING: errors kernel lists math namespaces sequences io
-strings unparser words ;
+strings words ;
 
 ! The parser uses a number of variables:
 ! line - the line being parsed
@@ -60,7 +60,7 @@ global [ string-mode off ] bind
 : scan-word ( -- obj )
     scan dup [
         dup ";" = not string-mode get and [
-            dup "use" get search [ ] [ str>number ] ?ifte
+            dup "use" get search [ ] [ string>number ] ?ifte
         ] unless
     ] when ;
 
index 2d0a2dc19a27ac39875a7acc782473565cd88d99..eb90cd087dc686e962b7a1751c4a2f3537ef39b4 100644 (file)
@@ -2,16 +2,11 @@
 ! See http://factor.sf.net/license.txt for BSD license.
 IN: prettyprint
 USING: alien generic hashtables io kernel lists math namespaces
-parser sequences strings styles unparser vectors words ;
+parser sequences strings styles vectors words ;
 
 ! TODO:
-! - newline styles: forced, long output style, normal
-! - long output flag, off with .
-! - margin & indent calculation fix
 ! - out of memory when printing global namespace
 ! - formatting HTML code
-! - limit strings
-! - merge unparse into this
 
 ! State
 SYMBOL: column
@@ -23,12 +18,15 @@ SYMBOL: line-count
 SYMBOL: end-printing
 
 ! Configuration
+SYMBOL: tab-size
 SYMBOL: margin
 SYMBOL: nesting-limit
 SYMBOL: length-limit
 SYMBOL: line-limit
+SYMBOL: string-limit
 
 global [
+    4 tab-size set
     64 margin set
     recursion-check off
     0 column set
@@ -36,30 +34,34 @@ global [
     last-newline? off
     0 last-newline set
     0 line-count set
+    string-limit off
 ] bind
 
-TUPLE: pprinter blocks block ;
+TUPLE: pprinter stack ;
 
 GENERIC: pprint-section*
 
-TUPLE: section start end ;
+TUPLE: section start end nl-after? indent ;
 
 C: section ( length -- section )
     >r column [ dup rot + dup ] change r>
     [ set-section-end ] keep
-    [ set-section-start ] keep ;
+    [ set-section-start ] keep
+    0 over set-section-indent ;
 
 : section-fits? ( section -- ? )
-    section-end last-newline get - margin get <= ;
+    section-end last-newline get - indent get + margin get <= ;
 
 : line-limit? ( -- ? )
     line-limit get dup [ line-count get <= ] when ;
 
-: fresh-line ( section -- )
-    section-start last-newline set
-    line-count [ 1 + ] change
+: do-indent indent get CHAR: \s fill write ;
+
+: fresh-line ( n -- )
+    last-newline set
+    line-count inc
     line-limit? [ " ..." write end-printing get call ] when
-    terpri indent get CHAR: \s fill write ;
+    terpri do-indent ;
 
 TUPLE: text string style ;
 
@@ -75,24 +77,55 @@ TUPLE: block sections ;
 
 C: block ( -- block )
     0 <section> over set-delegate
-    { } clone over set-block-sections ;
+    { } clone over set-block-sections
+    t over set-section-nl-after?
+    tab-size get over set-section-indent ;
+
+: pprinter-block pprinter-stack peek ;
+
+: block-empty? ( section -- ? )
+    dup block? [ block-sections empty? ] [ drop f ] ifte ;
 
 : add-section ( section stream -- )
-    pprinter-block block-sections push ;
+    over block-empty? [
+        2drop
+    ] [
+        pprinter-block block-sections push
+    ] ifte ;
 
 : text ( string style -- )
     <text> pprinter get add-section ;
 
 : bl ( -- ) " " f text ;
 
+: <indent ( section -- ) section-indent indent [ + ] change ;
+
+: indent> ( section -- ) section-indent indent [ swap - ] change ;
+
+: inset-section ( section -- )
+    dup <indent
+    dup section-start fresh-line dup pprint-section*
+    dup indent>
+    dup section-nl-after?
+    [ section-end fresh-line ] [ drop ] ifte ;
+
+: advance ( section -- )
+    section-start last-newline get = [
+        last-newline inc
+    ] [
+        " " write
+    ] ifte ;
+
 : pprint-section ( section -- )
     last-newline? get [
-        dup section-fits? [
-            " " write
+        last-newline? off dup section-fits? [
+            dup advance pprint-section*
         ] [
-            dup fresh-line
-        ] ifte last-newline? off
-    ] when pprint-section* ;
+            inset-section
+        ] ifte
+    ] [
+        pprint-section*
+    ] ifte ;
 
 TUPLE: newline forced? ;
 
@@ -102,46 +135,29 @@ C: newline ( forced -- section )
 
 M: newline pprint-section*
     dup newline-forced?
-    [ fresh-line ] [ drop last-newline? on ] ifte ;
-
-: section-length ( section -- n )
-    dup section-end swap section-start - ;
-
-: block-indent ( block -- indent )
-    block-sections first
-    dup block? [ drop 0 ] [ section-length 1 + ] ifte ;
+    [ section-start fresh-line ] [ drop last-newline? on ] ifte ;
 
 M: block pprint-section* ( block -- )
-    indent get dup >r
-    over block-indent + indent set
-    block-sections [ pprint-section ] each
-    r> indent set ;
-
-: <block ( -- )
-    pprinter get dup pprinter-block over pprinter-blocks push
-    <block> swap set-pprinter-block ;
+    block-sections [ pprint-section ] each ;
 
-: newline ( forced -- )
-    <newline> pprinter get add-section ;
+: <block ( -- ) <block> pprinter get pprinter-stack push ;
 
-: end-block ( block -- )
-    column get swap set-section-end ;
+: newline ( forced -- ) <newline> pprinter get add-section ;
 
-: pop-block ( pprinter -- )
-    dup pprinter-blocks pop swap set-pprinter-block ;
+: end-block ( block -- ) column get swap set-section-end ;
 
-: block-empty? block-sections empty? ;
+: pop-block ( pprinter -- ) pprinter-stack pop drop ;
 
 : block> ( -- )
-    pprinter get dup pprinter-block dup block-empty? [
-        drop pop-block
-    ] [
-        dup end-block swap dup pop-block add-section
-    ] ifte ;
+    pprinter get dup pprinter-block
+    dup end-block swap dup pop-block add-section ;
+
+: block; ( -- )
+    pprinter get pprinter-block f swap set-section-nl-after?
+    block> ;
 
 C: pprinter ( -- stream )
-    { } clone over set-pprinter-blocks
-    <block> over set-pprinter-block ;
+    <block> 1vector over set-pprinter-stack ;
 
 : do-pprint ( pprinter -- )
     [
@@ -162,23 +178,71 @@ GENERIC: pprint* ( obj -- )
         [[ "io-internals" [ [[ foreground [ 192 0 0 ] ]] ] ]]
     }} hash ;
 
-: object-style ( obj -- style )
-    dup word? [ dup word-vocabulary vocab-style ] [ { } ] ifte
-    swap presented swons add ;
+: word-style ( word -- style )
+    dup word-vocabulary vocab-style swap presented swons add ;
 
-: pprint-object ( obj -- )
-    dup unparse swap object-style text ;
+: pprint-word ( obj -- ) dup word-name swap word-style text ;
 
 M: object pprint* ( obj -- )
-    pprint-object ;
+    "( unprintable object: " swap class word-name " )" append3
+    f text ;
+
+M: real pprint* ( obj -- )
+    number>string f text ;
+
+M: complex pprint* ( num -- )
+    \ #{ pprint-word bl
+    dup real pprint* bl imaginary pprint* bl
+    \ }# pprint-word ;
+
+: ch>ascii-escape ( ch -- esc )
+    [
+        [[ CHAR: \e "\\e"  ]]
+        [[ CHAR: \n "\\n"  ]]
+        [[ CHAR: \r "\\r"  ]]
+        [[ CHAR: \t "\\t"  ]]
+        [[ CHAR: \0 "\\0"  ]]
+        [[ CHAR: \\ "\\\\" ]]
+        [[ CHAR: \" "\\\"" ]]
+    ] assoc ;
+
+: ch>unicode-escape ( ch -- esc )
+    >hex 4 CHAR: 0 pad-left "\\u" swap append ;
+
+: unparse-ch ( ch -- ch/str )
+    dup quotable? [
+        ,
+    ] [
+        dup ch>ascii-escape [ ] [ ch>unicode-escape ] ?ifte %
+    ] ifte ;
+
+: do-string-limit ( string -- string )
+    string-limit get [
+        dup length margin get > [
+            margin get 3 - swap head "..." append
+        ] when
+    ] when ;
+
+: pprint-string ( string prefix -- )
+    [ % [ unparse-ch ] each CHAR: " , ] make-string
+    do-string-limit f text ;
+
+M: string pprint* ( str -- str ) "\"" pprint-string ;
+
+M: sbuf pprint* ( str -- str ) "SBUF\" " pprint-string ;
 
 M: word pprint* ( word -- )
-    dup parsing? [ \ POSTPONE: pprint-object bl ] when
-    pprint-object ;
+    dup parsing? [ \ POSTPONE: pprint-word bl ] when pprint-word ;
+
+M: t pprint* drop "t" f text ;
+
+M: f pprint* drop "f" f text ;
+
+M: dll pprint* ( obj -- str ) dll-path "DLL\" " pprint-string ;
 
 : nesting-limit? ( -- ? )
     nesting-limit get dup
-    [ pprinter get pprinter-blocks length < ] when ;
+    [ pprinter get pprinter-stack length < ] when ;
 
 : check-recursion ( obj quot -- indent )
     #! We detect circular structure.
@@ -205,8 +269,8 @@ M: word pprint* ( word -- )
     r> [ "... " f text ] when ;
 
 : pprint-sequence ( seq start end -- )
-    <block swap pprint-object f newline
-    swap pprint-elements pprint-object block> ;
+    swap pprint-word f newline <block
+    swap pprint-elements block> pprint-word ;
 
 M: cons pprint* ( list -- )
    [
@@ -224,11 +288,11 @@ M: tuple pprint* ( tuple -- )
     [ <mirror> \ << \ >> pprint-sequence ] check-recursion ;
 
 M: alien pprint* ( alien -- )
-    \ ALIEN: pprint-object bl alien-address pprint-object ;
+    \ ALIEN: pprint-word bl alien-address number>string f text ;
 
 M: wrapper pprint* ( wrapper -- )
     dup wrapped word? [
-        \ \ pprint-object bl wrapped pprint-object
+        \ \ pprint-word bl wrapped pprint-word
     ] [
         wrapped 1vector \ W[ \ ]W pprint-sequence
     ] ifte ;
@@ -238,11 +302,9 @@ M: wrapper pprint* ( wrapper -- )
         <pprinter> pprinter set call pprinter get do-pprint
     ] with-scope ; inline
 
-: pprint ( object -- )
-    [ pprint* ] with-pprint ;
+: pprint ( object -- ) [ pprint* ] with-pprint ;
 
-: pprint>string ( object -- string )
-    [ pprint ] string-out ;
+: unparse ( object -- str ) [ pprint ] string-out ;
 
 : . ( obj -- ) pprint terpri ;
 
@@ -251,15 +313,15 @@ M: wrapper pprint* ( wrapper -- )
         1 line-limit set
         5 length-limit set
         2 nesting-limit set
+        string-limit on
         pprint
     ] with-scope ;
 
-: pprint>short-string ( object -- string )
-    [ pprint-short ] string-out ;
+: unparse-short ( object -- str ) [ pprint-short ] string-out ;
 
 : [.] ( sequence -- )
     #! Unparse each element on its own line.
-    [ [ pprint>short-string print ] each ] with-scope ;
+    [ dup unparse-short swap write-object terpri ] each ;
 
 : stack. reverse-slice [.] ;
 
index 67f3bedb61152d52d63573e3571223a381ebda16..a518860f562f4f94f505a429e8914f64de122ddf 100644 (file)
@@ -5,8 +5,7 @@ USING: generic hashtables io kernel lists namespaces sequences
 styles words ;
 
 : declaration. ( word prop -- )
-    tuck word-name word-prop
-    [ bl pprint-object ] [ drop ] ifte ;
+    tuck word-name word-prop [ bl pprint-word ] [ drop ] ifte ;
 
 : declarations. ( word -- )
     [
@@ -19,11 +18,16 @@ styles words ;
 : comment. ( comment -- )
     [ [[ font-style italic ]] ] text ;
 
-: stack-picture ( seq -- string )
-    [ [ word-name % " " % ] each ] make-string ;
+: stack-picture% ( seq -- string )
+    [ word-name % " " % ] each ;
 
 : effect>string ( effect -- string )
-    2unseq stack-picture >r stack-picture "-- " r> append3 ;
+    [
+        " " %
+        dup first stack-picture%
+        "-- " %
+        second stack-picture%
+    ] make-string ;
 
 : stack-effect ( word -- string )
     dup "stack-effect" word-prop [ ] [
@@ -32,15 +36,15 @@ styles words ;
     ] ?ifte ;
 
 : stack-effect. ( string -- )
-    [ bl "( " swap ")" append3 comment. ] when* ;
+    [ bl "(" swap ")" append3 comment. ] when* ;
 
 : in. ( word -- )
-    <block \ IN: pprint-object bl word-vocabulary f text block>
+    <block \ IN: pprint-word bl word-vocabulary f text block;
     t newline ;
 
 : definer. ( word -- )
-    dup definer pprint-object bl
-    dup pprint-object
+    dup definer pprint-word bl
+    dup pprint-word
     stack-effect stack-effect.
     f newline ;
 
@@ -53,27 +57,26 @@ M: word (see) definer. t newline ;
         "\n" split [ "#!" swap append comment. t newline ] each
     ] when* ;
 
-: pprint-; \ ; pprint-object ;
+: pprint-; \ ; pprint-word ;
 
 : see-body ( quot word -- )
     dup definer. <block dup documentation. swap pprint-elements
-    pprint-; declarations. block> ;
+    pprint-; declarations. block; ;
 
 M: compound (see)
     dup word-def swap see-body t newline ;
 
 : method. ( word [[ class method ]] -- )
-    <block
-    \ M: pprint-object bl
-    unswons pprint-object bl
-    swap pprint-object t newline
-    pprint-elements pprint-;
-    block> t newline ;
+    \ M: pprint-word bl
+    unswons pprint-word bl
+    swap pprint-word f newline
+    <block pprint-elements pprint-;
+    block; t newline ;
 
 M: generic (see)
     <block
     dup dup { "picker" "combination" } [ word-prop ] map-with
-    swap see-body block> t newline
+    swap see-body block; t newline
     dup methods [ method. ] each-with ;
 
 GENERIC: class. ( word -- )
@@ -81,7 +84,6 @@ GENERIC: class. ( word -- )
 : methods. ( class -- )
     #! List all methods implemented for this class.
     dup metaclass [
-        t newline
         dup implementors [
             dup in. tuck "methods" word-prop hash* method.
         ] each-with
@@ -90,28 +92,28 @@ GENERIC: class. ( word -- )
     ] ifte ;
 
 M: union class.
-    \ UNION: pprint-object bl
-    dup pprint-object bl
-    "members" word-prop pprint-elements pprint-; ;
+    \ UNION: pprint-word bl
+    dup pprint-word bl
+    "members" word-prop pprint-elements pprint-; t newline ;
 
 M: complement class.
-    \ COMPLEMENT: pprint-object bl
-    dup pprint-object bl
-    "complement" word-prop pprint-object ;
+    \ COMPLEMENT: pprint-word bl
+    dup pprint-word bl
+    "complement" word-prop pprint-word t newline ;
 
 M: predicate class.
-    \ PREDICATE: pprint-object bl
-    dup "superclass" word-prop pprint-object bl
-    dup pprint-object f newline
+    \ PREDICATE: pprint-word bl
+    dup "superclass" word-prop pprint-word bl
+    dup pprint-word f newline
     <block
     "definition" word-prop pprint-elements
-    pprint-; block> ;
+    pprint-; block; t newline ;
 
 M: tuple-class class.
-    \ TUPLE: pprint-object bl
-    dup pprint-object bl
+    \ TUPLE: pprint-word bl
+    dup pprint-word bl
     "slot-names" word-prop [ f text bl ] each
-    pprint-; ;
+    pprint-; t newline ;
 
 M: word class. drop ;
 
diff --git a/library/syntax/unparser.factor b/library/syntax/unparser.factor
deleted file mode 100644 (file)
index c741ac5..0000000
+++ /dev/null
@@ -1,100 +0,0 @@
-! Copyright (C) 2004, 2005 Slava Pestov.
-! See http://factor.sf.net/license.txt for BSD license.
-IN: unparser
-USING: alien generic kernel lists math memory namespaces parser
-sequences sequences stdio strings words ;
-
-GENERIC: unparse ( obj -- str )
-
-M: object unparse ( obj -- str )
-    "( " swap class word-name " )" append3 ;
-
-: >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-rstring ;
-
-: >dec ( num -- string ) 10 >base ;
-: >bin ( num -- string ) 2 >base ;
-: >oct ( num -- string ) 8 >base ;
-: >hex ( num -- string ) 16 >base ;
-
-M: integer unparse ( obj -- str ) >dec ;
-
-M: ratio unparse ( num -- str )
-    [
-        dup
-        numerator unparse %
-        CHAR: / ,
-        denominator unparse %
-    ] make-string ;
-
-: 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 unparse ( float -- str )
-    (unparse-float) fix-float ;
-
-M: complex unparse ( num -- str )
-    [
-        "#{ " %
-        dup
-        real unparse %
-        " " %
-        imaginary unparse %
-        " }#" %
-    ] make-string ;
-
-: ch>ascii-escape ( ch -- esc )
-    [
-        [[ CHAR: \e "\\e"  ]]
-        [[ CHAR: \n "\\n"  ]]
-        [[ CHAR: \r "\\r"  ]]
-        [[ CHAR: \t "\\t"  ]]
-        [[ CHAR: \0 "\\0"  ]]
-        [[ CHAR: \\ "\\\\" ]]
-        [[ CHAR: \" "\\\"" ]]
-    ] assoc ;
-
-: ch>unicode-escape ( ch -- esc )
-    >hex 4 CHAR: 0 pad-left "\\u" swap append ;
-
-: unparse-ch ( ch -- ch/str )
-    dup quotable? [
-        ,
-    ] [
-        dup ch>ascii-escape [ ] [ ch>unicode-escape ] ?ifte %
-    ] ifte ;
-
-: unparse-string [ unparse-ch ] each ;
-
-M: string unparse ( str -- str )
-    [ CHAR: " , unparse-string CHAR: " , ] make-string ;
-
-M: sbuf unparse ( str -- str )
-    [ "SBUF\" " % unparse-string CHAR: " , ] make-string ;
-
-M: word unparse ( obj -- str ) word-name dup "( unnamed )" ? ;
-
-M: t unparse drop "t" ;
-M: f unparse drop "f" ;
-
-M: dll unparse ( obj -- str )
-    [ "DLL\" " % dll-path unparse-string CHAR: " , ] make-string ;
index 09f1fd30f2858de4a34b352fb760071507015d07..0635d1ca31c2b5bbfaa32cd71119667f6c430773 100644 (file)
@@ -1,5 +1,5 @@
 IN: temporary
-USING: parser prettyprint sequences io strings unparser ;
+USING: parser prettyprint sequences io strings ;
 
 USE: hashtables
 USE: namespaces
@@ -160,9 +160,6 @@ M: f testing 3 ;
 M: sequence testing 4 ;
 [ [ 1 2 ] 2 ] [ [ 1 2 ] testing ] unit-test
 
-! Bootstrap hashing
-[ f ] [ \ f \ unparse "methods" word-prop hash not ] unit-test
-
 GENERIC: union-containment
 M: integer union-containment drop 1 ;
 M: number union-containment drop 2 ;
index 01419231a446fcb66445171c5c97defbabf75e8d..a2d46c7ffca0e4e01d37db1e15c117e42b0d54fd 100644 (file)
@@ -180,7 +180,7 @@ M: real iterate drop ;
 [ [ 2 1 ] ] [ [ >= ] infer ] unit-test
 [ [ 2 1 ] ] [ [ number= ] infer ] unit-test
 
-[ [ 1 1 ] ] [ [ str>number ] infer ] unit-test
+[ [ 1 1 ] ] [ [ string>number ] infer ] unit-test
 [ [ 2 1 ] ] [ [ = ] infer ] unit-test
 [ [ 1 1 ] ] [ [ get ] infer ] unit-test
 
index e8abcdcf16276b73ecbb4f04c08b427c5479e532..569235096ab0e414dc4da50138c9f5da6d12951b 100644 (file)
@@ -1,5 +1,4 @@
 IN: temporary
-USING: unparser ;
 USE: vectors
 USE: interpreter
 USE: test
@@ -76,10 +75,6 @@ USE: sequences
     [ [ "hi" print ] string-out ] test-interpreter
 ] unit-test
 
-[ { "4\n" } ] [
-    [ [ 2 2 + unparse print ] string-out ] test-interpreter
-] unit-test
-
 [ { "4\n" } ] [
     [ [ 2 2 + . ] string-out ] test-interpreter
 ] unit-test
index 3bcf7b70a56acb3e372d2a19985099d99106868a..c1e022557874eae27b5bcbbfc766fdbff5ab95c9 100644 (file)
@@ -1,5 +1,5 @@
 IN: temporary
-USING: kernel math test unparser ;
+USING: kernel math prettyprint test ;
 
 [ "-8" ] [ -8 unparse ] unit-test
 
index 9f817d02ade543fad1c7f20a1d7be0613de46c1e..fde01eeb147d6db4030ac0c8129d9ceb26732d4e 100644 (file)
@@ -2,7 +2,6 @@ IN: temporary
 USE: kernel
 USE: math
 USE: test
-USE: unparser
 
 [ 1 2 ] [ 1/2 >fraction ] unit-test
 
index 13c615324d3edcf3ef35f8526645b2307fb8408c..52d9e1a1565510db17f264bd32534bdcd87d1a75 100644 (file)
@@ -1,9 +1,9 @@
 IN: temporary
-USING: errors kernel math parser test unparser ;
+USING: errors kernel math parser test ;
 
 : parse-number ( str -- num )
     #! Convert a string to a number; return f on error.
-    [ str>number ] [ [ drop f ] when ] catch ;
+    [ string>number ] [ [ drop f ] when ] catch ;
 
 [ f ]
 [ f parse-number ]
@@ -30,19 +30,19 @@ unit-test
 unit-test
 
 [ "100.0" ]
-[ "1.0e2" parse-number unparse ]
+[ "1.0e2" parse-number number>string ]
 unit-test
 
 [ "-100.0" ]
-[ "-1.0e2" parse-number unparse ]
+[ "-1.0e2" parse-number number>string ]
 unit-test
 
 [ "0.01" ]
-[ "1.0e-2" parse-number unparse ]
+[ "1.0e-2" parse-number number>string ]
 unit-test
 
 [ "-0.01" ]
-[ "-1.0e-2" parse-number unparse ]
+[ "-1.0e-2" parse-number number>string ]
 unit-test
 
 [ f ]
@@ -50,7 +50,7 @@ unit-test
 unit-test
 
 [ "3.14" ]
-[ "3.14" parse-number unparse ]
+[ "3.14" parse-number number>string ]
 unit-test
 
 [ f ]
@@ -62,19 +62,19 @@ unit-test
 unit-test
 
 [ "101.0" ]
-[ "1.01e2" parse-number unparse ]
+[ "1.01e2" parse-number number>string ]
 unit-test
 
 [ "-101.0" ]
-[ "-1.01e2" parse-number unparse ]
+[ "-1.01e2" parse-number number>string ]
 unit-test
 
 [ "1.01" ]
-[ "101.0e-2" parse-number unparse ]
+[ "101.0e-2" parse-number number>string ]
 unit-test
 
 [ "-1.01" ]
-[ "-101.0e-2" parse-number unparse ]
+[ "-101.0e-2" parse-number number>string ]
 unit-test
 
 [ 5 ]
@@ -106,7 +106,7 @@ unit-test
 unit-test
 
 [ "33/100" ]
-[ "66/200" parse-number unparse ]
+[ "66/200" parse-number number>string ]
 unit-test
 
 [ "12" bin> ] unit-test-fails
index cee2561f278759fa4561881e82cd8c3fd6476872..c7d6ce9d55f56812b9d6ede189ffb36bc32653af 100644 (file)
@@ -1,7 +1,6 @@
 IN: temporary
 USE: parser
 USE: test
-USE: unparser
 USE: lists
 USE: kernel
 USE: generic
index 02fdcf810ae1f8b8c8dd313c033a264bc3dfccd5..52422f06dd97153278e0060addbf57caeb10c88f 100644 (file)
@@ -1,45 +1,52 @@
 IN: temporary
-USING: io kernel lists math prettyprint sequences test words ;
+USING: alien io kernel lists math prettyprint sequences
+test words inference namespaces vectors ;
 
-[ "4" ] [ 4 pprint>string ] unit-test
-[ "1.0" ] [ 1.0 pprint>string ] unit-test
-[ "#{ 1/2 2/3 }#" ] [ #{ 1/2 2/3 }# pprint>string ] unit-test
-[ "1267650600228229401496703205376" ] [ 1 100 shift pprint>string ] unit-test
+[ "4" ] [ 4 unparse ] unit-test
+[ "1.0" ] [ 1.0 unparse ] unit-test
+[ "#{ 1/2 2/3 }#" ] [ #{ 1/2 2/3 }# unparse ] unit-test
+[ "1267650600228229401496703205376" ] [ 1 100 shift unparse ] unit-test
 
-[ "+" ] [ \ + pprint>string ] unit-test
+[ "+" ] [ \ + unparse ] unit-test
 
-[ "\\ +" ] [ [ \ + ] first pprint>string ] unit-test
+[ "\\ +" ] [ [ \ + ] first unparse ] unit-test
 
-[ "1" ] [
-    [ [ <block 1 pprint-object block> ] with-pprint ] string-out
-] unit-test
-
-[ "{ }" ] [ { } pprint>string ] unit-test
+[ "{ }" ] [ { } unparse ] unit-test
 
-[ "{ 1 2 3 }" ] [ { 1 2 3 } pprint>string ] unit-test
+[ "{ 1 2 3 }" ] [ { 1 2 3 } unparse ] unit-test
 
 [ "\"hello\\\\backslash\"" ]
-[ "hello\\backslash" pprint>string ]
+[ "hello\\backslash" unparse ]
 unit-test
 
 [ "\"\\u1234\"" ]
-[ "\u1234" pprint>string ]
+[ "\u1234" unparse ]
 unit-test
 
 [ "\"\\e\"" ]
-[ "\e" pprint>string ]
+[ "\e" unparse ]
 unit-test
 
-[ "f" ] [ f pprint>string ] unit-test
-[ "t" ] [ t pprint>string ] unit-test
+[ "f" ] [ f unparse ] unit-test
+[ "t" ] [ t unparse ] unit-test
 
-[ "SBUF\" hello world\"" ] [ SBUF" hello world" pprint>string ] unit-test
+[ "SBUF\" hello world\"" ] [ SBUF" hello world" unparse ] unit-test
 
 : foo dup * ; inline
 
 [ "IN: temporary\n: foo dup * ; inline\n" ]
 [ [ \ foo see ] string-out ] unit-test
 
+: bar ( x -- y ) 2 + ;
+
+[ "IN: temporary\n: bar ( x -- y ) 2 + ;\n" ] [ [ \ bar see ] string-out ] unit-test
+
+: baz dup ;
+
+[ ] [ [ baz ] infer drop ] unit-test
+[ "IN: temporary\n: baz ( object -- object object ) dup ;\n" ]
+[ [ \ baz see ] string-out ] unit-test
+
 [ ] [ \ fixnum see ] unit-test
 
 [ ] [ \ integer see ] unit-test
@@ -49,3 +56,14 @@ unit-test
 [ ] [ \ compound see ] unit-test
 
 [ ] [ \ pprinter see ] unit-test
+
+[ "ALIEN: 1234" ] [ 1234 <alien> unparse ] unit-test
+
+[ "{\n    5 5 5 5 5 5 5 5 5 5\n}" ]
+[
+    [
+        4 tab-size set
+        23 margin set
+        10 5 <repeated> >vector unparse
+    ] with-scope
+] unit-test
index e3e095006d34740beeca6198adcde4c5d10b9b49..292c62fb6b5ceb3abe90d9905c31316eb68c677b 100644 (file)
@@ -2,7 +2,7 @@
 
 IN: test
 USING: errors kernel lists math memory namespaces parser
-prettyprint sequences io strings unparser vectors words ;
+prettyprint sequences io strings vectors words ;
 
 TUPLE: assert got expect ;
 
@@ -22,7 +22,8 @@ M: assert error.
     #! execute it.
     millis >r gc-time >r call gc-time r> - millis r> -
     [
-        unparse % " ms run / " % unparse % " ms GC time" %
+        number>string % " ms run / " %
+        number>string % " ms GC time" %
     ] make-string print ;
 
 : unit-test ( output input -- )
@@ -79,7 +80,7 @@ SYMBOL: failures
         "continuations" "errors" "hashtables" "strings"
         "namespaces" "generic" "tuple" "files" "parser"
         "parse-number" "init" "io/io"
-        "listener" "vectors" "words" "unparser" "random"
+        "listener" "vectors" "words" "prettyprint" "random"
         "stream" "math/bitops"
         "math/math-combinators" "math/rational" "math/float"
         "math/complex" "math/irrational" "math/integer"
index 674004dc26481920fc231fd53391c93cc3d17280..0e5642b541455316c29fc9ceef8c14de0b5be2be 100644 (file)
@@ -2,8 +2,7 @@
 ! See http://factor.sf.net/license.txt for BSD license.
 IN: errors
 USING: generic kernel kernel-internals lists math namespaces
-parser prettyprint sequences io strings unparser
-vectors words ;
+parser prettyprint sequences io strings vectors words ;
 
 : expired-error. ( obj -- )
     "Object did not survive image save/load: " write . ;
@@ -76,7 +75,7 @@ M: no-math-method error. ( error -- )
     "Parsing " write
     dup parse-error-file [ "<interactive>" ] unless* write
     ":" write
-    dup parse-error-line [ 1 ] unless* unparse print
+    dup parse-error-line [ 1 ] unless* number>string print
     
     dup parse-error-text dup string? [ print ] [ drop ] ifte
     
index 12943d8c884b73bcb97e48a7ed47b3e9dbc67d67..ab5f82397e205ad34681a221ebad93cfbf212bec 100644 (file)
@@ -1,14 +1,13 @@
 ! Copyright (C) 2004, 2005 Slava Pestov.
 ! See http://factor.sf.net/license.txt for BSD license.
-IN: words USING: kernel math namespaces sequences strings
-unparser ;
+IN: words USING: kernel math namespaces parser sequences strings ;
 
 SYMBOL: gensym-count
 
 : (gensym) ( -- name )
     "G:" global [
         gensym-count [ 1 + dup ] change
-    ] bind unparse append ;
+    ] bind number>string append ;
 
 : gensym ( -- word )
     #! Return a word that is distinct from every other word, and
index 48d604f5dd621f75c94afdc9b8842e3dc3d5a963..426f5a9d89ea7a965affb58ce8f62a2eba657692 100644 (file)
@@ -3,7 +3,7 @@
 IN: inspector
 USING: generic hashtables io kernel kernel-internals lists math
 memory namespaces prettyprint sequences strings styles test
-unparser vectors words ;
+vectors words ;
 
 SYMBOL: inspecting
 
@@ -13,7 +13,7 @@ M: object sheet ( obj -- sheet )
     dup class "slots" word-prop
     [ second ] map
     tuck [ execute ] map-with
-    2list ;
+    2vector ;
 
 M: list sheet unit ;
 
@@ -24,7 +24,7 @@ M: array sheet unit ;
 M: hashtable sheet dup hash-keys swap hash-values 2list ;
 
 : format-column ( list -- list )
-    [ pprint>short-string ] map
+    [ unparse-short ] map
     [ max-length ] keep
     [ swap CHAR: \s pad-right ] map-with ;
 
@@ -68,9 +68,8 @@ M: object extra-banner ( obj -- ) drop ;
     extra-banner ;
 
 : describe ( obj -- )
-    sheet dup format-sheet
-    swap peek [ presented swons unit ] map
-    [ format terpri ] 2each ;
+    sheet dup format-sheet swap peek
+    [ write-object terpri ] 2each ;
 
 : inspect ( obj -- )
     dup inspecting set dup inspect-banner describe ;
index 83468497aa51b05e20bdf228e56ad22c76c0ba56..bceced0fe3359d7acf5e245b4fcc22f3fa18787d 100644 (file)
@@ -1,8 +1,8 @@
 ! Copyright (C) 2004, 2005 Slava Pestov.
 ! See http://factor.sf.net/license.txt for BSD license.
 IN: jedit
-USING: kernel lists namespaces parser sequences io strings
-unparser words ;
+USING: io kernel lists namespaces parser prettyprint sequences
+strings unparser vectors words ;
 
 ! Some words to send requests to a running jEdit instance to
 ! edit files and position the cursor on a specific line number.
@@ -14,17 +14,17 @@ unparser words ;
 : jedit-server-info ( -- port auth )
     jedit-server-file <file-reader> [
         readln drop
-        readln str>number
-        readln str>number
+        readln string>number
+        readln string>number
     ] with-stream ;
 
 : make-jedit-request ( files params -- code )
     [
-        "EditServer.handleClient(false,false,false,null," %
-        "new String[] {" %
-        [ unparse % "," % ] each
-        "null});\n" %
-    ] make-string ;
+        "EditServer.handleClient(false,false,false,null," write
+        "new String[] {" write
+        [ pprint "," write ] each
+        "null});\n" write
+    ] string-out ;
 
 : send-jedit-request ( request -- )
     jedit-server-info swap "localhost" swap <client> [
@@ -34,11 +34,11 @@ unparser words ;
     ] with-stream ;
 
 : jedit-line/file ( file line -- )
-    unparse "+line:" swap append 2list
+    number>string "+line:" swap append 2vector
     make-jedit-request send-jedit-request ;
 
 : jedit-file ( file -- )
-    unit make-jedit-request send-jedit-request ;
+    1vector make-jedit-request send-jedit-request ;
 
 : jedit ( word -- )
     #! Note that line numbers here start from 1
index ea3e3a6c2deb6df7766d0adada2dc47071aeb445..c4808a43a911b7b58b6d711e755c9aafb7d2a748 100644 (file)
@@ -2,7 +2,7 @@
 ! See http://factor.sf.net/license.txt for BSD license.
 IN: listener
 USING: errors io kernel lists math memory namespaces parser
-presentation sequences strings styles unparser vectors words ;
+presentation sequences strings styles vectors words ;
 
 SYMBOL: listener-prompt
 SYMBOL: quit-flag
index c9a13dede3652963496735eee707fc85fc388e93..8c4f0683e753e2f9d055bb28c3458ba9317d345c 100644 (file)
@@ -1,9 +1,9 @@
 ! Copyright (C) 2004, 2005 Slava Pestov.
 ! See http://factor.sf.net/license.txt for BSD license.
 IN: memory
-USING: errors generic hashtables kernel kernel-internals lists
-math namespaces prettyprint sequences io strings unparser
-vectors words ;
+USING: errors generic hashtables io kernel kernel-internals
+lists math namespaces parser prettyprint sequences strings
+unparser vectors words ;
 
 : generations 15 getenv ;
 
@@ -15,7 +15,10 @@ vectors words ;
 
 ! Printing an overview of heap usage.
 
-: kb. 1024 /i unparse 6 CHAR: \s pad-left  write " KB" write ;
+: kb.
+    1024 /i number>string
+    6 CHAR: \s pad-left  write
+    " KB" write ;
 
 : (room.) ( free total -- )
     2dup swap - swap ( free used total )
@@ -26,7 +29,7 @@ vectors words ;
 : room. ( -- )
     room
     0 swap [
-        "Generation " write over unparse write ":" write
+        "Generation " write over pprint ":" write
         uncons (room.) 1 +
     ] each drop
     "Semi-space:  " write kb. terpri
@@ -92,8 +95,8 @@ M: object each-slot ( obj quot -- )
         3drop
     ] [
         rot type>class word-name write ": " write
-        unparse write " bytes, " write
-        unparse write " instances" print
+        pprint " bytes, " write
+        pprint " instances" print
     ] ifte ;
 
 : heap-stats. ( -- )
index 74c8a5bdd29f41e5d4da53bb695b32b66c7ae7c0..a56fe13a64ec9b7bf3aed81617facec3bdd21d25 100644 (file)
@@ -24,7 +24,7 @@ USING: errors listener kernel namespaces io threads parser ;
 IN: shells
 
 : telnet
-    "telnetd-port" get str>number telnetd ;
+    "telnetd-port" get string>number telnetd ;
 
-! This is a string since we str>number it above.
+! This is a string since we string>number it above.
 global [ "9999" "telnetd-port" set ] bind
index 4b9b2336b55870ad6d57dacb1e67563c9538aa47..597300d3ad6a6e33c1f9630804ea7db9c95e560b 100644 (file)
@@ -2,8 +2,7 @@
 ! See http://factor.sf.net/license.txt for BSD license.
 IN: words
 USING: generic inspector lists kernel namespaces
-prettyprint io strings sequences unparser math
-hashtables parser ;
+prettyprint io strings sequences math hashtables parser ;
 
 : vocab-apropos ( substring vocab -- list )
     #! Push a list of all words in a vocabulary whose names
index 73339aec923a23df88a5a399c8caf615fe1d2194..de03cc068da19735a0eb5fb46147677330ce3479 100644 (file)
@@ -28,13 +28,13 @@ SYMBOL: stack-display
             [[ font-style plain ]]
         }} world get set-gadget-paint
         
-        { 640 768 0 } world get set-gadget-dim
+        { 700 800 0 } world get set-gadget-dim
         
         <plain-gadget> add-layer
     
         <pane> dup pane set <scroller>
         <pane> dup stack-display set <scroller>
-        3/4 <x-splitter> add-layer
+        5/6 <x-splitter> add-layer
         
         [
             pane get [
index 70ae15979d6ef0515bcc14aff5a9f6a0caa45094..8bbf1290d0b0e47bcaf95ce11988f52de74256fc 100644 (file)
@@ -1,9 +1,9 @@
 ! Copyright (C) 2004, 2005 Slava Pestov.
 ! See http://factor.sf.net/license.txt for BSD license.
 IN: io-internals
-USING: alien assembler errors generic hashtables kernel
-kernel-internals lists math sequences io strings threads
-unix-internals unparser vectors ;
+USING: alien assembler errors generic hashtables io kernel
+kernel-internals lists math parser sequences strings threads
+unix-internals vectors ;
 
 ! We want namespaces::bind to shadow the bind system call from
 ! unix-internals
@@ -79,7 +79,7 @@ M: port set-timeout ( timeout port -- )
 : report-error ( error port -- )
     [
         "Error on fd " %
-        dup port-handle unparse %
+        dup port-handle number>string %
         ": " % swap %
     ] make-string swap set-port-error ;
 
index 7cd9fa8d3860fc22a0dbb729194ab8a35157cecc..00c83ad5acfd5353d828b99ce27d079d0d6639cd 100644 (file)
@@ -4,8 +4,8 @@
 ! We need to fiddle with the exact search order here, since
 ! unix-internals::accept shadows streams::accept.
 IN: io-internals
-USING: errors namespaces io threads unparser alien generic
-kernel math unix-internals ;
+USING: alien errors generic io kernel math namespaces parser
+threads unix-internals ;
 
 : <socket-stream> ( fd -- stream )
     dup f <fd-stream> ;
@@ -81,10 +81,10 @@ C: accept-task ( port -- task )
 
 : inet-ntoa ( n -- str )
     ntohl [
-        dup -24 shift HEX: ff bitand unparse % CHAR: . ,
-        dup -16 shift HEX: ff bitand unparse % CHAR: . ,
-        dup -8  shift HEX: ff bitand unparse % CHAR: . ,
-                      HEX: ff bitand unparse %
+        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 %
     ] make-string ;
 
 : do-accept ( port sockaddr fd -- )
index d93a4f34e274e72570ee4fd68cf18b692f8180a1..b427341ad78f93ddbb677bcaa309994ba653fdd7 100644 (file)
@@ -88,5 +88,5 @@ SYMBOL: vocabularies
         "jedit" "kernel" "listener" "lists" "math" "matrices"
         "memory" "namespaces" "parser" "prettyprint"
         "sequences" "io" "strings" "styles" "syntax" "test"
-        "threads" "unparser" "vectors" "words" "scratchpad"
+        "threads" "vectors" "words" "scratchpad"
     ] "use" set ;
index 11ea78993adf39e92a2adb2b65b2a0974d6a5195..7a8bfc7be4e08f1d4901411b8bd09e540ed7f727 100644 (file)
@@ -25,7 +25,7 @@
 
 IN: win32-stream
 USING: alien errors generic kernel kernel-internals lists math namespaces
-       prettyprint sequences io strings threads unparser win32-api
+       prettyprint sequences io strings threads win32-api
        win32-io-internals io-internals ;
 
 TUPLE: win32-server this ;