]> gitweb.factorcode.org Git - factor.git/commitdiff
presentation fixes, prettyprinter cleanup
authorSlava Pestov <slava@factorcode.org>
Thu, 14 Jul 2005 02:51:43 +0000 (02:51 +0000)
committerSlava Pestov <slava@factorcode.org>
Thu, 14 Jul 2005 02:51:43 +0000 (02:51 +0000)
14 files changed:
library/collections/namespaces.factor
library/syntax/parse-syntax.factor
library/syntax/prettyprint.factor
library/syntax/see.factor
library/tools/debugger.factor
library/tools/inspector.factor
library/tools/walker.factor
library/ui/hand.factor
library/ui/init-world.factor
library/ui/load.factor
library/ui/panes.factor
library/ui/presentations.factor
library/ui/world.factor
library/words.factor

index fd6b724e4d2bf878d2011f1fee7ae1922f72cfff..e359c7246f0edd0c411eb6ce964148fe0ff9771e 100644 (file)
@@ -2,7 +2,7 @@
 ! See http://factor.sf.net/license.txt for BSD license.
 IN: namespaces
 USING: hashtables kernel kernel-internals lists math sequences
-strings vectors ;
+strings vectors words ;
 
 ! Variables in Factor:
 !
@@ -117,7 +117,7 @@ SYMBOL: building
 : literal, ( word -- )
     #! Append some code that pushes the word on the stack. Used
     #! when building quotations.
-    unit , \ car , ;
+    literalize % ;
 
 : unique, ( obj -- )
     #! Add the object to the sequence being built with make-seq
index 2f355de4bcb98f221e1df7cd60bbe13565922ba1..335ab445efdfa330ad935abb8e51667abb4718c5 100644 (file)
@@ -73,11 +73,7 @@ BUILTIN: f 9 not ;
 : \
     #! Parsed as a piece of code that pushes a word on the stack
     #! \ foo ==> [ foo ] car
-    scan-word dup word? [
-        unit swons  \ car swons
-    ] [
-        swons
-    ] ifte ; parsing
+    scan-word literalize [ swons ] each ; parsing
 
 ! Vocabularies
 : PRIMITIVE:
index cb7220b4e4020a12d2178d2a905089802d0ba90a..396b52924c0cdbdb4cf9e14fdd3d617c0ad1ce90 100644 (file)
@@ -12,25 +12,14 @@ SYMBOL: recursion-check
 
 GENERIC: prettyprint* ( indent obj -- indent )
 
-M: object prettyprint* ( indent obj -- indent )
+: unparse. ( obj -- )
     dup unparse swap presented swons unit write-attr ;
 
-: word-attrs ( word -- style )
-    #! Return the style values for the HTML word browser
-    [
-        presented over cons ,
-        dup word-vocabulary [ 
-            "word" over word-name cons ,
-            "vocab" swap word-vocabulary cons ,
-        ] [
-            drop
-        ] ifte
-    ] make-list ;
-
-: word. ( word -- ) dup word-name swap word-attrs write-attr ;
+M: object prettyprint* ( indent obj -- indent )
+    unparse. ;
 
 M: word prettyprint* ( indent word -- indent )
-    dup parsing? [ \ POSTPONE: word. bl ] when word. ;
+    dup parsing? [ \ POSTPONE: unparse. bl ] when unparse. ;
 
 : indent ( indent -- )
     #! Print the given number of spaces.
@@ -54,8 +43,8 @@ M: word prettyprint* ( indent word -- indent )
 : prettyprint-elements ( indent list -- indent )
     [
         dup \? [
-            \ \ word. bl
-            uncons >r car word. bl
+            \ \ unparse. bl
+            uncons >r car unparse. bl
             r> cdr prettyprint-elements
         ] [
             uncons >r prettyprint* bl
@@ -96,11 +85,11 @@ M: word prettyprint* ( indent word -- indent )
     #! or { }, or << >>. The body of the list is indented,
     #! unless the list is empty.
     over [
-        >r >r word. <prettyprint
+        >r >r unparse. <prettyprint
         r> prettyprint-elements
-        prettyprint> r> word.
+        prettyprint> r> unparse.
     ] [
-        >r >r word. bl r> drop r> word.
+        >r >r unparse. bl r> drop r> unparse.
     ] ifte ;
 
 M: list prettyprint* ( indent list -- indent )
@@ -130,16 +119,16 @@ M: tuple prettyprint* ( indent tuple -- indent )
     ] check-recursion ;
 
 M: alien prettyprint* ( alien -- str )
-    \ ALIEN: word. bl alien-address unparse write ;
+    \ ALIEN: unparse. bl alien-address unparse write ;
 
 : matrix-rows. ( indent list -- indent )
     uncons >r [ one-line on prettyprint* ] with-scope r>
     [ over ?prettyprint-newline matrix-rows. ] when* ;
 
 M: matrix prettyprint* ( indent obj -- indent )
-    \ M[ word. bl >r 3 + r>
+    \ M[ unparse. bl >r 3 + r>
     row-list matrix-rows.
-    bl \ ]M word. 3 - ;
+    bl \ ]M unparse. 3 - ;
 
 : prettyprint ( obj -- )
     [
@@ -147,9 +136,6 @@ M: matrix prettyprint* ( indent obj -- indent )
         0 swap prettyprint* drop terpri
     ] with-scope ;
 
-: vocab-link ( vocab -- link )
-    "vocabularies'" swap append ;
-
 : . ( obj -- )
     [
         one-line on
index 52f9a9474f954aecc305249964373fc38747ce24..63b18999bf6fddd6c6b103562ce57da788152a53 100644 (file)
@@ -20,11 +20,11 @@ streams strings styles unparser words ;
 : vocab. ( vocab -- ) dup vocab-attrs write-attr ;
 
 : prettyprint-IN: ( word -- )
-    \ IN: word. bl word-vocabulary vocab. terpri ;
+    \ IN: unparse. bl word-vocabulary vocab. terpri ;
 
 : prettyprint-prop ( word prop -- )
     tuck word-name word-prop [
-        bl word.
+        bl unparse.
     ] [
         drop
     ] ifte ;
@@ -72,23 +72,23 @@ streams strings styles unparser words ;
         ] each
     ] when* ;
 
-: definer. ( word -- ) dup definer word. bl word. bl ;
+: definer. ( word -- ) dup definer unparse. bl unparse. bl ;
 
 GENERIC: (see) ( word -- )
 
 M: compound (see) ( word -- )
     tab-size get dup indent swap
     [ documentation. ] keep
-    [ word-def prettyprint-elements \ ; word. ] keep
+    [ word-def prettyprint-elements \ ; unparse. ] keep
     prettyprint-plist terpri drop ;
 
 : prettyprint-M: ( -- indent )
-    \ M: word. bl tab-size get ;
+    \ M: unparse. bl tab-size get ;
 
-: prettyprint-; \ ; word. terpri ;
+: prettyprint-; \ ; unparse. terpri ;
 
 : method. ( word [[ class method ]] -- )
-    uncons >r >r >r prettyprint-M: r> r> word. bl word. bl
+    uncons >r >r >r prettyprint-M: r> r> unparse. bl unparse. bl
     dup prettyprint-newline r> prettyprint-elements
     prettyprint-; drop ;
 
@@ -99,7 +99,7 @@ M: generic (see) ( word -- )
         over "dispatcher" word-prop prettyprint* bl
     ] with-scope
     drop
-    \ ; word. terpri
+    \ ; unparse. terpri
     dup methods [ method. ] each-with ;
 
 M: word (see) drop ;
@@ -107,34 +107,34 @@ M: word (see) drop ;
 GENERIC: class.
 
 M: union class.
-    \ UNION: word. bl
-    dup word. bl
+    \ UNION: unparse. bl
+    dup unparse. bl
     0 swap "members" word-prop prettyprint-elements drop
     prettyprint-; ;
 
 M: complement class.
-    \ COMPLEMENT: word. bl
-    dup word. bl
-    "complement" word-prop word. terpri ;
+    \ COMPLEMENT: unparse. bl
+    dup unparse. bl
+    "complement" word-prop unparse. terpri ;
 
 M: builtin class.
-    \ BUILTIN: word. bl
-    dup word. bl
+    \ BUILTIN: unparse. bl
+    dup unparse. bl
     dup "builtin-type" word-prop unparse write bl
     0 swap "slots" word-prop prettyprint-elements drop
     prettyprint-; ;
 
 M: predicate class.
-    \ PREDICATE: word. bl
-    dup "superclass" word-prop word. bl
-    dup word. bl
+    \ 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-; ;
 
 M: tuple-class class.
-    \ TUPLE: word. bl
-    dup word. bl
+    \ TUPLE: unparse. bl
+    dup unparse. bl
     "slot-names" word-prop [ write bl ] each
     prettyprint-; ;
 
index 705d9f70c66d3a06252e651a2fbb8f431b9a2e92..70519589cfe0bc34913e601850a44489d1f9fcfb 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 word. terpri
-    "Expected type: " write builtin-type word. terpri ;
+    "Object type: " write class unparse. terpri
+    "Expected type: " write builtin-type unparse. terpri ;
 
 : float-format-error. ( list -- )
     "Invalid floating point literal format: " write . ;
@@ -86,9 +86,9 @@ M: object error. ( error -- ) . ;
 : :get ( var -- value ) "error-namestack" get (get) ;
 
 : debug-help ( -- )
-    [ :s :r :n :c ] [ word. bl ] each
+    [ :s :r :n :c ] [ unparse. bl ] each
     "show stacks at time of error." print
-    \ :get word.
+    \ :get unparse.
     " ( var -- value ) inspects the error namestack." print ;
 
 : flush-error-handler ( error -- )
index 1a6994a0cdb18364fd59760ed21668aa6c7b3189..d0ba46eb8af7787577d8e3f4c0d321807559ee3e 100644 (file)
@@ -48,19 +48,13 @@ M: hashtable sheet hash>alist unzip 2list ;
     seq-transpose
     [ " | " join ] map ;
 
-: a/an ( noun -- str )
-    first "aeiouAEIOU" contains? "an " "a " ? ;
-
-: a/an. ( noun -- )
-    dup a/an write write ;
-
 : interned? ( word -- ? )
     dup word-name swap word-vocabulary vocab hash ;
 
 : class-banner ( word -- )
     dup metaclass dup [
         "This is a class whose behavior is specifed by the " write
-        unparse write " metaclass," print
+        unparse. " metaclass," print
         "currently having " write
         "predicate" word-prop instances length unparse write
         " instances." print
@@ -91,9 +85,9 @@ M: object extra-banner ( obj -- ) drop ;
 
 : inspect-banner ( obj -- )
     dup references length >r
-    "You are looking at " write dup class unparse a/an.
-    " object with the following printed representation:" print
-    "  " write dup unparse print
+    "You are looking at an instance of the " write dup class unparse.
+    " class:" print
+    "  " write dup unparse. terpri
     "The object has been placed in the inspecting variable." print
     "It is located at address " write dup address >hex write
     " and takes up " write dup size unparse write
index 4d925502cd53bf49d45146f58ddeb609210ebf7a..9aa414aec880c0a07dab664d37701ac37497831d 100644 (file)
@@ -50,14 +50,14 @@ sequences io strings vectors words ;
     set-callstack call ;
 
 : walk-banner ( -- )
-    [ &s &r &n &c ] [ word. bl ] each
+    [ &s &r &n &c ] [ unparse. bl ] each
     "show stepper stacks." print
-    \ &get word.
+    \ &get unparse.
     " ( var -- value ) inspects the stepper namestack." print
-    \ step word. " -- single step over" print
-    \ into word. " -- single step into" print
-    \ continue word. " -- continue execution" print
-    \ bye word. " -- exit single-stepper" print
+    \ step unparse. " -- single step over" print
+    \ into unparse. " -- single step into" print
+    \ continue unparse. " -- continue execution" print
+    \ bye unparse. " -- exit single-stepper" print
     report ;
 
 : walk-listener walk-banner "walk " listener-prompt set listener ;
index 033dbc5a29ae2a97c83144bbc76cb4fb03301bec..33c979de0c2d70eb91a13dea9a0437cf77b1b383 100644 (file)
@@ -42,6 +42,8 @@ C: hand ( world -- hand )
     [ set-gadget-parent ] 2keep
     [ set-hand-gadget ] keep ;
 
+: hand world get world-hand ;
+
 : button/ ( n hand -- )
     dup hand-gadget over set-hand-clicked
     dup screen-loc over set-hand-click-loc
index 61bf0d0a1df47a30a1d3334e239ff4eb84a612b2..cca0fadff7af58bcee06cb8c49f07a94082421e4 100644 (file)
@@ -5,9 +5,6 @@ USING: generic io kernel listener math namespaces styles threads ;
 
 SYMBOL: stack-display
 
-: <stack-display>
-     ;
-
 : init-world
     global [
         <world> world set
index 913da986a631769950d9bc6bd660638372f3d83c..1971521e0f526bb5db14a4331ba78f691f7abbbb 100644 (file)
@@ -7,11 +7,11 @@ USING: kernel parser sequences io ;
     "/library/ui/fonts.factor"
     "/library/ui/text.factor"
     "/library/ui/gestures.factor"
-    "/library/ui/hand.factor"
     "/library/ui/layouts.factor"
     "/library/ui/borders.factor"
     "/library/ui/frames.factor"
     "/library/ui/world.factor"
+    "/library/ui/hand.factor"
     "/library/ui/labels.factor"
     "/library/ui/buttons.factor"
     "/library/ui/line-editor.factor"
@@ -20,9 +20,9 @@ USING: kernel parser sequences io ;
     "/library/ui/editors.factor"
     "/library/ui/menus.factor"
     "/library/ui/splitters.factor"
-    "/library/ui/presentations.factor"
     "/library/ui/incremental.factor"
     "/library/ui/panes.factor"
+    "/library/ui/presentations.factor"
     "/library/ui/init-world.factor"
     "/library/ui/ui.factor"
 ] [
index fecbee8ff8fb43c5501ee30566b4cd16a7a26feb..587b07a355bfb4581a2afcaae68a52dfd9ca6ee6 100644 (file)
@@ -4,6 +4,8 @@ IN: gadgets
 USING: generic hashtables io kernel line-editor listener lists
 math namespaces prettyprint sequences strings styles threads ;
 
+DEFER: <presentation>
+
 ! A pane is an area that can display text.
 
 ! output: pile
@@ -62,7 +64,7 @@ M: pane focusable-child* ( pane -- editor )
     pane-input ;
 
 : pane-write-1 ( style text pane -- )
-    [ <presentation> ] keep pane-current add-gadget ;
+    >r <presentation> r> pane-current add-gadget ;
 
 : pane-terpri ( pane -- )
     dup pane-current over pane-output add-incremental
index 30de321d803cb3604543981c1638439e529484ed..364538ac19cb270dccfdee4cf31093759c34aee6 100644 (file)
@@ -11,39 +11,36 @@ global [ 100 <vector> commands set ] bind
 : define-command ( class name quot -- )
     3list commands get push ;
 
-: applicable ( object -- )
-    commands get >list
-    [ car call ] subset-with ;
-
-DEFER: pane-call
-
-: command-menu ( pane -- menu )
-    presented get dup applicable [
-        3dup third [
-            [ swap literal, % ] make-list , ,
-            [ pane-call drop ] %
-        ] make-list >r second r> cons
-    ] map 2nip ;
-
-: init-commands ( gadget pane -- )
-    over presented paint-prop [
-        [ drop ] swap
-        unit
-        [ command-menu <menu> show-menu ] append3
+: applicable ( object -- list )
+    commands get >list [ car call ] subset-with ;
+
+: command-quot ( presented quot -- quot )
+    [ swap literal, % ] make-list
+    [ pane get pane-call drop ] cons ;
+
+: command-menu ( presented -- menu )
+    dup applicable
+    [ [ third command-quot ] keep second swons ] map-with
+    <menu> ;
+
+: init-commands ( gadget -- )
+    dup presented paint-prop dup [
+        [
+            \ drop ,
+            literal,
+            [ command-menu show-menu ] %
+        ] make-list
         button-gestures
     ] [
         2drop
     ] ifte ;
 
 : <styled-label> ( style text -- label )
-    <label> swap alist>hash over set-gadget-paint ;
+    <label> swap dup [ alist>hash ] when over set-gadget-paint ;
 
-: <presentation> ( style text pane -- presentation )
-    pick gadget swap assoc dup [
-        >r 3drop r>
-    ] [
-        drop >r <styled-label> dup r> init-commands
-    ] ifte ;
+: <presentation> ( style text -- presentation )
+    gadget pick assoc dup
+    [ 2nip ] [ drop <styled-label> dup init-commands ] ifte ;
 
 : gadget. ( gadget -- )
     gadget swons unit "" swap write-attr ;
index db3454e060512ff1598b3feb18222bd8849dc295..57a3da2a3bf3aa5c025862b6acd4dbcb38ec43cb 100644 (file)
@@ -11,6 +11,8 @@ vectors ;
 ! need to be layout.
 TUPLE: world running? hand glass invalid ;
 
+DEFER: <hand>
+
 C: world ( -- world )
     f <stack> over set-delegate
     t over set-world-running?
@@ -42,11 +44,8 @@ C: world ( -- world )
 
 M: world inside? ( point world -- ? ) 2drop t ;
 
-: hand world get world-hand ;
-
 : draw-world ( world -- )
     [
-        dup
         { 0 0 0 } width get height get 0 3vector <rectangle> clip set
         draw-gadget
     ] with-surface ;
@@ -55,7 +54,7 @@ DEFER: handle-event
 
 : world-step ( -- ? )
     world get dup world-invalid >r layout-world r>
-    [ dup world-hand update-hand draw-world ] [ drop ] ifte ;
+    [ draw-world ] [ drop ] ifte ;
 
 : next-event ( -- event ? )
     <event> dup SDL_PollEvent ;
index f9dc56b1a943fb1a25efe25998348781fb38b74a..3157620f72624f9c3f9e68086272864890b28cfb 100644 (file)
@@ -121,3 +121,7 @@ M: compound definer drop \ : ;
     over f "picker" set-word-prop
     over f "dispatcher" set-word-prop
     (define-compound) ;
+
+: literalize ( word/obj -- quot )
+    #! Produce a quotation that pushes this object.
+    dup word? [ unit [ car ] ] [ f ] ifte cons ;