]> gitweb.factorcode.org Git - factor.git/commitdiff
Merge branch 'master' of git://factorcode.org/git/factor
authorU-WSCHLIEP-PC\wschliep <wschliep@wschliep-pc.(none)>
Sun, 23 Nov 2008 09:39:12 +0000 (04:39 -0500)
committerU-WSCHLIEP-PC\wschliep <wschliep@wschliep-pc.(none)>
Sun, 23 Nov 2008 09:39:12 +0000 (04:39 -0500)
173 files changed:
basis/alarms/alarms.factor
basis/bootstrap/help/help.factor
basis/bootstrap/image/image.factor
basis/bootstrap/stage2.factor
basis/calendar/calendar-docs.factor
basis/calendar/calendar-tests.factor
basis/calendar/calendar.factor
basis/calendar/model/model.factor
basis/cocoa/dialogs/dialogs.factor
basis/compiler/compiler.factor
basis/compiler/tests/alien.factor
basis/compiler/tests/redefine13.factor [new file with mode: 0644]
basis/compiler/tests/redefine14.factor [new file with mode: 0644]
basis/concurrency/combinators/combinators-tests.factor
basis/concurrency/flags/flags-tests.factor
basis/concurrency/futures/futures-docs.factor
basis/concurrency/locks/locks-tests.factor
basis/concurrency/promises/promises-docs.factor
basis/core-foundation/run-loop/run-loop.factor
basis/cpu/ppc/bootstrap.factor
basis/cpu/x86/32/bootstrap.factor
basis/cpu/x86/64/unix/bootstrap.factor
basis/cpu/x86/64/winnt/bootstrap.factor
basis/cpu/x86/bootstrap.factor
basis/farkup/farkup.factor
basis/io/launcher/launcher.factor
basis/io/sockets/secure/openssl/openssl.factor [new file with mode: 0644]
basis/io/unix/files/files.factor
basis/io/unix/kqueue/kqueue.factor
basis/io/unix/select/select.factor
basis/io/unix/sockets/secure/secure.factor
basis/io/windows/nt/pipes/pipes.factor
basis/io/windows/windows.factor [changed mode: 0644->0755]
basis/openssl/openssl.factor
basis/peg/parsers/parsers.factor
basis/peg/peg.factor
basis/regexp/classes/classes.factor
basis/regexp/parser/parser.factor
basis/regexp/regexp-tests.factor
basis/regexp/regexp.factor
basis/smtp/smtp.factor
basis/stack-checker/known-words/known-words.factor
basis/stack-checker/stack-checker.factor
basis/stack-checker/transforms/transforms.factor
basis/threads/threads-docs.factor
basis/threads/threads.factor
basis/tools/deploy/backend/backend.factor
basis/tools/deploy/deploy-tests.factor
basis/tools/deploy/shaker/next-methods.factor [new file with mode: 0644]
basis/tools/deploy/shaker/shaker.factor
basis/tools/deploy/shaker/strip-debugger.factor
basis/tools/deploy/test/1/1.factor
basis/tools/deploy/test/7/7.factor [new file with mode: 0644]
basis/tools/deploy/test/7/deploy.factor [new file with mode: 0644]
basis/tools/profiler/profiler-tests.factor
basis/tools/test/test.factor
basis/tools/threads/threads.factor
basis/tools/time/time-docs.factor
basis/tools/time/time.factor
basis/tools/vocabs/vocabs.factor
basis/tools/walker/walker.factor
basis/ui/gestures/gestures-docs.factor
basis/ui/gestures/gestures.factor
basis/ui/tools/interactor/interactor-tests.factor
basis/ui/tools/listener/listener-tests.factor
basis/ui/tools/search/search-tests.factor
basis/ui/ui.factor
basis/ui/windows/windows.factor [changed mode: 0644->0755]
basis/unix/time/time.factor
basis/urls/urls.factor
core/alien/alien-docs.factor
core/arrays/arrays.factor
core/assocs/assocs.factor
core/bootstrap/primitives.factor
core/checksums/checksums.factor
core/checksums/crc32/crc32.factor
core/classes/algebra/algebra-tests.factor
core/classes/algebra/algebra.factor
core/classes/tuple/tuple-tests.factor
core/classes/tuple/tuple.factor
core/combinators/combinators-docs.factor
core/combinators/combinators.factor
core/compiler/errors/errors.factor
core/continuations/continuations.factor
core/generic/generic-docs.factor
core/generic/generic.factor
core/generic/math/math.factor
core/generic/parser/parser.factor
core/generic/standard/engines/engines.factor
core/generic/standard/engines/predicate/predicate.factor
core/generic/standard/engines/tag/tag.factor
core/generic/standard/standard.factor
core/growable/growable.factor
core/hashtables/hashtables-tests.factor
core/hashtables/hashtables.factor
core/io/backend/backend-docs.factor
core/io/encodings/encodings.factor
core/io/files/files.factor
core/io/io.factor
core/io/streams/byte-array/byte-array.factor
core/io/streams/c/c.factor [changed mode: 0644->0755]
core/io/streams/nested/nested.factor
core/io/streams/string/string.factor
core/kernel/kernel-docs.factor
core/kernel/kernel-tests.factor
core/kernel/kernel.factor
core/lexer/lexer.factor
core/math/integers/integers.factor
core/math/math.factor
core/math/parser/parser.factor
core/namespaces/namespaces.factor
core/parser/parser-tests.factor
core/parser/parser.factor
core/quotations/quotations.factor
core/sequences/sequences.factor
core/slots/slots.factor
core/sorting/sorting.factor
core/splitting/splitting-docs.factor
core/splitting/splitting-tests.factor
core/splitting/splitting.factor
core/strings/parser/parser.factor
core/strings/strings.factor
core/syntax/syntax.factor
core/system/system-docs.factor
core/system/system.factor
core/vectors/vectors-tests.factor
core/vocabs/loader/loader-docs.factor
core/vocabs/loader/loader-tests.factor
core/vocabs/loader/loader.factor
core/vocabs/loader/test/f/f.factor [new file with mode: 0644]
core/vocabs/loader/test/f/tags.txt [new file with mode: 0644]
core/vocabs/loader/test/g/g.factor [new file with mode: 0644]
core/vocabs/loader/test/g/tags.txt [new file with mode: 0644]
core/vocabs/loader/test/h/h.factor [new file with mode: 0644]
core/vocabs/loader/test/h/tags.txt [new file with mode: 0644]
core/vocabs/loader/test/i/i.factor [new file with mode: 0644]
core/vocabs/loader/test/i/tags.txt [new file with mode: 0644]
core/vocabs/vocabs-docs.factor
core/vocabs/vocabs.factor
core/words/words.factor
extra/bake/fry/fry.factor
extra/crypto/timing/timing.factor
extra/jamshred/jamshred.factor
extra/mason/test/test.factor
extra/micros/authors.txt [deleted file]
extra/micros/backend/backend.factor [deleted file]
extra/micros/micros-docs.factor [deleted file]
extra/micros/micros-tests.factor [deleted file]
extra/micros/micros.factor [deleted file]
extra/micros/summary.txt [deleted file]
extra/micros/unix/tags.txt [deleted file]
extra/micros/unix/unix.factor [deleted file]
extra/micros/windows/tags.txt [deleted file]
extra/micros/windows/windows.factor [deleted file]
extra/nehe/4/4.factor
extra/nehe/5/5.factor
extra/openal/example/example.factor
extra/wordtimer/wordtimer.factor
vm/data_gc.c
vm/data_gc.h
vm/debug.c
vm/factor.c
vm/os-unix.c
vm/os-unix.h
vm/os-windows-ce.c
vm/os-windows-ce.h
vm/os-windows-nt.c
vm/os-windows.c
vm/os-windows.h
vm/primitives.c
vm/quotations.c
vm/run.c
vm/run.h

index 7fdeca9ae6cc39e5bb8bcf5ced6cd65196aed3a0..ad1838b3df4421afcbf4b34c7b2b29fd5912c694 100644 (file)
@@ -35,7 +35,7 @@ ERROR: bad-alarm-frequency frequency ;
     [ time>> ] dip before=? ;
 
 : reschedule-alarm ( alarm -- )
-    dup [ swap interval>> time+ ] change-time register-alarm ;
+    dup [ swap interval>> time+ now max ] change-time register-alarm ;
 
 : call-alarm ( alarm -- )
     [ entry>> box> drop ]
index e2a2288988f6f79ac161b4a118dbd0a7e0f68579..5b49ce28021a0a6722416bdc2aec7265e22bd0f8 100644 (file)
@@ -1,6 +1,6 @@
 USING: help help.topics help.syntax help.crossref
 help.definitions io io.files kernel namespaces vocabs sequences
-parser vocabs.loader ;
+parser vocabs.loader vocabs.loader.private accessors assocs ;
 IN: bootstrap.help
 
 : load-help ( -- )
@@ -10,8 +10,8 @@ IN: bootstrap.help
     t load-help? set-global
 
     [ drop ] load-vocab-hook [
-        vocabs
-        [ vocab-docs-loaded? not ] filter
+        dictionary get values
+        [ docs-loaded?>> not ] filter
         [ load-docs ] each
     ] with-variable ;
 
index c0fafdc0f53ac0b7d2b624b45cd368d86bc5ee5f..d5f36db776335c94bfa4ea872aa1c7cddf75fdc6 100644 (file)
@@ -130,6 +130,12 @@ SYMBOL: jit-if-word
 SYMBOL: jit-if-jump
 SYMBOL: jit-dispatch-word
 SYMBOL: jit-dispatch
+SYMBOL: jit-dip-word
+SYMBOL: jit-dip
+SYMBOL: jit-2dip-word
+SYMBOL: jit-2dip
+SYMBOL: jit-3dip-word
+SYMBOL: jit-3dip
 SYMBOL: jit-epilog
 SYMBOL: jit-return
 SYMBOL: jit-profiling
@@ -139,8 +145,8 @@ SYMBOL: jit-save-stack
 ! Default definition for undefined words
 SYMBOL: undefined-quot
 
-: userenv-offset ( symbol -- n )
-    {
+: userenvs ( -- assoc )
+    H{
         { bootstrap-boot-quot 20 }
         { bootstrap-global 21 }
         { jit-code-format 22 }
@@ -160,8 +166,17 @@ SYMBOL: undefined-quot
         { jit-push-immediate 36 }
         { jit-declare-word 42 }
         { jit-save-stack 43 }
+        { jit-dip-word 44 }
+        { jit-dip 45 }
+        { jit-2dip-word 46 }
+        { jit-2dip 47 }
+        { jit-3dip-word 48 }
+        { jit-3dip 49 }
         { undefined-quot 60 }
-    } at header-size + ;
+    } ; inline
+
+: userenv-offset ( symbol -- n )
+    userenvs at header-size + ;
 
 : emit ( cell -- ) image get push ;
 
@@ -443,6 +458,9 @@ M: quotation '
     \ dispatch jit-dispatch-word set
     \ do-primitive jit-primitive-word set
     \ declare jit-declare-word set
+    \ dip jit-dip-word set
+    \ 2dip jit-2dip-word set
+    \ 3dip jit-3dip-word set
     [ undefined ] undefined-quot set
     {
         jit-code-format
@@ -457,6 +475,12 @@ M: quotation '
         jit-if-jump
         jit-dispatch-word
         jit-dispatch
+        jit-dip-word
+        jit-dip
+        jit-2dip-word
+        jit-2dip
+        jit-3dip-word
+        jit-3dip
         jit-epilog
         jit-return
         jit-profiling
index d25394e978ba5122f6425aa4684b59e06bec64cf..ac8e5343e1eb4c94ca0383f5632cb0810c7ce415 100644 (file)
@@ -32,8 +32,8 @@ SYMBOL: bootstrap-time
 : count-words ( pred -- )
     all-words swap count number>string write ;
 
-: print-time ( time -- )
-    1000 /i
+: print-time ( us -- )
+    1000000 /i
     60 /mod swap
     number>string write
     " minutes and " write number>string write " seconds." print ;
@@ -52,7 +52,7 @@ SYMBOL: bootstrap-time
 
 [
     ! We time bootstrap
-    millis
+    micros
 
     default-image-name "output-image" set-global
 
@@ -67,7 +67,7 @@ SYMBOL: bootstrap-time
     os wince? [ "windows.ce" require ] when
     os winnt? [ "windows.nt" require ] when
 
-    "deploy-vocab" get [
+    "staging" get "deploy-vocab" get or [
         "stage2: deployment mode" print
     ] [
         "listener" require
@@ -77,7 +77,7 @@ SYMBOL: bootstrap-time
     [
         load-components
 
-        millis over - core-bootstrap-time set-global
+        micros over - core-bootstrap-time set-global
 
         run-bootstrap-init
     ] with-compiler-errors
@@ -100,7 +100,7 @@ SYMBOL: bootstrap-time
             ] [ print-error 1 exit ] recover
         ] set-boot-quot
 
-        millis swap - bootstrap-time set-global
+        micros swap - bootstrap-time set-global
         print-report
 
         "output-image" get save-image-and-exit
index 64c74a494a4dd35c359557371880844ea7046481..433459cb24457823fd5b61c253f88132580c0d19 100644 (file)
@@ -365,12 +365,12 @@ HELP: unix-1970
 { $values { "timestamp" timestamp } }
 { $description "Outputs the beginning of UNIX time, or midnight, January 1, 1970." } ;
 
-HELP: millis>timestamp
+HELP: micros>timestamp
 { $values { "x" number } { "timestamp" timestamp } }
-{ $description "Converts a number of milliseconds into a timestamp value in GMT time." }
+{ $description "Converts a number of microseconds into a timestamp value in GMT time." }
 { $examples
     { $example "USING: accessors calendar prettyprint ;"
-               "1000 millis>timestamp year>> ."
+               "1000 micros>timestamp year>> ."
                "1970"
     }
 } ;
index 995bd23c091392100cdc6e117eb3b817e3dd0c27..00d5730745728979aa94b2e49007e9e0f7327e07 100644 (file)
@@ -143,10 +143,10 @@ IN: calendar.tests
 [ +gt+ ] [ 2005 1 1 12 30 0 instant <timestamp>
         2004 1 1 13 30 0 instant <timestamp> <=> ] unit-test
 
-[ t ] [ now timestamp>millis millis - 1000 < ] unit-test
-[ t ] [ 0 millis>timestamp unix-1970 = ] unit-test
-[ t ] [ 123456789000 [ millis>timestamp timestamp>millis ] keep = ] unit-test
-[ t ] [ 123456789123456 [ millis>timestamp timestamp>millis ] keep = ] unit-test
+[ t ] [ now timestamp>micros micros - 1000000 < ] unit-test
+[ t ] [ 0 micros>timestamp unix-1970 = ] unit-test
+[ t ] [ 123456789000000 [ micros>timestamp timestamp>micros ] keep = ] unit-test
+[ t ] [ 123456789123456000 [ micros>timestamp timestamp>micros ] keep = ] unit-test
 
 : checktime+ now dup clone [ rot time+ drop ] keep = ;
 
index c0027607488f64a9238d27ecdafefdf940a8c1de..a78cf60eb0147d204966fbf8c5783df5ba639f47 100644 (file)
@@ -325,9 +325,15 @@ M: duration time-
 : timestamp>millis ( timestamp -- n )
     unix-1970 (time-) 1000 * >integer ;
 
+: micros>timestamp ( x -- timestamp )
+    >r unix-1970 r> microseconds time+ ;
+
+: timestamp>micros ( timestamp -- n )
+    unix-1970 (time-) 1000000 * >integer ;
+
 : gmt ( -- timestamp )
     #! GMT time, right now
-    unix-1970 millis milliseconds time+ ;
+    unix-1970 micros microseconds time+ ;
 
 : now ( -- timestamp ) gmt >local-time ;
 : hence ( duration -- timestamp ) now swap time+ ;
@@ -404,7 +410,7 @@ PRIVATE>
 : since-1970 ( duration -- timestamp )
     unix-1970 time+ >local-time ;
 
-M: timestamp sleep-until timestamp>millis sleep-until ;
+M: timestamp sleep-until timestamp>micros sleep-until ;
 
 M: duration sleep hence sleep-until ;
 
index 60a61c20267b386357bf161409d7fdaa589ddab1..8665cc22cefe67749a59f0dca7fbe8bd490a42a8 100644 (file)
@@ -7,7 +7,7 @@ SYMBOL: time
 \r
 : (time-thread) ( -- )\r
     now time get set-model\r
-    1000 sleep (time-thread) ;\r
+    1 seconds sleep (time-thread) ;\r
 \r
 : time-thread ( -- )\r
     [\r
index 606526a240fafa48b6ae6d03c110f2d648c1ef09..662b4a7bae784f481dd92e5cf94434318185e87c 100644 (file)
@@ -26,7 +26,7 @@ IN: cocoa.dialogs
     [ -> filenames CF>string-array ] [ drop f ] if ;
 
 : split-path ( path -- dir file )
-    "/" last-split1 [ <NSString> ] bi@ ;
+    "/" split1-last [ <NSString> ] bi@ ;
 
 : save-panel ( path -- paths )
     <NSSavePanel> dup
index a6afc4b243af077ff2d4cbdfed3bb8eacebcb198..e5cbd888d94f0ddc93127ce810380103882a2255 100644 (file)
@@ -91,8 +91,8 @@ t compile-dependencies? set-global
     [
         dup crossref?
         [
-            dependencies get >alist
-            generic-dependencies get >alist
+            dependencies get
+            generic-dependencies get
             compiled-xref
         ] [ drop ] if
     ] tri ;
index 3ca6fc87f3d14ef2cbcba5ba799560a5011b35b5..abcdb46ea2744e532c1773bb3a382fe285538bf3 100644 (file)
@@ -361,7 +361,7 @@ FUNCTION: ulonglong ffi_test_38 ( ulonglong x, ulonglong y ) ;
 [ 1 2 3 ] [ callback-6 callback_test_1 1 2 3 ] unit-test
 
 : callback-7 ( -- callback )
-    "void" { } "cdecl" [ 1000 sleep ] alien-callback ;
+    "void" { } "cdecl" [ 1000000 sleep ] alien-callback ;
 
 [ 1 2 3 ] [ callback-7 callback_test_1 1 2 3 ] unit-test
 
diff --git a/basis/compiler/tests/redefine13.factor b/basis/compiler/tests/redefine13.factor
new file mode 100644 (file)
index 0000000..d092cd4
--- /dev/null
@@ -0,0 +1,14 @@
+USING: math fry macros eval tools.test ;
+IN: compiler.tests.redefine13
+
+: breakage-word ( a b -- c ) + ;
+
+MACRO: breakage-macro ( a -- ) '[ _ breakage-word ] ;
+
+GENERIC: breakage-caller ( a -- c )
+
+M: fixnum breakage-caller 2 breakage-macro ;
+
+: breakage ( -- obj ) 2 breakage-caller ;
+
+! [ ] [ "IN: compiler.tests.redefine13 : breakage-word ( a b -- c ) ;" eval ] unit-test
diff --git a/basis/compiler/tests/redefine14.factor b/basis/compiler/tests/redefine14.factor
new file mode 100644 (file)
index 0000000..807f3ed
--- /dev/null
@@ -0,0 +1,8 @@
+USING: compiler.units definitions tools.test sequences ;
+IN: compiler.tests.redefine14
+
+! TUPLE: bad ;
+! 
+! M: bad length 1 2 3 ;
+! 
+! [ ] [ [ { bad length } forget ] with-compilation-unit ] unit-test
index 3a38daed8600d16464dca5781060a718c1f24758..1c2dea2d79ce62305457be3cb4b306316eb5591c 100644 (file)
@@ -11,7 +11,7 @@ math.parser ;
 \r
 [ { 1 4 9 } ] [ { 1 2 3 } [ sq ] parallel-map ] unit-test\r
 \r
-[ { 1 4 9 } ] [ { 1 2 3 } [ 1000 random sleep sq ] parallel-map ] unit-test\r
+[ { 1 4 9 } ] [ { 1 2 3 } [ 1000000 random sleep sq ] parallel-map ] unit-test\r
 \r
 [ { 1 2 3 } [ dup 2 mod 0 = [ "Even" throw ] when ] parallel-map ]\r
 [ error>> "Even" = ] must-fail-with\r
index 9d3f6de98cb0cba25824145fc231d369960a58f2..0f78183abaade2cd0d4aa2ed645f3c7dc3128a46 100644 (file)
@@ -1,6 +1,6 @@
 IN: concurrency.flags.tests\r
 USING: tools.test concurrency.flags concurrency.combinators\r
-kernel threads locals accessors ;\r
+kernel threads locals accessors calendar ;\r
 \r
 :: flag-test-1 ( -- )\r
     [let | f [ <flag> ] |\r
@@ -13,7 +13,7 @@ kernel threads locals accessors ;
 \r
 :: flag-test-2 ( -- )\r
     [let | f [ <flag> ] |\r
-        [ 1000 sleep f raise-flag ] "Flag test" spawn drop\r
+        [ 1 seconds sleep f raise-flag ] "Flag test" spawn drop\r
         f lower-flag\r
         f value>>\r
     ] ;\r
@@ -39,7 +39,7 @@ kernel threads locals accessors ;
 \r
 :: flag-test-5 ( -- )\r
     [let | f [ <flag> ] |\r
-        [ 1000 sleep f raise-flag ] "Flag test" spawn drop\r
+        [ 1 seconds sleep f raise-flag ] "Flag test" spawn drop\r
         f wait-for-flag\r
         f value>>\r
     ] ;\r
@@ -48,6 +48,6 @@ kernel threads locals accessors ;
 \r
 [ ] [\r
     { 1 2 } <flag>\r
-    [ [ 1000 sleep raise-flag ] curry "Flag test" spawn drop ]\r
+    [ [ 1 seconds sleep raise-flag ] curry "Flag test" spawn drop ]\r
     [ [ wait-for-flag drop ] curry parallel-each ] bi\r
 ] unit-test\r
index 22549c1720260dfc8f3e82bc4b6e79193e70407c..3d2ac552de7091c8886d97ae7b1c68c57fb00482 100644 (file)
@@ -1,7 +1,7 @@
 ! Copyright (C) 2005, 2008 Chris Double, Slava Pestov.\r
 ! See http://factorcode.org/license.txt for BSD license.\r
 USING: concurrency.promises concurrency.messaging kernel arrays\r
-continuations help.markup help.syntax quotations ;\r
+continuations help.markup help.syntax quotations calendar ;\r
 IN: concurrency.futures\r
 \r
 HELP: future\r
@@ -11,8 +11,8 @@ $nl
 "The quotation begins with an empty data stack, an empty catch stack, and a name stack containing the global namespace only. This means that the only way to pass data to the quotation is to partially apply the data, for example using " { $link curry } " or " { $link compose } "." } ;\r
 \r
 HELP: ?future-timeout\r
-{ $values { "future" future } { "timeout" "a timeout in milliseconds or " { $link f } } { "value" object } }\r
-{ $description "Waits for a deferred computation to complete, blocking indefinitely if " { $snippet "timeout" } " is " { $link f } ", otherwise waiting up to " { $snippet "timeout" } " milliseconds." }\r
+{ $values { "future" future } { "timeout" { $maybe duration } } { "value" object } }\r
+{ $description "Waits for a deferred computation to complete, blocking indefinitely if " { $snippet "timeout" } " is " { $link f } ", otherwise waiting up to the " { $snippet "timeout" } " before throwing an error." }\r
 { $errors "Throws an error if the timeout expires before the computation completes. Also throws an error if the future quotation threw an error." } ;\r
 \r
 HELP: ?future\r
index 67f9bbb15a241f5e71ceaf18b560cdb26c960222..7696e6c1ebe061a010ae0bf78da4cafda2a15863 100644 (file)
@@ -100,7 +100,7 @@ threads sequences calendar accessors ;
                c await\r
                l [\r
                    4 v push\r
-                   1000 sleep\r
+                   1 seconds sleep\r
                    5 v push\r
                ] with-write-lock\r
                c'' count-down\r
@@ -139,7 +139,7 @@ threads sequences calendar accessors ;
                l [\r
                    1 v push\r
                    c count-down\r
-                   1000 sleep\r
+                   1 seconds sleep\r
                    2 v push\r
                ] with-write-lock\r
                c' count-down\r
index be7a8cf65b932b0d4b941fe459dd2221bc293b64..8e160842a93d5f7abb0c907a70723f6bc8d32ff3 100644 (file)
@@ -13,7 +13,7 @@ HELP: promise-fulfilled?
 \r
 HELP: ?promise-timeout\r
 { $values { "promise" promise } { "timeout" { $maybe duration } } { "result" object } }\r
-{ $description "Waits for another thread to fulfill a promise, returning immediately if the promise has already been fulfilled. A timeout of " { $link f } " indicates that the thread may block indefinitely, otherwise it will wait up to " { $snippet "timeout" } " milliseconds." }\r
+{ $description "Waits for another thread to fulfill a promise, returning immediately if the promise has already been fulfilled. A timeout of " { $link f } " indicates that the thread may block indefinitely, otherwise it will wait up to the " { $snippet "timeout" } " before throwing an error." }\r
 { $errors "Throws an error if the timeout expires before the promise has been fulfilled." } ;\r
 \r
 HELP: ?promise\r
index e30cc2eb6013141d3d8b139f4355901fcf430b4f..9a5666b5d3b032b0c5be4e17594a9fd12a03cf6d 100644 (file)
@@ -1,7 +1,7 @@
 ! Copyright (C) 2008 Slava Pestov
 ! See http://factorcode.org/license.txt for BSD license.
 USING: alien.syntax kernel threads init namespaces alien
-core-foundation ;
+core-foundation calendar ;
 IN: core-foundation.run-loop
 
 : kCFRunLoopRunFinished 1 ; inline
@@ -30,7 +30,7 @@ FUNCTION: SInt32 CFRunLoopRunInMode (
 
 : run-loop-thread ( -- )
     CFRunLoopDefaultMode 0 f CFRunLoopRunInMode
-    kCFRunLoopRunHandledSource = [ 1000 sleep ] unless
+    kCFRunLoopRunHandledSource = [ 1 seconds sleep ] unless
     run-loop-thread ;
 
 : start-run-loop-thread ( -- )
index 014d2b31a06725c93afe9eaa3495df49cbbf6a92..56ef89884c87031196b0e41ee72a5347212f2cbd 100644 (file)
@@ -71,11 +71,16 @@ big-endian on
 \r
 [ 0 B ] rc-relative-ppc-3 rt-xt 0 jit-word-jump jit-define\r
 \r
-: jit-call-quot ( -- )\r
+: jit-jump-quot ( -- )\r
     4 3 quot-xt-offset LWZ\r
     4 MTCTR\r
     BCTR ;\r
 \r
+: jit-call-quot ( -- )\r
+    4 3 quot-xt-offset LWZ\r
+    4 MTLR\r
+    BLR ;\r
+\r
 [\r
     0 3 LOAD32\r
     6 ds-reg 0 LWZ\r
@@ -84,7 +89,7 @@ big-endian on
     3 3 4 ADDI\r
     3 3 0 LWZ\r
     ds-reg dup 4 SUBI\r
-    jit-call-quot\r
+    jit-jump-quot\r
 ] rc-absolute-ppc-2/2 rt-literal 1 jit-if-jump jit-define\r
 \r
 [\r
@@ -95,9 +100,83 @@ big-endian on
     3 3 6 ADD\r
     3 3 array-start-offset LWZ\r
     ds-reg dup 4 SUBI\r
-    jit-call-quot\r
+    jit-jump-quot\r
 ] rc-absolute-ppc-2/2 rt-literal 1 jit-dispatch jit-define\r
 \r
+! These should not clobber r3 since we store a quotation in there\r
+! in jit-dip\r
+\r
+: jit->r ( -- )\r
+    4 ds-reg 0 LWZ\r
+    ds-reg dup 4 SUBI\r
+    4 rs-reg 4 STWU ;\r
+\r
+: jit-2>r ( -- )\r
+    4 ds-reg 0 LWZ\r
+    5 ds-reg -4 LWZ\r
+    ds-reg dup 8 SUBI\r
+    rs-reg dup 8 ADDI\r
+    4 rs-reg 0 STW\r
+    5 rs-reg -4 STW ;\r
+\r
+: jit-3>r ( -- )\r
+    4 ds-reg 0 LWZ\r
+    5 ds-reg -4 LWZ\r
+    6 ds-reg -8 LWZ\r
+    ds-reg dup 12 SUBI\r
+    rs-reg dup 12 ADDI\r
+    4 rs-reg 0 STW\r
+    5 rs-reg -4 STW\r
+    6 rs-reg -8 STW ;\r
+\r
+: jit-r> ( -- )\r
+    4 ds-reg 0 LWZ\r
+    ds-reg dup 4 SUBI\r
+    4 rs-reg 4 STWU ;\r
+\r
+: jit-2r> ( -- )\r
+    4 rs-reg 0 LWZ\r
+    5 rs-reg -4 LWZ\r
+    rs-reg dup 8 SUBI\r
+    ds-reg dup 8 ADDI\r
+    4 ds-reg 0 STW\r
+    5 ds-reg -4 STW ;\r
+\r
+: jit-3r> ( -- )\r
+    4 rs-reg 0 LWZ\r
+    5 rs-reg -4 LWZ\r
+    6 rs-reg -8 LWZ\r
+    rs-reg dup 12 SUBI\r
+    ds-reg dup 12 ADDI\r
+    4 ds-reg 0 STW\r
+    5 ds-reg -4 STW\r
+    6 ds-reg -8 STW ;\r
+\r
+: prepare-dip ( -- )\r
+    0 3 LOAD32\r
+    3 3 0 LWZ ;\r
+\r
+[\r
+    prepare-dip\r
+    jit->r\r
+    jit-call-quot\r
+    jit-r>\r
+] rc-absolute-ppc-2/2 rt-literal 1 jit-dip jit-define\r
+\r
+[\r
+    prepare-dip\r
+    jit-2>r\r
+    jit-call-quot\r
+    jit-2r>\r
+] rc-absolute-ppc-2/2 rt-literal 1 jit-2dip jit-define\r
+\r
+[\r
+    prepare-dip\r
+    jit-3>r\r
+    jit-call-quot\r
+    jit-3r>\r
+] rc-absolute-ppc-2/2 rt-literal 1 jit-3dip jit-define\r
+\r
 [\r
     0 1 lr-save stack-frame + LWZ\r
     1 1 stack-frame ADDI\r
@@ -112,7 +191,7 @@ big-endian on
 [\r
     3 ds-reg 0 LWZ\r
     ds-reg dup 4 SUBI\r
-    jit-call-quot\r
+    jit-jump-quot\r
 ] f f f \ (call) define-sub-primitive\r
 \r
 [\r
@@ -245,17 +324,9 @@ big-endian on
     4 ds-reg 0 STW\r
 ] f f f \ -rot define-sub-primitive\r
 \r
-[\r
-    3 ds-reg 0 LWZ\r
-    ds-reg dup 4 SUBI\r
-    3 rs-reg 4 STWU\r
-] f f f \ >r define-sub-primitive\r
+[ jit->r ] f f f \ >r define-sub-primitive\r
 \r
-[\r
-    3 rs-reg 0 LWZ\r
-    rs-reg dup 4 SUBI\r
-    3 ds-reg 4 STWU\r
-] f f f \ r> define-sub-primitive\r
+[ jit-r> ] f f f \ r> define-sub-primitive\r
 \r
 ! Comparisons\r
 : jit-compare ( insn -- )\r
index ba963ab477d2f087df299394f8fb1319255558f9..04bdcca68b8498f392623d5212b33b8182cdaf78 100644 (file)
@@ -12,6 +12,7 @@ IN: bootstrap.x86
 : mod-arg ( -- reg ) EDX ;
 : arg0 ( -- reg ) EAX ;
 : arg1 ( -- reg ) EDX ;
+: arg2 ( -- reg ) ECX ;
 : temp-reg ( -- reg ) EBX ;
 : stack-reg ( -- reg ) ESP ;
 : ds-reg ( -- reg ) ESI ;
index 29d48bd7944b41b6241ab0f46c02764b018fca3c..f0ca56da1472bda5f28b42bf614c30b7cf3fe221 100644 (file)
@@ -7,6 +7,7 @@ IN: bootstrap.x86
 : stack-frame-size ( -- n ) 4 bootstrap-cells ;
 : arg0 ( -- reg ) RDI ;
 : arg1 ( -- reg ) RSI ;
+: arg2 ( -- reg ) RDX ;
 
 << "resource:basis/cpu/x86/64/bootstrap.factor" parse-file parsed >>
 call
index a62b946e83981782b8eff07d9142b34b3aec9886..459945d82e4d9715c6ede20b493dd9b6165c8aff 100644 (file)
@@ -7,6 +7,7 @@ IN: bootstrap.x86
 : stack-frame-size ( -- n ) 8 bootstrap-cells ;
 : arg0 ( -- reg ) RCX ;
 : arg1 ( -- reg ) RDX ;
+: arg2 ( -- reg ) R8 ;
 
 << "resource:basis/cpu/x86/64/bootstrap.factor" parse-file parsed >>
 call
index 2c54880788f6554e73acf48addfb370f5e9ef278..af7c9e2f0f8222fb01fcf4eaffdb33f33a92f031 100644 (file)
@@ -73,6 +73,80 @@ big-endian off
     arg0 quot-xt-offset [+] JMP                ! execute branch
 ] rc-absolute-cell rt-literal 1 rex-length + jit-dispatch jit-define
 
+! The jit->r words cannot clobber arg0
+
+: jit->r ( -- )
+    rs-reg bootstrap-cell ADD
+    temp-reg ds-reg [] MOV
+    ds-reg bootstrap-cell SUB
+    rs-reg [] temp-reg MOV ;
+
+: jit-2>r ( -- )
+    rs-reg 2 bootstrap-cells ADD
+    temp-reg ds-reg [] MOV
+    arg1 ds-reg -1 bootstrap-cells [+] MOV
+    ds-reg 2 bootstrap-cells SUB
+    rs-reg [] temp-reg MOV
+    rs-reg -1 bootstrap-cells [+] arg1 MOV ;
+
+: jit-3>r ( -- )
+    rs-reg 3 bootstrap-cells ADD
+    temp-reg ds-reg [] MOV
+    arg1 ds-reg -1 bootstrap-cells [+] MOV
+    arg2 ds-reg -2 bootstrap-cells [+] MOV
+    ds-reg 3 bootstrap-cells SUB
+    rs-reg [] temp-reg MOV
+    rs-reg -1 bootstrap-cells [+] arg1 MOV
+    rs-reg -2 bootstrap-cells [+] arg2 MOV ;
+
+: jit-r> ( -- )
+    ds-reg bootstrap-cell ADD
+    temp-reg rs-reg [] MOV
+    rs-reg bootstrap-cell SUB
+    ds-reg [] temp-reg MOV ;
+
+: jit-2r> ( -- )
+    ds-reg 2 bootstrap-cells ADD
+    temp-reg rs-reg [] MOV
+    arg1 rs-reg -1 bootstrap-cells [+] MOV
+    rs-reg 2 bootstrap-cells SUB
+    ds-reg [] temp-reg MOV
+    ds-reg -1 bootstrap-cells [+] arg1 MOV ;
+
+: jit-3r> ( -- )
+    ds-reg 3 bootstrap-cells ADD
+    temp-reg rs-reg [] MOV
+    arg1 rs-reg -1 bootstrap-cells [+] MOV
+    arg2 rs-reg -2 bootstrap-cells [+] MOV
+    rs-reg 3 bootstrap-cells SUB
+    ds-reg [] temp-reg MOV
+    ds-reg -1 bootstrap-cells [+] arg1 MOV
+    ds-reg -2 bootstrap-cells [+] arg2 MOV ;
+
+[
+    arg0 0 MOV                                 ! load quotation addr
+    arg0 arg0 [] MOV                           ! load quotation
+    jit->r
+    arg0 quot-xt-offset [+] CALL               ! call quotation
+    jit-r>
+] rc-absolute-cell rt-literal 1 rex-length + jit-dip jit-define
+
+[
+    arg0 0 MOV                                 ! load quotation addr
+    arg0 arg0 [] MOV                           ! load quotation
+    jit-2>r
+    arg0 quot-xt-offset [+] CALL               ! call quotation
+    jit-2r>
+] rc-absolute-cell rt-literal 1 rex-length + jit-2dip jit-define
+
+[
+    arg0 0 MOV                                 ! load quotation addr
+    arg0 arg0 [] MOV                           ! load quotation
+    jit-3>r                                    
+    arg0 quot-xt-offset [+] CALL               ! call quotation
+    jit-3r>
+] rc-absolute-cell rt-literal 1 rex-length + jit-3dip jit-define
+
 [
     stack-reg stack-frame-size bootstrap-cell - ADD ! unwind stack frame
 ] f f f jit-epilog jit-define
@@ -223,19 +297,9 @@ big-endian off
     ds-reg [] arg1 MOV
 ] f f f \ -rot define-sub-primitive
 
-[
-    rs-reg bootstrap-cell ADD
-    arg0 ds-reg [] MOV
-    ds-reg bootstrap-cell SUB
-    rs-reg [] arg0 MOV
-] f f f \ >r define-sub-primitive
+[ jit->r ] f f f \ >r define-sub-primitive
 
-[
-    ds-reg bootstrap-cell ADD
-    arg0 rs-reg [] MOV
-    rs-reg bootstrap-cell SUB
-    ds-reg [] arg0 MOV
-] f f f \ r> define-sub-primitive
+[ jit-r> ] f f f \ r> define-sub-primitive
 
 ! Comparisons
 : jit-compare ( insn -- )
@@ -305,7 +369,7 @@ big-endian off
     ds-reg [] arg1 MOV                         ! push to stack
 ] f f f \ fixnum-shift-fast define-sub-primitive
 
-: jit-fixnum-/mod
+: jit-fixnum-/mod ( -- )
     temp-reg ds-reg [] MOV                     ! load second parameter
     div-arg ds-reg bootstrap-cell neg [+] MOV  ! load first parameter
     mod-arg div-arg MOV                        ! make a copy
index 21e3c05d041bae54a89e9ea5bb6c403134ce9f9c..77a9038cd990aec6d3ec462d8d15a0ff4c5c73ac 100644 (file)
@@ -36,7 +36,7 @@ TUPLE: line-break ;
     { "http://" "https://" "ftp://" } [ head? ] with contains? ;
 
 : simple-link-title ( string -- string' )
-    dup absolute-url? [ "/" last-split1 swap or ] unless ;
+    dup absolute-url? [ "/" split1-last swap or ] unless ;
 
 EBNF: parse-farkup
 nl               = ("\r\n" | "\r" | "\n") => [[ drop "\n" ]]
index 3e1ef6ce0586e2d551bfd866899b0b9bb33b0d9c..bdccfc3f5713375ac66349497b3fb233a3402d56 100644 (file)
@@ -4,7 +4,8 @@ USING: system kernel namespaces strings hashtables sequences
 assocs combinators vocabs.loader init threads continuations
 math accessors concurrency.flags destructors environment
 io io.backend io.timeouts io.pipes io.pipes.private io.encodings
-io.streams.duplex io.ports debugger prettyprint summary ;
+io.streams.duplex io.ports debugger prettyprint summary
+calendar ;
 IN: io.launcher
 
 TUPLE: process < identity-tuple
@@ -65,7 +66,7 @@ SYMBOL: wait-flag
 : wait-loop ( -- )
     processes get assoc-empty?
     [ wait-flag get-global lower-flag ]
-    [ wait-for-processes [ 100 sleep ] when ] if ;
+    [ wait-for-processes [ 100 milliseconds sleep ] when ] if ;
 
 : start-wait-thread ( -- )
     <flag> wait-flag set-global
diff --git a/basis/io/sockets/secure/openssl/openssl.factor b/basis/io/sockets/secure/openssl/openssl.factor
new file mode 100644 (file)
index 0000000..ec45337
--- /dev/null
@@ -0,0 +1,196 @@
+! Copyright (C) 2007, 2008, Slava Pestov, Elie CHAFTARI.
+! See http://factorcode.org/license.txt for BSD license.
+USING: accessors byte-arrays kernel debugger sequences
+namespaces math math.order combinators init alien alien.c-types
+alien.strings libc continuations destructors debugger summary
+splitting assocs random math.parser locals unicode.case openssl
+openssl.libcrypto openssl.libssl io.backend io.ports io.files
+io.encodings.8-bit io.timeouts io.sockets.secure ;
+IN: io.sockets.secure.openssl
+
+GENERIC: ssl-method ( symbol -- method )
+
+M: SSLv2  ssl-method drop SSLv2_client_method ;
+M: SSLv23 ssl-method drop SSLv23_method ;
+M: SSLv3  ssl-method drop SSLv3_method ;
+M: TLSv1  ssl-method drop TLSv1_method ;
+
+TUPLE: openssl-context < secure-context aliens sessions ;
+
+: set-session-cache ( ctx -- )
+    handle>>
+    [ SSL_SESS_CACHE_BOTH SSL_CTX_set_session_cache_mode ssl-error ]
+    [ 32 random-bits >hex dup length SSL_CTX_set_session_id_context ssl-error ]
+    bi ;
+
+: load-certificate-chain ( ctx -- )
+    dup config>> key-file>> [
+        [ handle>> ] [ config>> key-file>> (normalize-path) ] bi
+        SSL_CTX_use_certificate_chain_file
+        ssl-error
+    ] [ drop ] if ;
+
+: password-callback ( -- alien )
+    "int" { "void*" "int" "bool" "void*" } "cdecl"
+    [| buf size rwflag password! |
+        password [ B{ 0 } password! ] unless
+
+        [let | len [ password strlen ] |
+            buf password len 1+ size min memcpy
+            len
+        ]
+    ] alien-callback ;
+
+: default-pasword ( ctx -- alien )
+    [ config>> password>> latin1 malloc-string ] [ aliens>> ] bi
+    [ push ] [ drop ] 2bi ;
+
+: set-default-password ( ctx -- )
+    [ handle>> password-callback SSL_CTX_set_default_passwd_cb ]
+    [
+        [ handle>> ] [ default-pasword ] bi
+        SSL_CTX_set_default_passwd_cb_userdata
+    ] bi ;
+
+: use-private-key-file ( ctx -- )
+    dup config>> key-file>> [
+        [ handle>> ] [ config>> key-file>> (normalize-path) ] bi
+        SSL_FILETYPE_PEM SSL_CTX_use_PrivateKey_file
+        ssl-error
+    ] [ drop ] if ;
+
+: load-verify-locations ( ctx -- )
+    dup config>> [ ca-file>> ] [ ca-path>> ] bi or [
+        [ handle>> ]
+        [
+            config>>
+            [ ca-file>> dup [ (normalize-path) ] when ]
+            [ ca-path>> dup [ (normalize-path) ] when ] bi
+        ] bi
+        SSL_CTX_load_verify_locations
+    ] [ handle>> SSL_CTX_set_default_verify_paths ] if ssl-error ;
+
+: set-verify-depth ( ctx -- )
+    dup config>> verify-depth>> [
+        [ handle>> ] [ config>> verify-depth>> ] bi
+        SSL_CTX_set_verify_depth
+    ] [ drop ] if ;
+
+TUPLE: bio handle disposed ;
+
+: <bio> ( handle -- bio ) f bio boa ;
+
+M: bio dispose* handle>> BIO_free ssl-error ;
+
+: <file-bio> ( path -- bio )
+    normalize-path "r" BIO_new_file dup ssl-error <bio> ;
+
+: load-dh-params ( ctx -- )
+    dup config>> dh-file>> [
+        [ handle>> ] [ config>> dh-file>> ] bi <file-bio> &dispose
+        handle>> f f f PEM_read_bio_DHparams dup ssl-error
+        SSL_CTX_set_tmp_dh ssl-error
+    ] [ drop ] if ;
+
+TUPLE: rsa handle disposed ;
+
+: <rsa> ( handle -- rsa ) f rsa boa ;
+
+M: rsa dispose* handle>> RSA_free ;
+
+: generate-eph-rsa-key ( ctx -- )
+    [ handle>> ]
+    [
+        config>> ephemeral-key-bits>> RSA_F4 f f RSA_generate_key
+        dup ssl-error <rsa> &dispose handle>>
+    ] bi
+    SSL_CTX_set_tmp_rsa ssl-error ;
+
+: <openssl-context> ( config ctx -- context )
+    openssl-context new
+        swap >>handle
+        swap >>config
+        V{ } clone >>aliens
+        H{ } clone >>sessions ;
+
+M: openssl <secure-context> ( config -- context )
+    maybe-init-ssl
+    [
+        dup method>> ssl-method SSL_CTX_new
+        dup ssl-error <openssl-context> |dispose
+        {
+            [ set-session-cache ]
+            [ load-certificate-chain ]
+            [ set-default-password ]
+            [ use-private-key-file ]
+            [ load-verify-locations ]
+            [ set-verify-depth ]
+            [ load-dh-params ]
+            [ generate-eph-rsa-key ]
+            [ ]
+        } cleave
+    ] with-destructors ;
+
+M: openssl-context dispose*
+    [ aliens>> [ free ] each ]
+    [ sessions>> values [ SSL_SESSION_free ] each ]
+    [ handle>> SSL_CTX_free ]
+    tri ;
+
+TUPLE: ssl-handle file handle connected disposed ;
+
+SYMBOL: default-secure-context
+
+: context-expired? ( context -- ? )
+    dup [ handle>> expired? ] [ drop t ] if ;
+
+: current-secure-context ( -- ctx )
+    secure-context get [
+        default-secure-context get dup context-expired? [
+            drop
+            <secure-config> <secure-context> default-secure-context set-global
+            current-secure-context
+        ] when
+    ] unless* ;
+
+: <ssl-handle> ( fd -- ssl )
+    current-secure-context handle>> SSL_new dup ssl-error
+    f f ssl-handle boa ;
+
+M: ssl-handle dispose*
+    [ handle>> SSL_free ] [ file>> dispose ] bi ;
+
+: check-verify-result ( ssl-handle -- )
+    SSL_get_verify_result dup X509_V_OK =
+    [ drop ] [ verify-message certificate-verify-error ] if ;
+
+: common-name ( certificate -- host )
+    X509_get_subject_name
+    NID_commonName 256 <byte-array>
+    [ 256 X509_NAME_get_text_by_NID ] keep
+    swap -1 = [ drop f ] [ latin1 alien>string ] if ;
+
+: common-names-match? ( expected actual -- ? )
+    [ >lower ] bi@ "*." ?head [ tail? ] [ = ] if ;
+
+: check-common-name ( host ssl-handle -- )
+    SSL_get_peer_certificate common-name
+    2dup common-names-match?
+    [ 2drop ] [ common-name-verify-error ] if ;
+
+M: openssl check-certificate ( host ssl -- )
+    current-secure-context config>> verify>> [
+        handle>>
+        [ nip check-verify-result ]
+        [ check-common-name ]
+        2bi
+    ] [ 2drop ] if ;
+
+: get-session ( addrspec -- session/f )
+    current-secure-context sessions>> at
+    dup expired? [ drop f ] when ;
+
+: save-session ( session addrspec -- )
+    current-secure-context sessions>> set-at ;
+
+openssl secure-socket-backend set-global
index ad5c192a39607fccaf695fe46d3e6bcf8af4a745..9fa1727e16c241dadd46f9b40e2e46a381dfdea5 100644 (file)
@@ -303,7 +303,7 @@ M: string other-execute? ( path -- ? ) OTHER-EXECUTE file-mode? ;
     dup length [ over [ pick set-timeval-nth ] [ 2drop ] if ] 2each ;
 
 : timestamp>timeval ( timestamp -- timeval )
-    unix-1970 time- duration>milliseconds make-timeval ;
+    unix-1970 time- duration>microseconds make-timeval ;
 
 : timestamps>byte-array ( timestamps -- byte-array )
     [ dup [ timestamp>timeval ] when ] map make-timeval-array ;
index b3e69a453cd8ae18942695187a7a41f4349f836c..ba4240de7ff8d94b3835ae391cf5732b4c204fdd 100644 (file)
@@ -94,7 +94,7 @@ M: kqueue-mx unregister-io-task ( task mx -- )
 : handle-kevents ( mx n -- )
     [ over events>> kevent-nth handle-kevent ] with each ;
 
-M: kqueue-mx wait-for-events ( ms mx -- )
+M: kqueue-mx wait-for-events ( us mx -- )
     swap dup [ make-timespec ] when
     dupd wait-kevent handle-kevents ;
 
index f2a802a859591f202779c33926ae70e2ac2b7bd2..530dfe7ab3467b99ac644c81a957d9bec6275b83 100644 (file)
@@ -48,9 +48,9 @@ TUPLE: select-mx < mx read-fdset write-fdset ;
     [ write-fdset/tasks [ init-fdset ] [ underlying>> ] bi ] tri
     f ;
 
-M:: select-mx wait-for-events ( ms mx -- )
+M:: select-mx wait-for-events ( us mx -- )
     mx
-    [ init-fdsets ms dup [ make-timeval ] when select multiplexer-error ]
+    [ init-fdsets us dup [ make-timeval ] when select multiplexer-error ]
     [ [ read-fdset/tasks ] keep [ input-available ] check-fdset ]
     [ [ write-fdset/tasks ] keep [ output-available ] check-fdset ]
     tri ;
index 649c68673fe4c34679e8fc48da0d0b5cbfdaff82..fb5ed939781a3b7868a98ccfa7ad6557dfbefb36 100644 (file)
@@ -1,11 +1,11 @@
 ! Copyright (C) 2007, 2008, Slava Pestov, Elie CHAFTARI.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: accessors unix byte-arrays kernel debugger sequences namespaces math
-math.order combinators init alien alien.c-types alien.strings libc
-continuations destructors
-openssl openssl.libcrypto openssl.libssl
-io.files io.ports io.unix.backend io.unix.sockets
-io.encodings.ascii io.buffers io.sockets io.sockets.secure
+USING: accessors unix byte-arrays kernel debugger sequences
+namespaces math math.order combinators init alien alien.c-types
+alien.strings libc continuations destructors openssl
+openssl.libcrypto openssl.libssl io.files io.ports
+io.unix.backend io.unix.sockets io.encodings.ascii io.buffers
+io.sockets io.sockets.secure io.sockets.secure.openssl
 io.timeouts system summary ;
 IN: io.unix.sockets.secure
 
index c9bf1ebf423f3c6b71c0c79f0819277717a55b3b..d498875c8755b4d573cc02e6bec0c01599c36291 100644 (file)
@@ -35,7 +35,7 @@ IN: io.windows.nt.pipes
         "-" %
         32 random-bits #
         "-" %
-        millis #
+        micros #
     ] "" make ;
 
 M: winnt (pipe) ( -- pipe )
old mode 100644 (file)
new mode 100755 (executable)
index 6f6c29f..ce75293
@@ -1,11 +1,10 @@
 ! Copyright (C) 2004, 2008 Mackenzie Straight, Doug Coleman.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: alien alien.c-types arrays destructors io io.backend
-io.buffers io.files io.ports io.sockets io.binary
-io.sockets io.timeouts windows.errors strings
-kernel math namespaces sequences windows windows.kernel32
-windows.shell32 windows.types windows.winsock splitting
-continuations math.bitwise system accessors ;
+io.buffers io.files io.ports io.binary io.timeouts
+windows.errors strings kernel math namespaces sequences windows
+windows.kernel32 windows.shell32 windows.types windows.winsock
+splitting continuations math.bitwise system accessors ;
 IN: io.windows
 
 : set-inherit ( handle ? -- )
index 284e42cd1b31399eba2c2bcf9af5fe52901e1298..8f14c60e14abf4bda8766efc662bd932d5d43654 100644 (file)
@@ -1,25 +1,13 @@
 ! Copyright (C) 2007, 2008, Slava Pestov, Elie CHAFTARI.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: accessors byte-arrays kernel debugger sequences namespaces math
-math.order combinators init alien alien.c-types alien.strings libc
-continuations destructors debugger summary splitting assocs
-random math.parser locals unicode.case
-openssl.libcrypto openssl.libssl
-io.backend io.ports io.files io.encodings.8-bit io.sockets.secure
-io.timeouts ;
+USING: init kernel namespaces openssl.libcrypto openssl.libssl
+sequences ;
 IN: openssl
 
 ! This code is based on http://www.rtfm.com/openssl-examples/
 
 SINGLETON: openssl
 
-GENERIC: ssl-method ( symbol -- method )
-
-M: SSLv2  ssl-method drop SSLv2_client_method ;
-M: SSLv23 ssl-method drop SSLv23_method ;
-M: SSLv3  ssl-method drop SSLv3_method ;
-M: TLSv1  ssl-method drop TLSv1_method ;
-
 : (ssl-error-string) ( n -- string )
     ERR_clear_error f ERR_error_string ;
 
@@ -47,183 +35,3 @@ SYMBOL: ssl-initialized?
     ] unless ;
 
 [ f ssl-initialized? set-global ] "openssl" add-init-hook
-
-TUPLE: openssl-context < secure-context aliens sessions ;
-
-: set-session-cache ( ctx -- )
-    handle>>
-    [ SSL_SESS_CACHE_BOTH SSL_CTX_set_session_cache_mode ssl-error ]
-    [ 32 random-bits >hex dup length SSL_CTX_set_session_id_context ssl-error ]
-    bi ;
-
-: load-certificate-chain ( ctx -- )
-    dup config>> key-file>> [
-        [ handle>> ] [ config>> key-file>> (normalize-path) ] bi
-        SSL_CTX_use_certificate_chain_file
-        ssl-error
-    ] [ drop ] if ;
-
-: password-callback ( -- alien )
-    "int" { "void*" "int" "bool" "void*" } "cdecl"
-    [| buf size rwflag password! |
-        password [ B{ 0 } password! ] unless
-
-        [let | len [ password strlen ] |
-            buf password len 1+ size min memcpy
-            len
-        ]
-    ] alien-callback ;
-
-: default-pasword ( ctx -- alien )
-    [ config>> password>> latin1 malloc-string ] [ aliens>> ] bi
-    [ push ] [ drop ] 2bi ;
-
-: set-default-password ( ctx -- )
-    [ handle>> password-callback SSL_CTX_set_default_passwd_cb ]
-    [
-        [ handle>> ] [ default-pasword ] bi
-        SSL_CTX_set_default_passwd_cb_userdata
-    ] bi ;
-
-: use-private-key-file ( ctx -- )
-    dup config>> key-file>> [
-        [ handle>> ] [ config>> key-file>> (normalize-path) ] bi
-        SSL_FILETYPE_PEM SSL_CTX_use_PrivateKey_file
-        ssl-error
-    ] [ drop ] if ;
-
-: load-verify-locations ( ctx -- )
-    dup config>> [ ca-file>> ] [ ca-path>> ] bi or [
-        [ handle>> ]
-        [
-            config>>
-            [ ca-file>> dup [ (normalize-path) ] when ]
-            [ ca-path>> dup [ (normalize-path) ] when ] bi
-        ] bi
-        SSL_CTX_load_verify_locations
-    ] [ handle>> SSL_CTX_set_default_verify_paths ] if ssl-error ;
-
-: set-verify-depth ( ctx -- )
-    dup config>> verify-depth>> [
-        [ handle>> ] [ config>> verify-depth>> ] bi
-        SSL_CTX_set_verify_depth
-    ] [ drop ] if ;
-
-TUPLE: bio handle disposed ;
-
-: <bio> ( handle -- bio ) f bio boa ;
-
-M: bio dispose* handle>> BIO_free ssl-error ;
-
-: <file-bio> ( path -- bio )
-    normalize-path "r" BIO_new_file dup ssl-error <bio> ;
-
-: load-dh-params ( ctx -- )
-    dup config>> dh-file>> [
-        [ handle>> ] [ config>> dh-file>> ] bi <file-bio> &dispose
-        handle>> f f f PEM_read_bio_DHparams dup ssl-error
-        SSL_CTX_set_tmp_dh ssl-error
-    ] [ drop ] if ;
-
-TUPLE: rsa handle disposed ;
-
-: <rsa> ( handle -- rsa ) f rsa boa ;
-
-M: rsa dispose* handle>> RSA_free ;
-
-: generate-eph-rsa-key ( ctx -- )
-    [ handle>> ]
-    [
-        config>> ephemeral-key-bits>> RSA_F4 f f RSA_generate_key
-        dup ssl-error <rsa> &dispose handle>>
-    ] bi
-    SSL_CTX_set_tmp_rsa ssl-error ;
-
-: <openssl-context> ( config ctx -- context )
-    openssl-context new
-        swap >>handle
-        swap >>config
-        V{ } clone >>aliens
-        H{ } clone >>sessions ;
-
-M: openssl <secure-context> ( config -- context )
-    maybe-init-ssl
-    [
-        dup method>> ssl-method SSL_CTX_new
-        dup ssl-error <openssl-context> |dispose
-        {
-            [ set-session-cache ]
-            [ load-certificate-chain ]
-            [ set-default-password ]
-            [ use-private-key-file ]
-            [ load-verify-locations ]
-            [ set-verify-depth ]
-            [ load-dh-params ]
-            [ generate-eph-rsa-key ]
-            [ ]
-        } cleave
-    ] with-destructors ;
-
-M: openssl-context dispose*
-    [ aliens>> [ free ] each ]
-    [ sessions>> values [ SSL_SESSION_free ] each ]
-    [ handle>> SSL_CTX_free ]
-    tri ;
-
-TUPLE: ssl-handle file handle connected disposed ;
-
-SYMBOL: default-secure-context
-
-: context-expired? ( context -- ? )
-    dup [ handle>> expired? ] [ drop t ] if ;
-
-: current-secure-context ( -- ctx )
-    secure-context get [
-        default-secure-context get dup context-expired? [
-            drop
-            <secure-config> <secure-context> default-secure-context set-global
-            current-secure-context
-        ] when
-    ] unless* ;
-
-: <ssl-handle> ( fd -- ssl )
-    current-secure-context handle>> SSL_new dup ssl-error
-    f f ssl-handle boa ;
-
-M: ssl-handle dispose*
-    [ handle>> SSL_free ] [ file>> dispose ] bi ;
-
-: check-verify-result ( ssl-handle -- )
-    SSL_get_verify_result dup X509_V_OK =
-    [ drop ] [ verify-message certificate-verify-error ] if ;
-
-: common-name ( certificate -- host )
-    X509_get_subject_name
-    NID_commonName 256 <byte-array>
-    [ 256 X509_NAME_get_text_by_NID ] keep
-    swap -1 = [ drop f ] [ latin1 alien>string ] if ;
-
-: common-names-match? ( expected actual -- ? )
-    [ >lower ] bi@ "*." ?head [ tail? ] [ = ] if ;
-
-: check-common-name ( host ssl-handle -- )
-    SSL_get_peer_certificate common-name
-    2dup common-names-match?
-    [ 2drop ] [ common-name-verify-error ] if ;
-
-M: openssl check-certificate ( host ssl -- )
-    current-secure-context config>> verify>> [
-        handle>>
-        [ nip check-verify-result ]
-        [ check-common-name ]
-        2bi
-    ] [ 2drop ] if ;
-
-: get-session ( addrspec -- session/f )
-    current-secure-context sessions>> at
-    dup expired? [ drop f ] when ;
-
-: save-session ( session addrspec -- )
-    current-secure-context sessions>> set-at ;
-
-openssl secure-socket-backend set-global
index 5739482093550d321726f0a05386588b99db6360..af1b4aec047c6db6a2f7e28d48df9bc8d6f9dabd 100644 (file)
@@ -1,7 +1,7 @@
 ! Copyright (C) 2007, 2008 Chris Double, Doug Coleman.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: kernel sequences strings namespaces make math assocs
-shuffle vectors arrays math.parser accessors unicode.categories
+vectors arrays math.parser accessors unicode.categories
 sequences.deep peg peg.private peg.search math.ranges words ;
 IN: peg.parsers
 
index cc13d5d42510fbfa3fcb788dea3187e0f00cef31..2dabf1edf789221520b6fd53422384699ab6b6a0 100644 (file)
@@ -1,7 +1,7 @@
 ! Copyright (C) 2007, 2008 Chris Double.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: kernel sequences strings fry namespaces make math assocs
-shuffle debugger io vectors arrays math.parser math.order
+debugger io vectors arrays math.parser math.order
 vectors combinators classes sets unicode.categories
 compiler.units parser words quotations effects memoize accessors
 locals effects splitting combinators.short-circuit
index 240b27a9ccd9da81298c7b55c0eba7f20f87b9ef..7b729b2e5088b3e9f01f32d0692a99f59c1dd947 100644 (file)
@@ -14,6 +14,9 @@ M: character-class-range class-member? ( obj class -- ? )
 
 M: any-char class-member? ( obj class -- ? )
     2drop t ;
+
+M: any-char-no-nl class-member? ( obj class -- ? )
+    drop CHAR: \n = not ;
     
 M: letter-class class-member? ( obj class -- ? )
     drop letter? ;
index 6a1d40c5735ed8b6589a9e7d8555079f35ff050a..7f1d92a1ab91baace3f7dcb967c245d3898f544a 100644 (file)
@@ -43,6 +43,7 @@ INSTANCE: comment-group parentheses-group
 TUPLE: character-class-range from to ; INSTANCE: character-class-range node
 SINGLETON: epsilon INSTANCE: epsilon node
 SINGLETON: any-char INSTANCE: any-char node
+SINGLETON: any-char-no-nl INSTANCE: any-char-no-nl node
 SINGLETON: front-anchor INSTANCE: front-anchor node
 SINGLETON: back-anchor INSTANCE: back-anchor node
 
@@ -172,7 +173,7 @@ DEFER: (parse-regexp)
     [ drop1 (parse-special-group) ]
     [ capture-group f nested-parse-regexp ] if ;
 
-: handle-dot ( -- ) any-char push-stack ;
+: handle-dot ( -- ) get-dotall any-char any-char-no-nl ? push-stack ;
 : handle-pipe ( -- ) pipe push-stack ;
 : (handle-star) ( obj -- kleene-star )
     peek1 {
index d01f0c55483644739994d614441c6f4b20143e23..777d0985e4c34e50ae570d9dc7ea829e2717bf58 100644 (file)
@@ -1,5 +1,5 @@
 USING: regexp tools.test kernel sequences regexp.parser
-regexp.traversal eval ;
+regexp.traversal eval strings ;
 IN: regexp-tests
 
 \ <regexp> must-infer
@@ -40,7 +40,12 @@ IN: regexp-tests
 [ f ] [ "" "." <regexp> matches? ] unit-test
 [ t ] [ "a" "." <regexp> matches? ] unit-test
 [ t ] [ "." "." <regexp> matches? ] unit-test
-! [ f ] [ "\n" "." <regexp> matches? ] unit-test
+
+! Dotall mode -- when on, . matches newlines.
+! Off by default.
+[ f ] [ "\n" "." <regexp> matches? ] unit-test
+[ t ] [ "\n" "(?s)." <regexp> matches? ] unit-test
+[ f ] [ "\n\n" "(?s).(?-s)." <regexp> matches? ] unit-test
 
 [ f ] [ "" ".+" <regexp> matches? ] unit-test
 [ t ] [ "a" ".+" <regexp> matches? ] unit-test
@@ -170,7 +175,6 @@ IN: regexp-tests
 [ f ] [ "ABC" "\\p{Lower}{3}" <regexp> matches? ] unit-test
 [ t ] [ "ABC" "\\p{Upper}{3}" <regexp> matches? ] unit-test
 [ f ] [ "abc" "\\p{Upper}{3}" <regexp> matches? ] unit-test
-! 
 [ f ] [ "abc" "[\\p{Upper}]{3}" <regexp> matches? ] unit-test
 [ t ] [ "ABC" "[\\p{Upper}]{3}" <regexp> matches? ] unit-test
 
@@ -252,7 +256,40 @@ IN: regexp-tests
 ! Comment
 [ t ] [ "ac" "a(?#boo)c" <regexp> matches? ] unit-test
 
+[ ] [ "USING: regexp kernel ; R' -{3}[+]{1,6}(?:!!)?\\s' drop" eval ] unit-test
+
+[ ] [ "USING: regexp kernel ; R' (ftp|http|https)://(\\w+:?\\w*@)?(\\S+)(:[0-9]+)?(/|/([\\w#!:.?+=&%@!\\-/]))?' drop" eval ] unit-test
+
+[ ] [ "USING: regexp kernel ; R' \\*[^\s*][^*]*\\*' drop" eval ] unit-test
+
+[ "ab" ] [ "ab" "(a|ab)(bc)?" <regexp> first-match >string ] unit-test
+[ "abc" ] [ "abc" "(a|ab)(bc)?" <regexp> first-match >string ] unit-test
+
+[ "ab" ] [ "ab" "(ab|a)(bc)?" <regexp> first-match >string ] unit-test
+[ "abc" ] [ "abc" "(ab|a)(bc)?" <regexp> first-match >string ] unit-test
+
+[ "b" ] [ "aaaaaaaaaaaaaaaaaaaaaaab" "((a*)*b)*b" <regexp> first-match >string ] unit-test
+
+[ t ] [ "a:b" ".+:?" <regexp> matches? ] unit-test
+
+[ 1 ] [ "hello" ".+?" <regexp> match length ] unit-test
+
+[ { "1" "2" "3" "4" } ]
+[ "1ABC2DEF3GHI4" R/ [A-Z]+/ re-split [ >string ] map ] unit-test
+
+[ { "1" "2" "3" "4" } ]
+[ "1ABC2DEF3GHI4JK" R/ [A-Z]+/ re-split [ >string ] map ] unit-test
+
+[ { "ABC" "DEF" "GHI" } ]
+[ "1ABC2DEF3GHI4" R/ [A-Z]+/ all-matches [ >string ] map ] unit-test
 
+[ "1.2.3.4" ]
+[ "1ABC2DEF3GHI4JK" R/ [A-Z]+/ "." re-replace ] unit-test
+
+[ f ] [ "ab" "a(?!b)" <regexp> first-match ] unit-test
+[ "a" ] [ "ab" "a(?=b)(?=b)" <regexp> first-match >string ] unit-test
+[ "a" ] [ "ba" "a(?<=b)(?<=b)" <regexp> first-match >string ] unit-test
+[ "a" ] [ "cab" "a(?=b)(?<=c)" <regexp> first-match >string ] unit-test
 
 ! [ "{Lower}" <regexp> ] [ invalid-range? ] must-fail-with
 
@@ -286,21 +323,10 @@ IN: regexp-tests
 ! [ t ] [ "fooxbar" "foo\\Bxbar" <regexp> matches? ] unit-test
 ! [ f ] [ "foo" "foo\\Bbar" <regexp> matches? ] unit-test
 
-[ ] [ "USING: regexp kernel ; R' -{3}[+]{1,6}(?:!!)?\\s' drop" eval ] unit-test
-
-[ ] [ "USING: regexp kernel ; R' (ftp|http|https)://(\\w+:?\\w*@)?(\\S+)(:[0-9]+)?(/|/([\\w#!:.?+=&%@!\\-/]))?' drop" eval ] unit-test
-
-[ ] [ "USING: regexp kernel ; R' \\*[^\s*][^*]*\\*' drop" eval ] unit-test
 
 ! Bug in parsing word
 ! [ t ] [ "a" R' a' matches?  ] unit-test
 
-! ((A)(B(C)))
-! 1.  ((A)(B(C)))
-! 2. (A)
-! 3. (B(C))
-! 4. (C) 
-
 ! clear "a(?=b*)" <regexp> "ab" over match
 ! clear "a(?=b*c)" <regexp> "abbbbbc" over match
 ! clear "a(?=b*)" <regexp> "ab" over match
@@ -327,26 +353,10 @@ IN: regexp-tests
 ! "a(?:bcdefg)" <regexp> "abcdefg" over first-match
 
 [ "a" ] [ "ac" "a(?!b)" <regexp> first-match >string ] unit-test
-[ f ] [ "ab" "a(?!b)" <regexp> first-match ] unit-test
 
 ! "a(?<=b)" <regexp> "caba" over first-match
 
-[ "a" ] [ "ab" "a(?=b)(?=b)" <regexp> first-match >string ] unit-test
-[ "a" ] [ "ba" "a(?<=b)(?<=b)" <regexp> first-match >string ] unit-test
-[ "a" ] [ "cab" "a(?=b)(?<=c)" <regexp> first-match >string ] unit-test
 
 ! capture group 1: "aaaa"  2: ""
 ! "aaaa" "(a*)(a*)" <regexp> match*
 ! "aaaa" "(a*)(a+)" <regexp> match*
-
-[ "ab" ] [ "ab" "(a|ab)(bc)?" <regexp> first-match >string ] unit-test
-[ "abc" ] [ "abc" "(a|ab)(bc)?" <regexp> first-match >string ] unit-test
-
-[ "ab" ] [ "ab" "(ab|a)(bc)?" <regexp> first-match >string ] unit-test
-[ "abc" ] [ "abc" "(ab|a)(bc)?" <regexp> first-match >string ] unit-test
-
-[ "b" ] [ "aaaaaaaaaaaaaaaaaaaaaaab" "((a*)*b)*b" <regexp> first-match >string ] unit-test
-
-[ t ] [ "a:b" ".+:?" <regexp> matches? ] unit-test
-
-[ 1 ] [ "hello" ".+?" <regexp> match length ] unit-test
index 32c3695f32ed803fb19753f9c423e1c6bfb3fe50..66bc39415bc0a9ec4af8e820d087250283fe8168 100644 (file)
@@ -3,7 +3,7 @@
 USING: accessors combinators kernel math sequences
 sets assocs prettyprint.backend make lexer namespaces parser
 arrays fry regexp.backend regexp.utils regexp.parser regexp.nfa
-regexp.dfa regexp.traversal regexp.transition-tables ;
+regexp.dfa regexp.traversal regexp.transition-tables splitting ;
 IN: regexp
 
 : default-regexp ( string -- regexp )
@@ -52,27 +52,25 @@ IN: regexp
         [ 3drop drop f f ] [ drop [ 1+ ] dip match-range ] if
     ] if ;
 
-: first-match ( string regexp -- pair/f )
+: first-match ( string regexp -- slice/f )
     dupd 0 swap match-range rot over [ <slice> ] [ 3drop f ] if ;
 
 : re-cut ( string regexp -- end/f start )
     dupd first-match
-    [ [ second tail-slice ] [ first head ] 2bi ]
-    [ "" like f swap ]
-    if* ;
+    [ split1-slice swap ] [ "" like f swap ] if* ;
 
 : re-split ( string regexp -- seq )
-    [ dup ] swap '[ _ re-cut ] [ ] produce nip ;
+    [ dup length 0 > ] swap '[ _ re-cut ] [ ] produce nip ;
 
 : re-replace ( string regexp replacement -- result )
     [ re-split ] dip join ;
 
 : next-match ( string regexp -- end/f match/f )
     dupd first-match dup
-    [ [ length 1+ tail-slice ] keep ] [ 2drop f f ] if ;
+    [ [ split1-slice nip ] keep ] [ 2drop f f ] if ;
 
 : all-matches ( string regexp -- seq )
-    [ dup ] swap '[ _ next-match ] [ ] produce nip ;
+    [ dup ] swap '[ _ next-match ] [ ] produce nip harvest ;
 
 : count-matches ( string regexp -- n )
     all-matches length 1- ;
index c17bccf064834a76f73a2a42517f3c607cd38839..9dc03dfac2a8ae7314a121a3612672f1e79873e8 100644 (file)
@@ -145,7 +145,7 @@ ERROR: invalid-header-string string ;
         "<" %
         64 random-bits #
         "-" %
-        millis #
+        micros #
         "@" %
         smtp-domain get [ host-name ] unless* %
         ">" %
@@ -153,7 +153,7 @@ ERROR: invalid-header-string string ;
 
 : extract-email ( recepient -- email )
     ! This could be much smarter.
-    " " last-split1 swap or "<" ?head drop ">" ?tail drop ;
+    " " split1-last swap or "<" ?head drop ">" ?tail drop ;
 
 : email>headers ( email -- hashtable )
     [
index fdc4b4b35c5d5204c6ac056dcc6b587cef608f4f..986bbe4c7239981817141c31b6c988ab556f5fbc 100644 (file)
@@ -87,6 +87,15 @@ M: composed infer-call*
 M: object infer-call*
     \ literal-expected inference-warning ;
 
+: infer-slip ( -- )
+    1 infer->r pop-d infer-call 1 infer-r> ;
+
+: infer-2slip ( -- )
+    2 infer->r pop-d infer-call 2 infer-r> ;
+
+: infer-3slip ( -- )
+    3 infer->r pop-d infer-call 3 infer-r> ;
+
 : infer-curry ( -- )
     2 consume-d
     dup first2 <curried> make-known
@@ -150,6 +159,9 @@ M: object infer-call*
         { \ declare [ infer-declare ] }
         { \ call [ pop-d infer-call ] }
         { \ (call) [ pop-d infer-call ] }
+        { \ slip [ infer-slip ] }
+        { \ 2slip [ infer-2slip ] }
+        { \ 3slip [ infer-3slip ] }
         { \ curry [ infer-curry ] }
         { \ compose [ infer-compose ] }
         { \ execute [ infer-execute ] }
@@ -175,9 +187,10 @@ M: object infer-call*
     (( value -- )) apply-word/effect ;
 
 {
-    >r r> declare call (call) curry compose execute (execute) if
-dispatch <tuple-boa> (throw) load-locals get-local drop-locals
-do-primitive alien-invoke alien-indirect alien-callback
+    >r r> declare call (call) slip 2slip 3slip curry compose
+    execute (execute) if dispatch <tuple-boa> (throw)
+    load-locals get-local drop-locals do-primitive alien-invoke
+    alien-indirect alien-callback
 } [ t "special" set-word-prop ] each
 
 { call execute dispatch load-locals get-local drop-locals }
@@ -423,8 +436,8 @@ do-primitive alien-invoke alien-indirect alien-callback
 \ code-room { } { integer integer integer integer } define-primitive
 \ code-room  make-flushable
 
-\ millis { } { integer } define-primitive
-\ millis make-flushable
+\ micros { } { integer } define-primitive
+\ micros make-flushable
 
 \ tag { object } { fixnum } define-primitive
 \ tag make-foldable
index c990a51cc184bd807adce0a04ba6bc4c7515209e..ff283ce9cab53e91b59954b013ec8e9e0b281874 100644 (file)
@@ -24,4 +24,7 @@ M: callable infer ( quot -- effect )
 
 : forget-effects ( -- )
     forget-errors
-    all-words [ f "inferred-effect" set-word-prop ] each ;
+    all-words [
+        dup subwords [ f "inferred-effect" set-word-prop ] each
+        f "inferred-effect" set-word-prop
+    ] each ;
index e4f8c50eeb9d3ee9b04d11cee4f7b8ed49b3432c..6e11eb1189aeee0cd50bfb95874e17587e5b9c2d 100644 (file)
@@ -90,8 +90,12 @@ IN: stack-checker.transforms
 \ spread [ spread>quot ] 1 define-transform
 
 \ (call-next-method) [
-    [ [ inlined-dependency depends-on ] bi@ ] [ next-method-quot ] 2bi
-] 2 define-transform
+    [
+        [ "method-class" word-prop ]
+        [ "method-generic" word-prop ] bi
+        [ inlined-dependency depends-on ] bi@
+    ] [ next-method-quot ] bi
+] 1 define-transform
 
 ! Constructors
 \ boa [
index 471cd2bd34f5eaace074a3fbd9ccaddddf385b7d..cc2216545d4001e8beb2238f2b3a48d62c637adc 100644 (file)
@@ -100,7 +100,7 @@ HELP: sleep-queue
 { $var-description "A " { $link min-heap } " storing the queue of sleeping threads." } ;
 
 HELP: sleep-time
-{ $values { "ms/f" "a non-negative integer or " { $link f } } }
+{ $values { "us/f" "a non-negative integer or " { $link f } } }
 { $description "Outputs the time until the next sleeping thread is scheduled to wake up, which could be zero if there are threads in the run queue, or threads which need to wake up right now. If there are no runnable or sleeping threads, outputs " { $link f } "." } ;
 
 HELP: stop
index 8a4d433273c2d6a914c8ae66ccfbef374058054b..5dca7be6336e86bb321f2217eb62a077009b90d9 100644 (file)
@@ -93,7 +93,7 @@ PRIVATE>
     {
         { [ run-queue deque-empty? not ] [ 0 ] }
         { [ sleep-queue heap-empty? ] [ f ] }
-        [ sleep-queue heap-peek nip millis [-] ]
+        [ sleep-queue heap-peek nip micros [-] ]
     } cond ;
 
 DEFER: stop
@@ -106,7 +106,7 @@ DEFER: stop
 
 : expire-sleep? ( heap -- ? )
     dup heap-empty?
-    [ drop f ] [ heap-peek nip millis <= ] if ;
+    [ drop f ] [ heap-peek nip micros <= ] if ;
 
 : expire-sleep ( thread -- )
     f >>sleep-entry resume ;
@@ -184,7 +184,7 @@ M: f sleep-until
 GENERIC: sleep ( dt -- )
 
 M: real sleep
-    millis + >integer sleep-until ;
+    micros + >integer sleep-until ;
 
 : interrupt ( thread -- )
     dup state>> [
index 9431cb2c1982cae9d729369fce1d9e2d83ce58ed..18713c7b0c12c9a8ba685f57a8f73141fff91f2f 100644 (file)
@@ -55,6 +55,8 @@ DEFER: ?make-staging-image
 
 : staging-command-line ( profile -- flags )
     [
+        "-staging" ,
+
         dup empty? [
             "-i=" my-boot-image-name append ,
         ] [
index 226cf654b12d0ff3dbe22187d1548c865e2084ff..e0ac391fdfdfff862bd45e1bf5b6ed714e5c8951 100644 (file)
@@ -106,3 +106,8 @@ M: quit-responder call-responder*
     "tools.deploy.test.6" shake-and-bake\r
     run-temp-image\r
 ] unit-test\r
+\r
+[ ] [\r
+    "tools.deploy.test.7" shake-and-bake\r
+    run-temp-image\r
+] unit-test\r
diff --git a/basis/tools/deploy/shaker/next-methods.factor b/basis/tools/deploy/shaker/next-methods.factor
new file mode 100644 (file)
index 0000000..2bff407
--- /dev/null
@@ -0,0 +1,4 @@
+USING: words ;
+IN: generic
+
+: next-method-quot ( method -- quot ) "next-method-quot" word-prop ;
index f5778e410f779481e651d9dce3cbd0e7a5768430..9cc5a66f7017fff29db7f51c0d7d4fb1b5de363c 100755 (executable)
@@ -5,7 +5,7 @@ namespaces make assocs kernel parser lexer strings.parser
 tools.deploy.config vocabs sequences words words.private memory
 kernel.private continuations io prettyprint vocabs.loader
 debugger system strings sets vectors quotations byte-arrays
-sorting compiler.units definitions ;
+sorting compiler.units definitions generic generic.standard ;
 QUALIFIED: bootstrap.stage2
 QUALIFIED: classes
 QUALIFIED: command-line
@@ -14,7 +14,6 @@ QUALIFIED: continuations
 QUALIFIED: definitions
 QUALIFIED: init
 QUALIFIED: layouts
-QUALIFIED: listener
 QUALIFIED: prettyprint.config
 QUALIFIED: source-files
 QUALIFIED: vocabs
@@ -95,20 +94,13 @@ IN: tools.deploy.shaker
 
 : stripped-word-props ( -- seq )
     [
-        strip-dictionary? deploy-compiler? get and [
-            {
-                "combination"
-                "members"
-                "methods"
-            } %
-        ] when
-
         strip-dictionary? [
             {
                 "alias"
                 "boa-check"
                 "cannot-infer"
                 "coercer"
+                "combination"
                 "compiled-effect"
                 "compiled-generic-uses"
                 "compiled-uses"
@@ -138,7 +130,9 @@ IN: tools.deploy.shaker
                 "local-writer?"
                 "local?"
                 "macro"
+                "members"
                 "memo-quot"
+                "methods"
                 "mixin"
                 "method-class"
                 "method-generic"
@@ -201,17 +195,13 @@ IN: tools.deploy.shaker
 
 : stripped-globals ( -- seq )
     [
-        "callbacks" "alien.compiler" lookup ,
-
         "inspector-hook" "inspector" lookup ,
 
         {
-            bootstrap.stage2:bootstrap-time
             continuations:error
             continuations:error-continuation
             continuations:error-thread
             continuations:restarts
-            listener:error-hook
             init:init-hooks
             source-files:source-files
             input-stream
@@ -234,6 +224,10 @@ IN: tools.deploy.shaker
             "tools"
             "io.launcher"
             "random"
+            "compiler"
+            "stack-checker"
+            "bootstrap"
+            "listener"
         } strip-vocab-globals %
 
         strip-dictionary? [
@@ -244,6 +238,7 @@ IN: tools.deploy.shaker
             {
                 gensym
                 name>char-hook
+                classes:next-method-quot-cache
                 classes:class-and-cache
                 classes:class-not-cache
                 classes:class-or-cache
@@ -304,10 +299,7 @@ IN: tools.deploy.shaker
             "ui-error-hook" "ui.gadgets.worlds" lookup ,
         ] when
 
-        "<value>" "stack-checker.state" lookup [ , ] when*
-
         "windows-messages" "windows.messages" lookup [ , ] when*
-
     ] { } make ;
 
 : strip-globals ( stripped-globals -- )
@@ -368,11 +360,21 @@ SYMBOL: deploy-vocab
     t "quiet" set-global
     f output-stream set-global ;
 
+: compute-next-methods ( -- )
+    [ standard-generic? ] instances [
+        "methods" word-prop [
+            nip
+            dup next-method-quot "next-method-quot" set-word-prop
+        ] assoc-each
+    ] each
+    "resource:basis/tools/deploy/shaker/next-methods.factor" run-file ;
+
 : strip ( -- )
     init-stripper
     strip-libc
     strip-cocoa
     strip-debugger
+    compute-next-methods
     strip-init-hooks
     strip-c-io
     f 5 setenv ! we can't use the Factor debugger or Factor I/O anymore
@@ -382,8 +384,7 @@ SYMBOL: deploy-vocab
     r> strip-words
     compress-byte-arrays
     compress-quotations
-    compress-strings
-    H{ } clone classes:next-method-quot-cache set-global ;
+    compress-strings ;
 
 : (deploy) ( final-image vocab config -- )
     #! Does the actual work of a deployment in the slave
index bdcc6c237eef7fe05114b9d66907172a58df6108..db7eb63bbfae62dfafd2542667f02e891aa6b345 100644 (file)
@@ -1,9 +1,13 @@
 USING: compiler.units words vocabs kernel threads.private ;
 IN: debugger
 
-: print-error ( error -- ) die drop ;
+: consume ( error -- )
+    #! We don't want DCE to drop the error before the die call!
+    drop ;
 
-: error. ( error -- ) die drop ;
+: print-error ( error -- ) die consume ;
+
+: error. ( error -- ) die consume ;
 
 "threads" vocab [
     [
index 0ca85bca8ce9c0a4493047fd7dd99cc8584af643..63b382e2f658b88c3f84cbdaf78c9e0705384769 100644 (file)
@@ -1,6 +1,6 @@
 IN: tools.deploy.test.1\r
 USING: threads ;\r
 \r
-: deploy-test-1 ( -- ) 1000 sleep ;\r
+: deploy-test-1 ( -- ) 1000000 sleep ;\r
 \r
 MAIN: deploy-test-1\r
diff --git a/basis/tools/deploy/test/7/7.factor b/basis/tools/deploy/test/7/7.factor
new file mode 100644 (file)
index 0000000..a16e3c8
--- /dev/null
@@ -0,0 +1,18 @@
+! Copyright (C) 2008 Slava Pestov.
+! See http://factorcode.org/license.txt for BSD license.
+USING: kernel math namespaces ;
+IN: tools.deploy.test.7
+
+SYMBOL: my-var
+
+GENERIC: my-generic ( x -- b )
+
+M: integer my-generic sq ;
+
+M: fixnum my-generic call-next-method my-var get call ;
+
+: test-7 ( -- )
+    [ 1 + ] my-var set-global
+    12 my-generic 145 assert= ;
+
+MAIN: test-7
diff --git a/basis/tools/deploy/test/7/deploy.factor b/basis/tools/deploy/test/7/deploy.factor
new file mode 100644 (file)
index 0000000..bc374f1
--- /dev/null
@@ -0,0 +1,15 @@
+USING: tools.deploy.config ;
+H{
+    { deploy-threads? t }
+    { deploy-word-props? f }
+    { deploy-ui? f }
+    { deploy-io 2 }
+    { deploy-math? t }
+    { "stop-after-last-window?" t }
+    { deploy-compiler? t }
+    { deploy-unicode? f }
+    { deploy-c-types? f }
+    { deploy-reflection 1 }
+    { deploy-word-defs? f }
+    { deploy-name "tools.deploy.test.7" }
+}
index f0c71aa311d68f579061511ade1fa7db4bda38c5..197ace74d8e8a7ceefdf073dc2b45ab626f3786a 100644 (file)
@@ -11,7 +11,7 @@ words ;
 
 [ ] [ [ 10 [ gc ] times ] profile ] unit-test
 
-[ ] [ [ 1000 sleep ] profile ] unit-test 
+[ ] [ [ 1000000 sleep ] profile ] unit-test 
 
 [ ] [ profile. ] unit-test
 
index 5c2bd8f4e322b77575e76c63428ba2abbd485e90..73b261bf13cb5de80c26dc7112ad4d2d2a53c752 100644 (file)
@@ -49,7 +49,7 @@ SYMBOL: this-test
     [ drop t ] must-fail-with ;
 
 : (run-test) ( vocab -- )
-    dup vocab-source-loaded? [
+    dup vocab source-loaded?>> [
         vocab-tests [ run-file ] each
     ] [ drop ] if ;
 
index 1b75e46e2545ec97b8e8abe20f564dd6d2670d28..fc4ba1f6b2641e34fa3a734399349e28f231bd47 100644 (file)
@@ -14,8 +14,8 @@ IN: tools.threads
     ] with-cell\r
     [\r
         sleep-entry>> [\r
-            key>> millis [-] number>string write\r
-            " ms" write\r
+            key>> micros [-] number>string write\r
+            " us" write\r
         ] when*\r
     ] with-cell ;\r
 \r
index fe3d709f78f9943163a63751b1afe33530ccebc7..d8dba044869f0f1290f2a3b87b5dae53716110d2 100644 (file)
@@ -7,7 +7,7 @@ ARTICLE: "timing" "Timing code"
 "A lower-level word puts timings on the stack, intead of printing:"
 { $subsection benchmark }
 "You can also read the system clock and garbage collection statistics directly:"
-{ $subsection millis } 
+{ $subsection micros } 
 { $subsection gc-stats }
 { $see-also "profiling" } ;
 
@@ -15,7 +15,7 @@ ABOUT: "timing"
 
 HELP: benchmark
 { $values { "quot" "a quotation" }
-          { "runtime" "an integer denoting milliseconds" } }
+          { "runtime" "the runtime in microseconds" } }
       { $description "Runs a quotation, measuring the total wall clock time." }
 { $notes "A nicer word for interactive use is " { $link time } "." } ;
 
@@ -23,4 +23,4 @@ HELP: time
 { $values { "quot" "a quotation" } }
 { $description "Runs a quotation and then prints the total run time and some garbage collection statistics." } ;
 
-{ benchmark millis time } related-words
+{ benchmark micros time } related-words
index 6873d6831676aff79cb0c696e9b0de7fe0696eee..1672017fc4161cd71261057837998f34db7bfb36 100644 (file)
@@ -5,20 +5,20 @@ namespaces system sequences splitting grouping assocs strings ;
 IN: tools.time
 
 : benchmark ( quot -- runtime )
-    millis >r call millis r> - ; inline
+    micros >r call micros r> - ; inline
 
 : time. ( data -- )
     unclip
-    "==== RUNNING TIME" print nl pprint " ms" print nl
+    "==== RUNNING TIME" print nl 1000000 /f pprint " seconds" print nl
     4 cut*
     "==== GARBAGE COLLECTION" print nl
     [
         6 group
         {
             "GC count:"
-            "Cumulative GC time (ms):"
-            "Longest GC pause (ms):"
-            "Average GC pause (ms):"
+            "Cumulative GC time (us):"
+            "Longest GC pause (us):"
+            "Average GC pause (us):"
             "Objects copied:"
             "Bytes copied:"
         } prefix
@@ -29,7 +29,7 @@ IN: tools.time
     [
         nl
         {
-            "Total GC time (ms):"
+            "Total GC time (us):"
             "Cards scanned:"
             "Decks scanned:"
             "Code heap literal scans:"
@@ -37,4 +37,4 @@ IN: tools.time
     ] bi* ;
 
 : time ( quot -- )
-    gc-reset millis >r call gc-stats millis r> - prefix time. ; inline
+    gc-reset micros >r call gc-stats micros r> - prefix time. ; inline
index b492ef4da22e0626135fc12e21469e326283a94a..d926b670786abc526be01ea0d427e0ec86b14a41 100644 (file)
@@ -134,12 +134,12 @@ SYMBOL: modified-docs
             [\r
                 [\r
                     [ modified-sources ]\r
-                    [ vocab-source-loaded? ]\r
+                    [ vocab source-loaded?>> ]\r
                     [ vocab-source-path ]\r
                     tri (to-refresh)\r
                 ] [\r
                     [ modified-docs ]\r
-                    [ vocab-docs-loaded? ]\r
+                    [ vocab docs-loaded?>> ]\r
                     [ vocab-docs-path ]\r
                     tri (to-refresh)\r
                 ] bi\r
@@ -154,8 +154,8 @@ SYMBOL: modified-docs
 : do-refresh ( modified-sources modified-docs unchanged -- )\r
     unchanged-vocabs\r
     [\r
-        [ [ f swap set-vocab-source-loaded? ] each ]\r
-        [ [ f swap set-vocab-docs-loaded? ] each ] bi*\r
+        [ [ vocab f >>source-loaded? drop ] each ]\r
+        [ [ vocab f >>docs-loaded? drop ] each ] bi*\r
     ]\r
     [\r
         append prune\r
index 9775bdff81a057b3ae8180dfb2e23e25af38b8d3..1d26567952e34a30e6a3cc660edeea52efc23094 100644 (file)
@@ -83,7 +83,7 @@ M: object add-breakpoint ;
 : (step-into-continuation) ( -- )
     continuation callstack >>call break ;
 
-: (step-into-call-next-method) ( class generic -- )
+: (step-into-call-next-method) ( method -- )
     next-method-quot (step-into-quot) ;
 
 ! Messages sent to walker thread
index b7c5c94c62c049a3feb88f19d5245af6f0ceed22..1e472e921f0591ca9d8d8ada303af57a7f52f318 100644 (file)
@@ -143,7 +143,7 @@ HELP: hand-last-button
 { $var-description "Global variable. The mouse button most recently pressed." } ;
 
 HELP: hand-last-time
-{ $var-description "Global variable. The timestamp of the most recent mouse button click. This timestamp has the same format as the output value of " { $link millis } "." } ;
+{ $var-description "Global variable. The timestamp of the most recent mouse button click. This timestamp has the same format as the output value of " { $link micros } "." } ;
 
 HELP: hand-buttons
 { $var-description "Global variable. A vector of mouse buttons currently held down." } ;
index 2f7bee927bedefd55230a4ff27a3ad9df0fc2c4f..ffb9795ef8584105ed313faa7de55ac8988df0f0 100644 (file)
@@ -1,8 +1,8 @@
 ! Copyright (C) 2005, 2008 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: accessors arrays assocs kernel math models namespaces
-make sequences words strings system hashtables math.parser
-math.vectors classes.tuple classes  boxes calendar
+USING: accessors arrays assocs kernel math math.order models
+namespaces make sequences words strings system hashtables
+math.parser math.vectors classes.tuple classes boxes calendar
 alarms symbols combinators sets columns fry deques ui.gadgets ;
 IN: ui.gestures
 
@@ -109,7 +109,7 @@ SYMBOL: hand-click#
 SYMBOL: hand-last-button
 SYMBOL: hand-last-time
 0 hand-last-button set-global
-0 hand-last-time set-global
+<zero> hand-last-time set-global
 
 SYMBOL: hand-buttons
 V{ } clone hand-buttons set-global
@@ -118,7 +118,7 @@ SYMBOL: scroll-direction
 { 0 0 } scroll-direction set-global
 
 SYMBOL: double-click-timeout
-300 double-click-timeout set-global
+300 milliseconds double-click-timeout set-global
 
 : hand-moved? ( -- ? )
     hand-loc get hand-click-loc get = not ;
@@ -199,7 +199,7 @@ SYMBOL: drag-timer
     hand-click-loc get-global swap screen-loc v- ;
 
 : multi-click-timeout? ( -- ? )
-    millis hand-last-time get - double-click-timeout get <= ;
+    now hand-last-time get time- double-click-timeout get before=? ;
 
 : multi-click-button? ( button -- button ? )
     dup hand-last-button get = ;
@@ -224,7 +224,7 @@ SYMBOL: drag-timer
             1 hand-click# set
         ] if
         hand-last-button set
-        millis hand-last-time set
+        now hand-last-time set
     ] bind ;
 
 : update-clicked ( -- )
index 37f43faa8badb821d096f3267976fd5c0e89ba22..628570c3e36b22da93cb4b93b486d30a3b2092c1 100644 (file)
@@ -38,7 +38,7 @@ tools.test kernel calendar parser accessors calendar io ;
 
 [ ] [ [ "interactor" get stream-read-quot drop ] "B" spawn drop ] unit-test
 
-[ ] [ 1000 sleep ] unit-test
+[ ] [ 1 seconds sleep ] unit-test
 
 [ ] [ "interactor" get interactor-eof ] unit-test
 
@@ -57,11 +57,11 @@ tools.test kernel calendar parser accessors calendar io ;
     ] in-thread
 ] unit-test
 
-[ ] [ 100 sleep ] unit-test
+[ ] [ 100 milliseconds sleep ] unit-test
 
 [ ] [ "interactor" get evaluate-input ] unit-test
 
-[ ] [ 100 sleep ] unit-test
+[ ] [ 100 milliseconds sleep ] unit-test
     
 [ ] [ "interactor" get interactor-eof ] unit-test
 
@@ -80,7 +80,7 @@ tools.test kernel calendar parser accessors calendar io ;
     ] in-thread
 ] unit-test
 
-[ ] [ 100 sleep ] unit-test
+[ ] [ 100 milliseconds sleep ] unit-test
 
 [ ] [ "interactor" get evaluate-input ] unit-test
 
index 616226a9c5ef5a4c3a8147b833158d1091340907..28fdef6cb7ce4d92d18844c0d201e4c05b8a8b3c 100644 (file)
@@ -2,7 +2,8 @@ USING: continuations documents ui.tools.interactor
 ui.tools.listener hashtables kernel namespaces parser sequences
 tools.test ui.commands ui.gadgets ui.gadgets.editors
 ui.gadgets.panes vocabs words tools.test.ui slots.private
-threads arrays generic threads accessors listener math ;
+threads arrays generic threads accessors listener math
+calendar ;
 IN: ui.tools.listener.tests
 
 [ f ] [ "word" source-editor command-map commands>> empty? ] unit-test
@@ -47,7 +48,7 @@ IN: ui.tools.listener.tests
 
     [ ] [ "listener" get restart-listener ] unit-test
 
-    [ ] [ 1000 sleep ] unit-test
+    [ ] [ 1 seconds sleep ] unit-test
 
     [ ] [ "listener" get com-end ] unit-test
 ] with-grafted-gadget
index d47727452042fc246b067ad993f17d438e4bc061..c8c7c6c2191035bbe63834553cf87ad25968fb57 100644 (file)
@@ -1,7 +1,7 @@
 USING: assocs ui.tools.search help.topics io.files io.styles
 kernel namespaces sequences source-files threads
 tools.test ui.gadgets ui.gestures vocabs accessors
-vocabs.loader words tools.test.ui debugger ;
+vocabs.loader words tools.test.ui debugger calendar ;
 IN: ui.tools.search.tests
 
 [ f ] [
@@ -14,7 +14,7 @@ IN: ui.tools.search.tests
 
 : update-live-search ( search -- seq )
     dup [
-        300 sleep
+        300 milliseconds sleep
         list>> control-value
     ] with-grafted-gadget ;
 
@@ -30,7 +30,7 @@ IN: ui.tools.search.tests
     "" all-words t <definition-search>
     dup [
         { "set-word-prop" } over field>> set-control-value
-        300 sleep
+        300 milliseconds sleep
         search-value \ set-word-prop eq?
     ] with-grafted-gadget
 ] unit-test
index e05341f3fc97df29102acd976f4fe4adae4aa880..de2eb713072989a25b8af0c592c0415df46ba51d 100644 (file)
@@ -4,7 +4,7 @@ USING: arrays assocs io kernel math models namespaces make
 prettyprint dlists deques sequences threads sequences words
 debugger ui.gadgets ui.gadgets.worlds ui.gadgets.tracks
 ui.gestures ui.backend ui.render continuations init combinators
-hashtables concurrency.flags sets accessors ;
+hashtables concurrency.flags sets accessors calendar ;
 IN: ui
 
 ! Assoc mapping aliens to gadgets
@@ -153,7 +153,7 @@ SYMBOL: ui-hook
     ] [ ui-error ] recover ;
 
 : ui-wait ( -- )
-    10 sleep ;
+    10 milliseconds sleep ;
 
 SYMBOL: ui-thread
 
old mode 100644 (file)
new mode 100755 (executable)
index fc22f30..512930d
@@ -6,9 +6,10 @@ ui.gadgets ui.backend ui.clipboards ui.gadgets.worlds
 ui.gestures io kernel math math.vectors namespaces make
 sequences strings vectors words windows.kernel32 windows.gdi32
 windows.user32 windows.opengl32 windows.messages windows.types
-windows.nt windows threads libc combinators continuations
-command-line shuffle opengl ui.render unicode.case ascii
-math.bitwise locals symbols accessors math.geometry.rect ;
+windows.nt windows threads libc combinators
+combinators.short-circuit continuations command-line shuffle
+opengl ui.render ascii math.bitwise locals symbols accessors
+math.geometry.rect math.order ascii ;
 IN: ui.windows
 
 SINGLETON: windows-ui-backend
@@ -144,11 +145,6 @@ SYMBOLS: msg-obj class-name-ptr mouse-captured ;
 : alt? ( -- ? ) left-alt? right-alt? or ;
 : caps-lock? ( -- ? ) VK_CAPITAL GetKeyState zero? not ;
 
-: switch-case ( seq -- seq )
-    dup first CHAR: a >= [ >upper ] [ >lower ] if ;
-
-: switch-case? ( -- ? ) shift? caps-lock? xor not ;
-
 : key-modifiers ( -- seq )
     [
         shift? [ S+ , ] when
@@ -179,33 +175,53 @@ SYMBOLS: msg-obj class-name-ptr mouse-captured ;
 : exclude-key-wm-char? ( n -- bool )
     exclude-keys-wm-char key? ;
 
-: keystroke>gesture ( n -- mods sym ? )
-    dup wm-keydown-codes at* [
-        nip >r key-modifiers r> t
-    ] [
-        drop 1string >r key-modifiers r>
-        C+ pick member? >r A+ pick member? r> or [
-            shift? [ >lower ] unless f
-        ] [
-            switch-case? [ switch-case ] when t
-        ] if
-    ] if ;
+: keystroke>gesture ( n -- mods sym )
+    wm-keydown-codes at* [ key-modifiers swap ] [ drop f f ] if ;
+
+: send-key-gesture ( sym action? quot hWnd -- )
+    [ [ key-modifiers ] 3dip call ] dip
+    window-focus propagate-gesture ; inline
+
+: send-key-down ( sym action? hWnd -- )
+    [ [ <key-down> ] ] dip send-key-gesture ;
+
+: send-key-up ( sym action? hWnd -- )
+    [ [ <key-up> ] ] dip send-key-gesture ;
+
+: key-sym ( wParam -- string/f action? )
+    {
+        {
+            [ dup LETTER? ]
+            [ shift? caps-lock? xor [ CHAR: a + CHAR: A - ] unless 1string f ]
+        }
+        { [ dup digit? ] [ 1string f ] }
+        [ wm-keydown-codes at t ]
+    } cond ;
 
 :: handle-wm-keydown ( hWnd uMsg wParam lParam -- )
     wParam exclude-key-wm-keydown? [
-        wParam keystroke>gesture <key-down>
-        hWnd window-focus propagate-gesture
+        wParam key-sym over [
+            dup ctrl? alt? xor or [
+                hWnd send-key-down
+            ] [ 2drop ] if
+        ] [ 2drop ] if
     ] unless ;
 
 :: handle-wm-char ( hWnd uMsg wParam lParam -- )
-    wParam exclude-key-wm-char? ctrl? alt? xor or [
-        wParam 1string
-        hWnd window-focus user-input
+    wParam exclude-key-wm-char? [
+        ctrl? alt? xor [
+            wParam 1string
+            [ f hWnd send-key-down ]
+            [ hWnd window-focus user-input ] bi
+        ] unless
     ] unless ;
 
 :: handle-wm-keyup ( hWnd uMsg wParam lParam -- )
-    wParam keystroke>gesture <key-up>
-    hWnd window-focus propagate-gesture ;
+    wParam exclude-key-wm-keydown? [
+        wParam key-sym over [
+            hWnd send-key-up
+        ] [ 2drop ] if
+    ] unless ;
 
 :: set-window-active ( hwnd uMsg wParam lParam ? -- n )
     ? hwnd window (>>active?)
@@ -241,20 +257,20 @@ M: windows-ui-backend (close-window)
 
 : message>button ( uMsg -- button down? )
     {
-        { [ dup WM_LBUTTONDOWN   = ] [ drop 1 t ] }
-        { [ dup WM_LBUTTONUP     = ] [ drop 1 f ] }
-        { [ dup WM_MBUTTONDOWN   = ] [ drop 2 t ] }
-        { [ dup WM_MBUTTONUP     = ] [ drop 2 f ] }
-        { [ dup WM_RBUTTONDOWN   = ] [ drop 3 t ] }
-        { [ dup WM_RBUTTONUP     = ] [ drop 3 f ] }
-
-        { [ dup WM_NCLBUTTONDOWN = ] [ drop 1 t ] }
-        { [ dup WM_NCLBUTTONUP   = ] [ drop 1 f ] }
-        { [ dup WM_NCMBUTTONDOWN = ] [ drop 2 t ] }
-        { [ dup WM_NCMBUTTONUP   = ] [ drop 2 f ] }
-        { [ dup WM_NCRBUTTONDOWN = ] [ drop 3 t ] }
-        { [ dup WM_NCRBUTTONUP   = ] [ drop 3 f ] }
-    } cond ;
+        { WM_LBUTTONDOWN   [ 1 t ] }
+        { WM_LBUTTONUP     [ 1 f ] }
+        { WM_MBUTTONDOWN   [ 2 t ] }
+        { WM_MBUTTONUP     [ 2 f ] }
+        { WM_RBUTTONDOWN   [ 3 t ] }
+        { WM_RBUTTONUP     [ 3 f ] }
+
+        { WM_NCLBUTTONDOWN [ 1 t ] }
+        { WM_NCLBUTTONUP   [ 1 f ] }
+        { WM_NCMBUTTONDOWN [ 2 t ] }
+        { WM_NCMBUTTONUP   [ 2 f ] }
+        { WM_NCRBUTTONDOWN [ 3 t ] }
+        { WM_NCRBUTTONUP   [ 3 f ] }
+    } case ;
 
 ! If the user clicks in the window border ("non-client area")
 ! Windows sends us an NC[LMR]BUTTONDOWN message; but if the
index c664aa3bfbb94a2a2c0b3bbc412832298ab7e11e..9847b097789b0fd3aa7d20411f980b330e1c63f9 100644 (file)
@@ -11,14 +11,14 @@ C-STRUCT: timespec
     { "time_t" "sec" }
     { "long" "nsec" } ;
 
-: make-timeval ( ms -- timeval )
-    1000 /mod 1000 *
+: make-timeval ( us -- timeval )
+    1000000 /mod
     "timeval" <c-object>
     [ set-timeval-usec ] keep
     [ set-timeval-sec ] keep ;
 
-: make-timespec ( ms -- timespec )
-    1000 /mod 1000000 *
+: make-timespec ( us -- timespec )
+    1000000 /mod 1000 *
     "timespec" <c-object>
     [ set-timespec-nsec ] keep
     [ set-timespec-sec ] keep ;
index 597cdfdb7fdcaa773b459b55a2568c629bd42f3b..c0fb1695c3358603e6abbd3fa1bcdb5a32358a81 100644 (file)
@@ -132,7 +132,7 @@ M: url present
         { [ dup empty? ] [ drop ] }
         { [ over "/" tail? ] [ append ] }
         { [ "/" pick start not ] [ nip ] }
-        [ [ "/" last-split1 drop "/" ] dip 3append ]
+        [ [ "/" split1-last drop "/" ] dip 3append ]
     } cond ;
 
 PRIVATE>
index ce3497439ab7125de6ffe61b56cdfb2457006b1e..edac8c09cc6a46dfefbfbb18e6487d751d690688 100644 (file)
@@ -281,8 +281,8 @@ $nl
         "Gives all Factor threads a chance to run."
     } }
     { {
-        { $code "void factor_sleep(long ms)" }
-        "Gives all Factor threads a chance to run for " { $snippet "ms" } " milliseconds."
+        { $code "void factor_sleep(long us)" }
+        "Gives all Factor threads a chance to run for " { $snippet "us" } " microseconds."
     } }
 } ;
 
index b023398762af1c75bec09b8013c32e4cd2142692..74bc57e9db80c80940e44df38831ffffdfac3e8a 100644 (file)
@@ -6,8 +6,8 @@ IN: arrays
 
 M: array clone (clone) ;
 M: array length length>> ;
-M: array nth-unsafe >r >fixnum r> array-nth ;
-M: array set-nth-unsafe >r >fixnum r> set-array-nth ;
+M: array nth-unsafe [ >fixnum ] dip array-nth ;
+M: array set-nth-unsafe [ >fixnum ] dip set-array-nth ;
 M: array resize resize-array ;
 
 : >array ( seq -- array ) { } clone-like ;
index 9b8065e6c471f161b92539c29bd615bd80d25197..953cc38c5632283fabc023c07dca72513fed58e9 100644 (file)
@@ -21,7 +21,7 @@ GENERIC: assoc-clone-like ( assoc exemplar -- newassoc )
 GENERIC: >alist ( assoc -- newassoc )
 
 : (assoc-each) ( assoc quot -- seq quot' )
-    >r >alist r> [ first2 ] prepose ; inline
+    [ >alist ] dip [ first2 ] prepose ; inline
 
 : assoc-find ( assoc quot -- key value ? )
     (assoc-each) find swap [ first2 t ] [ drop f f f ] if ; inline
@@ -32,23 +32,26 @@ GENERIC: >alist ( assoc -- newassoc )
     (assoc-each) each ; inline
 
 : assoc>map ( assoc quot exemplar -- seq )
-    >r accumulator >r assoc-each r> r> like ; inline
+    [ accumulator [ assoc-each ] dip ] dip like ; inline
 
 : assoc-map-as ( assoc quot exemplar -- newassoc )
-    >r [ 2array ] compose V{ } assoc>map r> assoc-like ; inline
+    [ [ 2array ] compose V{ } assoc>map ] dip assoc-like ; inline
 
 : assoc-map ( assoc quot -- newassoc )
     over assoc-map-as ; inline
 
 : assoc-push-if ( key value quot accum -- )
-    >r 2keep r> roll
-    [ >r 2array r> push ] [ 3drop ] if ; inline
+    [ 2keep rot ] dip swap
+    [ [ 2array ] dip push ] [ 3drop ] if ; inline
 
 : assoc-pusher ( quot -- quot' accum )
     V{ } clone [ [ assoc-push-if ] 2curry ] keep ; inline
 
+: assoc-filter-as ( assoc quot exemplar -- subassoc )
+    [ assoc-pusher [ assoc-each ] dip ] dip assoc-like ; inline
+
 : assoc-filter ( assoc quot -- subassoc )
-    over >r assoc-pusher >r assoc-each r> r> assoc-like ; inline
+    over assoc-filter-as ; inline
 
 : assoc-contains? ( assoc quot -- ? )
     assoc-find 2nip ; inline
@@ -83,7 +86,7 @@ M: assoc assoc-clone-like ( assoc exemplar -- newassoc )
         3drop f
     ] [
         3dup nth-unsafe at*
-        [ >r 3drop r> ] [ drop >r 1- r> (assoc-stack) ] if
+        [ [ 3drop ] dip ] [ drop [ 1- ] dip (assoc-stack) ] if
     ] if ; inline recursive
 
 : assoc-stack ( key seq -- value )
@@ -97,7 +100,7 @@ M: assoc assoc-clone-like ( assoc exemplar -- newassoc )
 
 : assoc-hashcode ( n assoc -- code )
     [
-        >r over r> hashcode* 2/ >r dupd hashcode* r> bitxor
+        [ over ] dip hashcode* 2/ [ dupd hashcode* ] dip bitxor
     ] { } assoc>map hashcode* ;
 
 : assoc-intersect ( assoc1 assoc2 -- intersection )
@@ -130,19 +133,19 @@ M: assoc assoc-clone-like ( assoc exemplar -- newassoc )
 
 : cache ( key assoc quot -- value )
     2over at* [
-        >r 3drop r>
+        [ 3drop ] dip
     ] [
-        drop pick rot >r >r call dup r> r> set-at
+        drop pick rot [ call dup ] 2dip set-at
     ] if ; inline
 
 : change-at ( key assoc quot -- )
-    [ >r at r> call ] 3keep drop set-at ; inline
+    [ [ at ] dip call ] 3keep drop set-at ; inline
 
 : at+ ( n key assoc -- )
     [ 0 or + ] change-at ;
 
 : map>assoc ( seq quot exemplar -- assoc )
-    >r [ 2array ] compose { } map-as r> assoc-like ; inline
+    [ [ 2array ] compose { } map-as ] dip assoc-like ; inline
 
 : extract-keys ( seq assoc -- subassoc )
     [ [ dupd at ] curry ] keep map>assoc ;
@@ -173,7 +176,7 @@ M: sequence at*
 M: sequence set-at
     2dup search-alist
     [ 2nip set-second ]
-    [ drop >r swap 2array r> push ] if ;
+    [ drop [ swap 2array ] dip push ] if ;
 
 M: sequence new-assoc drop <vector> ;
 
@@ -186,10 +189,10 @@ M: sequence delete-at
 M: sequence assoc-size length ;
 
 M: sequence assoc-clone-like
-    >r >alist r> clone-like ;
+    [ >alist ] dip clone-like ;
 
 M: sequence assoc-like
-    >r >alist r> like ;
+    [ >alist ] dip like ;
 
 M: sequence >alist ;
 
index 65731dd1adfe4ba1bdc55c7e08dece1ba0bae932..8f280cb53a37ecc5c648aee0a3ecc2d0e37efab1 100644 (file)
@@ -129,8 +129,7 @@ bootstrapping? on
     [ "slots" set-word-prop ] [ define-accessors ] 2bi ;
 
 : define-builtin ( symbol slotspec -- )
-    >r [ define-builtin-predicate ] keep
-    r> define-builtin-slots ;
+    [ [ define-builtin-predicate ] keep ] dip define-builtin-slots ;
 
 "fixnum" "math" create register-builtin
 "bignum" "math" create register-builtin
@@ -327,9 +326,7 @@ tuple
     [ ]
     [
         [
-            \ >r ,
-            callable instance-check-quot %
-            \ r> ,
+            callable instance-check-quot [ dip ] curry %
             callable instance-check-quot %
             tuple-layout ,
             \ <tuple-boa> ,
@@ -389,7 +386,7 @@ tuple
 
 ! Primitive words
 : make-primitive ( word vocab n -- )
-    >r create dup reset-word r>
+    [ create dup reset-word ] dip
     [ do-primitive ] curry [ ] like define ;
 
 {
@@ -460,7 +457,7 @@ tuple
     { "exit" "system" }
     { "data-room" "memory" }
     { "code-room" "memory" }
-    { "millis" "system" }
+    { "micros" "system" }
     { "modify-code-heap" "compiler.units" }
     { "dlopen" "alien" }
     { "dlsym" "alien" }
@@ -533,7 +530,7 @@ tuple
     { "unimplemented" "kernel.private" }
     { "gc-reset" "memory" }
 }
-[ >r first2 r> make-primitive ] each-index
+[ [ first2 ] dip make-primitive ] each-index
 
 ! Bump build number
 "build" "kernel" create build 1+ 1quotation define
index 08a13297d11be2b74ed0d392343668933e5144ce..4b0d9e5072658b35e4f976801a4e313b866bb6da 100644 (file)
@@ -12,14 +12,17 @@ GENERIC: checksum-stream ( stream checksum -- value )
 
 GENERIC: checksum-lines ( lines checksum -- value )
 
-M: checksum checksum-bytes >r binary <byte-reader> r> checksum-stream ;
+M: checksum checksum-bytes
+    [ binary <byte-reader> ] dip checksum-stream ;
 
-M: checksum checksum-stream >r contents r> checksum-bytes ;
+M: checksum checksum-stream
+    [ contents ] dip checksum-bytes ;
 
-M: checksum checksum-lines >r B{ CHAR: \n } join r> checksum-bytes ;
+M: checksum checksum-lines
+    [ B{ CHAR: \n } join ] dip checksum-bytes ;
 
 : checksum-file ( path checksum -- value )
-    >r binary <file-reader> r> checksum-stream ;
+    [ binary <file-reader> ] dip checksum-stream ;
 
 : hex-string ( seq -- str )
     [ >hex 2 CHAR: 0 pad-left ] { } map-as concat ;
index e1f0b9417bf3c958c66a730f032b582ce4f57344..7cff22de19bedd11402b1d1f6de7d504cce40b33 100644 (file)
@@ -11,7 +11,7 @@ IN: checksums.crc32
 
 256 [
     8 [
-        dup even? >r 2/ r> [ crc32-polynomial bitxor ] unless
+        [ 2/ ] [ even? ] bi [ crc32-polynomial bitxor ] unless
     ] times >bignum
 ] map 0 crc32-table copy
 
@@ -24,7 +24,7 @@ SINGLETON: crc32
 
 INSTANCE: crc32 checksum
 
-: init-crc32 drop >r HEX: ffffffff dup r> ; inline
+: init-crc32 drop [ HEX: ffffffff dup ] dip ; inline
 
 : finish-crc32 bitxor 4 >be ; inline
 
index 4558ce4737a71d34dfeaa58b0cd80fde0267c439..a3610ff7c56d2e31c628fde3de2bc3d05ece2492 100644 (file)
@@ -13,9 +13,9 @@ IN: classes.algebra.tests
 \ flatten-class must-infer\r
 \ flatten-builtin-class must-infer\r
 \r
-: class-and* ( cls1 cls2 cls3 -- ? ) >r class-and r> class= ;\r
+: class-and* ( cls1 cls2 cls3 -- ? ) [ class-and ] dip class= ;\r
 \r
-: class-or* ( cls1 cls2 cls3 -- ? ) >r class-or r> class= ;\r
+: class-or* ( cls1 cls2 cls3 -- ? ) [ class-or ] dip class= ;\r
 \r
 [ t ] [ object  object  object class-and* ] unit-test\r
 [ t ] [ fixnum  object  fixnum class-and* ] unit-test\r
@@ -240,9 +240,9 @@ UNION: z1 b1 c1 ;
         20 [ random-boolean-op ] [ ] replicate-as dup .\r
         [ infer in>> [ random-boolean ] replicate dup . ] keep\r
         \r
-        [ >r [ ] each r> call ] 2keep\r
+        [ [ [ ] each ] dip call ] 2keep\r
         \r
-        >r [ boolean>class ] each r> [ boolean-op>class-op ] map call object class=\r
+        [ [ boolean>class ] each ] dip [ boolean-op>class-op ] map call object class=\r
         \r
         =\r
     ] unit-test\r
index b7e6800950cd10d27ace132138efb410b9c4af3e..1b86ce0b0a939e44afd21b709222af71ade524a6 100644 (file)
@@ -18,7 +18,7 @@ TUPLE: anonymous-complement class ;
 C: <anonymous-complement> anonymous-complement\r
 \r
 : 2cache ( key1 key2 assoc quot -- value )\r
-    >r >r 2array r> [ first2 ] r> compose cache ; inline\r
+    [ 2array ] 2dip [ first2 ] prepose cache ; inline\r
 \r
 GENERIC: valid-class? ( obj -- ? )\r
 \r
@@ -66,13 +66,13 @@ DEFER: (class-or)
     swap superclass dup [ swap class<= ] [ 2drop f ] if ;\r
 \r
 : left-anonymous-union<= ( first second -- ? )\r
-    >r members>> r> [ class<= ] curry all? ;\r
+    [ members>> ] dip [ class<= ] curry all? ;\r
 \r
 : right-anonymous-union<= ( first second -- ? )\r
     members>> [ class<= ] with contains? ;\r
 \r
 : left-anonymous-intersection<= ( first second -- ? )\r
-    >r participants>> r> [ class<= ] curry contains? ;\r
+    [ participants>> ] dip [ class<= ] curry contains? ;\r
 \r
 : right-anonymous-intersection<= ( first second -- ? )\r
     participants>> [ class<= ] with all? ;\r
@@ -95,7 +95,7 @@ DEFER: (class-or)
     } cond ;\r
 \r
 : left-anonymous-complement<= ( first second -- ? )\r
-    >r normalize-complement r> class<= ;\r
+    [ normalize-complement ] dip class<= ;\r
 \r
 PREDICATE: nontrivial-anonymous-complement < anonymous-complement\r
     class>> {\r
@@ -212,7 +212,7 @@ M: anonymous-complement (classes-intersect?)
 : sort-classes ( seq -- newseq )\r
     [ [ name>> ] compare ] sort >vector\r
     [ dup empty? not ]\r
-    [ dup largest-class >r over delete-nth r> ]\r
+    [ dup largest-class [ over delete-nth ] dip ]\r
     [ ] produce nip ;\r
 \r
 : min-class ( class seq -- class/f )\r
index 8261e713a55228e3f091d150397cc67fd3a4ebfb..8d2610ccd7ffce1d9cbe2a74872f5008e8a268e0 100644 (file)
@@ -485,7 +485,7 @@ must-fail-with
 [ t ] [ "forget-accessors-test" "classes.tuple.tests" lookup class? ] unit-test
 
 : accessor-exists? ( class name -- ? )
-    >r "forget-accessors-test" "classes.tuple.tests" lookup r>
+    [ "forget-accessors-test" "classes.tuple.tests" lookup ] dip
     ">>" append "accessors" lookup method >boolean ;
 
 [ t ] [ "x" accessor-exists? ] unit-test
index 70b189852f3e8611044c2499a0d565d9cce7e76b..b6b277a32f41b6d3897711209be03ce58aa7dbe8 100644 (file)
@@ -58,7 +58,7 @@ PRIVATE>
 
 : tuple>array ( tuple -- array )
     prepare-tuple>array
-    >r copy-tuple-slots r>
+    [ copy-tuple-slots ] dip
     first prefix ;
 
 : tuple-slots ( tuple -- seq )
@@ -178,9 +178,9 @@ ERROR: bad-superclass class ;
 
 : update-slot ( old-values n class initial -- value )
     pick [
-        >r >r swap nth dup r> instance? r> swap
+        [ [ swap nth dup ] dip instance? ] dip swap
         [ drop ] [ nip ] if
-    ] [ >r 3drop r> ] if ;
+    ] [ [ 3drop ] dip ] if ;
 
 : apply-slot-permutation ( old-values triples -- new-values )
     [ first3 update-slot ] with map ;
@@ -233,7 +233,7 @@ M: tuple-class update-class
     class-usages [ tuple-class? ] filter ;
 
 : each-subclass ( class quot -- )
-    >r subclasses r> each ; inline
+    [ subclasses ] dip each ; inline
 
 : redefine-tuple-class ( class superclass slots -- )
     [
@@ -320,7 +320,7 @@ M: tuple equal? over tuple? [ tuple= ] [ 2drop f ] if ;
 M: tuple hashcode*
     [
         [ class hashcode ] [ tuple-size ] [ ] tri
-        >r rot r> [
+        [ rot ] dip [
             swapd array-nth hashcode* sequence-hashcode-step
         ] 2curry each
     ] recursive-hashcode ;
index 0caabf2fad7104a487db3c5fb3fadcb29a26662e..3afc0a3c3d1ce853714e12a00a540c3be8a8143e 100644 (file)
@@ -74,7 +74,7 @@ HELP: spread
     { $code
         "! Equivalent"
         "{ [ p ] [ q ] [ r ] [ s ] } spread"
-        ">r >r >r p r> q r> r r> s"
+        "[ [ [ p ] dip q ] dip r ] dip s"
     }
 } ;
 
index 82744276fd5080981000d83320d905ba772deed8..893078fb39d3c71903d6de0328e5dda49da799af 100644 (file)
@@ -80,7 +80,7 @@ ERROR: no-case ;
         drop [ swap adjoin ] curry each
     ] [
         [
-            >r 2dup r> hashcode pick length rem rot nth adjoin
+            [ 2dup ] dip hashcode pick length rem rot nth adjoin
         ] each 2drop
     ] if ;
 
@@ -88,13 +88,13 @@ ERROR: no-case ;
     next-power-of-2 swap [ nip clone ] curry map ;
 
 : distribute-buckets ( alist initial quot -- buckets )
-    swapd [ >r dup first r> call 2array ] curry map
+    swapd [ [ dup first ] dip call 2array ] curry map
     [ length <buckets> dup ] keep
     [ first2 (distribute-buckets) ] with each ; inline
 
 : hash-case-table ( default assoc -- array )
     V{ } [ 1array ] distribute-buckets
-    [ [ >r literalize r> ] assoc-map linear-case-quot ] with map ;
+    [ [ [ literalize ] dip ] assoc-map linear-case-quot ] with map ;
 
 : hash-dispatch-quot ( table -- quot )
     [ length 1- [ fixnum-bitand ] curry ] keep
@@ -130,20 +130,20 @@ ERROR: no-case ;
         { [ dup [ length 4 <= ] [ [ word? ] contains? ] bi or ] [ drop linear-case-quot ] }
         { [ dup contiguous-range? ] [ drop dispatch-case-quot ] }
         { [ dup [ wrapper? ] contains? not ] [ drop hash-case-quot ] }
-        { [ dup [ wrapper? ] all? ] [ drop [ >r wrapped>> r> ] assoc-map hash-case-quot ] }
+        { [ dup [ wrapper? ] all? ] [ drop [ [ wrapped>> ] dip ] assoc-map hash-case-quot ] }
         [ drop linear-case-quot ]
     } cond ;
 
 ! assert-depth
 : trim-datastacks ( seq1 seq2 -- seq1' seq2' )
-    2dup [ length ] bi@ min tuck tail >r tail r> ;
+    2dup [ length ] bi@ min tuck [ tail ] 2bi@ ;
 
 ERROR: relative-underflow stack ;
 
 ERROR: relative-overflow stack ;
 
 : assert-depth ( quot -- )
-    >r datastack r> dip >r datastack r>
+    [ datastack ] dip dip [ datastack ] dip
     2dup [ length ] compare {
         { +lt+ [ trim-datastacks nip relative-underflow ] }
         { +eq+ [ 2drop ] }
index c2452f719da75038f39175adc1d7f93ea0a66720..1ea497c3fc5cbeab65f5e8b63329c4dac23b7a7d 100644 (file)
@@ -20,7 +20,7 @@ SYMBOL: with-compiler-errors?
 
 : errors-of-type ( type -- assoc )
     compiler-errors get-global
-    swap [ >r nip compiler-error-type r> eq? ] curry
+    swap [ [ nip compiler-error-type ] dip eq? ] curry
     assoc-filter ;
 
 : compiler-errors. ( type -- )
index 6dde851963442774f3b24cfaf305a43f60ddfb39..af8cda37c69cfb655e98d59b732ec29f63eb1ff7 100644 (file)
@@ -65,7 +65,7 @@ C: <continuation> continuation
     #! ( value f r:capture r:restore )
     #! Execution begins right after the call to 'continuation'.
     #! The 'restore' branch is taken.
-    >r >r dummy-1 continuation r> r> [ dummy-2 ] prepose ?if ; inline
+    [ dummy-1 continuation ] 2dip [ dummy-2 ] prepose ?if ; inline
 
 : callcc0 ( quot -- ) [ drop ] ifcc ; inline
 
@@ -78,7 +78,7 @@ C: <continuation> continuation
     set-catchstack
     set-namestack
     set-retainstack
-    >r set-datastack r>
+    [ set-datastack ] dip
     set-callstack ;
 
 : (continue-with) ( obj continuation -- )
@@ -87,7 +87,7 @@ C: <continuation> continuation
     set-catchstack
     set-namestack
     set-retainstack
-    >r set-datastack drop 4 getenv f 4 setenv f r>
+    [ set-datastack drop 4 getenv f 4 setenv f ] dip
     set-callstack ;
 
 PRIVATE>
@@ -135,14 +135,13 @@ SYMBOL: thread-error-hook
     c> continue-with ;
 
 : recover ( try recovery -- )
-    >r [ swap >c call c> drop ] curry r> ifcc ; inline
+    [ [ swap >c call c> drop ] curry ] dip ifcc ; inline
 
 : ignore-errors ( quot -- )
     [ drop ] recover ; inline
 
 : cleanup ( try cleanup-always cleanup-error -- )
-    over >r compose [ dip rethrow ] curry
-    recover r> call ; inline
+    [ compose [ dip rethrow ] curry recover ] [ drop ] 2bi call ; inline
 
 ERROR: attempt-all-error ;
 
index b5f22ec1207a81e7d6a3dcf81ff54dab4d3689bf..35029a3fb0976e34dba5bba8424da45bb61135e7 100644 (file)
@@ -162,6 +162,6 @@ HELP: forget-methods
 { sort-classes order } related-words
 
 HELP: (call-next-method)
-{ $values { "class" class } { "generic" generic } }
+{ $values { "method" method-body } }
 { $description "Low-level word implementing " { $link POSTPONE: call-next-method } "." }
 { $notes "In most cases, " { $link POSTPONE: call-next-method } " should be used instead." } ;
index e2818a51b21958db220c5230e9c94a9106f774d1..8d7ed4cb600cf1df616227d441c42281be29b356 100644 (file)
@@ -49,12 +49,16 @@ GENERIC: effective-method ( generic -- method )
 
 GENERIC: next-method-quot* ( class generic combination -- quot )
 
-: next-method-quot ( class generic -- quot )
+: next-method-quot ( method -- quot )
     next-method-quot-cache get [
-        dup "combination" word-prop next-method-quot*
-    ] 2cache ;
+        [ "method-class" word-prop ]
+        [
+            "method-generic" word-prop
+            dup "combination" word-prop
+        ] bi next-method-quot*
+    ] cache ;
 
-: (call-next-method) ( class generic -- )
+: (call-next-method) ( method -- )
     next-method-quot call ;
 
 TUPLE: check-method class generic ;
index ebe1c08cb3d1e426018736f739c0ffd3fb953c63..0c7bb2d8e8dbeb122aef81db283adda6fd717245 100644 (file)
@@ -36,9 +36,10 @@ PREDICATE: math-class < class
 
 : math-upgrade ( class1 class2 -- quot )
     [ math-class-max ] 2keep
-    >r over r> (math-upgrade) >r (math-upgrade)
-    dup empty? [ [ dip ] curry [ ] like ] unless
-    r> append ;
+    [ over ] dip (math-upgrade) [
+        (math-upgrade)
+        dup empty? [ [ dip ] curry [ ] like ] unless
+    ] dip append ;
 
 ERROR: no-math-method left right generic ;
 
@@ -55,9 +56,9 @@ ERROR: no-math-method left right generic ;
 
 : math-method ( word class1 class2 -- quot )
     2dup and [
-        2dup math-upgrade >r
-        math-class-max over order min-class applicable-method
-        r> prepend
+        2dup math-upgrade
+        [ math-class-max over order min-class applicable-method ] dip
+        prepend
     ] [
         2drop object-method
     ] if ;
@@ -85,7 +86,7 @@ M: math-combination perform-combination
     dup
     \ over [
         dup math-class? [
-            \ dup [ >r 2dup r> math-method ] math-vtable
+            \ dup [ [ 2dup ] dip math-method ] math-vtable
         ] [
             over object-method
         ] if nip
index 7380399b5c10b8b5af0f555f5ef93bdc9efbf36e..c6420164d2bc83d084ce354c3d3c729cbd0ec8c3 100644 (file)
@@ -13,17 +13,10 @@ ERROR: not-in-a-method-error ;
 : CREATE-METHOD ( -- method )
     scan-word bootstrap-word scan-word create-method-in ;
 
-SYMBOL: current-class
-SYMBOL: current-generic
-
-: with-method-definition ( quot -- parsed )
-    [
-        [
-            [ "method-class" word-prop current-class set ]
-            [ "method-generic" word-prop current-generic set ]
-            [ ] tri
-        ] dip call
-    ] with-scope ; inline
+SYMBOL: current-method
+
+: with-method-definition ( method quot -- )
+    [ dup current-method ] dip with-variable ; inline
 
 : (M:) ( method def -- )
     CREATE-METHOD [ parse-definition ] with-method-definition ;
index 6a5e8d1bb0310fc09c09c89ef6e9d9f218d482e3..b6cb9fc9f7aeab1aff28903ad42a67958f041808 100644 (file)
@@ -18,7 +18,7 @@ GENERIC: engine>quot ( engine -- quot )
     [ over assumed [ engine>quot ] with-variable ] assoc-map ;
 
 : if-small? ( assoc true false -- )
-    >r >r dup assoc-size 4 <= r> r> if ; inline
+    [ dup assoc-size 4 <= ] 2dip if ; inline
 
 : linear-dispatch-quot ( alist -- quot )
     default get [ drop ] prepend swap
@@ -45,7 +45,7 @@ GENERIC: engine>quot ( engine -- quot )
         { 0 [ [ dup ] ] }
         { 1 [ [ over ] ] }
         { 2 [ [ pick ] ] }
-        [ 1- (picker) [ >r ] swap [ r> swap ] 3append ]
+        [ 1- (picker) [ dip swap ] curry ]
     } case ;
 
 : picker ( -- quot ) \ (dispatch#) get (picker) ;
index 8846c9eee776072afa6ca39202fb7b738cb798b2..152b112c2a73114a4be6e97487e61763f223909a 100644 (file)
@@ -10,7 +10,7 @@ TUPLE: predicate-dispatch-engine methods ;
 C: <predicate-dispatch-engine> predicate-dispatch-engine
 
 : class-predicates ( assoc -- assoc )
-    [ >r "predicate" word-prop picker prepend r> ] assoc-map ;
+    [ [ "predicate" word-prop picker prepend ] dip ] assoc-map ;
 
 : keep-going? ( assoc -- ? )
     assumed get swap second first class<= ;
index d1bc6d7417d883e8518f21225d884f7e407f2b72..dbdc6e0742b94fe76c4d3bacfa92bcf48de45162 100644 (file)
@@ -26,7 +26,7 @@ C: <lo-tag-dispatch-engine> lo-tag-dispatch-engine
 
 M: lo-tag-dispatch-engine engine>quot
     methods>> engines>quots*
-    [ >r lo-tag-number r> ] assoc-map
+    [ [ lo-tag-number ] dip ] assoc-map
     [
         picker % [ tag ] % [
             sort-tags linear-dispatch-quot
@@ -53,13 +53,13 @@ C: <hi-tag-dispatch-engine> hi-tag-dispatch-engine
 
 M: hi-tag-dispatch-engine engine>quot
     methods>> engines>quots*
-    [ >r hi-tag-number r> ] assoc-map
+    [ [ hi-tag-number ] dip ] assoc-map
     [
         picker % hi-tag-quot % [
             sort-tags linear-dispatch-quot
         ] [
             num-tags get , \ fixnum-fast ,
-            [ >r num-tags get - r> ] assoc-map
+            [ [ num-tags get - ] dip ] assoc-map
             num-hi-tags direct-dispatch-quot
         ] if-small? %
     ] [ ] make ;
index 284a58836f3ee68715a60168909ce86581e0f7ef..4f26c40e7807f3518c6796c062b055b6eed73929 100644 (file)
@@ -33,8 +33,8 @@ ERROR: no-method object generic ;
     ] change-at ;
 
 : flatten-method ( class method assoc -- )
-    >r >r dup flatten-class keys swap r> r> [
-        >r spin r> push-method
+    [ dup flatten-class keys swap ] 2dip [
+        [ spin ] dip push-method
     ] 3curry each ;
 
 : flatten-methods ( assoc -- assoc' )
@@ -113,7 +113,7 @@ PREDICATE: simple-generic < standard-generic
     T{ standard-combination f 0 } define-generic ;
 
 : with-standard ( combination quot -- quot' )
-    >r #>> (dispatch#) r> with-variable ; inline
+    [ #>> (dispatch#) ] dip with-variable ; inline
 
 M: standard-generic extra-values drop 0 ;
 
index 336f1da91a5d55f164710d57d2a921e8d1e3bedb..3c487af0a54245e5e82631f282af97d4bb3b5497 100644 (file)
@@ -43,10 +43,10 @@ M: growable set-length ( n seq -- )
     growable-check
     2dup length >= [
         2dup capacity >= [ over new-size over expand ] when
-        >r >fixnum r>
+        [ >fixnum ] dip
         over 1 fixnum+fast over (>>length)
     ] [
-        >r >fixnum r>
+        [ >fixnum ] dip
     ] if ; inline
 
 M: growable set-nth ensure set-nth-unsafe ;
index a59c6495983b9bdde080ea63452af2e1070d5bba..0e6deb77465488387704519adfb632a08bd4e48d 100644 (file)
@@ -134,7 +134,7 @@ H{ } "x" set
 
 [ H{ { -1 4 } { -3 16 } { -5 36 } } ] [
     H{ { 1 2 } { 3 4 } { 5 6 } }
-    [ >r neg r> sq ] assoc-map
+    [ [ neg ] dip sq ] assoc-map
 ] unit-test
 
 ! Bug discovered by littledan
index 0fde459a25b129dadba2b9c97d9b55165882cac1..474cf4c9d60b40b65ed3733ae53e487077a71987 100644 (file)
@@ -15,7 +15,7 @@ TUPLE: hashtable
     length>> 1 fixnum-fast fixnum-bitand ; inline
 
 : hash@ ( key array -- i )
-    >r hashcode >fixnum dup fixnum+fast r> wrap ; inline
+    [ hashcode >fixnum dup fixnum+fast ] dip wrap ; inline
 
 : probe ( array i -- array i )
     2 fixnum+fast over wrap ; inline
@@ -105,7 +105,7 @@ M: hashtable clear-assoc ( hash -- )
 
 M: hashtable delete-at ( key hash -- )
     tuck key@ [
-        >r >r ((tombstone)) dup r> r> set-nth-pair
+        [ ((tombstone)) dup ] 2dip set-nth-pair
         hash-deleted+
     ] [
         3drop
@@ -115,9 +115,9 @@ M: hashtable assoc-size ( hash -- n )
     [ count>> ] [ deleted>> ] bi - ;
 
 : rehash ( hash -- )
-    dup >alist >r
+    dup >alist [
     dup clear-assoc
-    r> (rehash) ;
+    ] dip (rehash) ;
 
 M: hashtable set-at ( value key hash -- )
     dup ?grow-hash
@@ -133,7 +133,7 @@ M: hashtable set-at ( value key hash -- )
 : push-unsafe ( elt seq -- )
     [ length ] keep
     [ underlying>> set-array-nth ]
-    [ >r 1+ r> (>>length) ]
+    [ [ 1+ ] dip (>>length) ]
     2bi ; inline
 
 PRIVATE>
@@ -141,9 +141,10 @@ PRIVATE>
 M: hashtable >alist
     [ array>> [ length 2/ ] keep ] [ assoc-size <vector> ] bi [
         [
-            >r
-            >r 1 fixnum-shift-fast r>
-            [ array-nth ] [ >r 1 fixnum+fast r> array-nth ] 2bi r>
+            [
+                [ 1 fixnum-shift-fast ] dip
+                [ array-nth ] [ [ 1 fixnum+fast ] dip array-nth ] 2bi
+            ] dip
             pick tombstone? [ 3drop ] [ [ 2array ] dip push-unsafe ] if
         ] 2curry each
     ] keep { } like ;
index 48b49ed32b66fedc5fea449161db80c253f3479b..e129a9b0bc356293c59e3f4e6b0010e81d3f9b9c 100644 (file)
@@ -2,8 +2,8 @@ USING: help.markup help.syntax io io.backend strings
 byte-arrays ;
 
 HELP: io-multiplex
-{ $values { "ms" "a non-negative integer" } }
-{ $contract "Waits up to " { $snippet "ms" } " milliseconds for pending I/O requests to complete." } ;
+{ $values { "us" "a non-negative integer" } }
+{ $contract "Waits up to " { $snippet "us" } " microseconds for pending I/O requests to complete." } ;
 
 HELP: init-io
 { $contract "Initializes the I/O system. Called on startup." } ;
index 48a428d36e6c480a7b789bee4b2e4395e662b603..d165ad3138cc7c5e939b25bcc53c7acac2915f8e 100644 (file)
@@ -95,7 +95,7 @@ M: decoder stream-read-partial stream-read ;
 
 : ((read-until)) ( buf quot: ( -- char stop? ) -- string/f sep/f )
     dup call
-    [ >r drop "" like r> ]
+    [ [ drop "" like ] dip ]
     [ pick push ((read-until)) ] if ; inline recursive
 
 : (read-until) ( quot -- string/f sep/f )
index 25f6f36e7c27e86885baaa706d74391505d5f854..7c7a2ece313cecfcac346e0bbbfa54a6839fc5bb 100644 (file)
@@ -26,13 +26,13 @@ HOOK: (file-appender) io-backend ( path -- stream )
     <file-reader> lines ;
 
 : with-file-reader ( path encoding quot -- )
-    >r <file-reader> r> with-input-stream ; inline
+    [ <file-reader> ] dip with-input-stream ; inline
 
 : file-contents ( path encoding -- str )
     <file-reader> contents ;
 
 : with-file-writer ( path encoding quot -- )
-    >r <file-writer> r> with-output-stream ; inline
+    [ <file-writer> ] dip with-output-stream ; inline
 
 : set-file-lines ( seq path encoding -- )
     [ [ print ] each ] with-file-writer ;
@@ -41,7 +41,7 @@ HOOK: (file-appender) io-backend ( path -- stream )
     [ write ] with-file-writer ;
 
 : with-file-appender ( path encoding quot -- )
-    >r <file-appender> r> with-output-stream ; inline
+    [ <file-appender> ] dip with-output-stream ; inline
 
 ! Pathnames
 : path-separator? ( ch -- ? ) os windows? "/\\" "/" ? member? ;
@@ -127,13 +127,13 @@ PRIVATE>
         { [ dup head.? ] [ rest trim-left-separators append-path ] }
         { [ dup head..? ] [
             2 tail trim-left-separators
-            >r parent-directory r> append-path
+            [ parent-directory ] dip append-path
         ] }
         { [ over absolute-path? over first path-separator? and ] [
-            >r 2 head r> append
+            [ 2 head ] dip append
         ] }
         [
-            >r trim-right-separators "/" r>
+            [ trim-right-separators "/" ] dip
             trim-left-separators 3append
         ]
     } cond ;
@@ -150,7 +150,7 @@ PRIVATE>
     ] unless ;
 
 : file-extension ( filename -- extension )
-    "." last-split1 nip ;
+    "." split1-last nip ;
 
 ! File info
 TUPLE: file-info type size permissions created modified
@@ -166,7 +166,7 @@ HOOK: make-link io-backend ( target symlink -- )
 HOOK: read-link io-backend ( symlink -- path )
 
 : copy-link ( target symlink -- )
-    >r read-link r> make-link ;
+    [ read-link ] dip make-link ;
 
 SYMBOL: +regular-file+
 SYMBOL: +directory+
@@ -228,7 +228,7 @@ M: object normalize-path ( path -- path' )
     (normalize-path) current-directory set ;
 
 : with-directory ( path quot -- )
-    >r (normalize-path) current-directory r> with-variable ; inline
+    [ (normalize-path) current-directory ] dip with-variable ; inline
 
 ! Creating directories
 HOOK: make-directory io-backend ( path -- )
index c50fc6f46c6004c959a5799660412c05175fc7bd..d7d4edf49ff1656c56457069e989dd510155f2eb 100644 (file)
@@ -69,7 +69,7 @@ SYMBOL: error-stream
     [ ] cleanup ; inline
 
 : tabular-output ( style quot -- )
-    swap >r { } make r> output-stream get stream-write-table ; inline
+    swap [ { } make ] dip output-stream get stream-write-table ; inline
 
 : with-row ( quot -- )
     { } make , ; inline
@@ -89,8 +89,8 @@ SYMBOL: error-stream
     ] if ; inline
 
 : with-nesting ( style quot -- )
-    >r output-stream get make-block-stream
-    r> with-output-stream ; inline
+    [ output-stream get make-block-stream ] dip
+    with-output-stream ; inline
 
 : print ( string -- ) output-stream get stream-print ;
 
index 28d789d66f1ee514e070746c74d422c9307e412c..9d89c3d814d8e6e3ba43c17f279da60fffad3f76 100644 (file)
@@ -6,11 +6,11 @@ IN: io.streams.byte-array
     512 <byte-vector> swap <encoder> ;
 
 : with-byte-writer ( encoding quot -- byte-array )
-    >r <byte-writer> r> [ output-stream get ] compose with-output-stream*
+    [ <byte-writer> ] dip [ output-stream get ] compose with-output-stream*
     dup encoder? [ stream>> ] when >byte-array ; inline
 
 : <byte-reader> ( byte-array encoding -- stream )
-    >r >byte-vector dup reverse-here r> <decoder> ;
+    [ >byte-vector dup reverse-here ] dip <decoder> ;
 
 : with-byte-reader ( byte-array encoding quot -- )
-    >r <byte-reader> r> with-input-stream* ; inline
+    [ <byte-reader> ] dip with-input-stream* ; inline
old mode 100644 (file)
new mode 100755 (executable)
index 1e12d7e..47e19d2
@@ -67,7 +67,7 @@ M: c-io-backend init-io ;
 
 M: c-io-backend (init-stdio) init-c-stdio ;
 
-M: c-io-backend io-multiplex 60 60 * 1000 * or (sleep) ;
+M: c-io-backend io-multiplex 60 60 * 1000 * 1000 * or (sleep) ;
 
 M: c-io-backend (file-reader)
     "rb" fopen <c-reader> ;
@@ -83,6 +83,6 @@ M: c-io-backend (file-appender)
     #! print stuff from contexts where the I/O system would
     #! otherwise not work (tools.deploy.shaker, the I/O
     #! multiplexer thread).
-    "\r\n" append >byte-array
+    "\n" append >byte-array
     stdout-handle fwrite
     stdout-handle fflush ;
index bb6a7a9111ac0258a2e5d2843f68917a4f2ff389..a155f842afade620893237502d3b146ea661e931 100644 (file)
@@ -56,7 +56,7 @@ M: style-stream stream-write
     [ style>> ] [ stream>> ] bi stream-format ;
 
 M: style-stream stream-write1
-    >r 1string r> stream-write ;
+    [ 1string ] dip stream-write ;
 
 M: style-stream make-span-stream
     do-nested-style make-span-stream ;
index 10d8f7d9476fa11b117058790a4a2aaaf19b25e1..57c0cb37e8a25780fa3c6b951ad90ed6ff47fe8b 100644 (file)
@@ -24,7 +24,7 @@ M: null-encoding decode-char drop stream-read1 ;
     ] unless ;
 
 : map-last ( seq quot -- seq )
-    >r dup length <reversed> [ zero? ] r> compose 2map ; inline
+    [ dup length <reversed> ] dip [ 0 = ] prepose 2map ; inline
 
 PRIVATE>
 
@@ -75,7 +75,7 @@ M: growable stream-read-partial
     >sbuf dup reverse-here null-encoding <decoder> ;
 
 : with-string-reader ( str quot -- )
-    >r <string-reader> r> with-input-stream ; inline
+    [ <string-reader> ] dip with-input-stream ; inline
 
 INSTANCE: growable plain-writer
 
index 40094d5589e2c7f9285044c35c9ad24f6ba47a33..31798c92957908b965d323325616a3a1e7dfd931 100644 (file)
@@ -29,12 +29,6 @@ HELP: spin                           $shuffle ;
 HELP: roll                           $shuffle ;
 HELP: -roll                          $shuffle ;
 
-HELP: >r ( x -- )
-{ $values { "x" object } } { $description "Moves the top of the data stack to the retain stack." } ;
-
-HELP: r> ( -- x )
-{ $values { "x" object } } { $description "Moves the top of the retain stack to the data stack." } ;
-
 HELP: datastack ( -- ds )
 { $values { "ds" array } }
 { $description "Outputs an array containing a copy of the data stack contents right before the call to this word, with the top of the stack at the end of the array." } ;
@@ -212,7 +206,10 @@ HELP: 3slip
 
 HELP: keep
 { $values { "quot" { $quotation "( x -- )" } } { "x" object } }
-{ $description "Call a quotation with a value on the stack, restoring the value when the quotation returns." } ;
+{ $description "Call a quotation with a value on the stack, restoring the value when the quotation returns." }
+{ $examples
+    { $example "USING: arrays kernel prettyprint ;" "2 \"greetings\" [ <array> ] keep 2array ." "{ { \"greetings\" \"greetings\" } \"greetings\" }" }
+} ;
 
 HELP: 2keep
 { $values { "quot" { $quotation "( x y -- )" } } { "x" object } { "y" object } }
@@ -347,7 +344,7 @@ HELP: bi*
     "The following two lines are equivalent:"
     { $code
         "[ p ] [ q ] bi*"
-        ">r p r> q"
+        "[ p ] dip q"
     }
 } ;
 
@@ -358,7 +355,7 @@ HELP: 2bi*
     "The following two lines are equivalent:"
     { $code
         "[ p ] [ q ] 2bi*"
-        ">r >r p r> r> q"
+        "[ p ] 2dip q"
     }
 } ;
 
@@ -369,7 +366,7 @@ HELP: tri*
     "The following two lines are equivalent:"
     { $code
         "[ p ] [ q ] [ r ] tri*"
-        ">r >r p r> q r> r"
+        "[ [ p ] dip q ] dip r"
     }
 } ;
 
@@ -380,7 +377,7 @@ HELP: bi@
     "The following two lines are equivalent:"
     { $code
         "[ p ] bi@"
-        ">r p r> p"
+        "[ p ] dip p"
     }
     "The following two lines are also equivalent:"
     { $code
@@ -396,7 +393,7 @@ HELP: 2bi@
     "The following two lines are equivalent:"
     { $code
         "[ p ] 2bi@"
-        ">r >r p r> r> p"
+        "[ p ] 2dip p"
     }
     "The following two lines are also equivalent:"
     { $code
@@ -412,7 +409,7 @@ HELP: tri@
     "The following two lines are equivalent:"
     { $code
         "[ p ] tri@"
-        ">r >r p r> p r> p"
+        "[ [ p ] dip p ] dip p"
     }
     "The following two lines are also equivalent:"
     { $code
@@ -565,11 +562,7 @@ HELP: compose
 { $values { "quot1" callable } { "quot2" callable } { "compose" compose } }
 { $description "Quotation composition. Outputs a " { $link callable } " which calls " { $snippet "quot1" } " followed by " { $snippet "quot2" } "." }
 { $notes
-    "The two quotations must leave the retain stack in the same state on exit as it was on entry, so the following code is not allowed:"
-    { $code
-        "[ 3 >r ] [ r> . ] compose"
-    }
-    "Except for this restriction, the following two lines are equivalent:"
+    "The following two lines are equivalent:"
     { $code
         "compose call"
         "append call"
@@ -589,15 +582,7 @@ HELP: 3compose
 { $values { "quot1" callable } { "quot2" callable } { "quot3" callable } { "compose" compose } }
 { $description "Quotation composition. Outputs a " { $link callable } " which calls " { $snippet "quot1" } ", " { $snippet "quot2" } " and then " { $snippet "quot3" } "." }
 { $notes
-    "The three quotations must leave the retain stack in the same state on exit as it was on entry, so for example, the following code is not allowed:"
-    { $code
-        "[ >r ] swap [ r> ] 3compose"
-    }
-    "The correct way to achieve the effect of the above is the following:"
-    { $code
-        "[ dip ] curry"
-    }
-    "Excepting the retain stack restriction, the following two lines are equivalent:"
+    "The following two lines are equivalent:"
     { $code
         "3compose call"
         "3append call"
@@ -608,16 +593,15 @@ HELP: 3compose
 HELP: dip
 { $values { "x" object } { "quot" quotation } }
 { $description "Calls " { $snippet "quot" } " with " { $snippet "obj" } " hidden on the retain stack." }
-{ $notes "The following are equivalent:"
-    { $code ">r foo bar r>" }
-    { $code "[ foo bar ] dip" }
+{ $examples
+    { $example "USING: arrays kernel math prettyprint ;" "10 20 30 [ / ] dip 2array ." "{ 1/2 30 }" }
 } ;
 
 HELP: 2dip
 { $values { "x" object } { "y" object } { "quot" quotation } }
 { $description "Calls " { $snippet "quot" } " with " { $snippet "obj1" } " and " { $snippet "obj2" } " hidden on the retain stack." }
 { $notes "The following are equivalent:"
-    { $code ">r >r foo bar r> r>" }
+    { $code "[ [ foo bar ] dip ] dip" }
     { $code "[ foo bar ] 2dip" }
 } ;
 
@@ -625,7 +609,7 @@ HELP: 3dip
 { $values { "x" object } { "y" object } { "z" object } { "quot" quotation } }
 { $description "Calls " { $snippet "quot" } " with " { $snippet "obj1" } ", " { $snippet "obj2" } " and " { $snippet "obj3" } " hidden on the retain stack." }
 { $notes "The following are equivalent:"
-    { $code ">r >r >r foo bar r> r> r>" }
+    { $code "[ [ [ foo bar ] dip ] dip ] dip" }
     { $code "[ foo bar ] 3dip" }
 } ;
 
@@ -692,15 +676,7 @@ $nl
 { $subsection -rot }
 { $subsection spin }
 { $subsection roll }
-{ $subsection -roll }
-"Sometimes an additional storage area is needed to hold objects. The " { $emphasis "retain stack" } " is an auxilliary stack for this purpose. Objects can be moved between the data and retain stacks using the following two words:"
-{ $subsection >r }
-{ $subsection r> }
-"The top of the data stack is ``hidden'' between " { $link >r } " and " { $link r> } ":"
-{ $example "1 2 3 >r .s r>" "1\n2" }
-"Usages of " { $link >r } " and " { $link r> } " must be balanced within a single quotation; quotations are not permitted to pop retain stack elements they did not push, or leave elements on the retain stack after returning."
-$nl
-"The " { $link "inference" } " tool checks retain stack usage. The " { $link "slip-keep-combinators" } " combinators abstract out common retain stack usage patterns." ;
+{ $subsection -roll } ;
 
 ARTICLE: "cleave-shuffle-equivalence" "Expressing shuffle words with cleave combinators"
 "Cleave combinators are defined in terms of shuffle words, and mappings from certain shuffle idioms to cleave combinators are discussed in the documentation for " { $link bi } ", " { $link 2bi } ", " { $link 3bi } ", " { $link tri } ", " { $link 2tri } " and " { $link 3tri } "."
@@ -793,14 +769,10 @@ $nl
 { $subsection tri* }
 "Technically, the spread combinators are redundant because they can be simulated using shuffle words and other combinators, and in addition, they do not reduce token counts by much, if at all. However, they can make code more readable by expressing intention and exploiting any inherent symmetry. For example, a piece of code which performs three operations on three related values can be written in one of two ways:"
 { $code
-    "! First alternative; uses retain stack explicitly"
-    ">r >r 1 +"
-    "r> 1 -"
-    "r> 2 *"
+    "! First alternative; uses dip"
+    "[ [ 1 + ] dip 1 - dip ] 2 *"
     "! Second alternative: uses tri*"
-    "[ 1 + ]"
-    "[ 1 - ]"
-    "[ 2 * ] tri*"
+    "[ 1 + ] [ 1 - ] [ 2 * ] tri*"
 }
 
 $nl
@@ -819,7 +791,9 @@ $nl
 { $subsection both? }
 { $subsection either? } ;
 
-ARTICLE: "slip-keep-combinators" "The dip, slip and keep combinators"
+ARTICLE: "slip-keep-combinators" "Retain stack combinators"
+"Sometimes an additional storage area is needed to hold objects. The " { $emphasis "retain stack" } " is an auxilliary stack for this purpose. Objects can be moved between the data and retain stacks using a set of combinators."
+$nl
 "The dip combinators invoke the quotation at the top of the stack, hiding the values underneath:"
 { $subsection dip }
 { $subsection 2dip }
@@ -851,7 +825,7 @@ ARTICLE: "implementing-combinators" "Implementing combinators"
 "These words are used to implement combinators. Note that combinator definitions must be followed by the " { $link POSTPONE: inline } " declaration in order to compile in the optimizing compiler; for example:"
 { $code
     ": keep ( x quot -- x )"
-    "    over >r call r> ; inline"
+    "    over [ call ] dip ; inline"
 }
 "Word inlining is documented in " { $link "declarations" } "." ;
 
@@ -935,10 +909,10 @@ ARTICLE: "dataflow" "Data and control flow"
 { $subsection "booleans" }
 { $subsection "shuffle-words" }
 "A central concept in Factor is that of a " { $emphasis "combinator" } ", which is a word taking code as input."
+{ $subsection "slip-keep-combinators" }
 { $subsection "cleave-combinators" }
 { $subsection "spread-combinators" }
 { $subsection "apply-combinators" }
-{ $subsection "slip-keep-combinators" }
 { $subsection "conditionals" }
 { $subsection "compositional-combinators" }
 { $subsection "combinators" }
index 8a51d45447a2e88307b4140e08a9a331670f4d0b..6619d331f17ab8ea1e65ff1e48431b8236e703f3 100644 (file)
@@ -106,11 +106,11 @@ IN: kernel.tests
 
 ! Regression
 : (loop) ( a b c d -- )
-    >r pick r> swap >r pick r> swap
-    < [ >r >r >r 1+ r> r> r> (loop) ] [ 2drop 2drop ] if ; inline
+    [ pick ] dip swap [ pick ] dip swap
+    < [ [ 1+ ] 3dip (loop) ] [ 2drop 2drop ] if ; inline
 
 : loop ( obj obj -- )
-    H{ } values swap >r dup length swap r> 0 -roll (loop) ;
+    H{ } values swap [ dup length swap ] dip 0 -roll (loop) ;
 
 [ loop ] must-fail
 
index 18bead109dac4a9027cea2b04abd930476043af8..1677a2faaac1e1d9cdc84320dd9cc30c209f5a03 100644 (file)
@@ -3,12 +3,16 @@
 USING: kernel.private slots.private classes.tuple.private ;
 IN: kernel
 
+DEFER: dip
+DEFER: 2dip
+DEFER: 3dip
+
 ! Stack stuff
 : spin ( x y z -- z y x ) swap rot ; inline
 
-: roll ( x y z t -- y z t x ) >r rot r> swap ; inline
+: roll ( x y z t -- y z t x ) [ rot ] dip swap ; inline
 
-: -roll ( x y z t -- t x y z ) swap >r -rot r> ; inline
+: -roll ( x y z t -- t x y z ) swap [ -rot ] dip ; inline
 
 : 2over ( x y z -- x y z x y ) pick pick ; inline
 
@@ -49,56 +53,68 @@ DEFER: if
     pick [ roll 2drop call ] [ 2nip call ] if ; inline
 
 ! Slippers
-: slip ( quot x -- x ) >r call r> ; inline
-
-: 2slip ( quot x y -- x y ) >r >r call r> r> ; inline
-
-: 3slip ( quot x y z -- x y z ) >r >r >r call r> r> r> ; inline
+: slip ( quot x -- x )
+    #! 'slip' and 'dip' can be defined in terms of each other
+    #! because the JIT special-cases a 'dip' preceeded by
+    #! a literal quotation.
+    [ call ] dip ;
+
+: 2slip ( quot x y -- x y )
+    #! '2slip' and '2dip' can be defined in terms of each other
+    #! because the JIT special-cases a '2dip' preceeded by
+    #! a literal quotation.
+    [ call ] 2dip ;
+
+: 3slip ( quot x y z -- x y z )
+    #! '3slip' and '3dip' can be defined in terms of each other
+    #! because the JIT special-cases a '3dip' preceeded by
+    #! a literal quotation.
+    [ call ] 3dip ;
 
 : dip ( x quot -- x ) swap slip ; inline
 
-: 2dip ( x y quot -- x y ) swap >r dip r> ; inline
+: 2dip ( x y quot -- x y ) -rot 2slip ; inline
 
-: 3dip ( x y z quot -- x y z ) swap >r 2dip r> ; inline
+: 3dip ( x y z quot -- x y z ) -roll 3slip ; inline
 
 ! Keepers
-: keep ( x quot -- x ) dupd dip ; inline
+: keep ( x quot -- x ) over slip ; inline
 
-: 2keep ( x y quot -- x y ) >r 2dup r> 2dip ; inline
+: 2keep ( x y quot -- x y ) [ 2dup ] dip 2dip ; inline
 
-: 3keep ( x y z quot -- x y z ) >r 3dup r> 3dip ; inline
+: 3keep ( x y z quot -- x y z ) [ 3dup ] dip 3dip ; inline
 
 ! Cleavers
 : bi ( x p q -- )
-    >r keep r> call ; inline
+    [ keep ] dip call ; inline
 
 : tri ( x p q r -- )
-    >r >r keep r> keep r> call ; inline
+    [ [ keep ] dip keep ] dip call ; inline
 
 ! Double cleavers
 : 2bi ( x y p q -- )
-    >r 2keep r> call ; inline
+    [ 2keep ] dip call ; inline
 
 : 2tri ( x y p q r -- )
-    >r >r 2keep r> 2keep r> call ; inline
+    [ [ 2keep ] dip 2keep ] dip call ; inline
 
 ! Triple cleavers
 : 3bi ( x y z p q -- )
-    >r 3keep r> call ; inline
+    [ 3keep ] dip call ; inline
 
 : 3tri ( x y z p q r -- )
-    >r >r 3keep r> 3keep r> call ; inline
+    [ [ 3keep ] dip 3keep ] dip call ; inline
 
 ! Spreaders
 : bi* ( x y p q -- )
-    >r dip r> call ; inline
+    [ dip ] dip call ; inline
 
 : tri* ( x y z p q r -- )
-    >r >r 2dip r> dip r> call ; inline
+    [ [ 2dip ] dip dip ] dip call ; inline
 
 ! Double spreaders
 : 2bi* ( w x y z p q -- )
-    >r 2dip r> call ; inline
+    [ 2dip ] dip call ; inline
 
 ! Appliers
 : bi@ ( x y quot -- )
@@ -115,8 +131,8 @@ DEFER: if
     dup slip swap [ loop ] [ drop ] if ; inline recursive
 
 : while ( pred: ( -- ? ) body: ( -- ) tail: ( -- ) -- )
-    >r >r dup slip r> r> roll
-    [ >r tuck 2slip r> while ]
+    [ dup slip ] 2dip roll
+    [ [ tuck 2slip ] dip while ]
     [ 2nip call ] if ; inline recursive
 
 ! Object protocol
@@ -182,7 +198,7 @@ GENERIC: boa ( ... class -- tuple )
 : either? ( x y quot -- ? ) bi@ or ; inline
 
 : most ( x y quot -- z )
-    >r 2dup r> call [ drop ] [ nip ] if ; inline
+    [ 2dup ] dip call [ drop ] [ nip ] if ; inline
 
 ! Error handling -- defined early so that other files can
 ! throw errors before continuations are loaded
index 0d6f566d36a1174305ae2853355d1a58d88e9ce2..c36e6da19056d11ab1de53bc8821d8f690878532 100644 (file)
@@ -23,7 +23,7 @@ TUPLE: lexer text line line-text line-length column ;
     lexer new-lexer ;
 
 : skip ( i seq ? -- n )
-    >r tuck r>
+    [ tuck ] dip
     [ swap CHAR: \s eq? xor ] curry find-from drop
     [ ] [ length ] ?if ;
 
index 74a93d39bd306e50b70f6087f95716fa64ea1c90..fcb1b65d80c466bd4dc57fd1b1dd83dba39c81e7 100644 (file)
@@ -25,7 +25,7 @@ M: fixnum + fixnum+ ;
 M: fixnum - fixnum- ;
 M: fixnum * fixnum* ;
 M: fixnum /i fixnum/i ;
-M: fixnum /f >r >float r> >float float/f ;
+M: fixnum /f [ >float ] dip >float float/f ;
 
 M: fixnum mod fixnum-mod ;
 
@@ -41,7 +41,7 @@ M: fixnum bitnot fixnum-bitnot ;
 M: fixnum bit? neg shift 1 bitand 0 > ;
 
 : (fixnum-log2) ( accum n -- accum )
-    dup 1 number= [ drop ] [ >r 1+ r> 2/ (fixnum-log2) ] if ;
+    dup 1 number= [ drop ] [ [ 1+ ] [ 2/ ] bi* (fixnum-log2) ] if ;
     inline recursive
 
 M: fixnum (log2) 0 swap (fixnum-log2) ;
@@ -94,7 +94,7 @@ M: bignum (log2) bignum-log2 ;
 
 : pre-scale ( num den -- scale shifted-num scaled-den )
     2dup [ log2 ] bi@ -
-    tuck [ neg 54 + shift ] [ >r scale-denonimator r> + ] 2bi*
+    tuck [ neg 54 + shift ] [ [ scale-denonimator ] dip + ] 2bi*
     -rot ; inline
 
 ! Second step: loop
@@ -103,7 +103,7 @@ M: bignum (log2) bignum-log2 ;
 
 : /f-loop ( scale mantissa den -- scale' fraction-and-guard rem )
     [ 2dup /i log2 53 > ]
-    [ >r shift-mantissa r> ]
+    [ [ shift-mantissa ] dip ]
     [ ] while /mod ; inline
 
 ! Third step: post-scaling
@@ -111,7 +111,7 @@ M: bignum (log2) bignum-log2 ;
     52 2^ 1- bitand 1022 52 shift bitor bits>double ; inline
 
 : scale-float ( scale mantissa -- float' )
-    >r dup 0 < [ neg 2^ recip ] [ 2^ ] if r> * ; inline
+    [ dup 0 < [ neg 2^ recip ] [ 2^ ] if ] dip * ; inline
 
 : post-scale ( scale mantissa -- n )
     2/ dup log2 52 > [ shift-mantissa ] when
index 6efdd53825d884474d3b8b706f06007b35820a10..5c53d99cff566a31f604fd4ae81bedd58b899e30 100644 (file)
@@ -107,7 +107,7 @@ M: float fp-infinity? ( float -- ? )
     2dup >= [
         drop
     ] [
-        >r 1 shift r> (next-power-of-2)
+        [ 1 shift ] dip (next-power-of-2)
     ] if ;
 
 : next-power-of-2 ( m -- n ) 2 swap (next-power-of-2) ; foldable
@@ -122,13 +122,13 @@ M: float fp-infinity? ( float -- ? )
 
 : iterate-prep 0 -rot ; inline
 
-: if-iterate? >r >r 2over < r> r> if ; inline
+: if-iterate? [ 2over < ] 2dip if ; inline
 
 : iterate-step ( i n quot -- i n quot )
     #! Apply quot to i, keep i and quot, hide n.
-    swap >r 2dup 2slip r> swap ; inline
+    swap [ 2dup 2slip ] dip swap ; inline
 
-: iterate-next >r >r 1+ r> r> ; inline
+: iterate-next [ 1+ ] 2dip ; inline
 
 PRIVATE>
 
@@ -167,6 +167,6 @@ PRIVATE>
         2dup 2slip rot [
             drop
         ] [
-            >r 1- r> find-last-integer
+            [ 1- ] dip find-last-integer
         ] if
     ] if ; inline recursive
index 0134693761969ab845b793380d8dc524658fe4bc..8fc6e6dd9e488a3cc4407dd72a822d206996082d 100644 (file)
@@ -51,12 +51,12 @@ SYMBOL: negative?
 : (base>) ( str -- n ) radix get base> ;
 
 : whole-part ( str -- m n )
-    sign split1 >r (base>) r>
+    sign split1 [ (base>) ] dip
     dup [ (base>) ] [ drop 0 swap ] if ;
 
 : string>ratio ( str -- a/b )
     "-" ?head dup negative? set swap
-    "/" split1 (base>) >r whole-part r>
+    "/" split1 (base>) [ whole-part ] dip
     3dup and and [ / + swap [ neg ] when ] [ 2drop 2drop f ] if ;
 
 : valid-digits? ( seq -- ? )
@@ -137,7 +137,7 @@ M: ratio >base
     {
         {
             [ CHAR: e over member? ]
-            [ "e" split1 >r fix-float "e" r> 3append ]
+            [ "e" split1 [ fix-float "e" ] dip 3append ]
         } {
             [ CHAR: . over member? ]
             [ ]
index 20400f4e54d11848677f99b0d54b71a919f2bf19..427c294759bb570d2836f3a3b20672232dd61ec3 100644 (file)
@@ -23,7 +23,7 @@ PRIVATE>
 : off ( variable -- ) f swap set ; inline
 : get-global ( variable -- value ) global at ;
 : set-global ( value variable -- ) global set-at ;
-: change ( variable quot -- ) >r dup get r> rot slip set ; inline
+: change ( variable quot -- ) [ [ get ] keep ] dip dip set ; inline
 : +@ ( n variable -- ) [ 0 or + ] change ;
 : inc ( variable -- ) 1 swap +@ ; inline
 : dec ( variable -- ) -1 swap +@ ; inline
@@ -37,4 +37,4 @@ PRIVATE>
     H{ } clone >n call ndrop ; inline
 
 : with-variable ( value key quot -- )
-    >r associate >n r> call ndrop ; inline
+    [ associate >n ] dip call ndrop ; inline
index ca80533a2e9f5ed7fe355c6e0628ede2fa3ae621..1e93a762f2cc8dd3e7cc7ec9db9d4a10eeae4637 100644 (file)
@@ -498,3 +498,5 @@ DEFER: blah
 [ error>> error>> def>> \ blah eq? ] must-fail-with
 
 [ ] [ f lexer set f file set "Hello world" note. ] unit-test
+
+[ "CHAR: \\u9999999999999" eval ] must-fail
index 1728b471e26b6e897fe7e14315ec6eaca21f2da3..42e4e7705540c1b9596bfe7c68ccc1c88072e630 100644 (file)
@@ -10,7 +10,7 @@ IN: parser
 
 : location ( -- loc )
     file get lexer get line>> 2dup and
-    [ >r path>> r> 2array ] [ 2drop f ] if ;
+    [ [ path>> ] dip 2array ] [ 2drop f ] if ;
 
 : save-location ( definition -- )
     location remember-definition ;
@@ -140,7 +140,7 @@ ERROR: staging-violation word ;
     } cond ;
 
 : (parse-until) ( accum end -- accum )
-    dup >r parse-step [ r> (parse-until) ] [ r> drop ] if ;
+    [ parse-step ] keep swap [ (parse-until) ] [ drop ] if ;
 
 : parse-until ( end -- vec )
     100 <vector> swap (parse-until) ;
@@ -156,7 +156,7 @@ ERROR: staging-violation word ;
     lexer-factory get call (parse-lines) ;
 
 : parse-literal ( accum end quot -- accum )
-    >r parse-until r> call parsed ; inline
+    [ parse-until ] dip call parsed ; inline
 
 : parse-definition ( -- quot )
     \ ; parse-until >quotation ;
index 31e5e4753d2b86613b663316bda4cfd0855e7226..2df11d485874958d20f3acbd412844110f307abc 100644 (file)
@@ -49,7 +49,10 @@ M: wrapper literalize <wrapper> ;
 M: curry length quot>> length 1+ ;
 
 M: curry nth
-    over zero? [ nip obj>> literalize ] [ >r 1- r> quot>> nth ] if ;
+    over 0 =
+    [ nip obj>> literalize ]
+    [ [ 1- ] dip quot>> nth ]
+    if ;
 
 INSTANCE: curry immutable-sequence
 
index 9afc7c6168bf8ece294923f6c2d271b36bfe5e0b..832de612dd1276a323cbba53f3eeb379f5df9d8a 100644 (file)
@@ -16,7 +16,7 @@ GENERIC: like ( seq exemplar -- newseq ) flushable
 GENERIC: clone-like ( seq exemplar -- newseq ) flushable
 
 : new-like ( len exemplar quot -- seq )
-    over >r >r new-sequence r> call r> like ; inline
+    over [ [ new-sequence ] dip call ] dip like ; inline
 
 M: sequence like drop ;
 
@@ -111,14 +111,14 @@ INSTANCE: integer immutable-sequence
     [ first3-unsafe 3 ] [ nth-unsafe ] bi ; inline
 
 : exchange-unsafe ( m n seq -- )
-    [ tuck nth-unsafe >r nth-unsafe r> ] 3keep tuck
-    >r >r set-nth-unsafe r> r> set-nth-unsafe ; inline
+    [ tuck [ nth-unsafe ] 2bi@ ]
+    [ tuck [ set-nth-unsafe ] 2bi@ ] 3bi ; inline
 
 : (head) ( seq n -- from to seq ) 0 spin ; inline
 
 : (tail) ( seq n -- from to seq ) over length rot ; inline
 
-: from-end >r dup length r> - ; inline
+: from-end [ dup length ] dip - ; inline
 
 : (2sequence)
     tuck 1 swap set-nth-unsafe
@@ -188,7 +188,7 @@ TUPLE: slice
 { seq read-only } ;
 
 : collapse-slice ( m n slice -- m' n' seq )
-    [ from>> ] [ seq>> ] bi >r tuck + >r + r> r> ; inline
+    [ from>> ] [ seq>> ] bi [ tuck [ + ] 2bi@ ] dip ; inline
 
 ERROR: slice-error from to seq reason ;
 
@@ -253,12 +253,12 @@ INSTANCE: repetition immutable-sequence
 
 : prepare-subseq ( from to seq -- dst i src j n )
     #! The check-length call forces partial dispatch
-    [ >r swap - r> new-sequence dup 0 ] 3keep
+    [ [ swap - ] dip new-sequence dup 0 ] 3keep
     -rot drop roll length check-length ; inline
 
 : check-copy ( src n dst -- )
     over 0 < [ bounds-error ] when
-    >r swap length + r> lengthen ; inline
+    [ swap length + ] dip lengthen ; inline
 
 PRIVATE>
 
@@ -279,11 +279,11 @@ PRIVATE>
 
 : copy ( src i dst -- )
     #! The check-length call forces partial dispatch
-    pick length check-length >r 3dup check-copy spin 0 r>
+    pick length check-length [ 3dup check-copy spin 0 ] dip
     (copy) drop ; inline
 
 M: sequence clone-like
-    >r dup length r> new-sequence [ 0 swap copy ] keep ;
+    [ dup length ] dip new-sequence [ 0 swap copy ] keep ;
 
 M: immutable-sequence clone-like like ;
 
@@ -291,31 +291,31 @@ M: immutable-sequence clone-like like ;
 
 <PRIVATE
 
-: ((append)) ( seq1 seq2 accum -- accum )
-    [ >r over length r> copy ]
-    [ 0 swap copy ] 
+: (append) ( seq1 seq2 accum -- accum )
+    [ [ over length ] dip copy ]
+    [ 0 swap copy ]
     [ ] tri ; inline
 
-: (append) ( seq1 seq2 exemplar -- newseq )
-    >r over length over length + r>
-    [ ((append)) ] new-like ; inline
+PRIVATE>
 
-: (3append) ( seq1 seq2 seq3 exemplar -- newseq )
-    >r pick length pick length pick length + + r> [
-        [ >r pick length pick length + r> copy ]
-        [ ((append)) ] bi
-    ] new-like ; inline
+: append-as ( seq1 seq2 exemplar -- newseq )
+    [ over length over length + ] dip
+    [ (append) ] new-like ; inline
 
-PRIVATE>
+: 3append-as ( seq1 seq2 seq3 exemplar -- newseq )
+    [ pick length pick length pick length + + ] dip [
+        [ [ pick length pick length + ] dip copy ]
+        [ (append) ] bi
+    ] new-like ; inline
 
-: append ( seq1 seq2 -- newseq ) over (append) ;
+: append ( seq1 seq2 -- newseq ) over append-as ;
 
 : prepend ( seq1 seq2 -- newseq ) swap append ; inline
 
-: 3append ( seq1 seq2 seq3 -- newseq ) pick (3append) ;
+: 3append ( seq1 seq2 seq3 -- newseq ) pick 3append-as ;
 
 : change-nth ( i seq quot -- )
-    [ >r nth r> call ] 3keep drop set-nth ; inline
+    [ [ nth ] dip call ] 3keep drop set-nth ; inline
 
 : min-length ( seq1 seq2 -- n ) [ length ] bi@ min ; inline
 
@@ -324,32 +324,32 @@ PRIVATE>
 <PRIVATE
 
 : (each) ( seq quot -- n quot' )
-    >r dup length swap [ nth-unsafe ] curry r> compose ; inline
+    [ dup length swap [ nth-unsafe ] curry ] dip compose ; inline
 
 : (collect) ( quot into -- quot' )
-    [ >r keep r> set-nth-unsafe ] 2curry ; inline
+    [ [ keep ] dip set-nth-unsafe ] 2curry ; inline
 
 : collect ( n quot into -- )
     (collect) each-integer ; inline
 
 : map-into ( seq quot into -- )
-    >r (each) r> collect ; inline
+    [ (each) ] dip collect ; inline
 
 : 2nth-unsafe ( n seq1 seq2 -- elt1 elt2 )
-    >r over r> nth-unsafe >r nth-unsafe r> ; inline
+    [ over ] dip nth-unsafe [ nth-unsafe ] dip ; inline
 
 : (2each) ( seq1 seq2 quot -- n quot' )
-    >r [ min-length ] 2keep r>
-    [ >r 2nth-unsafe r> call ] 3curry ; inline
+    [ [ min-length ] 2keep ] dip
+    [ [ 2nth-unsafe ] dip call ] 3curry ; inline
 
 : 2map-into ( seq1 seq2 quot into -- newseq )
-    >r (2each) r> collect ; inline
+    [ (2each) ] dip collect ; inline
 
 : finish-find ( i seq -- i elt )
     over [ dupd nth-unsafe ] [ drop f ] if ; inline
 
 : (find) ( seq quot quot' -- i elt )
-    pick >r >r (each) r> call r> finish-find ; inline
+    pick [ [ (each) ] dip call ] dip finish-find ; inline
 
 : (find-from) ( n seq quot quot' -- i elt )
     [ 2dup bounds-check? ] 2dip
@@ -373,7 +373,7 @@ PRIVATE>
     swapd each ; inline
 
 : map-as ( seq quot exemplar -- newseq )
-    >r over length r> [ [ map-into ] keep ] new-like ; inline
+    [ over length ] dip [ [ map-into ] keep ] new-like ; inline
 
 : map ( seq quot -- newseq )
     over map-as ; inline
@@ -382,7 +382,7 @@ PRIVATE>
     [ drop ] prepose map ; inline
 
 : replicate-as ( seq quot exemplar -- newseq )
-    >r [ drop ] prepose r> map-as ; inline
+    [ [ drop ] prepose ] dip map-as ; inline
 
 : change-each ( seq quot -- )
     over map-into ; inline
@@ -394,13 +394,13 @@ PRIVATE>
     (2each) each-integer ; inline
 
 : 2reverse-each ( seq1 seq2 quot -- )
-    >r [ <reversed> ] bi@ r> 2each ; inline
+    [ [ <reversed> ] bi@ ] dip 2each ; inline
 
 : 2reduce ( seq1 seq2 identity quot -- result )
-    >r -rot r> 2each ; inline
+    [ -rot ] dip 2each ; inline
 
 : 2map-as ( seq1 seq2 quot exemplar -- newseq )
-    >r 2over min-length r>
+    [ 2over min-length ] dip
     [ [ 2map-into ] keep ] new-like ; inline
 
 : 2map ( seq1 seq2 quot -- newseq )
@@ -422,49 +422,49 @@ PRIVATE>
     [ nip find-last-integer ] (find-from) ; inline
 
 : find-last ( seq quot -- i elt )
-    [ >r 1- r> find-last-integer ] (find) ; inline
+    [ [ 1- ] dip find-last-integer ] (find) ; inline
 
 : all? ( seq quot -- ? )
     (each) all-integers? ; inline
 
 : push-if ( elt quot accum -- )
-    >r keep r> rot [ push ] [ 2drop ] if  ; inline
+    [ keep ] dip rot [ push ] [ 2drop ] if ; inline
 
 : pusher ( quot -- quot accum )
     V{ } clone [ [ push-if ] 2curry ] keep ; inline
 
 : filter ( seq quot -- subseq )
-    over >r pusher >r each r> r> like ; inline
+    over [ pusher [ each ] dip ] dip like ; inline
 
 : push-either ( elt quot accum1 accum2 -- )
-    >r >r keep swap r> r> ? push ; inline
+    [ keep swap ] 2dip ? push ; inline
 
 : 2pusher ( quot -- quot accum1 accum2 )
     V{ } clone V{ } clone [ [ push-either ] 3curry ] 2keep ; inline
 
 : partition ( seq quot -- trueseq falseseq )
-    over >r 2pusher >r >r each r> r> r> tuck [ like ] 2bi@ ; inline
+    over [ 2pusher [ each ] 2dip ] dip tuck [ like ] 2bi@ ; inline
 
 : monotonic? ( seq quot -- ? )
-    >r dup length 1- swap r> (monotonic) all? ; inline
+    [ dup length 1- swap ] dip (monotonic) all? ; inline
 
 : interleave ( seq between quot -- )
-    [ (interleave) ] 2curry >r dup length swap r> 2each ; inline
+    [ (interleave) ] 2curry [ dup length swap ] dip 2each ; inline
 
 : accumulator ( quot -- quot' vec )
     V{ } clone [ [ push ] curry compose ] keep ; inline
 
 : produce-as ( pred quot tail exemplar -- seq )
-    >r swap accumulator >r swap while r> r> like ; inline
+    [ swap accumulator [ swap while ] dip ] dip like ; inline
 
 : produce ( pred quot tail -- seq )
     { } produce-as ; inline
 
 : follow ( obj quot -- seq )
-    >r [ dup ] r> [ keep ] curry [ ] produce nip ; inline
+    [ dup ] swap [ keep ] curry [ ] produce nip ; inline
 
 : prepare-index ( seq quot -- seq n quot )
-    >r dup length r> ; inline
+    [ dup length ] dip ; inline
 
 : each-index ( seq quot -- )
     prepare-index 2each ; inline
@@ -518,9 +518,9 @@ PRIVATE>
 
 : cache-nth ( i seq quot -- elt )
     2over ?nth dup [
-        >r 3drop r>
+        [ 3drop ] dip
     ] [
-        drop swap >r over >r call dup r> r> set-nth
+        drop swap [ over [ call dup ] dip ] dip set-nth
     ] if ; inline
 
 : mismatch ( seq1 seq2 -- i )
@@ -575,14 +575,14 @@ PRIVATE>
     [ eq? not ] with filter-here ;
 
 : prefix ( seq elt -- newseq )
-    over >r over length 1+ r> [
+    over [ over length 1+ ] dip [
         [ 0 swap set-nth-unsafe ] keep
         [ 1 swap copy ] keep
     ] new-like ;
 
 : suffix ( seq elt -- newseq )
-    over >r over length 1+ r> [
-        [ >r over length r> set-nth-unsafe ] keep
+    over [ over length 1+ ] dip [
+        [ [ over length ] dip set-nth-unsafe ] keep
         [ 0 swap copy ] keep
     ] new-like ;
 
@@ -596,7 +596,7 @@ PRIVATE>
     2over = [
         2drop 2drop
     ] [
-        [ >r 2over + pick r> move >r 1+ r> ] keep
+        [ [ 2over + pick ] dip move [ 1+ ] dip ] keep
         move-backward
     ] if ;
 
@@ -604,15 +604,15 @@ PRIVATE>
     2over = [
         2drop 2drop
     ] [
-        [ >r pick >r dup dup r> + swap r> move 1- ] keep
+        [ [ pick [ dup dup ] dip + swap ] dip move 1- ] keep
         move-forward
     ] if ;
 
 : (open-slice) ( shift from to seq ? -- )
     [
-        >r [ 1- ] bi@ r> move-forward
+        [ [ 1- ] bi@ ] dip move-forward
     ] [
-        >r >r over - r> r> move-backward
+        [ over - ] 2dip move-backward
     ] if ;
 
 PRIVATE>
@@ -621,19 +621,19 @@ PRIVATE>
     pick 0 = [
         3drop
     ] [
-        pick over length + over >r >r
-        pick 0 > >r [ length ] keep r> (open-slice)
-        r> r> set-length
+        pick over length + over
+        [ pick 0 > [ [ length ] keep ] dip (open-slice) ] 2dip
+        set-length
     ] if ;
 
 : delete-slice ( from to seq -- )
-    check-slice >r over >r - r> r> open-slice ;
+    check-slice [ over [ - ] dip ] dip open-slice ;
 
 : delete-nth ( n seq -- )
-    >r dup 1+ r> delete-slice ;
+    [ dup 1+ ] dip delete-slice ;
 
 : replace-slice ( new from to seq -- )
-    [ >r >r dup pick length + r> - over r> open-slice ] keep
+    [ [ [ dup pick length + ] dip - over ] dip open-slice ] keep
     copy ;
 
 : remove-nth ( n seq -- seq' )
@@ -652,7 +652,7 @@ PRIVATE>
 
 : reverse-here ( seq -- )
     dup length dup 2/ [
-        >r 2dup r>
+        [ 2dup ] dip
         tuck - 1- rot exchange-unsafe
     ] each 2drop ;
 
@@ -679,7 +679,7 @@ PRIVATE>
 <PRIVATE
 
 : joined-length ( seq glue -- n )
-    >r dup sum-lengths swap length 1 [-] r> length * + ;
+    [ dup sum-lengths swap length 1 [-] ] dip length * + ;
 
 PRIVATE>
 
@@ -696,7 +696,7 @@ PRIVATE>
     ] dip compose if ; inline
 
 : pad-left ( seq n elt -- padded )
-    [ swap dup (append) ] padding ;
+    [ swap dup append-as ] padding ;
 
 : pad-right ( seq n elt -- padded )
     [ append ] padding ;
@@ -735,12 +735,12 @@ PRIVATE>
         >fixnum {
             [ drop nip ]
             [ 2drop first ]
-            [ >r drop first2 r> call ]
-            [ >r drop first3 r> bi@ ]
+            [ [ drop first2 ] dip call ]
+            [ [ drop first3 ] dip bi@ ]
         } dispatch
     ] [
         drop
-        >r >r halves r> r>
+        [ halves ] 2dip
         [ [ binary-reduce ] 2curry bi@ ] keep
         call
     ] if ; inline recursive
@@ -755,7 +755,7 @@ PRIVATE>
 
 : (start) ( subseq seq n -- subseq seq ? )
     pick length [
-        >r 3dup r> [ + swap nth-unsafe ] keep rot nth-unsafe =
+        [ 3dup ] dip [ + swap nth-unsafe ] keep rot nth-unsafe =
     ] all? nip ; inline
 
 PRIVATE>
@@ -763,7 +763,7 @@ PRIVATE>
 : start* ( subseq seq n -- i )
     pick length pick length swap - 1+
     [ (start) ] find-from
-    swap >r 3drop r> ;
+    swap [ 3drop ] dip ;
 
 : start ( subseq seq -- i ) 0 start* ; inline
 
@@ -771,7 +771,7 @@ PRIVATE>
 
 : drop-prefix ( seq1 seq2 -- slice1 slice2 )
     2dup mismatch [ 2dup min-length ] unless*
-    tuck tail-slice >r tail-slice r> ;
+    tuck [ tail-slice ] 2bi@ ;
 
 : unclip ( seq -- rest first )
     [ rest ] [ first ] bi ;
@@ -801,14 +801,14 @@ PRIVATE>
     inline
 
 : trim-left-slice ( seq quot -- slice )
-    over >r [ not ] compose find drop r> swap
+    over [ [ not ] compose find drop ] dip swap
     [ tail-slice ] [ dup length tail-slice ] if* ; inline
     
 : trim-left ( seq quot -- newseq )
     over [ trim-left-slice ] dip like ; inline
 
 : trim-right-slice ( seq quot -- slice )
-    over >r [ not ] compose find-last drop r> swap
+    over [ [ not ] compose find-last drop ] dip swap
     [ 1+ head-slice ] [ 0 head-slice ] if* ; inline
 
 : trim-right ( seq quot -- newseq )
index 72c79928cb34bb50888f859c5193b23da11045d9..35aa49d0534c6ede10b45bba61a6395d87b469d6 100644 (file)
@@ -3,7 +3,7 @@
 USING: arrays byte-arrays kernel kernel.private math namespaces
 make sequences strings words effects generic generic.standard
 classes classes.algebra slots.private combinators accessors
-words sequences.private assocs alien ;
+words sequences.private assocs alien quotations ;
 IN: slots
 
 TUPLE: slot-spec name offset class initial read-only ;
@@ -23,7 +23,7 @@ PREDICATE: writer < word "writer" word-prop ;
     3bi ;
 
 : create-accessor ( name effect -- word )
-    >r "accessors" create dup r>
+    [ "accessors" create dup ] dip
     "declared-effect" set-word-prop ;
 
 : reader-quot ( slot-spec -- quot )
@@ -59,7 +59,7 @@ ERROR: bad-slot-value value class ;
     offset>> , \ set-slot , ;
 
 : writer-quot/coerce ( slot-spec -- )
-    [ \ >r , class>> "coercer" word-prop % \ r> , ]
+    [ class>> "coercer" word-prop [ dip ] curry % ]
     [ offset>> , \ set-slot , ]
     bi ;
 
@@ -75,7 +75,7 @@ ERROR: bad-slot-value value class ;
     bi ;
 
 : writer-quot/fixnum ( slot-spec -- )
-    [ >r >fixnum r> ] % writer-quot/check ;
+    [ [ >fixnum ] dip ] % writer-quot/check ;
 
 : writer-quot ( slot-spec -- quot )
     [
@@ -108,9 +108,9 @@ ERROR: bad-slot-value value class ;
 : define-changer ( name -- )
     dup changer-word dup deferred? [
         [
-            [ over >r >r ] %
-            over reader-word ,
-            [ r> call r> swap ] %
+            \ over ,
+            over reader-word 1quotation
+            [ dip call ] curry [ dip swap ] curry %
             swap setter-word ,
         ] [ ] make define-inline
     ] [ 2drop ] if ;
index b57e6616247a2708854a07825a9c8900509d4f33..47399b61767940882bfa83bc17878c441811e669 100644 (file)
@@ -25,20 +25,20 @@ TUPLE: merge
 
 : dump ( from to seq accum -- )
     #! Optimize common case where to - from = 1, 2, or 3.
-    >r >r 2dup swap - r> r> pick 1 = 
-    [ >r >r 2drop r> nth-unsafe r> push ] [
+    [ 2dup swap - ] 2dip pick 1 = 
+    [ [ [ 2drop ] dip nth-unsafe ] dip push ] [
         pick 2 = [
-            >r >r 2drop dup 1+
-            r> [ nth-unsafe ] curry bi@
-            r> [ push ] curry bi@
+            [
+                [ 2drop dup 1+ ] dip
+                [ nth-unsafe ] curry bi@
+            ] dip [ push ] curry bi@
         ] [
             pick 3 = [
-                >r >r 2drop dup 1+ dup 1+
-                r> [ nth-unsafe ] curry tri@
-                r> [ push ] curry tri@
-            ] [
-                >r nip subseq r> push-all
-            ] if
+                [
+                    [ 2drop dup 1+ dup 1+ ] dip
+                    [ nth-unsafe ] curry tri@
+                ] dip [ push ] curry tri@
+            ] [ [ nip subseq ] dip push-all ] if
         ] if
     ] if ; inline
 
index 472b303059ef50380e37f954b30ac362ec9b35e0..354df832cab99bd2d1c3bb722c22a88c21c14c04 100644 (file)
@@ -8,6 +8,9 @@ ARTICLE: "sequences-split" "Splitting sequences"
 { $subsection ?tail }
 { $subsection ?tail-slice }
 { $subsection split1 }
+{ $subsection split1-slice }
+{ $subsection split1-last }
+{ $subsection split1-last-slice }
 { $subsection split }
 "Splitting a string into lines:"
 { $subsection string-lines } ;
@@ -18,11 +21,19 @@ HELP: split1
 { $values { "seq" "a sequence" } { "subseq" "a sequence" } { "before" "a new sequence" } { "after" "a new sequence" } }
 { $description "Splits " { $snippet "seq" } " at the first occurrence of " { $snippet "subseq" } ", and outputs the pieces before and after the split. If " { $snippet "subseq" } " does not occur in " { $snippet "seq" } ", then " { $snippet "before" } " is just " { $snippet "seq" } " and " { $snippet "after" } " is " { $link f } "." } ;
 
-HELP: last-split1
+HELP: split1-slice
+{ $values { "seq" "a sequence" } { "subseq" "a sequence" } { "before-slice" slice } { "after-slice" slice } }
+{ $description "Splits " { $snippet "seq" } " at the first occurrence of " { $snippet "subseq" } ", and outputs the pieces before and after the split as slices. If " { $snippet "subseq" } " does not occur in " { $snippet "seq" } ", then " { $snippet "before" } " is just " { $snippet "seq" } " and " { $snippet "after" } " is " { $link f } "." } ;
+
+HELP: split1-last
 { $values { "seq" "a sequence" } { "subseq" "a sequence" } { "before" "a new sequence" } { "after" "a new sequence" } }
 { $description "Splits " { $snippet "seq" } " at the last occurrence of " { $snippet "subseq" } ", and outputs the pieces before and after the split. If " { $snippet "subseq" } " does not occur in " { $snippet "seq" } ", then " { $snippet "before" } " is just " { $snippet "seq" } " and " { $snippet "after" } " is " { $link f } "." } ;
 
-{ split1 last-split1 } related-words
+HELP: split1-last-slice
+{ $values { "seq" "a sequence" } { "subseq" "a sequence" } { "before-slice" slice } { "after-slice" slice } }
+{ $description "Splits " { $snippet "seq" } " at the last occurrence of " { $snippet "subseq" } ", and outputs the pieces before and after the split as slices. If " { $snippet "subseq" } " does not occur in " { $snippet "seq" } ", then " { $snippet "before" } " is just " { $snippet "seq" } " and " { $snippet "after" } " is " { $link f } "." } ;
+
+{ split1 split1-slice split1-last split1-last-slice } related-words
 
 HELP: split
 { $values { "seq" "a sequence" } { "separators" "a sequence" } { "pieces" "a new array" } }
index 0f3dbdea1b0189e0bb48f4e60e811f4e15eccdb7..ed68038fa6ddc5579c48fc0c93cda31cec0772ac 100644 (file)
@@ -1,4 +1,4 @@
-USING: splitting tools.test kernel sequences arrays ;
+USING: splitting tools.test kernel sequences arrays strings ;
 IN: splitting.tests
 
 [ "hello" "world ." ] [ "hello world ." " " split1 ] unit-test
@@ -6,10 +6,15 @@ IN: splitting.tests
 [ "goodbye" f ] [ "goodbye" " " split1 ] unit-test
 [ "" "" ] [ "great" "great" split1 ] unit-test
 
-[ "hello world" "." ] [ "hello world ." " " last-split1 ] unit-test
-[ "hello-+world" "." ] [ "hello-+world-+." "-+" last-split1 ] unit-test
-[ "goodbye" f ] [ "goodbye" " " last-split1 ] unit-test
-[ "" "" ] [ "great" "great" last-split1 ] unit-test
+[ "hello world" "." ] [ "hello world ." " " split1-last ] unit-test
+[ "hello-+world" "." ] [ "hello-+world-+." "-+" split1-last ] unit-test
+[ "goodbye" f ] [ "goodbye" " " split1-last ] unit-test
+[ "" "" ] [ "great" "great" split1-last ] unit-test
+
+[ "hello world" "." ] [ "hello world ." " " split1-last-slice [ >string ] bi@ ] unit-test
+[ "hello-+world" "." ] [ "hello-+world-+." "-+" split1-last-slice [ >string ] bi@ ] unit-test
+[ "goodbye" f ] [ "goodbye" " " split1-last-slice [ >string ] dip ] unit-test
+[ "" f ] [ "great" "great" split1-last-slice [ >string ] dip ] unit-test
 
 [ "and end" t ] [ "Beginning and end" "Beginning " ?head ] unit-test
 [ "Beginning and end" f ] [ "Beginning and end" "Beginning x" ?head ] unit-test
index aac32784a1f8c49465c72f61b460b7fe31ea66cb..29fee2e5c3c063d0b3cb2d65ae9760fabd2244ef 100644 (file)
@@ -18,15 +18,26 @@ IN: splitting
 
 : split1 ( seq subseq -- before after )
     dup pick start dup [
-        [ >r over r> head -rot length ] keep + tail
+        [ [ over ] dip head -rot length ] keep + tail
     ] [
         2drop f
     ] if ;
 
-: last-split1 ( seq subseq -- before after )
+: split1-slice ( seq subseq -- before-slice after-slice )
+    dup pick start dup [
+        [ [ over ] dip head-slice -rot length ] keep + tail-slice
+    ] [
+        2drop f
+    ] if ;
+
+: split1-last ( seq subseq -- before after )
     [ <reversed> ] bi@ split1 [ reverse ] bi@
     dup [ swap ] when ;
 
+: split1-last-slice ( seq subseq -- before-slice after-slice )
+    [ <reversed> ] bi@ split1-slice [ <reversed> ] bi@
+    [ f ] [ swap ] if-empty ;
+
 : (split) ( separators n seq -- )
     3dup rot [ member? ] curry find-from drop
     [ [ swap subseq , ] 2keep 1+ swap (split) ]
index 2695860a59b53c7c5cbba4c6350df41667297dfc..cfe5d1a90ac9acf822c3fca4fc8ab3bfa3805915 100644 (file)
@@ -29,10 +29,10 @@ name>char-hook global [
 : unicode-escape ( str -- ch str' )
     "{" ?head-slice [
         CHAR: } over index cut-slice
-        >r >string name>char-hook get call r>
+        [ >string name>char-hook get call ] dip
         rest-slice
     ] [
-        6 cut-slice >r hex> r>
+        6 cut-slice [ hex> ] dip
     ] if ;
 
 : next-escape ( str -- ch str' )
@@ -44,11 +44,11 @@ name>char-hook global [
 
 : (parse-string) ( str -- m )
     dup [ "\"\\" member? ] find dup [
-        >r cut-slice >r % r> rest-slice r>
+        [ cut-slice [ % ] dip rest-slice ] dip
         dup CHAR: " = [
             drop from>>
         ] [
-            drop next-escape >r , r> (parse-string)
+            drop next-escape [ , ] dip (parse-string)
         ] if
     ] [
         "Unterminated string" throw
index 944286cce567d72bbd5f01b30c015e76a22cc297..39628ede98cdfd64edb60f02d3447ac6523e908c 100644 (file)
@@ -34,11 +34,11 @@ M: string length
     length>> ;
 
 M: string nth-unsafe
-    >r >fixnum r> string-nth ;
+    [ >fixnum ] dip string-nth ;
 
 M: string set-nth-unsafe
     dup reset-string-hashcode
-    >r >fixnum >r >fixnum r> r> set-string-nth ;
+    [ [ >fixnum ] dip >fixnum ] dip set-string-nth ;
 
 M: string clone
     (clone) [ clone ] change-aux ;
index 105bdc325f123a6673f849956acafc418eef2d78..7d3553faeed48cb26849676d76f80e1b3eb890fa 100644 (file)
@@ -23,7 +23,7 @@ IN: bootstrap.syntax
     "syntax" lookup t "delimiter" set-word-prop ;
 
 : define-syntax ( name quot -- )
-    >r "syntax" lookup dup r> define t "parsing" set-word-prop ;
+    [ "syntax" lookup dup ] dip define t "parsing" set-word-prop ;
 
 [
     { "]" "}" ";" ">>" } [ define-delimiter ] each
@@ -62,7 +62,7 @@ IN: bootstrap.syntax
     "CHAR:" [
         scan {
             { [ dup length 1 = ] [ first ] }
-            { [ "\\" ?head ] [ next-escape drop ] }
+            { [ "\\" ?head ] [ next-escape >string "" assert= ] }
             [ name>char-hook get call ]
         } cond parsed
     ] define-syntax
@@ -145,9 +145,10 @@ IN: bootstrap.syntax
     ] define-syntax
 
     "INSTANCE:" [
-        location >r
-        scan-word scan-word 2dup add-mixin-instance
-        <mixin-instance> r> remember-definition
+        location [
+            scan-word scan-word 2dup add-mixin-instance
+            <mixin-instance>
+        ] dip remember-definition
     ] define-syntax
 
     "PREDICATE:" [
@@ -202,13 +203,12 @@ IN: bootstrap.syntax
     ] define-syntax
 
     "call-next-method" [
-        current-class get current-generic get
-        2dup [ word? ] both? [
-            [ literalize parsed ] bi@
+        current-method get [
+            literalize parsed
             \ (call-next-method) parsed
         ] [
             not-in-a-method-error
-        ] if
+        ] if*
     ] define-syntax
     
     "initial:" "syntax" lookup define-symbol
index acd42b094f9a61c713391c7518cd9fa5ab92ed08..3adf82af7feca35846f78d532720f8013b29d3ba 100644 (file)
@@ -11,7 +11,7 @@ ARTICLE: "system" "System interface"
 { $subsection vm }
 { $subsection image }
 "Getting the current time:"
-{ $subsection millis }
+{ $subsection micros }
 "Exiting the Factor VM:"
 { $subsection exit } ;
 
@@ -64,8 +64,13 @@ HELP: exit ( n -- )
 { $values { "n" "an integer exit code" } }
 { $description "Exits the Factor process." } ;
 
-HELP: millis ( -- n )
-{ $values { "n" integer } }
+HELP: micros ( -- us )
+{ $values { "us" integer } }
+{ $description "Outputs the number of microseconds ellapsed since midnight January 1, 1970." }
+{ $notes "This is a low-level word. The " { $vocab-link "calendar" } " vocabulary provides features for date/time arithmetic and formatting." } ;
+
+HELP: millis ( -- ms )
+{ $values { "us" integer } }
 { $description "Outputs the number of milliseconds ellapsed since midnight January 1, 1970." }
 { $notes "This is a low-level word. The " { $vocab-link "calendar" } " vocabulary provides features for date/time arithmetic and formatting." } ;
 
index 66662a23e1de2d4e911de3fedaa72128cf61703f..2d8ed1b657fb085a9f92d362b6ba627cf55c5fac 100644 (file)
@@ -65,3 +65,5 @@ PRIVATE>
 ] "system" add-init-hook
 
 : embedded? ( -- ? ) 15 getenv ;
+
+: millis ( -- ms ) micros 1000 /i ;
index 4f9bba348320409eacafa36cb228aae3a9cecf74..f2e29d79e84de3c3ddc3c27a8de5fe937ab59cb2 100644 (file)
@@ -71,7 +71,7 @@ IN: vectors.tests
 
 [ t ] [
     V{ 1 2 3 4 } dup underlying>> length
-    >r clone underlying>> length r>
+    [ clone underlying>> length ] dip
     =
 ] unit-test
 
@@ -91,7 +91,7 @@ IN: vectors.tests
 [ 4 ] [ 5 V{ 1 2 3 4 5 } index ] unit-test
 
 [ t ] [
-    100 >array dup >vector <reversed> >array >r reverse r> =
+    100 >array dup >vector <reversed> >array [ reverse ] dip =
 ] unit-test
 
 [ fixnum ] [ 1 >bignum V{ } new-sequence length class ] unit-test
index 1325110122d31fb4fb0837bc2e4ca6d84558ba00..89b8a0728de60454a6977ca58f3be345db700186 100644 (file)
@@ -1,4 +1,5 @@
-USING: vocabs help.markup help.syntax words strings io ;
+USING: vocabs vocabs.loader.private help.markup help.syntax
+words strings io ;
 IN: vocabs.loader
 
 ARTICLE: "vocabs.roots" "Vocabulary roots"
index 3f06b9735ce020f5e18bd0b8aa4511fe3ffa6282..7b53e98df18526b8ff56dcbfb12f1e5b54f52766 100644 (file)
@@ -51,7 +51,7 @@ IN: vocabs.loader.tests
 2 [
     [ "vocabs.loader.test.a" require ] must-fail
     
-    [ f ] [ "vocabs.loader.test.a" vocab-source-loaded? ] unit-test
+    [ f ] [ "vocabs.loader.test.a" vocab source-loaded?>> ] unit-test
     
     [ t ] [
         "resource:core/vocabs/loader/test/a/a.factor"
@@ -129,9 +129,9 @@ IN: vocabs.loader.tests
     ] with-compilation-unit
 ] unit-test
 
-[ t ] [
+[ +done+ ] [
     [ "vocabs.loader.test.d" require ] [ :1 ] recover
-    "vocabs.loader.test.d" vocab-source-loaded?
+    "vocabs.loader.test.d" vocab source-loaded?>>
 ] unit-test
 
 : forget-junk
@@ -156,3 +156,21 @@ forget-junk
 
 [ "vocabs.loader.test.e" require ]
 [ relative-overflow? ] must-fail-with
+
+0 "vocabs.loader.test.g" set-global
+
+[
+    "vocabs.loader.test.f" forget-vocab
+    "vocabs.loader.test.g" forget-vocab
+] with-compilation-unit
+
+[ ] [ "vocabs.loader.test.g" require ] unit-test
+
+[ 1 ] [ "vocabs.loader.test.g" get-global ] unit-test
+
+[
+    "vocabs.loader.test.h" forget-vocab
+    "vocabs.loader.test.i" forget-vocab
+] with-compilation-unit
+
+[ ] [ "vocabs.loader.test.h" require ] unit-test
index 690b8b0d920a7c5ed0f48fed8a2bfa440e70a57f..49fad2626fb6f212b540fbbf55412ccff33a22b4 100644 (file)
@@ -19,24 +19,27 @@ V{
     vocab-name { { CHAR: . CHAR: / } } substitute ;
 
 : vocab-dir+ ( vocab str/f -- path )
-    >r vocab-name "." split r>
-    [ >r dup peek r> append suffix ] when*
+    [ vocab-name "." split ] dip
+    [ [ dup peek ] dip append suffix ] when*
     "/" join ;
 
 : vocab-dir? ( root name -- ? )
-    over [
-        ".factor" vocab-dir+ append-path exists?
-    ] [
-        2drop f
-    ] if ;
+    over
+    [ ".factor" vocab-dir+ append-path exists? ]
+    [ 2drop f ]
+    if ;
 
 SYMBOL: root-cache
 
 H{ } clone root-cache set-global
 
+<PRIVATE
+
 : (find-vocab-root) ( name -- path/f )
     vocab-roots get swap [ vocab-dir? ] curry find nip ;
 
+PRIVATE>
+
 : find-vocab-root ( vocab -- path/f )
     vocab-name dup root-cache get at [ ] [ (find-vocab-root) ] ?if ;
 
@@ -51,26 +54,37 @@ H{ } clone root-cache set-global
 
 SYMBOL: load-help?
 
-: load-source ( vocab -- vocab )
-    f over set-vocab-source-loaded?
-    [ vocab-source-path [ parse-file ] [ [ ] ] if* ] keep
-    t swap set-vocab-source-loaded?
-    [ % ] [ assert-depth ] if-bootstrapping ;
+ERROR: circular-dependency name ;
 
-: load-docs ( vocab -- vocab )
-    load-help? get [
-        f over set-vocab-docs-loaded?
-        [ vocab-docs-path [ ?run-file ] when* ] keep
-        t swap set-vocab-docs-loaded?
-    ] [ drop ] if ;
+<PRIVATE
 
-: reload ( name -- )
+: load-source ( vocab -- )
     [
-        dup vocab [ [ load-source ] [ load-docs ] bi ] [ no-vocab ] ?if
-    ] with-compiler-errors ;
+        +parsing+ >>source-loaded?
+        dup vocab-source-path [ parse-file ] [ [ ] ] if*
+        [ % ] [ assert-depth ] if-bootstrapping
+        +done+ >>source-loaded? drop
+    ] [ ] [ f >>source-loaded? ] cleanup ;
+
+: load-docs ( vocab -- )
+    load-help? get [
+        [
+            +parsing+ >>docs-loaded?
+            [ vocab-docs-path [ ?run-file ] when* ] keep
+            +done+ >>docs-loaded?
+        ] [ ] [ f >>docs-loaded? ] cleanup
+    ] when drop ;
+
+PRIVATE>
 
 : require ( vocab -- )
-    load-vocab drop ;
+    [ load-vocab drop ] with-compiler-errors ;
+
+: reload ( name -- )
+    dup vocab
+    [ [ [ load-source ] [ load-docs ] bi ] with-compiler-errors ]
+    [ require ]
+    ?if ;
 
 : run ( vocab -- )
     dup load-vocab vocab-main [
@@ -83,6 +97,8 @@ SYMBOL: load-help?
 
 SYMBOL: blacklist
 
+<PRIVATE
+
 : add-to-blacklist ( error vocab -- )
     vocab-name blacklist get dup [ set-at ] [ 3drop ] if ;
 
@@ -90,9 +106,10 @@ GENERIC: (load-vocab) ( name -- )
 
 M: vocab (load-vocab)
     [
-        dup vocab-source-loaded? [ dup load-source ] unless
-        dup vocab-docs-loaded? [ dup load-docs ] unless
-        drop
+        dup source-loaded?>> +parsing+ eq? [
+            dup source-loaded?>> [ dup load-source ] unless
+            dup docs-loaded?>> [ dup load-docs ] unless
+        ] unless drop
     ] [ [ swap add-to-blacklist ] keep rethrow ] recover ;
 
 M: vocab-link (load-vocab)
@@ -103,19 +120,17 @@ M: string (load-vocab)
 
 [
     [
-        dup vocab-name blacklist get at* [
-            rethrow
-        ] [
-            drop
-            dup find-vocab-root [
-                [ (load-vocab) ] with-compiler-errors
-            ] [
-                dup vocab [ drop ] [ no-vocab ] if
-            ] if
+        dup vocab-name blacklist get at* [ rethrow ] [
+            drop dup find-vocab-root
+            [ [ (load-vocab) ] with-compiler-errors ]
+            [ dup vocab [ drop ] [ no-vocab ] if ]
+            if
         ] if
     ] with-compiler-errors
 ] load-vocab-hook set-global
 
+PRIVATE>
+
 : vocab-where ( vocab -- loc )
     vocab-source-path dup [ 1 2array ] when ;
 
diff --git a/core/vocabs/loader/test/f/f.factor b/core/vocabs/loader/test/f/f.factor
new file mode 100644 (file)
index 0000000..39d4534
--- /dev/null
@@ -0,0 +1,4 @@
+IN: vocabs.laoder.test.f
+USE: vocabs.loader
+
+"vocabs.loader.test.g" require
diff --git a/core/vocabs/loader/test/f/tags.txt b/core/vocabs/loader/test/f/tags.txt
new file mode 100644 (file)
index 0000000..6bf6830
--- /dev/null
@@ -0,0 +1 @@
+unportable
diff --git a/core/vocabs/loader/test/g/g.factor b/core/vocabs/loader/test/g/g.factor
new file mode 100644 (file)
index 0000000..8f124b1
--- /dev/null
@@ -0,0 +1,4 @@
+IN: vocabs.loader.test.g
+USING: vocabs.loader.test.f namespaces ;
+
+global [ "vocabs.loader.test.g" inc ] bind
diff --git a/core/vocabs/loader/test/g/tags.txt b/core/vocabs/loader/test/g/tags.txt
new file mode 100644 (file)
index 0000000..6bf6830
--- /dev/null
@@ -0,0 +1 @@
+unportable
diff --git a/core/vocabs/loader/test/h/h.factor b/core/vocabs/loader/test/h/h.factor
new file mode 100644 (file)
index 0000000..5100621
--- /dev/null
@@ -0,0 +1 @@
+USE: vocabs.loader.test.i
diff --git a/core/vocabs/loader/test/h/tags.txt b/core/vocabs/loader/test/h/tags.txt
new file mode 100644 (file)
index 0000000..6bf6830
--- /dev/null
@@ -0,0 +1 @@
+unportable
diff --git a/core/vocabs/loader/test/i/i.factor b/core/vocabs/loader/test/i/i.factor
new file mode 100644 (file)
index 0000000..932288d
--- /dev/null
@@ -0,0 +1,2 @@
+IN: vocabs.loader.test.i
+USE: vocabs.loader.test.h
diff --git a/core/vocabs/loader/test/i/tags.txt b/core/vocabs/loader/test/i/tags.txt
new file mode 100644 (file)
index 0000000..6bf6830
--- /dev/null
@@ -0,0 +1 @@
+unportable
index 64a5a589dc6b0f23bb33086e85293cb5842cd782..2929b5008180fd1d1f1386b7394eea41911566b9 100644 (file)
@@ -53,14 +53,6 @@ HELP: vocab-words
 { $values { "vocab-spec" "a vocabulary specifier" } { "words" "an assoc mapping strings to words" } }
 { $description "Outputs the words defined in a vocabulary." } ;
 
-HELP: vocab-source-loaded?
-{ $values { "vocab-spec" "a vocabulary specifier" } { "?" "a boolean" } }
-{ $description "Outputs if the source for this vocubulary has been loaded." } ;
-
-HELP: vocab-docs-loaded?
-{ $values { "vocab-spec" "a vocabulary specifier" } { "?" "a boolean" } }
-{ $description "Outputs if the documentation for this vocubulary has been loaded." } ;
-
 HELP: words
 { $values { "vocab" string } { "seq" "a sequence of words" } }
 { $description "Outputs a sequence of words defined in the vocabulary, or " { $link f } " if no vocabulary with this name exists." } ;
index 1bdbe3ce1401b63dca1d61c2fa865942291c3ea4..13f79b04ecccbb5dac560b7b29a8a8057e58d146 100644 (file)
@@ -11,6 +11,11 @@ name words
 main help
 source-loaded? docs-loaded? ;
 
+! sources-loaded? slot is one of these two
+SYMBOL: +parsing+
+SYMBOL: +running+
+SYMBOL: +done+
+
 : <vocab> ( name -- vocab )
     \ vocab new
         swap >>name
@@ -52,42 +57,6 @@ M: object vocab-main vocab vocab-main ;
 
 M: f vocab-main ;
 
-GENERIC: vocab-source-loaded? ( vocab-spec -- ? )
-
-M: vocab vocab-source-loaded? source-loaded?>> ;
-
-M: object vocab-source-loaded?
-    vocab vocab-source-loaded? ;
-
-M: f vocab-source-loaded? ;
-
-GENERIC: set-vocab-source-loaded? ( ? vocab-spec -- )
-
-M: vocab set-vocab-source-loaded? (>>source-loaded?) ;
-
-M: object set-vocab-source-loaded?
-    vocab set-vocab-source-loaded? ;
-
-M: f set-vocab-source-loaded? 2drop ;
-
-GENERIC: vocab-docs-loaded? ( vocab-spec -- ? )
-
-M: vocab vocab-docs-loaded? docs-loaded?>> ;
-
-M: object vocab-docs-loaded?
-    vocab vocab-docs-loaded? ;
-
-M: f vocab-docs-loaded? ;
-
-GENERIC: set-vocab-docs-loaded? ( ? vocab-spec -- )
-
-M: vocab set-vocab-docs-loaded? (>>docs-loaded?) ;
-
-M: object set-vocab-docs-loaded?
-    vocab set-vocab-docs-loaded? ;
-
-M: f set-vocab-docs-loaded? 2drop ;
-
 : create-vocab ( name -- vocab )
     dictionary get [ <vocab> ] cache ;
 
index 66c60dc06e5c322b1a94820e428903749f7817f3..929161c5d6e87f4fdd7d1d357fe0248ea421af58 100644 (file)
@@ -87,11 +87,11 @@ M: word (quot-uses) over crossref? [ conjoin ] [ 2drop ] if ;
 
 M: array (quot-uses) seq-uses ;
 
-M: hashtable (quot-uses) >r >alist r> seq-uses ;
+M: hashtable (quot-uses) [ >alist ] dip seq-uses ;
 
 M: callable (quot-uses) seq-uses ;
 
-M: wrapper (quot-uses) >r wrapped>> r> (quot-uses) ;
+M: wrapper (quot-uses) [ wrapped>> ] dip (quot-uses) ;
 
 : quot-uses ( quot -- assoc )
     global [ H{ } clone [ (quot-uses) ] keep ] bind ;
@@ -113,7 +113,7 @@ compiled-generic-crossref global [ H{ } assoc-like ] change-at
     bi* 2bi ;
 
 : compiled-xref ( word dependencies generic-dependencies -- )
-    [ [ drop crossref? ] assoc-filter ] bi@
+    [ [ drop crossref? ] { } assoc-filter-as f like ] bi@
     [ over ] dip
     [ "compiled-uses" compiled-crossref (compiled-xref) ]
     [ "compiled-generic-uses" compiled-generic-crossref (compiled-xref) ]
@@ -121,7 +121,7 @@ compiled-generic-crossref global [ H{ } assoc-like ] change-at
 
 : (compiled-unxref) ( word word-prop variable -- )
     [ [ [ dupd word-prop ] dip get remove-vertex* ] 2curry ]
-    [ drop [ f swap set-word-prop ] curry ]
+    [ drop [ remove-word-prop ] curry ]
     2bi bi ;
 
 : compiled-unxref ( word -- )
@@ -239,7 +239,7 @@ ERROR: bad-create name vocab ;
     dup [ 2nip ] [ drop <word> dup reveal ] if ;
 
 : constructor-word ( name vocab -- word )
-    >r "<" swap ">" 3append r> create ;
+    [ "<" swap ">" 3append ] dip create ;
 
 PREDICATE: parsing-word < word "parsing" word-prop ;
 
index b9f9882e88d935b4cd00480c0b64a3777b6cc06c..d82500edba98454d804886c1f83873ab4015faa7 100644 (file)
@@ -44,7 +44,7 @@ DEFER: shallow-fry
 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 
 : deep-fry ( quot -- quot )
-  { _ } last-split1 dup
+  { _ } split1-last dup
     [
       shallow-fry [ >r ] rot
       deep-fry    [ [ dip ] curry r> compose ] 4array concat
@@ -77,4 +77,4 @@ DEFER: shallow-fry
 
 MACRO: fry ( seq -- quot ) [fry] ;
 
-: '[ \ ] [ >quotation ] parse-literal \ fry parsed ; parsing
\ No newline at end of file
+: '[ \ ] [ >quotation ] parse-literal \ fry parsed ; parsing
index a17d65d90bfcde020aee0383b0a790ef69d6e46f..8fdb807c6a7a87df104c10f9c939811e55fa9da4 100644 (file)
@@ -1,6 +1,6 @@
-USING: kernel math threads system ;
+USING: kernel math threads system calendar ;
 IN: crypto.timing
 
 : with-timing ( quot n -- )
     #! force the quotation to execute in, at minimum, n milliseconds
-    millis 2slip millis - + sleep ; inline
+    millis 2slip millis - + milliseconds sleep ; inline
index 2357742fdeb75d0c27253039e2a10490400739e6..d0b74417d188c3b9b50f40cb1c8b7236c02edaef 100755 (executable)
@@ -23,7 +23,7 @@ M: jamshred-gadget draw-gadget* ( gadget -- )
     ] [
         [ jamshred>> jamshred-update ]
         [ relayout-1 ]
-        [ 10 sleep yield jamshred-loop ] tri
+        [ 10 milliseconds sleep yield jamshred-loop ] tri
     ] if ;
 
 : fullscreen ( gadget -- )
index 0206df7db913141ee75c91179a714497382637c5..3de1fa643f46f8d675a81bd368297263a0ab80e9 100644 (file)
@@ -40,14 +40,17 @@ M: method-body word-vocabulary "method-generic" word-prop word-vocabulary ;
 : do-benchmarks ( -- )
     run-benchmarks benchmarks-file to-file ;
 
+: benchmark-ms ( quot -- ms )
+    benchmark 1000 /i ; inline
+
 : do-all ( -- )
     ".." [
         bootstrap-time get boot-time-file to-file
-        [ do-load do-compile-errors ] benchmark load-time-file to-file
-        [ generate-help ] benchmark html-help-time-file to-file
-        [ do-tests ] benchmark test-time-file to-file
-        [ do-help-lint ] benchmark help-lint-time-file to-file
-        [ do-benchmarks ] benchmark benchmark-time-file to-file
+        [ do-load do-compile-errors ] benchmark-ms load-time-file to-file
+        [ generate-help ]  html-help-time-file to-file
+        [ do-tests ] benchmark-ms test-time-file to-file
+        [ do-help-lint ] benchmark-ms help-lint-time-file to-file
+        [ do-benchmarks ] benchmark-ms benchmark-time-file to-file
     ] with-directory ;
 
 MAIN: do-all
\ No newline at end of file
diff --git a/extra/micros/authors.txt b/extra/micros/authors.txt
deleted file mode 100644 (file)
index 0be42b2..0000000
+++ /dev/null
@@ -1 +0,0 @@
-Phil Dawes
diff --git a/extra/micros/backend/backend.factor b/extra/micros/backend/backend.factor
deleted file mode 100644 (file)
index 905b6aa..0000000
+++ /dev/null
@@ -1,4 +0,0 @@
-IN: micros.backend
-USING: io.backend ;
-    
-HOOK: (micros) io-backend ( -- n )
diff --git a/extra/micros/micros-docs.factor b/extra/micros/micros-docs.factor
deleted file mode 100644 (file)
index 98dcb99..0000000
+++ /dev/null
@@ -1,14 +0,0 @@
-IN: micros
-USING: help.syntax help.markup kernel prettyprint sequences ;
-
-HELP: micros
-{ $values { "n" "an integer" } } 
-{ $description "Outputs the number of microseconds ellapsed since midnight January 1, 1970"
-} ;
-
-    
-HELP: micro-time
-{ $values { "quot" "a quot" }
-          { "n" "an integer" } }
-{ $description "executes the quotation and pushes the number of microseconds taken onto the stack"
-} ;
diff --git a/extra/micros/micros-tests.factor b/extra/micros/micros-tests.factor
deleted file mode 100644 (file)
index 991ce04..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-IN: micros.tests
-USING: micros tools.test math math.functions system kernel ;
-
-! a bit racy but I can't think of a better way to check this right now
-[ t ]
-[ millis 1000 / micros 1000000 / [ truncate ] bi@ = ] unit-test
-
diff --git a/extra/micros/micros.factor b/extra/micros/micros.factor
deleted file mode 100644 (file)
index 554c838..0000000
+++ /dev/null
@@ -1,13 +0,0 @@
-IN: micros
-USING: micros.backend system kernel combinators vocabs.loader math ;
-
-: micros ( -- n ) (micros) ; inline
-
-: micro-time ( quot -- n )
-  micros slip micros swap - ; inline
-
-{
-    { [ os unix? ] [ "micros.unix" ] }
-    { [ os windows? ] [ "micros.windows" ] }
-} cond require
-
diff --git a/extra/micros/summary.txt b/extra/micros/summary.txt
deleted file mode 100644 (file)
index c1bc9d6..0000000
+++ /dev/null
@@ -1 +0,0 @@
-Microsecond precision clock
diff --git a/extra/micros/unix/tags.txt b/extra/micros/unix/tags.txt
deleted file mode 100644 (file)
index 6bf6830..0000000
+++ /dev/null
@@ -1 +0,0 @@
-unportable
diff --git a/extra/micros/unix/unix.factor b/extra/micros/unix/unix.factor
deleted file mode 100644 (file)
index c16d362..0000000
+++ /dev/null
@@ -1,6 +0,0 @@
-IN: micros.unix
-USING: micros.backend io.backend system alien.c-types kernel unix.time math ;
-
-M: unix (micros)
-  "timespec" <c-object> dup f gettimeofday drop
-  [ timespec-sec 1000000 * ] [ timespec-nsec ] bi + ;
diff --git a/extra/micros/windows/tags.txt b/extra/micros/windows/tags.txt
deleted file mode 100644 (file)
index 6bf6830..0000000
+++ /dev/null
@@ -1 +0,0 @@
-unportable
diff --git a/extra/micros/windows/windows.factor b/extra/micros/windows/windows.factor
deleted file mode 100644 (file)
index b2beab7..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-IN: micros.windows
-USING: system kernel windows.time math math.functions micros.backend ;
-
-! 116444736000000000 is the windowstime epoch offset
-! since windowstime starts at 1600 and unix epoch is 1970
-M: windows (micros)
-  windows-time 116444736000000000 - 10 / truncate ;
\ No newline at end of file
index 4c1545b4ae39d865da053667936dd0a04156d96b..10217c93cbfb4087c34118730e58bdebd1b6b0bb 100644 (file)
@@ -1,12 +1,13 @@
 USING: arrays kernel math opengl opengl.gl opengl.glu
-opengl.demo-support ui ui.gadgets ui.render threads accessors ;
+opengl.demo-support ui ui.gadgets ui.render threads accessors
+calendar ;
 IN: nehe.4
 
 TUPLE: nehe4-gadget < gadget rtri rquad thread quit? ;
 
 : width 256 ;
 : height 256 ;
-: redraw-interval 10 ;
+: redraw-interval 10 milliseconds ;
 
 : <nehe4-gadget> (  -- gadget )
   nehe4-gadget new-gadget
index 59170ff96458f93c78b35ca948e4d65b5835242f..2c9b51c63fa25bbdbde983b9f728909443710c96 100755 (executable)
@@ -1,11 +1,12 @@
 USING: arrays kernel math opengl opengl.gl opengl.glu\r
-opengl.demo-support ui ui.gadgets ui.render threads accessors ;\r
+opengl.demo-support ui ui.gadgets ui.render threads accessors\r
+calendar ;\r
 IN: nehe.5\r
 \r
 TUPLE: nehe5-gadget < gadget rtri rquad thread quit? ;\r
 : width 256 ;\r
 : height 256 ;\r
-: redraw-interval 10 ;\r
+: redraw-interval 10 milliseconds ;\r
 \r
 : <nehe5-gadget> (  -- gadget )\r
   nehe5-gadget new-gadget\r
index ebdb6da5ce85a19e2cf2cf9022640500b7a18df9..ae0b50afff82b7841fb0356eeaf6766ece70bdc2 100644 (file)
@@ -2,17 +2,17 @@
 ! See http://factorcode.org/license.txt for BSD license.\r
 !\r
 IN: openal.example\r
-USING: openal kernel alien threads sequences ;\r
+USING: openal kernel alien threads sequences calendar ;\r
 \r
 : play-hello ( -- )\r
   init-openal\r
   1 gen-sources\r
   first dup AL_BUFFER  alutCreateBufferHelloWorld set-source-param\r
   source-play\r
-  1000 sleep ;\r
+  1000 milliseconds sleep ;\r
   \r
 : (play-file) ( source -- )\r
-  100 sleep\r
+  100 milliseconds sleep\r
   dup source-playing? [ (play-file) ] [ drop ] if ;\r
 \r
 : play-file ( filename -- )\r
index ae3ce224149b93731209b794543368f2a9cab735..15a9c100713c63a7d9049e6610f48ee011aeced6 100644 (file)
@@ -1,5 +1,5 @@
 USING: kernel sequences namespaces make math assocs words arrays
-tools.annotations vocabs sorting prettyprint io micros
+tools.annotations vocabs sorting prettyprint io system
 math.statistics accessors ;
 IN: wordtimer
 
@@ -30,7 +30,7 @@ SYMBOL: *calling*
   *calling* get-global at ; inline
     
 : timed-call ( quot word -- )
-  [ calling ] [ >r micro-time r> register-time ] [ finished ] tri ; inline
+  [ calling ] [ >r benchmark r> register-time ] [ finished ] tri ; inline
 
 : time-unless-recursing ( quot word -- )
   dup called-recursively? not
@@ -51,7 +51,7 @@ SYMBOL: *calling*
 : dummy-word ( -- ) ;
 
 : time-dummy-word ( -- n )
-  [ 100000 [ [ dummy-word ] micro-time , ] times ] { } make median ;
+  [ 100000 [ [ dummy-word ] benchmark , ] times ] { } make median ;
 
 : subtract-overhead ( {oldtime,n} overhead -- {newtime,n} )
   [ first2 ] dip
@@ -71,7 +71,7 @@ SYMBOL: *calling*
 
 : wordtimer-call ( quot -- )
   reset-word-timer 
-  [ call ] micro-time >r
+  benchmark >r
   correct-for-timing-overhead
   "total time:" write r> pprint nl
   print-word-timings nl ;
@@ -81,7 +81,7 @@ SYMBOL: *calling*
   over [ reset-vocab ] [ add-timers ] bi
   reset-word-timer
   "executing quotation..." print flush
-  [ call ] micro-time >r
+  benchmark >r
   "resetting annotations..." print flush
   reset-vocab
   correct-for-timing-overhead
index 9f8ffb625e1af3affba70d67ffb9da7f4fc9b84c..23836c560c62530e9c1d5a564175abe868b9d3ea 100755 (executable)
@@ -793,7 +793,7 @@ void garbage_collection(CELL gen,
                return;
        }
 
-       s64 start = current_millis();
+       s64 start = current_micros();
 
        performing_gc = true;
        growing_data_heap = growing_data_heap_;
@@ -860,7 +860,7 @@ void garbage_collection(CELL gen,
        while(scan < newspace->here)
                scan = collect_next(scan);
 
-       CELL gc_elapsed = (current_millis() - start);
+       CELL gc_elapsed = (current_micros() - start);
 
        end_gc(gc_elapsed);
 
@@ -887,14 +887,14 @@ void primitive_gc_stats(void)
        GROWABLE_ARRAY(stats);
 
        CELL i;
-       CELL total_gc_time = 0;
+       u64 total_gc_time = 0;
 
        for(i = 0; i < MAX_GEN_COUNT; i++)
        {
                F_GC_STATS *s = &gc_stats[i];
                GROWABLE_ARRAY_ADD(stats,allot_cell(s->collections));
-               GROWABLE_ARRAY_ADD(stats,allot_cell(s->gc_time));
-               GROWABLE_ARRAY_ADD(stats,allot_cell(s->max_gc_time));
+               GROWABLE_ARRAY_ADD(stats,tag_bignum(long_long_to_bignum(s->gc_time)));
+               GROWABLE_ARRAY_ADD(stats,tag_bignum(long_long_to_bignum(s->max_gc_time)));
                GROWABLE_ARRAY_ADD(stats,allot_cell(s->collections == 0 ? 0 : s->gc_time / s->collections));
                GROWABLE_ARRAY_ADD(stats,allot_cell(s->object_count));
                GROWABLE_ARRAY_ADD(stats,tag_bignum(long_long_to_bignum(s->bytes_copied)));
@@ -902,7 +902,7 @@ void primitive_gc_stats(void)
                total_gc_time += s->gc_time;
        }
 
-       GROWABLE_ARRAY_ADD(stats,allot_cell(total_gc_time));
+       GROWABLE_ARRAY_ADD(stats,tag_bignum(long_long_to_bignum(total_gc_time)));
        GROWABLE_ARRAY_ADD(stats,tag_bignum(long_long_to_bignum(cards_scanned)));
        GROWABLE_ARRAY_ADD(stats,tag_bignum(long_long_to_bignum(decks_scanned)));
        GROWABLE_ARRAY_ADD(stats,allot_cell(code_heap_scans));
index 0d63cc6bfee00173ec902ce27defb79f6f579def..a407ed761cf0dd801f32c5cb826625b4d4688c74 100755 (executable)
@@ -161,8 +161,8 @@ void init_data_heap(CELL gens,
 /* statistics */
 typedef struct {
        CELL collections;
-       CELL gc_time;
-       CELL max_gc_time;
+       u64 gc_time;
+       u64 max_gc_time;
        CELL object_count;
        u64 bytes_copied;
 } F_GC_STATS;
index 8c6ec203adaed612e6a5654539d297547ba5d004..db8e60c781232a67f4d36b39973089c5e758b205 100755 (executable)
@@ -167,7 +167,9 @@ void print_stack_frame(F_STACK_FRAME *frame)
        print_obj(frame_scan(frame));
        print_string("\n");
        print_cell_hex((CELL)frame_executing(frame));
+       print_string(" ");
        print_cell_hex((CELL)frame->xt);
+       print_string("\n");
 }
 
 void print_callstack(void)
index 8e0aadb4fd2ed752804cafe3d8aa829060af8179..f198370ebe9d944626d4972c69fa10696834df0e 100755 (executable)
@@ -91,7 +91,7 @@ void init_factor(F_PARAMETERS *p)
        if(p->image == NULL)
                p->image = default_image_path();
 
-       srand(current_millis());
+       srand(current_micros());
        init_ffi();
        init_stacks(p->ds_size,p->rs_size);
        load_image(p);
@@ -216,8 +216,8 @@ void factor_yield(void)
        callback();
 }
 
-void factor_sleep(long ms)
+void factor_sleep(long us)
 {
        void (*callback)() = alien_offset(userenv[SLEEP_CALLBACK_ENV]);
-       callback(ms);
+       callback(us);
 }
index c11962f6e1dde1249b4605719a99387657cdc77a..952d2683cfe43a4356ca8c3012c4d46d10b31e5b 100755 (executable)
@@ -16,16 +16,16 @@ void start_thread(void *(*start_routine)(void *))
 
 static void *null_dll;
 
-s64 current_millis(void)
+s64 current_micros(void)
 {
        struct timeval t;
        gettimeofday(&t,NULL);
-       return (s64)t.tv_sec * 1000 + t.tv_usec / 1000;
+       return (s64)t.tv_sec * 1000000 + t.tv_usec;
 }
 
-void sleep_millis(CELL msec)
+void sleep_micros(CELL usec)
 {
-       usleep(msec * 1000);
+       usleep(usec);
 }
 
 void init_ffi(void)
index 2c5cc20e8d15ff85b10fd40db960f19e590fcd8f..97b1b39129e8e92b4d05762c388994c9f7c7f144 100755 (executable)
@@ -50,7 +50,7 @@ void unix_init_signals(void);
 void signal_handler(int signal, siginfo_t* siginfo, void* uap);
 void dump_stack_signal(int signal, siginfo_t* siginfo, void* uap);
 
-s64 current_millis(void);
-void sleep_millis(CELL msec);
+s64 current_micros(void);
+void sleep_micros(CELL usec);
 
 void open_console(void);
index 02b51b82ed4fe2fb999e0d4f5082607003a63e74..621198ff7dc58212c3fee3fbaefa6f0c8388c3c7 100755 (executable)
@@ -1,13 +1,13 @@
 #include "master.h"
 
-s64 current_millis(void)
+s64 current_micros(void)
 {
        SYSTEMTIME st;
        FILETIME ft;
        GetSystemTime(&st);
        SystemTimeToFileTime(&st, &ft);
        return (((s64)ft.dwLowDateTime
-               | (s64)ft.dwHighDateTime<<32) - EPOCH_OFFSET) / 10000;
+               | (s64)ft.dwHighDateTime<<32) - EPOCH_OFFSET) / 10;
 }
 
 char *strerror(int err)
index f1d6df6f3d5775edfeccac407108956346360691..a2be5fe475fe60490f69f5416ebab714c0b58219 100755 (executable)
@@ -22,6 +22,6 @@ char *getenv(char *name);
 #define snprintf _snprintf
 #define snwprintf _snwprintf
 
-s64 current_millis(void);
+s64 current_micros(void);
 void c_to_factor_toplevel(CELL quot);
 void open_console(void);
index e22ea1446b4c6fe9d4c306cc4e043a5905dd0c4c..f982abfb1b94c295c510a88f5b4b971dc0cb43c2 100755 (executable)
@@ -1,11 +1,11 @@
 #include "master.h"
 
-s64 current_millis(void)
+s64 current_micros(void)
 {
        FILETIME t;
        GetSystemTimeAsFileTime(&t);
        return (((s64)t.dwLowDateTime | (s64)t.dwHighDateTime<<32)
-               - EPOCH_OFFSET) / 10000;
+               - EPOCH_OFFSET) / 10;
 }
 
 long exception_handler(PEXCEPTION_POINTERS pe)
index 7d486bb86bb488b30c591f61ff0806571e49170f..0aeb77741ba896c072c4a6f241348c66a9e33429 100755 (executable)
@@ -166,7 +166,7 @@ long getpagesize(void)
        return g_pagesize;
 }
 
-void sleep_millis(DWORD msec)
+void sleep_micros(DWORD usec)
 {
-       Sleep(msec);
+       Sleep(msec / 1000);
 }
index 8d0f15648a63aed3e2b37d322929d3d912ed261f..b12d677af2bd1f5ae9d0b47055ffab3bb757e6ba 100755 (executable)
@@ -49,7 +49,7 @@ void ffi_dlopen(F_DLL *dll);
 void *ffi_dlsym(F_DLL *dll, F_SYMBOL *symbol);
 void ffi_dlclose(F_DLL *dll);
 
-void sleep_millis(DWORD msec);
+void sleep_micros(DWORD msec);
 
 INLINE void init_signals(void) {}
 INLINE void early_init(void) {}
@@ -57,5 +57,5 @@ const F_CHAR *vm_executable_path(void);
 const F_CHAR *default_image_path(void);
 long getpagesize (void);
 
-s64 current_millis(void);
+s64 current_micros(void);
 
index 69e77f81ed5529e97d2243f08d6c805352ce75aa..5adb135c820d5f46c26474d5443f37b8e67c39d7 100755 (executable)
@@ -68,7 +68,7 @@ void *primitives[] = {
        primitive_exit,
        primitive_data_room,
        primitive_code_room,
-       primitive_millis,
+       primitive_micros,
        primitive_modify_code_heap,
        primitive_dlopen,
        primitive_dlsym,
index bf917aeec06a7c40155870ee2c42d3dc6e7306dd..179224f7987d0acaa6047d98302b5c520dc81b36 100755 (executable)
@@ -54,6 +54,27 @@ bool jit_fast_dispatch_p(F_ARRAY *array, CELL i)
                && array_nth(array,i + 1) == userenv[JIT_DISPATCH_WORD];
 }
 
+bool jit_fast_dip_p(F_ARRAY *array, CELL i)
+{
+       return (i + 2) <= array_capacity(array)
+               && type_of(array_nth(array,i)) == QUOTATION_TYPE
+               && array_nth(array,i + 1) == userenv[JIT_DIP_WORD];
+}
+
+bool jit_fast_2dip_p(F_ARRAY *array, CELL i)
+{
+       return (i + 2) <= array_capacity(array)
+               && type_of(array_nth(array,i)) == QUOTATION_TYPE
+               && array_nth(array,i + 1) == userenv[JIT_2DIP_WORD];
+}
+
+bool jit_fast_3dip_p(F_ARRAY *array, CELL i)
+{
+       return (i + 2) <= array_capacity(array)
+               && type_of(array_nth(array,i)) == QUOTATION_TYPE
+               && array_nth(array,i + 1) == userenv[JIT_3DIP_WORD];
+}
+
 bool jit_ignore_declare_p(F_ARRAY *array, CELL i)
 {
        return (i + 1) < array_capacity(array)
@@ -115,6 +136,13 @@ bool jit_stack_frame_p(F_ARRAY *array)
                        if(word->subprimitive == F && obj != userenv[JIT_DECLARE_WORD])
                                return true;
                }
+               else if(type_of(obj) == QUOTATION_TYPE)
+               {
+                       if(jit_fast_dip_p(array,i)
+                               || jit_fast_2dip_p(array,i)
+                               || jit_fast_3dip_p(array,i))
+                               return true;
+               }
        }
 
        return false;
@@ -232,6 +260,30 @@ void jit_compile(CELL quot, bool relocate)
                                tail_call = true;
                                break;
                        }
+                       else if(jit_fast_dip_p(untag_object(array),i))
+                       {
+                               GROWABLE_ARRAY_ADD(literals,array_nth(untag_object(array),i));
+                               EMIT(userenv[JIT_DIP],literals_count - 1);
+
+                               i++;
+                               break;
+                       }
+                       else if(jit_fast_2dip_p(untag_object(array),i))
+                       {
+                               GROWABLE_ARRAY_ADD(literals,array_nth(untag_object(array),i));
+                               EMIT(userenv[JIT_2DIP],literals_count - 1);
+
+                               i++;
+                               break;
+                       }
+                       else if(jit_fast_3dip_p(untag_object(array),i))
+                       {
+                               GROWABLE_ARRAY_ADD(literals,array_nth(untag_object(array),i));
+                               EMIT(userenv[JIT_3DIP],literals_count - 1);
+
+                               i++;
+                               break;
+                       }
                case ARRAY_TYPE:
                        if(jit_fast_dispatch_p(untag_object(array),i))
                        {
@@ -366,6 +418,24 @@ F_FIXNUM quot_code_offset_to_scan(CELL quot, F_FIXNUM offset)
                                tail_call = true;
                                break;
                        }
+                       else if(jit_fast_dip_p(untag_object(array),i))
+                       {
+                               i++;
+                               COUNT(userenv[JIT_DIP],i)
+                               break;
+                       }
+                       else if(jit_fast_2dip_p(untag_object(array),i))
+                       {
+                               i++;
+                               COUNT(userenv[JIT_2DIP],i)
+                               break;
+                       }
+                       else if(jit_fast_3dip_p(untag_object(array),i))
+                       {
+                               i++;
+                               COUNT(userenv[JIT_3DIP],i)
+                               break;
+                       }
                case ARRAY_TYPE:
                        if(jit_fast_dispatch_p(untag_object(array),i))
                        {
index 79792d79f3ed4e796750f0819f85a684f77044d7..a28a956f2974257e6a25099037103a4b88e72499 100755 (executable)
--- a/vm/run.c
+++ b/vm/run.c
@@ -173,14 +173,14 @@ void primitive_exit(void)
        exit(to_fixnum(dpop()));
 }
 
-void primitive_millis(void)
+void primitive_micros(void)
 {
-       box_unsigned_8(current_millis());
+       box_unsigned_8(current_micros());
 }
 
 void primitive_sleep(void)
 {
-       sleep_millis(to_cell(dpop()));
+       sleep_micros(to_cell(dpop()));
 }
 
 void primitive_set_slot(void)
index be133b7eca99f2a7f30de78b7472cc63e75cafd6..eae0146298835c70a74129fbd6b1cd4be78168c0 100755 (executable)
--- a/vm/run.h
+++ b/vm/run.h
@@ -50,6 +50,12 @@ typedef enum {
        JIT_PUSH_IMMEDIATE,
        JIT_DECLARE_WORD    = 42,
        JIT_SAVE_STACK,
+       JIT_DIP_WORD,
+       JIT_DIP,
+       JIT_2DIP_WORD,
+       JIT_2DIP,
+       JIT_3DIP_WORD,
+       JIT_3DIP,
 
        STACK_TRACES_ENV    = 59,
 
@@ -238,7 +244,7 @@ void primitive_os_envs(void);
 void primitive_set_os_env(void);
 void primitive_unset_os_env(void);
 void primitive_set_os_envs(void);
-void primitive_millis(void);
+void primitive_micros(void);
 void primitive_sleep(void);
 void primitive_set_slot(void);