diff --git a/basis/formatting/formatting-tests.factor b/basis/formatting/formatting-tests.factor index 8616325a81..c7e9fb985e 100644 --- a/basis/formatting/formatting-tests.factor +++ b/basis/formatting/formatting-tests.factor @@ -85,13 +85,13 @@ IN: formatting.tests [ t ] [ "12:03:15" testtime "%H:%M:%S" strftime = ] unit-test [ t ] [ "12:03:15" testtime "%X" strftime = ] unit-test - [ t ] [ "10/09/2008" testtime "%m/%d/%Y" strftime = ] unit-test [ t ] [ "10/09/2008" testtime "%x" strftime = ] unit-test - +[ t ] [ "10/09/08" testtime "%m/%d/%y" strftime = ] unit-test [ t ] [ "Thu" testtime "%a" strftime = ] unit-test [ t ] [ "Thursday" testtime "%A" strftime = ] unit-test - [ t ] [ "Oct" testtime "%b" strftime = ] unit-test [ t ] [ "October" testtime "%B" strftime = ] unit-test +[ t ] [ "Thu Oct 09 12:03:15 2008" testtime "%c" strftime = ] unit-test +[ t ] [ "PM" testtime "%p" strftime = ] unit-test diff --git a/basis/formatting/formatting.factor b/basis/formatting/formatting.factor index 7dd8458488..3f12c36bbd 100644 --- a/basis/formatting/formatting.factor +++ b/basis/formatting/formatting.factor @@ -2,7 +2,7 @@ ! See http://factorcode.org/license.txt for BSD license USING: accessors arrays ascii calendar combinators fry kernel -io io.encodings.ascii io.files io.streams.string +generalizations io io.encodings.ascii io.files io.streams.string macros math math.functions math.parser peg.ebnf quotations sequences splitting strings unicode.case vectors ; @@ -32,10 +32,7 @@ IN: formatting [ "." split1 ] dip [ CHAR: 0 pad-right ] [ head-slice ] bi "." glue ; : max-digits ( n digits -- n' ) - 10 swap ^ [ * round ] keep / ; - -: max-width ( string length -- string' ) - short head ; + 10 swap ^ [ * round ] keep / ; inline : >exp ( x -- exp base ) [ @@ -69,7 +66,7 @@ pad = pad-align pad-char pad-width => [[ reverse >quotation dup first 0 = sign = ("+")? => [[ [ dup CHAR: - swap index [ "+" prepend ] unless ] [ ] ? ]] -width_ = "." ([0-9])* => [[ second >digits '[ _ max-width ] ]] +width_ = "." ([0-9])* => [[ second >digits '[ _ short head ] ]] width = (width_)? => [[ [ ] or ]] digits_ = "." ([0-9])* => [[ second >digits ]] @@ -113,23 +110,25 @@ MACRO: printf ( format-string -- ) <PRIVATE -: zero-pad ( str -- str' ) 2 CHAR: 0 pad-left ; inline +: pad-00 ( n -- string ) number>string 2 CHAR: 0 pad-left ; inline + +: pad-000 ( n -- string ) number>string 3 CHAR: 0 pad-left ; inline : >time ( timestamp -- string ) [ hour>> ] [ minute>> ] [ second>> floor ] tri 3array - [ number>string zero-pad ] map ":" join ; inline + [ pad-00 ] map ":" join ; inline : >date ( timestamp -- string ) [ month>> ] [ day>> ] [ year>> ] tri 3array - [ number>string zero-pad ] map "/" join ; inline + [ pad-00 ] map "/" join ; inline : >datetime ( timestamp -- string ) { [ day-of-week day-abbreviation3 ] [ month>> month-abbreviation ] - [ day>> number>string zero-pad ] + [ day>> pad-00 ] [ >time ] [ year>> number>string ] - } cleave 3array [ 2array ] dip append " " join ; inline + } cleave 5 narray " " join ; inline : (week-of-year) ( timestamp day -- n ) [ dup clone 1 >>month 1 >>day day-of-week dup ] dip > [ 7 swap - ] when @@ -147,20 +146,20 @@ fmt-A = "A" => [[ [ dup day-of-week day-name ] ]] fmt-b = "b" => [[ [ dup month>> month-abbreviation ] ]] fmt-B = "B" => [[ [ dup month>> month-name ] ]] fmt-c = "c" => [[ [ dup >datetime ] ]] -fmt-d = "d" => [[ [ dup day>> number>string zero-pad ] ]] -fmt-H = "H" => [[ [ dup hour>> number>string zero-pad ] ]] -fmt-I = "I" => [[ [ dup hour>> dup 12 > [ 12 - ] when number>string zero-pad ] ]] -fmt-j = "j" => [[ [ dup day-of-year number>string ] ]] -fmt-m = "m" => [[ [ dup month>> number>string zero-pad ] ]] -fmt-M = "M" => [[ [ dup minute>> number>string zero-pad ] ]] +fmt-d = "d" => [[ [ dup day>> pad-00 ] ]] +fmt-H = "H" => [[ [ dup hour>> pad-00 ] ]] +fmt-I = "I" => [[ [ dup hour>> dup 12 > [ 12 - ] when pad-00 ] ]] +fmt-j = "j" => [[ [ dup day-of-year pad-000 ] ]] +fmt-m = "m" => [[ [ dup month>> pad-00 ] ]] +fmt-M = "M" => [[ [ dup minute>> pad-00 ] ]] fmt-p = "p" => [[ [ dup hour>> 12 < "AM" "PM" ? ] ]] -fmt-S = "S" => [[ [ dup second>> round number>string zero-pad ] ]] -fmt-U = "U" => [[ [ dup week-of-year-sunday ] ]] +fmt-S = "S" => [[ [ dup second>> floor pad-00 ] ]] +fmt-U = "U" => [[ [ dup week-of-year-sunday pad-00 ] ]] fmt-w = "w" => [[ [ dup day-of-week number>string ] ]] -fmt-W = "W" => [[ [ dup week-of-year-monday ] ]] +fmt-W = "W" => [[ [ dup week-of-year-monday pad-00 ] ]] fmt-x = "x" => [[ [ dup >date ] ]] fmt-X = "X" => [[ [ dup >time ] ]] -fmt-y = "y" => [[ [ dup year>> 100 mod number>string ] ]] +fmt-y = "y" => [[ [ dup year>> 100 mod pad-00 ] ]] fmt-Y = "Y" => [[ [ dup year>> number>string ] ]] fmt-Z = "Z" => [[ [ "Not yet implemented" throw ] ]] unknown = (.)* => [[ "Unknown directive" throw ]] diff --git a/basis/logging/parser/parser-docs.factor b/basis/logging/parser/parser-docs.factor index 76c7ab6c90..7ab1ad3883 100644 --- a/basis/logging/parser/parser-docs.factor +++ b/basis/logging/parser/parser-docs.factor @@ -13,7 +13,7 @@ HELP: parse-log } ; ARTICLE: "logging.parser" "Log file parser" -"The " { $vocab-link "logging.parser" } " vocabulary parses log files output by the " { $vocab-link "logging" } " vocabulary. It is used by " { $link "logging.analysis" } " and " { $link "logging.insomniac" } " to analyze logs." +"The " { $vocab-link "logging.parser" } " vocabulary parses log files output by the " { $vocab-link "logging" } " vocabulary. It is used by " { $link "logging.analysis" } " and " { $vocab-link "logging.insomniac" } " to analyze logs." $nl "There is only one primary entry point:" { $subsection parse-log } ; diff --git a/basis/tools/profiler/profiler-docs.factor b/basis/tools/profiler/profiler-docs.factor index 69edf1a7e0..da9171cedf 100644 --- a/basis/tools/profiler/profiler-docs.factor +++ b/basis/tools/profiler/profiler-docs.factor @@ -2,14 +2,18 @@ USING: tools.profiler.private tools.time help.markup help.syntax quotations io strings words definitions ; IN: tools.profiler -ARTICLE: "profiling" "Profiling code" -"The " { $vocab-link "tools.profiler" } " vocabulary implements a simple call counting profiler. The profiler is completely accurate with words and methods which are compiled with the non-optimizing compiler. Some optimizations performed by the optimizing compiler can inhibit accurate call counting, however:" +ARTICLE: "profiler-limitations" "Profiler limitations" +"Certain optimizations performed by the compiler can inhibit accurate call counting:" { $list - "The optimizing compiler open-codes certain primitives with inline machine code, and in some cases optimizes them out altogether; this includes stack shuffling operations, conditionals, and many object allocation operations." - { "Calls to " { $link POSTPONE: inline } " words are not counted.." } + "Calls to open-coded intrinsics are not counted. Certain words are open-coded as inline machine code, and in some cases optimized out altogether; this includes stack shuffling operations, conditionals, and many object allocation operations." + { "Calls to " { $link POSTPONE: inline } " words are not counted." } { "Calls to methods which were inlined as a result of type inference are not counted." } "Tail-recursive loops will only count the initial invocation of the word, not every tail call." -} +} ; + +ARTICLE: "profiling" "Profiling code" +"The " { $vocab-link "tools.profiler" } " vocabulary implements a simple call counting profiler." +$nl "Quotations can be passed to a combinator which calls them with the profiler enabled:" { $subsection profile } "After a quotation has been profiled, call counts can be presented in various ways:" @@ -17,7 +21,9 @@ ARTICLE: "profiling" "Profiling code" { $subsection vocab-profile. } { $subsection usage-profile. } { $subsection vocabs-profile. } -{ $subsection method-profile. } ; +{ $subsection method-profile. } +{ $subsection "profiler-limitations" } +{ $see-also "ui-profiler" } ; ABOUT: "profiling" diff --git a/basis/uuid/authors.txt b/basis/uuid/authors.txt new file mode 100644 index 0000000000..e091bb8164 --- /dev/null +++ b/basis/uuid/authors.txt @@ -0,0 +1 @@ +John Benediktsson diff --git a/basis/uuid/summary.txt b/basis/uuid/summary.txt new file mode 100644 index 0000000000..ba555627a8 --- /dev/null +++ b/basis/uuid/summary.txt @@ -0,0 +1 @@ +Generates UUID's. diff --git a/basis/uuid/uuid-docs.factor b/basis/uuid/uuid-docs.factor new file mode 100644 index 0000000000..0408da85b8 --- /dev/null +++ b/basis/uuid/uuid-docs.factor @@ -0,0 +1,45 @@ + +USING: help.syntax help.markup kernel prettyprint sequences strings ; + +IN: uuid + +HELP: uuid1 +{ $description + "Generates a UUID (version 1) from the host ID, sequence number, " + "and current time." +} ; + +HELP: uuid3 +{ $description + "Generates a UUID (version 3) from the MD5 hash of a namespace " + "UUID and a name." +} ; + +HELP: uuid4 +{ $description + "Generates a UUID (version 4) from random bits." +} ; + +HELP: uuid5 +{ $description + "Generates a UUID (version 5) from the SHA-1 hash of a namespace " + "UUID and a name." +} ; + + +ARTICLE: "uuid" "UUID (Universally Unique Identifier)" +"The " { $vocab-link "uuid" } " vocabulary is used to generate UUID's. " +"The words uuid1, uuid3, uuid4, uuid5 can be used to generate version " +"1, 3, 4, and 5 UUIDs as specified in RFC 4122.\n" +"\n" +"If all you want is a unique ID, you should probably call uuid1 or uuid4." +"\n" +{ $subsection uuid1 } +{ $subsection uuid3 } +{ $subsection uuid4 } +{ $subsection uuid5 } +; + +ABOUT: "uuid" + + diff --git a/basis/uuid/uuid-tests.factor b/basis/uuid/uuid-tests.factor new file mode 100644 index 0000000000..909e5f603d --- /dev/null +++ b/basis/uuid/uuid-tests.factor @@ -0,0 +1,18 @@ +! Copyright (C) 2008 John Benediktsson +! See http://factorcode.org/license.txt for BSD license + +USING: kernel uuid tools.test ; + +IN: uuid.tests + +[ t ] [ NAMESPACE_DNS [ uuid-parse uuid-unparse ] keep = ] unit-test +[ t ] [ NAMESPACE_URL [ uuid-parse uuid-unparse ] keep = ] unit-test +[ t ] [ NAMESPACE_OID [ uuid-parse uuid-unparse ] keep = ] unit-test +[ t ] [ NAMESPACE_X500 [ uuid-parse uuid-unparse ] keep = ] unit-test + +[ t ] [ NAMESPACE_URL "ABCD" uuid3 + "2e10e403-d7fa-3ffb-808f-ab834a46890e" = ] unit-test + +[ t ] [ NAMESPACE_URL "ABCD" uuid5 + "0aa883d6-7953-57e7-a8f0-66db29ce5a91" = ] unit-test + diff --git a/basis/uuid/uuid.factor b/basis/uuid/uuid.factor new file mode 100644 index 0000000000..8b491d7cf2 --- /dev/null +++ b/basis/uuid/uuid.factor @@ -0,0 +1,94 @@ +! Copyright (C) 2008 John Benediktsson +! See http://factorcode.org/license.txt for BSD license + +USING: byte-arrays checksums checksums.md5 checksums.sha1 +kernel math math.parser math.ranges random unicode.case +sequences strings system ; + +IN: uuid + +<PRIVATE + +: (timestamp) ( -- time_high time_mid time_low ) + ! 0x01b21dd213814000L is the number of 100-ns intervals + ! between the UUID epoch 1582-10-15 00:00:00 and the + ! Unix epoch 1970-01-01 00:00:00. + micros 10 * HEX: 01b21dd213814000 + + [ -48 shift HEX: 0fff bitand ] + [ -32 shift HEX: ffff bitand ] + [ HEX: ffffffff bitand ] tri ; + +: (hardware) ( -- address ) + ! Choose a random 48-bit number with eighth bit + ! set to 1 (as recommended in RFC 4122) + 48 random-bits HEX: 010000000000 bitor ; + +: (clock) ( -- clockseq ) + ! Choose a random 14-bit number + 14 random-bits ; + +: <uuid> ( address clockseq time_high time_mid time_low -- n ) + 96 shift + [ 80 shift ] dip bitor + [ 64 shift ] dip bitor + [ 48 shift ] dip bitor + bitor ; + +: (version) ( n version -- n' ) + [ HEX: c000 48 shift bitnot bitand + HEX: 8000 48 shift bitor + HEX: f000 64 shift bitnot bitand + ] dip 76 shift bitor ; + +: uuid>string ( n -- string ) + >hex 32 CHAR: 0 pad-left + [ CHAR: - 20 ] dip insert-nth + [ CHAR: - 16 ] dip insert-nth + [ CHAR: - 12 ] dip insert-nth + [ CHAR: - 8 ] dip insert-nth ; + +: string>uuid ( string -- n ) + [ CHAR: - = not ] filter 16 base> ; + +: uuid>byte-array ( n -- byte-array ) + 16 <byte-array> 15 -1 [a,b) [ + [ dup HEX: ff bitand ] 2dip swap + [ set-nth -8 shift ] keep + ] each nip ; + +: byte-array>uuid ( byte-array -- n ) + 0 swap [ [ 8 shift ] dip + ] each ; + +PRIVATE> + +: uuid-parse ( string -- byte-array ) + string>uuid uuid>byte-array ; + +: uuid-unparse ( byte-array -- string ) + byte-array>uuid uuid>string ; + +: uuid1 ( -- string ) + (hardware) (clock) (timestamp) <uuid> + 1 (version) uuid>string ; + +: uuid3 ( namespace name -- string ) + [ uuid-parse ] dip >byte-array append + md5 checksum-bytes 16 short head byte-array>uuid + 3 (version) uuid>string ; + +: uuid4 ( -- string ) + 128 random-bits + 4 (version) uuid>string ; + +: uuid5 ( namespace name -- string ) + [ uuid-parse ] dip >byte-array append + sha1 checksum-bytes 16 short head byte-array>uuid + 5 (version) uuid>string ; + + +: NAMESPACE_DNS "6ba7b810-9dad-11d1-80b4-00c04fd430c8" ; inline +: NAMESPACE_URL "6ba7b811-9dad-11d1-80b4-00c04fd430c8" ; inline +: NAMESPACE_OID "6ba7b812-9dad-11d1-80b4-00c04fd430c8" ; inline +: NAMESPACE_X500 "6ba7b814-9dad-11d1-80b4-00c04fd430c8" ; inline + + diff --git a/core/compiler/errors/errors-docs.factor b/core/compiler/errors/errors-docs.factor index aa4f8e329d..f5ecf5add1 100644 --- a/core/compiler/errors/errors-docs.factor +++ b/core/compiler/errors/errors-docs.factor @@ -3,18 +3,20 @@ USING: help.markup help.syntax vocabs.loader words io quotations words.symbol ; ARTICLE: "compiler-errors" "Compiler warnings and errors" -"The compiler saves various notifications in a global variable:" +"The compiler saves " { $link "inference-errors" } " in a global variable:" { $subsection compiler-errors } "These notifications can be viewed later:" { $subsection :errors } { $subsection :warnings } { $subsection :linkage } "Words such as " { $link require } " use a combinator which counts errors and prints a report at the end:" -{ $link with-compiler-errors } ; +{ $subsection with-compiler-errors } ; HELP: compiler-errors { $var-description "Global variable holding an assoc mapping words to compiler errors. This variable is set by " { $link with-compiler-errors } "." } ; +ABOUT: "compiler-errors" + HELP: compiler-error { $values { "error" "an error" } { "word" word } } { $description "If inside a " { $link with-compiler-errors } ", saves the error for future persual via " { $link :errors } ", " { $link :warnings } " and " { $link :linkage } ". If not inside a " { $link with-compiler-errors } ", ignores the error." } ; diff --git a/extra/google-tech-talk/google-tech-talk.factor b/extra/google-tech-talk/google-tech-talk.factor index 3477fbe4bd..84c0134b82 100644 --- a/extra/google-tech-talk/google-tech-talk.factor +++ b/extra/google-tech-talk/google-tech-talk.factor @@ -203,7 +203,7 @@ IN: google-tech-talk { $code "13 <circle> tell-me" } { $code "103 76 <rectangle> tell-me" } { $code "101 tell-me" } - { { $link integer } ", " { $link array } ", and others area built-in classes" } + { { $link integer } ", " { $link array } ", and others are built-in classes" } } { $slide "Object system" "Anyone can define new shapes..."