Add a lint check for swap .. swap that can be replaced by dip. Clean up the cases it finds.

db4
Doug Coleman 2011-10-26 13:01:04 -07:00
parent 1882e3de3e
commit 7b6f27eda6
5 changed files with 22 additions and 10 deletions

View File

@ -27,7 +27,7 @@ IN: opengl.capabilities
"." split [ string>number ] map ;
: version-before? ( version1 version2 -- ? )
swap version-seq swap version-seq before=? ;
[ version-seq ] bi@ before=? ;
: (gl-version) ( -- version vendor )
GL_VERSION glGetString " " split1 ;

View File

@ -14,8 +14,7 @@ TUPLE: border < gadget
new swap add-gadget ; inline
: <border> ( child gap -- border )
swap border new-border
swap >>size ;
[ border new-border ] dip >>size ;
: <filled-border> ( child gap -- border )
<border> { 1 1 } >>fill ;

View File

@ -25,8 +25,8 @@ TUPLE: presentation < button object hook ;
[ [ object>> ] keep show-summary ] [ button-update ] bi ;
: <presentation> ( label object -- button )
swap [ invoke-primary ] presentation new-button
swap >>object
[ [ invoke-primary ] presentation new-button ] dip
>>object
[ drop ] >>hook
roll-button-theme ;

View File

@ -16,7 +16,7 @@ SINGLETON: utf8
: append-nums ( stream byte -- stream char )
over stream-read1 dup starts-2?
[ swap 6 shift swap BIN: 111111 bitand bitor ]
[ [ 6 shift ] dip BIN: 111111 bitand bitor ]
[ 2drop replacement-char ] if ; inline
: minimum-code-point ( char minimum -- char )

View File

@ -2,10 +2,11 @@
! See http://factorcode.org/license.txt for BSD license.
USING: accessors alien arrays assocs classes
classes.tuple.private combinators.short-circuit fry hashtables
io kernel kernel.private locals.backend make math namespaces
prettyprint quotations sequences sequences.deep shuffle
slots.private vectors vocabs words words.alias ;
classes.tuple.private combinators.short-circuit continuations
fry hashtables io kernel kernel.private locals.backend make
math namespaces prettyprint quotations sequences sequences.deep
shuffle slots.private splitting stack-checker vectors vocabs
words words.alias ;
IN: lint
@ -287,6 +288,18 @@ M: word run-lint ( word -- seq ) 1array run-lint ;
PRIVATE>
: find-swap/swap ( word -- ? )
def>> [ callable? ] deep-filter
[
{
[ [ \ swap = ] count 2 >= ]
[
{ swap } split rest but-last
[ [ infer ] [ 2drop ( -- ) ] recover ( x -- x ) = ] any?
]
} 1&&
] any? ;
: lint-all ( -- seq )
all-words run-lint dup lint. ;