]> gitweb.factorcode.org Git - factor.git/commitdiff
new prettyprinter
authorSlava Pestov <slava@factorcode.org>
Sun, 21 Aug 2005 05:17:37 +0000 (05:17 +0000)
committerSlava Pestov <slava@factorcode.org>
Sun, 21 Aug 2005 05:17:37 +0000 (05:17 +0000)
18 files changed:
TODO.FACTOR.txt
library/bootstrap/primitives.factor
library/collections/arrays.factor
library/collections/sequences-epilogue.factor
library/compiler/compiler.factor
library/httpd/html-tags.factor
library/inference/print-dataflow.factor
library/io/directories.factor
library/io/stdio.factor
library/syntax/prettyprint.factor
library/syntax/see.factor
library/test/interpreter.factor
library/test/prettyprint.factor [new file with mode: 0644]
library/test/unparser.factor [deleted file]
library/tools/debugger.factor
library/tools/inspector.factor
library/tools/walker.factor
library/ui/presentations.factor

index f3d54afd2db046214cf175335ddb75c6e6bb55a2..b8d6c3aa6b73a889053a99218388dac2a2d4f65b 100644 (file)
@@ -1,11 +1,5 @@
 - flushing optimization\r
 - new prettyprinter\r
-  - limit output to n lines\r
-  - limit sequences to n elements\r
-  - put newlines where necessary\r
-  - limit lines to 64 chars\r
-  - conditional newlines after certain words\r
-  - rename prettyprint* to pprint, prettyprint to pp\r
   - reader syntax for arrays, byte arrays, displaced aliens\r
   - print parsing words in bold\r
   - unify unparse and prettyprint\r
index 720ca33d53c8f7a574dcf548799e48f9010047b8..c8c07dfef28ac95a19968c11c82c0f8c1eaf2ae2 100644 (file)
@@ -317,6 +317,8 @@ num-types empty-vector builtins set
 
 "tuple" "kernel" create 18 "tuple?" "kernel" create { } define-builtin
 
+"byte-array" "kernel-internals" create 19 "byte-array?" "kernel-internals" create { } define-builtin
+
 "displaced-alien" "alien" create 20 "displaced-alien?" "alien" create { } define-builtin
 
 FORGET: builtin-predicate
index 970e39712d425714d8a1812ec893f8167b6556c5..586dd245687c9d131d0692d46c04b814c0431d31 100644 (file)
@@ -31,9 +31,6 @@ M: array resize resize-array ;
         3dup swap array-nth pick rot set-array-nth
     ] repeat 2drop ;
 
-DEFER: byte-array?
-BUILTIN: byte-array 19 byte-array? ;
-
 M: byte-array length array-capacity ;
 M: byte-array resize resize-array ;
 
index 6c5b1486b25bf1d766928bd9ca634dcad2469343..c013cfb11ce0fe4746d291f3fbd28452b9a9f4db 100644 (file)
@@ -229,7 +229,7 @@ IN: kernel
 
 : cond ( conditions -- )
     #! Conditions is a sequence of quotation pairs.
-    #! { { [ X ] [ Y ] } { [ Z ] [ T ] }
+    #! { { [ X ] [ Y ] } { [ Z ] [ T ] } }
     #! => X [ Y ] [ Z [ T ] [ ] ifte ] ifte
     #! The last condition should be a catch-all 't'.
     [ first call ] find nip second call ;
index c9b8c799faf0db3848a61ca610be9e79ee12f363..ac37b982aea509ef2362a64bd8c5cfa04918f460 100644 (file)
@@ -12,9 +12,7 @@ io kernel lists math namespaces prettyprint words ;
     ] unless ;
 
 : compiling ( word -- word parameter )
-    check-architecture
-    "Compiling " write dup unparse. terpri flush
-    dup word-def ;
+    check-architecture "Compiling " write dup pp dup word-def ;
 
 GENERIC: (compile) ( word -- )
 
@@ -43,7 +41,7 @@ M: compound (compile) ( word -- )
     "compile" get [ word compile ] when ; parsing
 
 : cannot-compile ( word error -- )
-    "Cannot compile " write swap unparse. terpri print-error ;
+    "Cannot compile " write swap pp print-error ;
 
 : try-compile ( word -- )
     [ compile ] [ [ cannot-compile ] when* ] catch ;
@@ -52,7 +50,7 @@ M: compound (compile) ( word -- )
 
 : decompile ( word -- )
     dup compiled? [
-        "Decompiling " write dup unparse. terpri flush
+        "Decompiling " write dup pp
         [ word-primitive ] keep set-word-primitive
     ] [
         drop
index a8c263bd7c9ddadd562e9deddc8813222802690f..24f6a38f0adec8d4671d12f352882fd3a2215fa9 100644 (file)
@@ -84,7 +84,7 @@ USE: sequences
     #! With the attribute namespace on the stack, get the attributes
     #! and write them to standard output. If no attributes exist, write
     #! nothing.
-    "attrs" get [ bl attrs>string write ] when* ;
+    "attrs" get [ " " write attrs>string write ] when* ;
 
 : store-prev-attribute ( n: tag value -- )     
     #! Assumes an attribute namespace is on the stack.
index 2a96ed99dbfc2df5884bcfe651e96c657e92aba4..9fe0705decd6bf69f1f78c6a3122ef9531de002f 100644 (file)
@@ -1,6 +1,6 @@
 IN: inference
 USING: generic hashtables inference io kernel kernel-internals
-math namespaces prettyprint sequences vectors words ;
+lists math namespaces prettyprint sequences styles vectors words ;
 
 ! A simple tool for turning dataflow IR into quotations, for
 ! debugging purposes.
@@ -9,9 +9,9 @@ GENERIC: node>quot ( node -- )
 
 TUPLE: comment node text ;
 
-M: comment prettyprint* ( ann -- )
+M: comment pprint* ( ann -- )
     "( " over comment-text " )" append3
-    swap comment-node object. ;
+    swap comment-node presented swons unit format ;
 
 : comment, ( ? node text -- )
     rot [ <comment> , ] [ 2drop ] ifte ;
@@ -82,4 +82,4 @@ M: #entry node>quot ( ? node -- ) "#entry" comment, ;
 : dataflow. ( quot ? -- )
     #! Print dataflow IR for a quotation. Flag indicates if
     #! annotations should be printed or not.
-    >r dataflow optimize r> dataflow>quot prettyprint ;
+    >r dataflow optimize r> dataflow>quot pp ;
index 5c505f658fc274b7575ff799bba3ee801d26edce..b8cb2f71917fd06576da7914a9e8c5a1d7a879af 100644 (file)
@@ -15,7 +15,7 @@ strings styles unparser ;
 
 : file. ( dir name -- )
     #! If "doc-root" set, create links relative to it.
-    2dup path+ file-icon. bl file-link. terpri ;
+    2dup path+ file-icon. " " write file-link. terpri ;
 
 : directory. ( dir -- )
     #! If "doc-root" set, create links relative to it.
index 6de164ae9adee08025be2a7c8f3e1614e3d685f2..7912fa633dad0141eb8927ed1c467335ceada38e 100644 (file)
@@ -15,7 +15,6 @@ USING: errors generic kernel lists namespaces strings styles ;
 : close  ( -- )              stdio get stream-close ;\r
 \r
 : crlf   ( -- )              "\r\n" write ;\r
-: bl     ( -- )              " " write ;\r
 \r
 : write-icon ( resource -- )\r
     #! Write an icon. Eg, /library/icons/File.png\r
index fbcd9bb0fd9ebd9d8e6b8771cb067d3788ae68bc..31acd365dc1ab6a4f9f71639ca943b4466ba295e 100644 (file)
 ! Copyright (C) 2003, 2005 Slava Pestov.
 ! See http://factor.sf.net/license.txt for BSD license.
 IN: prettyprint
-USING: alien errors generic hashtables io kernel lists math
-memory namespaces parser presentation sequences strings
-styles unparser vectors words ;
+USING: alien generic hashtables io kernel lists math namespaces
+parser sequences strings styles unparser vectors words ;
 
-SYMBOL: prettyprint-limit
-SYMBOL: one-line
-SYMBOL: tab-size
+! 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
+
+! State
+SYMBOL: column
+SYMBOL: indent
+SYMBOL: last-newline?
+SYMBOL: last-newline
 SYMBOL: recursion-check
+SYMBOL: line-count
+SYMBOL: end-printing
+
+! Configuration
+SYMBOL: margin
+SYMBOL: nesting-limit
+SYMBOL: length-limit
+SYMBOL: line-limit
+
+global [
+    64 margin set
+    recursion-check off
+    0 column set
+    0 indent set
+    last-newline? off
+    0 last-newline set
+    0 line-count set
+] bind
+
+TUPLE: pprinter blocks block ;
+
+GENERIC: pprint-section*
+
+TUPLE: section start end ;
+
+C: section ( length -- section )
+    >r column [ dup rot + dup ] change r>
+    [ set-section-end ] keep
+    [ set-section-start ] keep ;
+
+: section-fits? ( section -- ? )
+    section-end last-newline 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
+    line-limit? [ " ..." write end-printing get call ] when
+    terpri indent get CHAR: \s fill write ;
+
+TUPLE: text string style ;
+
+C: text ( string style -- section )
+    pick length <section> over set-delegate
+    [ set-text-style ] keep
+    [ set-text-string ] keep ;
+
+M: text pprint-section*
+    dup text-string swap text-style format ;
+
+TUPLE: block sections ;
+
+C: block ( -- block )
+    0 <section> over set-delegate
+    { } clone over set-block-sections ;
+
+: add-section ( section stream -- )
+    pprinter-block block-sections push ;
+
+: text ( string style -- )
+    <text> pprinter get add-section ;
+
+: bl ( -- ) " " f text ;
+
+: pprint-section ( section -- )
+    last-newline? get [
+        dup section-fits? [
+            " " write
+        ] [
+            dup fresh-line
+        ] ifte last-newline? off
+    ] when pprint-section* ;
+
+TUPLE: newline forced? ;
+
+C: newline ( forced -- section )
+    1 <section> over set-delegate
+    [ set-newline-forced? ] keep ;
+
+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 ;
 
-GENERIC: prettyprint* ( indent obj -- indent )
+M: block pprint-section* ( block -- )
+    indent get dup >r
+    over block-indent + indent set
+    block-sections [ pprint-section ] each
+    r> indent set ;
 
-: object. ( str obj -- )
-    presented swons unit format ;
+: <block ( -- )
+    pprinter get dup pprinter-block over pprinter-blocks push
+    <block> swap set-pprinter-block ;
 
-: unparse. ( obj -- )
-    [ unparse ] keep object. ;
+: newline ( forced -- )
+    <newline> pprinter get add-section ;
 
-M: object prettyprint* ( indent obj -- indent )
-    unparse. ;
+: end-block ( block -- )
+    column get swap set-section-end ;
 
-M: word prettyprint* ( indent word -- indent )
-    dup parsing? [ \ POSTPONE: unparse. bl ] when unparse. ;
+: pop-block ( pprinter -- )
+    dup pprinter-blocks pop swap set-pprinter-block ;
 
-: indent ( indent -- )
-    #! Print the given number of spaces.
-    CHAR: \s fill write ;
+: block-empty? block-sections empty? ;
 
-: prettyprint-newline ( indent -- )
-    "\n" write indent ;
+: block> ( -- )
+    pprinter get dup pprinter-block dup block-empty? [
+        drop pop-block
+    ] [
+        dup end-block swap dup pop-block add-section
+    ] ifte ;
+
+C: pprinter ( -- stream )
+    { } clone over set-pprinter-blocks
+    <block> over set-pprinter-block ;
+
+: do-pprint ( pprinter -- )
+    [
+        end-printing set
+        dup pprinter-block pprint-section
+    ] callcc0 drop ;
+
+GENERIC: pprint* ( obj -- )
+
+: vocab-style ( vocab -- style )
+    {{
+        [[ "syntax" [ [[ foreground [ 128 128 128 ] ]] ] ]]
+        [[ "kernel" [ [[ foreground [ 0 0 128 ] ]] ] ]]
+        [[ "sequences" [ [[ foreground [ 128 0 0 ] ]] ] ]]
+        [[ "math" [ [[ foreground [ 0 128 0 ] ]] ] ]]
+        [[ "math-internals" [ [[ foreground [ 192 0 0 ] ]] ] ]]
+        [[ "kernel-internals" [ [[ foreground [ 192 0 0 ] ]] ] ]]
+        [[ "io-internals" [ [[ foreground [ 192 0 0 ] ]] ] ]]
+    }} hash ;
 
-: ?prettyprint-newline ( indent -- )
-    one-line get [ bl drop ] [ prettyprint-newline ] ifte ;
+: object-style ( obj -- style )
+    dup word? [ dup word-vocabulary vocab-style ] [ { } ] ifte
+    swap presented swons add ;
 
-: <prettyprint ( indent -- indent )
-    tab-size get + dup ?prettyprint-newline ;
+: pprint-object ( obj -- )
+    dup unparse swap object-style text ;
 
-: prettyprint> ( indent -- indent )
-    tab-size get - one-line get
-    [ dup prettyprint-newline ] unless ;
+M: object pprint* ( obj -- )
+    pprint-object ;
 
-: prettyprint-limit? ( indent -- ? )
-    prettyprint-limit get dup [ >= ] [ nip ] ifte ;
+M: word pprint* ( word -- )
+    dup parsing? [ \ POSTPONE: pprint-object bl ] when
+    pprint-object ;
 
-: check-recursion ( indent obj quot -- indent )
+: nesting-limit? ( -- ? )
+    nesting-limit get dup
+    [ pprinter get pprinter-blocks length < ] when ;
+
+: check-recursion ( obj quot -- indent )
     #! We detect circular structure.
-    pick prettyprint-limit? [
-        2drop "#" write
+    nesting-limit? [
+        2drop "&" f text
     ] [
         over recursion-check get memq? [
-            2drop "&" write
+            2drop "#" f text
         ] [
             over recursion-check [ cons ] change
             call
@@ -58,78 +193,74 @@ M: word prettyprint* ( indent word -- indent )
         ] ifte
     ] ifte ; inline
 
-: prettyprint-elements ( indent list -- indent )
-    [ prettyprint* bl ] each ;
-
-: prettyprint-sequence ( indent start list end -- indent )
-    #! Prettyprint a list, with start/end delimiters; eg, [ ],
-    #! or { }, or << >>. The body of the list is indented,
-    #! unless the list is empty.
-    over [
-        >r >r unparse. <prettyprint
-        r> prettyprint-elements
-        prettyprint> r> unparse.
-    ] [
-        >r >r unparse. bl r> drop r> unparse.
-    ] ifte ;
+: length-limit? ( seq -- seq ? )
+    length-limit get dup
+    [ swap 2dup length < [ head t ] [ nip f ] ifte ]
+    [ drop f ] ifte ;
 
-M: cons prettyprint* ( indent list -- indent )
+: pprint-elements ( seq -- )
+    length-limit? >r
+    [ pprint* f newline ] each
+    r> [ "... " f text ] when ;
+
+: pprint-sequence ( seq start end -- )
+    <block swap pprint-object f newline
+    swap pprint-elements pprint-object block> ;
+
+M: cons pprint* ( list -- )
    [
-       dup list? [
-           \ [ swap \ ]
-       ] [
-           \ [[ swap uncons 2list \ ]]
-       ] ifte prettyprint-sequence
+       dup list? [ \ [ \ ] ] [ uncons 2list \ [[ \ ]] ] ifte
+       pprint-sequence
    ] check-recursion ;
 
-M: vector prettyprint* ( indent vector -- indent )
-    [
-        \ { swap \ } prettyprint-sequence
-    ] check-recursion ;
+M: vector pprint* ( vector -- )
+    [ \ { \ } pprint-sequence ] check-recursion ;
 
-M: hashtable prettyprint* ( indent hashtable -- indent )
-    [
-        \ {{ swap hash>alist \ }} prettyprint-sequence
-    ] check-recursion ;
+M: hashtable pprint* ( hashtable -- )
+    [ hash>alist \ {{ \ }} pprint-sequence ] check-recursion ;
 
-M: tuple prettyprint* ( indent tuple -- indent )
-    [
-        \ << swap <mirror> \ >> prettyprint-sequence
-    ] check-recursion ;
+M: tuple pprint* ( tuple -- )
+    [ <mirror> \ << \ >> pprint-sequence ] check-recursion ;
 
-M: alien prettyprint* ( alien -- )
-    \ ALIEN: unparse. bl alien-address unparse write ;
+M: alien pprint* ( alien -- )
+    \ ALIEN: pprint-object bl alien-address pprint-object ;
 
-M: wrapper prettyprint* ( wrapper -- )
+M: wrapper pprint* ( wrapper -- )
     dup wrapped word? [
-        \ \ unparse. bl wrapped unparse.
+        \ \ pprint-object bl wrapped pprint-object
     ] [
-        \ W[ unparse. bl wrapped prettyprint* \ ]W unparse.
+        wrapped 1vector \ W[ \ ]W pprint-sequence
     ] ifte ;
 
-: prettyprint ( obj -- )
+: with-pprint ( quot -- )
     [
-        recursion-check off
-        0 swap prettyprint* drop terpri
-    ] with-scope ;
+        <pprinter> pprinter set call pprinter get do-pprint
+    ] with-scope ; inline
+
+: pprint ( object -- )
+    [ pprint* ] with-pprint ;
+
+: pprint>string ( object -- string )
+    [ pprint ] string-out ;
+
+: pp ( obj -- ) pprint terpri ;
 
 : . ( obj -- )
-    [
-        one-line on
-        16 prettyprint-limit set
-        prettyprint
-    ] with-scope ;
+    [ 2 nesting-limit set 100 length-limit set pp ] with-scope ;
 
 : [.] ( sequence -- )
     #! Unparse each element on its own line.
-    [ . ] each ;
+    [
+        1 line-limit set 10 length-limit set
+        [ pp ] each
+    ] with-scope ;
+
+: stack. reverse-slice [.] ;
 
-: .s datastack  reverse [.] flush ;
-: .r callstack  reverse [.] flush ;
+: .s datastack stack. ;
+: .r callstack stack. ;
 
 ! For integers only
 : .b >bin print ;
 : .o >oct print ;
 : .h >hex print ;
-
-global [ 4 tab-size set ] bind
index 381c58b66cd3cdb2dcab2ba43844dacb8c5568bf..1c47e3db1e13d22dcfe499766e8846ae1f5e4a1a 100644 (file)
 ! Copyright (C) 2003, 2005 Slava Pestov.
 ! See http://factor.sf.net/license.txt for BSD license.
 IN: prettyprint
-USING: generic hashtables io kernel lists namespaces sequences
-streams strings styles unparser words ;
+USING: generic io kernel lists namespaces sequences styles words ;
 
-: prettyprint-IN: ( word -- )
-    \ IN: unparse. bl word-vocabulary write terpri ;
+: declaration. ( word prop -- )
+    tuck word-name word-prop
+    [ bl pprint-object ] [ drop ] ifte ;
 
-: prettyprint-prop ( word prop -- )
-    tuck word-name word-prop [
-        bl unparse.
-    ] [
-        drop
-    ] ifte ;
-
-: prettyprint-plist ( word -- )
+: declarations. ( word -- )
     [
         POSTPONE: parsing
         POSTPONE: inline
         POSTPONE: foldable
         POSTPONE: flushable
-    ] [ prettyprint-prop ] each-with ;
+    ] [ declaration. ] each-with ;
 
 : comment. ( comment -- )
-    [ [[ font-style italic ]] ] format ;
+    [ [[ font-style italic ]] ] text ;
 
-: infer-effect. ( effect -- )
-    [
-        "(" %
-        2unlist >r [ " " % unparse % ] each r>
-        " --" %
-        [ " " % unparse % ] each
-        " )" %
-    ] make-string comment. ;
-
-: stack-effect. ( word -- )
-    dup "stack-effect" word-prop [
-        [ CHAR: ( , % CHAR: ) , ] make-string
-        comment.
-    ] [
-        "infer-effect" word-prop dup [
-            infer-effect.
-        ] [
-            drop
-        ] ifte
-    ] ?ifte ;
-
-: documentation. ( indent word -- indent )
-    "documentation" word-prop [
-        "\n" split [
-            "#!" swap append comment.
-            dup prettyprint-newline
-        ] each
-    ] when* ;
-
-: definer. ( word -- ) dup definer unparse. bl unparse. bl ;
-
-GENERIC: (see) ( word -- )
+: stack-picture ( seq -- string )
+    [ [ word-name % " " % ] each ] make-string ;
 
-M: compound (see) ( word -- )
-    tab-size get dup indent swap
-    [ documentation. ] keep
-    [ word-def prettyprint-elements \ ; unparse. ] keep
-    prettyprint-plist terpri drop ;
+: effect>string ( effect -- string )
+    2unseq stack-picture >r stack-picture "-- " r> append3 ;
 
-: prettyprint-M: ( -- indent )
-    \ M: unparse. bl tab-size get ;
+: stack-effect ( word -- string )
+    dup "stack-effect" word-prop [ ] [
+        "infer-effect" word-prop
+        dup [ effect>string ] when
+    ] ?ifte ;
 
-: prettyprint-; \ ; unparse. terpri ;
+: stack-effect. ( string -- )
+    [ bl "( " swap ")" append3 comment. ] when* ;
 
-: method. ( word [[ class method ]] -- )
-    uncons >r >r >r prettyprint-M: r> r> unparse. bl unparse. bl
-    dup prettyprint-newline r> prettyprint-elements
-    prettyprint-; drop ;
-
-M: generic (see) ( word -- )
-    tab-size get dup indent [
-        one-line on
-        over "picker" word-prop prettyprint* bl
-        over "combination" word-prop prettyprint* bl
-    ] with-scope
-    drop
-    \ ; unparse.
-    dup prettyprint-plist
-    terpri
-    dup methods [ method. ] each-with ;
+: in. ( word -- )
+    <block \ IN: pprint-object bl word-vocabulary f text block>
+    t newline ;
 
-M: word (see) drop ;
+: definer. ( word -- )
+    dup definer pprint-object bl
+    dup pprint-object
+    stack-effect stack-effect.
+    f newline ;
 
-GENERIC: class.
+GENERIC: (see) ( word -- )
 
-M: union class.
-    \ UNION: unparse. bl
-    dup unparse. bl
-    0 swap "members" word-prop prettyprint-elements drop
-    prettyprint-; ;
+M: word (see) definer. t newline ;
 
-M: complement class.
-    \ COMPLEMENT: unparse. bl
-    dup unparse. bl
-    "complement" word-prop unparse. terpri ;
+: documentation. ( word -- )
+    "documentation" word-prop [
+        "\n" split [ "#!" swap append comment. t newline ] each
+    ] when* ;
 
-M: predicate class.
-    \ PREDICATE: unparse. bl
-    dup "superclass" word-prop unparse. bl
-    dup unparse. bl
-    tab-size get dup prettyprint-newline swap
-    "definition" word-prop prettyprint-elements drop
-    prettyprint-; ;
+: see-body ( quot word -- )
+    dup definer. <block dup documentation. swap pprint-elements
+    \ ; pprint-object declarations. block> ;
 
-M: tuple-class class.
-    \ TUPLE: unparse. bl
-    dup unparse. bl
-    "slot-names" word-prop [ write bl ] each
-    prettyprint-; ;
+M: compound (see)
+    dup word-def swap see-body t newline ;
 
-M: word class. drop ;
+: method. ( word [[ class method ]] -- )
+    <block
+    \ M: pprint-object bl
+    unswons pprint-object bl
+    swap pprint-object t newline
+    pprint-elements \ ; pprint-object
+    block> t newline ;
+
+M: generic (see)
+    <block
+    dup dup { "picker" "combination" } [ word-prop ] map-with
+    swap see-body block> t newline
+    dup methods [ method. ] each-with ;
 
 : see ( word -- )
-    dup prettyprint-IN: dup definer.
-    dup stack-effect. terpri dup (see) class. ;
-
-: methods. ( class -- )
-    #! List all methods implemented for this class.
-    dup class.
-    dup implementors [
-        dup prettyprint-IN:
-        [ "methods" word-prop hash* ] keep swap method.
-    ] each-with ;
+    [ dup in. (see) ] with-pprint ;
index 965eeda937d45b333665ae2b43579081d39c141e..e8abcdcf16276b73ecbb4f04c08b427c5479e532 100644 (file)
@@ -80,10 +80,6 @@ USE: sequences
     [ [ 2 2 + unparse print ] string-out ] test-interpreter
 ] unit-test
 
-[ { "4" } ] [
-    [ [ 0 2 2 + prettyprint* drop ] string-out ] test-interpreter
-] unit-test
-
 [ { "4\n" } ] [
     [ [ 2 2 + . ] string-out ] test-interpreter
 ] unit-test
diff --git a/library/test/prettyprint.factor b/library/test/prettyprint.factor
new file mode 100644 (file)
index 0000000..6e8dd2d
--- /dev/null
@@ -0,0 +1,41 @@
+IN: temporary
+USING: io kernel math sequences test xp ;
+
+[ "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
+
+[ "+" ] [ \ + pprint>string ] unit-test
+
+[ "\\ +" ] [ [ \ + ] first pprint>string ] unit-test
+
+[ "1" ] [
+    [ [ <block 1 pprint-object block> ] with-pprint ] string-out
+] unit-test
+
+[ "{ }" ] [ { } pprint>string ] unit-test
+
+[ "{ 1 2 3 }" ] [ { 1 2 3 } pprint>string ] unit-test
+
+[ "\"hello\\\\backslash\"" ]
+[ "hello\\backslash" pprint>string ]
+unit-test
+
+[ "\"\\u1234\"" ]
+[ "\u1234" pprint>string ]
+unit-test
+
+[ "\"\\e\"" ]
+[ "\e" pprint>string ]
+unit-test
+
+[ "f" ] [ f pprint>string ] unit-test
+[ "t" ] [ t pprint>string ] unit-test
+
+[ "SBUF\" hello world\"" ] [ SBUF" hello world" pprint>string ] unit-test
+
+: foo dup * ; inline
+
+[ "IN: temporary\n: foo dup * ; inline\n" ]
+[ [ \ foo see ] string-out ] unit-test
diff --git a/library/test/unparser.factor b/library/test/unparser.factor
deleted file mode 100644 (file)
index c6d157d..0000000
+++ /dev/null
@@ -1,32 +0,0 @@
-IN: temporary
-USE: lists
-USE: math
-USE: parser
-USE: test
-USE: unparser
-USE: kernel
-USE: kernel-internals
-USE: io-internals
-
-[ "\"hello\\\\backslash\"" ]
-[ "hello\\backslash" unparse ]
-unit-test
-
-[ "\"\\u1234\"" ]
-[ "\u1234" unparse ]
-unit-test
-
-[ "\"\\e\"" ]
-[ "\e" unparse ]
-unit-test
-
-[ "1.0" ] [ 1.0 unparse ] unit-test
-[ "f" ] [ f unparse ] unit-test
-[ "t" ] [ t unparse ] unit-test
-[ "car" ] [ \ car unparse ] unit-test
-[ "#{ 1/2 2/3 }#" ] [ #{ 1/2 2/3 }# unparse ] unit-test
-[ "1267650600228229401496703205376" ] [ 1 100 shift unparse ] unit-test
-
-[ ] [ { 1 2 3 } unparse drop ] unit-test
-
-[ "SBUF\" hello world\"" ] [ SBUF" hello world" unparse ] unit-test
index 57446d828972268c91cb12af5de181f828cc00e3..b22e6774e453fa575d18124e8e4d2d1edee94f16 100644 (file)
@@ -17,8 +17,8 @@ vectors words ;
 : type-check-error. ( list -- )
     "Type check error" print
     uncons car dup "Object: " write .
-    "Object type: " write class unparse. terpri
-    "Expected type: " write type>class unparse. terpri ;
+    "Object type: " write class pp
+    "Expected type: " write type>class pp ;
 
 : float-format-error. ( list -- )
     "Invalid floating point literal format: " write . ;
@@ -102,10 +102,8 @@ M: object error. ( error -- ) . ;
 : :get ( var -- value ) "error-namestack" get (get) ;
 
 : debug-help ( -- )
-    [ :s :r ] [ unparse. bl ] each
-    "show stacks at time of error." print
-    \ :get unparse.
-    " ( var -- value ) inspects the error namestack." print ;
+    ":s :r show stacks at time of error." print
+    ":get ( var -- value ) inspects the error namestack." print ;
 
 : flush-error-handler ( error -- )
     #! Last resort.
index 3bf1d81626a9eb320348be9d2b338e32f8dd092e..43dd1c2470413dc9c06748cf3d443d7f19869aa4 100644 (file)
@@ -57,16 +57,16 @@ M: word extra-banner ( obj -- )
     dup vocab-banner
     metaclass [
         "This is a class whose behavior is specifed by the " write
-        unparse. " metaclass." print
+        pprint " metaclass." print
     ] when* ;
 
 M: object extra-banner ( obj -- ) drop ;
 
 : inspect-banner ( obj -- )
-    "You are looking at an instance of the " write dup class unparse.
+    "You are looking at an instance of the " write dup class pprint
     " class:" print
-    "  " write dup unparse. terpri
-    "It takes up " write dup size unparse write " bytes of memory." print
+    "  " write dup pp
+    "It takes up " write dup size pprint " bytes of memory." print
     extra-banner ;
 
 : describe ( obj -- )
index 050bfdaa51b413041b9bb04e1e2917dd6e04d91b..8fb83c2828ae6c1ff370924632f73aba19afdb70 100644 (file)
@@ -42,14 +42,12 @@ sequences io strings vectors words ;
     set-callstack call ;
 
 : walk-banner ( -- )
-    [ &s &r ] [ unparse. bl ] each
-    "show stepper stacks." print
-    \ &get unparse.
-    " ( var -- value ) inspects the stepper namestack." print
-    \ step unparse. " -- single step over" print
-    \ into unparse. " -- single step into" print
-    \ continue unparse. " -- continue execution" print
-    \ bye unparse. " -- exit single-stepper" print
+    "&s &r show stepper stacks." print
+    "&get ( var -- value ) inspects the stepper namestack." print
+    "step -- single step over" print
+    "into -- single step into" print
+    "continue -- continue execution" print
+    "bye -- exit single-stepper" print
     report ;
 
 : walk-listener walk-banner "walk " listener-prompt set listener ;
index 47fa520d73ddf5cef18f55037eac4fb5a0542dfa..29a2fd396bbcddb5be0dc5451a66ed4827e36be7 100644 (file)
@@ -47,7 +47,7 @@ global [ 100 <vector> commands set ] bind
     "This stream does not support live gadgets"
     swap format terpri ;
 
-[ drop t ] "Prettyprint" [ prettyprint ] define-command
+[ drop t ] "Prettyprint" [ pp ] define-command
 [ drop t ] "Inspect" [ inspect ] define-command
 [ drop t ] "References" [ references inspect ] define-command