diff --git a/basis/checksums/hmac/hmac-tests.factor b/basis/checksums/hmac/hmac-tests.factor index ffae146614..70451252f7 100755 --- a/basis/checksums/hmac/hmac-tests.factor +++ b/basis/checksums/hmac/hmac-tests.factor @@ -6,43 +6,43 @@ IN: checksums.hmac.tests [ "\u000092\u000094rz68\u0000bb\u00001c\u000013\u0000f4\u00008e\u0000f8\u000015\u00008b\u0000fc\u00009d" ] [ - 16 11 "Hi There" md5 hmac-bytes >string ] unit-test + "Hi There" 16 11 md5 hmac-bytes >string ] unit-test [ "u\u00000cx>j\u0000b0\u0000b5\u000003\u0000ea\u0000a8n1\n]\u0000b78" ] -[ "Jefe" "what do ya want for nothing?" md5 hmac-bytes >string ] unit-test +[ "what do ya want for nothing?" "Jefe" md5 hmac-bytes >string ] unit-test [ "V\u0000be4R\u00001d\u000014L\u000088\u0000db\u0000b8\u0000c73\u0000f0\u0000e8\u0000b3\u0000f6" ] [ - 16 HEX: aa - 50 HEX: dd md5 hmac-bytes >string + 50 HEX: dd + 16 HEX: aa md5 hmac-bytes >string ] unit-test [ "g[\u00000b:\eM\u0000dfN\u000012Hr\u0000dal/c+\u0000fe\u0000d9W\u0000e9" ] [ - 16 11 "Hi There" sha1 hmac-bytes >string + "Hi There" 16 11 sha1 hmac-bytes >string ] unit-test [ "\u0000ef\u0000fc\u0000dfj\u0000e5\u0000eb/\u0000a2\u0000d2t\u000016\u0000d5\u0000f1\u000084\u0000df\u00009c%\u00009a|y" ] [ - "Jefe" "what do ya want for nothing?" sha1 hmac-bytes >string + "what do ya want for nothing?" "Jefe" sha1 hmac-bytes >string ] unit-test [ "\u0000d70YM\u000016~5\u0000d5\u000095o\u0000d8\0=\r\u0000b3\u0000d3\u0000f4m\u0000c7\u0000bb" ] [ - 16 HEX: aa - 50 HEX: dd sha1 hmac-bytes >string + 50 HEX: dd + 16 HEX: aa sha1 hmac-bytes >string ] unit-test [ "b0344c61d8db38535ca8afceaf0bf12b881dc200c9833da726e9376c2e32cff7" ] -[ 20 HEX: b "Hi There" sha-256 hmac-bytes hex-string ] unit-test +[ "Hi There" 20 HEX: b sha-256 hmac-bytes hex-string ] unit-test [ "167f928588c5cc2eef8e3093caa0e87c9ff566a14794aa61648d81621a2a40c6" ] [ - "JefeJefeJefeJefeJefeJefeJefeJefe" - "what do ya want for nothing?" sha-256 hmac-bytes hex-string + "what do ya want for nothing?" + "JefeJefeJefeJefeJefeJefeJefeJefe" sha-256 hmac-bytes hex-string ] unit-test diff --git a/basis/checksums/hmac/hmac.factor b/basis/checksums/hmac/hmac.factor index b163766016..9ec78248a1 100755 --- a/basis/checksums/hmac/hmac.factor +++ b/basis/checksums/hmac/hmac.factor @@ -13,27 +13,26 @@ IN: checksums.hmac : ipad ( checksum-state -- seq ) block-size>> HEX: 36 ; -:: init-K ( K checksum checksum-state -- o i ) - checksum-state block-size>> K length < - [ K checksum checksum-bytes ] [ K ] if +:: init-key ( checksum key checksum-state -- o i ) + checksum-state block-size>> key length < + [ key checksum checksum-bytes ] [ key ] if checksum-state block-size>> 0 pad-tail [ checksum-state opad seq-bitxor ] [ checksum-state ipad seq-bitxor ] bi ; PRIVATE> -:: hmac-stream ( K stream checksum -- value ) - K checksum dup initialize-checksum-state - dup :> checksum-state - init-K :> Ki :> Ko +:: hmac-stream ( stream key checksum -- value ) + checksum initialize-checksum-state :> checksum-state + checksum key checksum-state init-key :> Ki :> Ko checksum-state Ki add-checksum-bytes stream add-checksum-stream get-checksum checksum initialize-checksum-state Ko add-checksum-bytes swap add-checksum-bytes get-checksum ; -: hmac-file ( K path checksum -- value ) - [ binary ] dip hmac-stream ; +: hmac-file ( path key checksum -- value ) + [ binary ] 2dip hmac-stream ; -: hmac-bytes ( K seq checksum -- value ) - [ binary ] dip hmac-stream ; +: hmac-bytes ( seq key checksum -- value ) + [ binary ] 2dip hmac-stream ; diff --git a/basis/tools/annotations/annotations-docs.factor b/basis/tools/annotations/annotations-docs.factor index 005f5f7af8..8d73d85fb5 100644 --- a/basis/tools/annotations/annotations-docs.factor +++ b/basis/tools/annotations/annotations-docs.factor @@ -39,11 +39,6 @@ HELP: breakpoint-if { $values { "quot" { $quotation "( -- ? )" } } { "word" word } } { $description "Annotates a word definition to enter the single stepper if the quotation yields true." } ; -HELP: annotate-methods -{ $values - { "word" word } { "quot" quotation } } -{ $description "Annotates the word -- for generic words, all its methods -- with the quotation." } ; - HELP: reset { $values { "word" word } } diff --git a/basis/tools/annotations/annotations-tests.factor b/basis/tools/annotations/annotations-tests.factor index bbd2ac2ca8..c312b54edb 100644 --- a/basis/tools/annotations/annotations-tests.factor +++ b/basis/tools/annotations/annotations-tests.factor @@ -39,6 +39,9 @@ M: object another-generic ; [ "" ] [ [ 3 another-generic drop ] with-string-writer ] unit-test +! reset should do the right thing for generic words +[ ] [ \ another-generic watch ] unit-test + GENERIC: blah-generic ( a -- b ) M: string blah-generic ; diff --git a/basis/tools/annotations/annotations.factor b/basis/tools/annotations/annotations.factor index 3cb74fb00b..3aac371a6a 100644 --- a/basis/tools/annotations/annotations.factor +++ b/basis/tools/annotations/annotations.factor @@ -9,8 +9,7 @@ IN: tools.annotations GENERIC: reset ( word -- ) M: generic reset - [ call-next-method ] - [ subwords [ reset ] each ] bi ; + subwords [ reset ] each ; M: word reset dup "unannotated-def" word-prop [ @@ -22,6 +21,8 @@ M: word reset ERROR: cannot-annotate-twice word ; +M: cannot-annotate-twice summary drop "Cannot annotate a word twice" ; + > "unannotated-def" set-word-prop ; - -: (annotate) ( word quot -- ) - [ dup def>> ] dip call( old -- new ) define ; - PRIVATE> -: annotate ( word quot -- ) +GENERIC# annotate 1 ( word quot -- ) + +M: generic annotate + [ "methods" word-prop values ] dip '[ _ annotate ] each ; + +M: word annotate [ check-annotate-twice ] dip - [ over save-unannotated-def (annotate) ] with-compilation-unit ; + [ + [ dup def>> 2dup "unannotated-def" set-word-prop ] dip + call( old -- new ) define + ] with-compilation-unit ; : watch-vars ( word vars -- ) dupd '[ [ _ _ ] dip (watch-vars) ] annotate ; -GENERIC# annotate-methods 1 ( word quot -- ) - -M: generic annotate-methods - [ "methods" word-prop values ] dip [ annotate ] curry each ; - -M: word annotate-methods - annotate ; - : breakpoint ( word -- ) - [ add-breakpoint ] annotate-methods ; + [ add-breakpoint ] annotate ; : breakpoint-if ( word quot -- ) - '[ [ _ [ [ break ] when ] ] dip 3append ] annotate-methods ; + '[ [ _ [ [ break ] when ] ] dip 3append ] annotate ; SYMBOL: word-timing diff --git a/core/destructors/destructors-docs.factor b/core/destructors/destructors-docs.factor index 0b6ca15f31..536ee19c8b 100644 --- a/core/destructors/destructors-docs.factor +++ b/core/destructors/destructors-docs.factor @@ -26,7 +26,7 @@ HELP: with-disposal HELP: with-destructors { $values { "quot" "a quotation" } } -{ $description "Calls a quotation within a new dynamic scope. This quotation may register destructors, on any object, by wrapping the object in a destructor and implementing " { $link dispose } " on that object type. After the quotation finishes, if an error was thrown, all destructors are called and the error is then rethrown. However, if the quotation was successful, only those destructors created with an 'always cleanup' flag will be destroyed." } +{ $description "Calls a quotation within a new dynamic scope. This quotation may register destructors using " { $link &dispose } " or " { $link |dispose } ". The former registers a destructor that will always run whether or not the quotation threw an error, and the latter registers a destructor that only runs if the quotation throws an error only. Destructors are run in reverse order from the order in which they were registered." } { $notes "Destructors generalize " { $link with-disposal } ". The following two lines are equivalent, except that the second line establishes a new dynamic scope:" { $code diff --git a/core/io/encodings/utf16/utf16.factor b/core/io/encodings/utf16/utf16.factor index a6ccc95bf5..1fb5ad1116 100644 --- a/core/io/encodings/utf16/utf16.factor +++ b/core/io/encodings/utf16/utf16.factor @@ -59,7 +59,7 @@ M: utf16be decode-char ] [ append-nums ] if ; : begin-utf16le ( stream byte -- stream char ) - over stream-read1 [ double-le ] [ drop replacement-char ] if* ; + over stream-read1 dup [ double-le ] [ 2drop replacement-char ] if ; M: utf16le decode-char drop dup stream-read1 dup [ begin-utf16le ] when nip ; @@ -68,36 +68,34 @@ M: utf16le decode-char : encode-first ( char -- byte1 byte2 ) -10 shift - dup -8 shift BIN: 11011000 bitor - swap HEX: FF bitand ; + [ -8 shift BIN: 11011000 bitor ] [ HEX: FF bitand ] bi ; : encode-second ( char -- byte3 byte4 ) BIN: 1111111111 bitand - dup -8 shift BIN: 11011100 bitor - swap BIN: 11111111 bitand ; + [ -8 shift BIN: 11011100 bitor ] [ BIN: 11111111 bitand ] bi ; -: stream-write2 ( stream char1 char2 -- ) - rot [ stream-write1 ] curry bi@ ; +: stream-write2 ( char1 char2 stream -- ) + [ stream-write1 ] curry bi@ ; -: char>utf16be ( stream char -- ) - dup HEX: FFFF > [ - HEX: 10000 - - 2dup encode-first stream-write2 - encode-second stream-write2 - ] [ h>b/b swap stream-write2 ] if ; +: char>utf16be ( char stream -- ) + over HEX: FFFF > [ + [ HEX: 10000 - ] dip + [ [ encode-first ] dip stream-write2 ] + [ [ encode-second ] dip stream-write2 ] 2bi + ] [ [ h>b/b swap ] dip stream-write2 ] if ; M: utf16be encode-char ( char stream encoding -- ) - drop swap char>utf16be ; + drop char>utf16be ; -: char>utf16le ( char stream -- ) - dup HEX: FFFF > [ - HEX: 10000 - - 2dup encode-first swap stream-write2 - encode-second swap stream-write2 - ] [ h>b/b stream-write2 ] if ; +: char>utf16le ( stream char -- ) + over HEX: FFFF > [ + [ HEX: 10000 - ] dip + [ [ encode-first swap ] dip stream-write2 ] + [ [ encode-second swap ] dip stream-write2 ] 2bi + ] [ [ h>b/b ] dip stream-write2 ] if ; M: utf16le encode-char ( char stream encoding -- ) - drop swap char>utf16le ; + drop char>utf16le ; ! UTF-16 diff --git a/extra/descriptive/descriptive.factor b/extra/descriptive/descriptive.factor index 9af94aa4ed..0756c5c975 100755 --- a/extra/descriptive/descriptive.factor +++ b/extra/descriptive/descriptive.factor @@ -28,7 +28,7 @@ PRIVATE> : make-descriptive ( word -- ) dup [ ] [ def>> ] [ stack-effect ] tri [descriptive] - '[ drop _ ] annotate-methods ; + '[ drop _ ] annotate ; : define-descriptive ( word def effect -- ) [ drop "descriptive-definition" set-word-prop ] diff --git a/extra/images/processing/rotation/authors.txt b/extra/images/processing/rotation/authors.txt new file mode 100644 index 0000000000..09801441c8 --- /dev/null +++ b/extra/images/processing/rotation/authors.txt @@ -0,0 +1,2 @@ +Kobi Lurie +Doug Coleman diff --git a/extra/images/processing/rotation/rotation-tests.factor b/extra/images/processing/rotation/rotation-tests.factor new file mode 100755 index 0000000000..493f09b145 --- /dev/null +++ b/extra/images/processing/rotation/rotation-tests.factor @@ -0,0 +1,77 @@ +! Copyright (C) 2009 Kobi Lurie, Doug Coleman. +! See http://factorcode.org/license.txt for BSD license. +USING: accessors fry images.loader images.normalization +images.processing.rotation kernel literals math sequences +tools.test images.processing.rotation.private ; +IN: images.processing.rotation.tests + +: first-row ( seq^2 -- seq ) first ; +: first-col ( seq^2 -- item ) harvest [ first ] map ; +: last-row ( seq^2 -- item ) last ; +: last-col ( seq^2 -- item ) harvest [ last ] map ; +: end-of-first-row ( seq^2 -- item ) first-row last ; +: first-of-first-row ( seq^2 -- item ) first-row first ; +: end-of-last-row ( seq^2 -- item ) last-row last ; +: first-of-last-row ( seq^2 -- item ) last-row first ; + +<< + +: clone-image ( image -- new-image ) + clone [ clone ] change-bitmap ; + +>> + +CONSTANT: pasted-image + $[ + "vocab:images/processing/rotation/test-bitmaps/PastedImage.bmp" + load-image normalize-image clone-image + ] + +CONSTANT: pasted-image90 + $[ + "vocab:images/processing/rotation/test-bitmaps/PastedImage90.bmp" + load-image normalize-image clone-image + ] + +CONSTANT: lake-image + $[ + "vocab:images/processing/rotation/test-bitmaps/lake.bmp" + load-image preprocess + ] + +[ t ] [ pasted-image dup clone-image 4 [ 90 rotate ] times = ] unit-test +[ t ] [ pasted-image dup clone-image 2 [ 180 rotate ] times = ] unit-test +[ t ] [ pasted-image dup clone-image 270 rotate 90 rotate = ] unit-test +[ t ] [ + pasted-image dup clone-image dup { 90 180 90 } [ rotate drop ] with each = +] unit-test + +[ t ] [ + pasted-image 90 rotate + pasted-image90 = +] unit-test + +[ t ] [ + "vocab:images/processing/rotation/test-bitmaps/small.bmp" + load-image 90 rotate + "vocab:images/processing/rotation/test-bitmaps/small-rotated.bmp" + load-image normalize-image = +] unit-test + +[ t ] [ + lake-image + [ first-of-first-row ] + [ 90 (rotate) end-of-first-row ] bi = +] unit-test + +[ t ] +[ lake-image [ first-row ] [ 90 (rotate) last-col ] bi = ] unit-test + +[ t ] +[ lake-image [ last-col ] [ 90 (rotate) last-row reverse ] bi = ] unit-test + +[ t ] +[ lake-image [ last-row ] [ 90 (rotate) first-col ] bi = ] unit-test + +[ t ] +[ lake-image [ first-col ] [ 90 (rotate) first-row reverse ] bi = ] unit-test diff --git a/extra/images/processing/rotation/rotation.factor b/extra/images/processing/rotation/rotation.factor new file mode 100644 index 0000000000..c10bfa0ee0 --- /dev/null +++ b/extra/images/processing/rotation/rotation.factor @@ -0,0 +1,71 @@ +! Copyright (C) 2009 Kobi Lurie. +! See http://factorcode.org/license.txt for BSD license. +USING: accessors arrays colors combinators +combinators.short-circuit fry grouping images images.bitmap +images.loader images.normalization kernel locals math sequences ; +IN: images.processing.rotation + +ERROR: unsupported-rotation degrees ; + +> length ] [ dim>> second ] bi /i ; + +: image>byte-rows ( image -- byte-rows ) + [ bitmap>> ] [ row-length ] bi group rows-remove-pad ; + +: (seperate-to-pixels) ( byte-rows image -- pixel-rows ) + component-order>> bytes-per-pixel '[ _ group ] map ; + +: image>pixel-rows ( image -- pixel-rows ) + [ image>byte-rows ] keep (seperate-to-pixels) ; + +: flatten-table ( seq^3 -- seq ) + [ concat ] map concat ; + +: preprocess ( image -- pixelrows ) + normalize-image image>pixel-rows ; + +: ?reverse-dimensions ( image n -- ) + { 270 90 } member? [ [ reverse ] change-dim ] when drop ; + +: normalize-degree ( n -- n' ) 360 rem ; + +: processing-effect ( image quot -- image' ) + '[ preprocess @ flatten-table ] [ (>>bitmap) ] [ ] tri ; inline + +:: rotate' ( image n -- image ) + n normalize-degree :> n' + image preprocess :> pixel-table + image n' ?reverse-dimensions + pixel-table n' (rotate) :> table-rotated + image table-rotated flatten-table >>bitmap ; + +PRIVATE> + +: rotate ( image n -- image' ) + normalize-degree + [ '[ _ (rotate) ] processing-effect ] [ ?reverse-dimensions ] 2bi ; + +: reflect-y-axis ( image -- image ) + [ [ reverse ] map ] processing-effect ; + +: reflect-x-axis ( image -- image ) + [ reverse ] processing-effect ; diff --git a/extra/images/processing/rotation/test-bitmaps/PastedImage.bmp b/extra/images/processing/rotation/test-bitmaps/PastedImage.bmp new file mode 100755 index 0000000000..8edfedd4b5 Binary files /dev/null and b/extra/images/processing/rotation/test-bitmaps/PastedImage.bmp differ diff --git a/extra/images/processing/rotation/test-bitmaps/PastedImage90.bmp b/extra/images/processing/rotation/test-bitmaps/PastedImage90.bmp new file mode 100755 index 0000000000..2aa6ef1e27 Binary files /dev/null and b/extra/images/processing/rotation/test-bitmaps/PastedImage90.bmp differ diff --git a/extra/images/processing/rotation/test-bitmaps/lake.bmp b/extra/images/processing/rotation/test-bitmaps/lake.bmp new file mode 100755 index 0000000000..431e4ef8ae Binary files /dev/null and b/extra/images/processing/rotation/test-bitmaps/lake.bmp differ diff --git a/extra/images/processing/rotation/test-bitmaps/small-rotated.bmp b/extra/images/processing/rotation/test-bitmaps/small-rotated.bmp new file mode 100755 index 0000000000..571ea835ff Binary files /dev/null and b/extra/images/processing/rotation/test-bitmaps/small-rotated.bmp differ diff --git a/extra/images/processing/rotation/test-bitmaps/small.bmp b/extra/images/processing/rotation/test-bitmaps/small.bmp new file mode 100755 index 0000000000..72748574bd Binary files /dev/null and b/extra/images/processing/rotation/test-bitmaps/small.bmp differ diff --git a/extra/webapps/planet/planet.factor b/extra/webapps/planet/planet.factor index 52d64f0f9e..12b7ccda24 100755 --- a/extra/webapps/planet/planet.factor +++ b/extra/webapps/planet/planet.factor @@ -166,9 +166,7 @@ posting "POSTINGS" [ f [ deposit-blog-slots ] - [ "id" value >>id ] - [ update-tuple ] - tri + [ "id" value >>id update-tuple ] bi "$planet/admin" >>path