Fix prettyprint of CONSTANT: and ALIAS:

db4
Slava Pestov 2009-04-05 20:44:34 -05:00
parent 87121c1468
commit 68728d1cc4
5 changed files with 45 additions and 7 deletions

View File

@ -0,0 +1,11 @@
IN: see.tests
USING: see tools.test io.streams.string math ;
CONSTANT: test-const 10
[ "IN: see.tests\nCONSTANT: test-const 10 inline\n" ]
[ [ \ test-const see ] with-string-writer ] unit-test
ALIAS: test-alias +
[ "USING: math ;\nIN: see.tests\nALIAS: test-alias + inline\n" ]
[ [ \ test-alias see ] with-string-writer ] unit-test

View File

@ -7,7 +7,7 @@ definitions effects generic generic.standard io io.pathnames
io.streams.string io.styles kernel make namespaces prettyprint io.streams.string io.styles kernel make namespaces prettyprint
prettyprint.backend prettyprint.config prettyprint.custom prettyprint.backend prettyprint.config prettyprint.custom
prettyprint.sections sequences sets sorting strings summary prettyprint.sections sequences sets sorting strings summary
words words.symbol ; words words.symbol words.constant words.alias ;
IN: see IN: see
GENERIC: synopsis* ( defspec -- ) GENERIC: synopsis* ( defspec -- )
@ -29,8 +29,16 @@ GENERIC: see* ( defspec -- )
: comment. ( text -- ) : comment. ( text -- )
H{ { font-style italic } } styled-text ; H{ { font-style italic } } styled-text ;
GENERIC: print-stack-effect? ( word -- ? )
M: parsing-word print-stack-effect? drop f ;
M: symbol print-stack-effect? drop f ;
M: constant print-stack-effect? drop f ;
M: alias print-stack-effect? drop f ;
M: word print-stack-effect? drop t ;
: stack-effect. ( word -- ) : stack-effect. ( word -- )
[ [ parsing-word? ] [ symbol? ] bi or not ] [ stack-effect ] bi and [ print-stack-effect? ] [ stack-effect ] bi and
[ effect>string comment. ] when* ; [ effect>string comment. ] when* ;
<PRIVATE <PRIVATE

View File

@ -1,6 +1,6 @@
! Copyright (C) 2008 Doug Coleman. ! Copyright (C) 2008 Doug Coleman.
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
USING: quotations effects accessors sequences words kernel ; USING: quotations effects accessors sequences words kernel definitions ;
IN: words.alias IN: words.alias
PREDICATE: alias < word "alias" word-prop ; PREDICATE: alias < word "alias" word-prop ;
@ -12,5 +12,6 @@ PREDICATE: alias < word "alias" word-prop ;
M: alias reset-word M: alias reset-word
[ call-next-method ] [ f "alias" set-word-prop ] bi ; [ call-next-method ] [ f "alias" set-word-prop ] bi ;
M: alias stack-effect M: alias definer drop \ ALIAS: f ;
def>> first stack-effect ;
M: alias definition def>> first 1quotation ;

View File

@ -0,0 +1,14 @@
IN: words.constant.tests
USING: tools.test math ;
CONSTANT: a +
[ + ] [ a ] unit-test
CONSTANT: b \ +
[ \ + ] [ b ] unit-test
CONSTANT: c { 1 2 3 }
[ { 1 2 3 } ] [ c ] unit-test

View File

@ -1,6 +1,6 @@
! Copyright (C) 2008 Slava Pestov. ! Copyright (C) 2008, 2009 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
USING: accessors kernel sequences words ; USING: accessors kernel sequences words definitions quotations ;
IN: words.constant IN: words.constant
PREDICATE: constant < word ( obj -- ? ) PREDICATE: constant < word ( obj -- ? )
@ -8,3 +8,7 @@ PREDICATE: constant < word ( obj -- ? )
: define-constant ( word value -- ) : define-constant ( word value -- )
[ ] curry (( -- value )) define-inline ; [ ] curry (( -- value )) define-inline ;
M: constant definer drop \ CONSTANT: f ;
M: constant definition def>> first literalize 1quotation ;