From 7b6f27eda68a0d07bb70f06da98d5d9bc35ac296 Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Wed, 26 Oct 2011 13:01:04 -0700 Subject: [PATCH] Add a lint check for swap .. swap that can be replaced by dip. Clean up the cases it finds. --- basis/opengl/capabilities/capabilities.factor | 2 +- basis/ui/gadgets/borders/borders.factor | 3 +-- .../presentations/presentations.factor | 4 ++-- core/io/encodings/utf8/utf8.factor | 2 +- extra/lint/lint.factor | 21 +++++++++++++++---- 5 files changed, 22 insertions(+), 10 deletions(-) diff --git a/basis/opengl/capabilities/capabilities.factor b/basis/opengl/capabilities/capabilities.factor index 37bfabc19b..b1b1731774 100644 --- a/basis/opengl/capabilities/capabilities.factor +++ b/basis/opengl/capabilities/capabilities.factor @@ -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 ; diff --git a/basis/ui/gadgets/borders/borders.factor b/basis/ui/gadgets/borders/borders.factor index 90de5a9287..a15919658a 100644 --- a/basis/ui/gadgets/borders/borders.factor +++ b/basis/ui/gadgets/borders/borders.factor @@ -14,8 +14,7 @@ TUPLE: border < gadget new swap add-gadget ; inline : ( child gap -- border ) - swap border new-border - swap >>size ; + [ border new-border ] dip >>size ; : ( child gap -- border ) { 1 1 } >>fill ; diff --git a/basis/ui/gadgets/presentations/presentations.factor b/basis/ui/gadgets/presentations/presentations.factor index 93a585e330..350b695e22 100644 --- a/basis/ui/gadgets/presentations/presentations.factor +++ b/basis/ui/gadgets/presentations/presentations.factor @@ -25,8 +25,8 @@ TUPLE: presentation < button object hook ; [ [ object>> ] keep show-summary ] [ button-update ] bi ; : ( label object -- button ) - swap [ invoke-primary ] presentation new-button - swap >>object + [ [ invoke-primary ] presentation new-button ] dip + >>object [ drop ] >>hook roll-button-theme ; diff --git a/core/io/encodings/utf8/utf8.factor b/core/io/encodings/utf8/utf8.factor index 8fbc71e016..44850c0ab8 100644 --- a/core/io/encodings/utf8/utf8.factor +++ b/core/io/encodings/utf8/utf8.factor @@ -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 ) diff --git a/extra/lint/lint.factor b/extra/lint/lint.factor index 29fd5e9b3a..e6710302cc 100644 --- a/extra/lint/lint.factor +++ b/extra/lint/lint.factor @@ -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. ;