]> gitweb.factorcode.org Git - factor.git/commitdiff
rename millis to system-millis, micros to system-micros, add nano-count
authorDoug Coleman <doug.coleman@gmail.com>
Wed, 18 Nov 2009 21:58:48 +0000 (15:58 -0600)
committerDoug Coleman <doug.coleman@gmail.com>
Wed, 18 Nov 2009 21:58:48 +0000 (15:58 -0600)
36 files changed:
basis/bootstrap/stage2.factor
basis/calendar/calendar.factor
basis/furnace/cache/cache.factor
basis/stack-checker/known-words/known-words.factor
basis/threads/threads.factor
basis/tools/memory/memory.factor
basis/tools/threads/threads.factor
basis/tools/time/time-docs.factor
basis/tools/time/time.factor
basis/ui/gestures/gestures-docs.factor
core/bootstrap/primitives.factor
core/system/system-docs.factor
core/system/system.factor
extra/animations/animations-docs.factor [deleted file]
extra/animations/animations.factor [deleted file]
extra/animations/authors.txt [deleted file]
extra/game/loop/loop.factor
extra/jamshred/player/player.factor
extra/space-invaders/space-invaders.factor
extra/tetris/game/game.factor
unmaintained/animations/animations-docs.factor [new file with mode: 0644]
unmaintained/animations/animations.factor [new file with mode: 0644]
unmaintained/animations/authors.txt [new file with mode: 0644]
vm/factor.cpp
vm/gc.cpp
vm/os-genunix.cpp
vm/os-macosx.mm
vm/os-unix.cpp
vm/os-unix.hpp
vm/os-windows-ce.cpp
vm/os-windows-ce.hpp
vm/os-windows-nt.cpp
vm/os-windows.hpp
vm/primitives.cpp
vm/run.cpp
vm/vm.hpp

index b011b41c4b8735fe50bacadb68fa3041de903b48..674cb2e7d5419e15b1e20a6ce9d75a59011f6559 100644 (file)
@@ -59,7 +59,7 @@ SYMBOL: bootstrap-time
 
 [
     ! We time bootstrap
-    millis
+    system-millis
 
     default-image-name "output-image" set-global
 
@@ -84,14 +84,14 @@ SYMBOL: bootstrap-time
 
     load-components
 
-    millis over - core-bootstrap-time set-global
+    system-millis over - core-bootstrap-time set-global
 
     run-bootstrap-init
 
     f error set-global
     f error-continuation set-global
 
-    millis swap - bootstrap-time set-global
+    system-millis swap - bootstrap-time set-global
     print-report
 
     "deploy-vocab" get [
index 1564bc3ee4de3b2c158103f7df91dfa9ee201c0f..e40b9be7fa41bc925d15f7b34041f3371e5ef31e 100644 (file)
@@ -391,7 +391,7 @@ M: duration time-
 
 : gmt ( -- timestamp )
     #! GMT time, right now
-    unix-1970 micros microseconds time+ ;
+    unix-1970 system-micros microseconds time+ ;
 
 : now ( -- timestamp ) gmt >local-time ;
 : hence ( duration -- timestamp ) now swap time+ ;
index fe2840c9eba3d2e1f14e71daeb82cac4ae386176..d5d72b117ff863e599b141dcc58f91e3af9b020c 100644 (file)
@@ -22,7 +22,7 @@ server-state f
 
 : expire-state ( class -- )
     new
-        -1/0. millis [a,b] >>expires
+        -1/0. system-millis [a,b] >>expires
     delete-tuples ;
 
 TUPLE: server-state-manager < filter-responder timeout ;
index d45b54bd2394abdd8ba83726937f90a06cd8b8df..40e41d1a8d68bb4a58a04a471670b3c986ab0d54 100644 (file)
@@ -511,11 +511,11 @@ M: bad-executable summary
 \ code-room { } { byte-array } define-primitive
 \ code-room  make-flushable
 
-\ micros { } { integer } define-primitive
-\ micros make-flushable
+\ system-micros { } { integer } define-primitive
+\ system-micros make-flushable
 
-\ nanos { } { integer } define-primitive
-\ nanos make-flushable
+\ nano-count { } { integer } define-primitive
+\ nano-count make-flushable
 
 \ tag { object } { fixnum } define-primitive
 \ tag make-foldable
index b7e0e1b87f1e8f9ed275d15b1d2673e712a5b0b9..036324be87c61cf291de280a4b9a3cf168f50a3e 100644 (file)
@@ -95,7 +95,7 @@ PRIVATE>
     {
         { [ run-queue deque-empty? not ] [ 0 ] }
         { [ sleep-queue heap-empty? ] [ f ] }
-        [ sleep-queue heap-peek nip micros [-] ]
+        [ sleep-queue heap-peek nip system-micros [-] ]
     } cond ;
 
 DEFER: stop
@@ -108,7 +108,7 @@ DEFER: stop
 
 : expire-sleep? ( heap -- ? )
     dup heap-empty?
-    [ drop f ] [ heap-peek nip micros <= ] if ;
+    [ drop f ] [ heap-peek nip system-micros <= ] if ;
 
 : expire-sleep ( thread -- )
     f >>sleep-entry resume ;
@@ -184,7 +184,7 @@ M: f sleep-until
 GENERIC: sleep ( dt -- )
 
 M: real sleep
-    micros + >integer sleep-until ;
+    system-micros + >integer sleep-until ;
 
 : interrupt ( thread -- )
     dup state>> [
index cf7e3ee38d81b6aa67001da1ef313302cd93b572..6746031a3d1085d8bd3227ce77ccdcd99853d2d2 100644 (file)
@@ -18,8 +18,8 @@ IN: tools.memory
 : kilobytes ( n -- str )
     1024 /i commas " KB" append ;
 
-: micros>string ( n -- str )
-    commas " µs" append ;
+: nanos>string ( n -- str )
+    1000 /i commas " µs" append ;
 
 : copying-room. ( copying-sizes -- )
     {
@@ -153,11 +153,11 @@ TUPLE: gc-stats collections times ;
             [ collections>> ]
             [
                 times>> {
-                    [ sum micros>string ]
-                    [ mean >integer micros>string ]
-                    [ median >integer micros>string ]
-                    [ infimum micros>string ]
-                    [ supremum micros>string ]
+                    [ sum nanos>string ]
+                    [ mean >integer nanos>string ]
+                    [ median >integer nanos>string ]
+                    [ infimum nanos>string ]
+                    [ supremum nanos>string ]
                 } cleave
             ] bi
         ] bi
@@ -172,7 +172,7 @@ PRIVATE>
 : gc-event. ( event -- )
     {
         { "Event type:" [ op>> gc-op-string ] }
-        { "Total time:" [ total-time>> micros>string ] }
+        { "Total time:" [ total-time>> nanos>string ] }
         { "Space reclaimed:" [ space-reclaimed kilobytes ] }
     } object-table. ;
 
@@ -188,10 +188,10 @@ PRIVATE>
         { "Cards scanned:" [ [ cards-scanned>> ] map-sum commas ] }
         { "Decks scanned:" [ [ decks-scanned>> ] map-sum commas ] }
         { "Code blocks scanned:" [ [ code-blocks-scanned>> ] map-sum commas ] }
-        { "Total time:" [ [ total-time>> ] map-sum micros>string ] }
-        { "Card scan time:" [ [ card-scan-time>> ] map-sum micros>string ] }
-        { "Code block scan time:" [ [ code-scan-time>> ] map-sum micros>string ] }
-        { "Data heap sweep time:" [ [ data-sweep-time>> ] map-sum micros>string ] }
-        { "Code heap sweep time:" [ [ code-sweep-time>> ] map-sum micros>string ] }
-        { "Compaction time:" [ [ compaction-time>> ] map-sum micros>string ] }
+        { "Total time:" [ [ total-time>> ] map-sum nanos>string ] }
+        { "Card scan time:" [ [ card-scan-time>> ] map-sum nanos>string ] }
+        { "Code block scan time:" [ [ code-scan-time>> ] map-sum nanos>string ] }
+        { "Data heap sweep time:" [ [ data-sweep-time>> ] map-sum nanos>string ] }
+        { "Code heap sweep time:" [ [ code-sweep-time>> ] map-sum nanos>string ] }
+        { "Compaction time:" [ [ compaction-time>> ] map-sum nanos>string ] }
     } object-table. ;
index 18dd8ce2b793a53228686eb6cbd77a18a5b9c6f4..aa07d3de92b10fd4c03cddac24dfd45095e5f3d8 100644 (file)
@@ -14,7 +14,7 @@ IN: tools.threads
     ] with-cell\r
     [\r
         sleep-entry>> [\r
-            key>> micros [-] number>string write\r
+            key>> nano-count 1000 /i [-] number>string write\r
             " us" write\r
         ] when*\r
     ] with-cell ;\r
index 9e892c33eccf24f2834f64704358971253602706..4d3054db8aa21e7e1ace27c7a5990c8a2a1838cc 100644 (file)
@@ -10,7 +10,7 @@ ARTICLE: "timing" "Timing code and collecting statistics"
 "A lower-level word puts timings on the stack, intead of printing:"
 { $subsections benchmark }
 "You can also read the system clock directly:"
-{ $subsections micros }
+{ $subsections system-micros }
 { $see-also "profiling" "calendar" } ;
 
 ABOUT: "timing"
@@ -25,7 +25,7 @@ HELP: time
 { $values { "quot" quotation } }
 { $description "Runs a quotation, gathering statistics about method dispatch and garbage collection, and then prints the total run time." } ;
 
-{ benchmark micros time } related-words
+{ benchmark system-micros system-millis time } related-words
 
 HELP: collect-gc-events
 { $values { "quot" quotation } }
index 3724a741b7f6e068e5b8173961cdecff20a03efc..0bd97f563dbf3bbc5b0e8468f21446938bb54675 100644 (file)
@@ -5,10 +5,10 @@ tools.dispatch ;
 IN: tools.time
 
 : benchmark ( quot -- runtime )
-    micros [ call micros ] dip - ; inline
+    nano-count [ call nano-count ] dip - ; inline
 
 : time. ( time -- )
-    "Running time: " write 1000000 /f pprint " seconds" print ;
+    "Running time: " write 1000000000 /f pprint " seconds" print ;
 
 : time-banner. ( -- )
     "Additional information was collected." print
index 3deb0c619dfca0610ae1d4095d68a5317688e9bc..bb33e28da3c281060772b3ac57abbb8dbf81bc1d 100644 (file)
@@ -174,7 +174,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 micros } "." } ;
+{ $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 system-micros } "." } ;
 
 HELP: hand-buttons
 { $var-description "Global variable. A vector of mouse buttons currently held down." } ;
index 072f41c0868e3dbc16d9a555b57dcb7f976cded1..64e22ebabf4453ee12d068060c8f04feb51225c8 100644 (file)
@@ -432,8 +432,8 @@ tuple
     { "(exit)" "system" (( n -- )) }
     { "data-room" "memory" (( -- data-room )) }
     { "code-room" "memory" (( -- code-room )) }
-    { "micros" "system" (( -- us )) }
-    { "nanos" "system" (( -- us )) }
+    { "system-micros" "system" (( -- us )) }
+    { "nano-count" "system" (( -- ns )) }
     { "modify-code-heap" "compiler.units" (( alist -- )) }
     { "(dlopen)" "alien.libraries" (( path -- dll )) }
     { "(dlsym)" "alien.libraries" (( name dll -- alien )) }
index ba9411fac69ccf41cd2952226807398f7549ee87..364ad04fa2a2176c409bd4f1190f87a7542c1cf6 100644 (file)
@@ -16,8 +16,8 @@ ARTICLE: "system" "System interface"
 }
 "Getting the current time:"
 { $subsections
-    micros
-    millis
+    system-micros
+    system-micros
 }
 "Exiting the Factor VM:"
 { $subsections exit } ;
@@ -77,12 +77,12 @@ HELP: exit ( n -- )
 { $values { "n" "an integer exit code" } }
 { $description "Exits the Factor process." } ;
 
-HELP: micros ( -- us )
+HELP: system-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 )
+HELP: system-millis ( -- ms )
 { $values { "ms" 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 5ee10374fc7253c8f34c71831217731cfc0061a7..31daa49b9fbc535ad14d9ef1057de6c05d91fd40 100644 (file)
@@ -55,6 +55,6 @@ PRIVATE>
 
 : embedded? ( -- ? ) 15 getenv ;
 
-: millis ( -- ms ) micros 1000 /i ;
+: system-millis ( -- ms ) system-micros 1000 /i ;
 
 : exit ( n -- ) do-shutdown-hooks (exit) ;
diff --git a/extra/animations/animations-docs.factor b/extra/animations/animations-docs.factor
deleted file mode 100644 (file)
index 3e426a2..0000000
+++ /dev/null
@@ -1,67 +0,0 @@
-USING: help.markup help.syntax ;
-IN: animations
-
-HELP: animate ( quot duration -- )
-
-{ $values
-    { "quot" "a quot which uses " { $link progress } }
-    { "duration" "a duration of time" }
-}
-{ $description
-    { $link animate } " calls " { $link reset-progress }
-    " , then continously calls the given quot until the"
-    " duration of time has elapsed. The quot should use "
-    { $link progress } " at least once."
-}
-{ $examples
-    { $unchecked-example 
-        "USING: animations calendar threads prettyprint ;"
-        "[ 1 sleep progress unparse write \" ms elapsed\" print ] "
-        "1/20 seconds animate ;"
-        "46 ms elapsed\n17 ms elapsed"
-    }
-    { $notes "The amount of time elapsed between these iterations will very." }
-} ;
-
-HELP: reset-progress ( -- )
-{ $description
-    "Initiates the timer. Call this before using "
-    "a loop which makes use of " { $link progress } "."
-} ;
-
-HELP: progress
-{ $values { "time" "an integer" } }
-{ $description
-    "Gives the time elapsed since the last time"
-    " this word was called, in milliseconds." 
-}
-{ $examples
-    { $unchecked-example
-        "USING: animations threads prettyprint ;"
-        "reset-progress 3 "
-        "[ 1 sleep progress unparse write \"ms elapsed\" print ] "
-        "times ;"
-        "31 ms elapsed\n18 ms elapsed\n16 ms elapsed"
-    }
-    { $notes "The amount of time elapsed between these iterations will very." }
-} ;
-
-ARTICLE: "animations" "Animations"
-"Provides a lightweight framework for properly simulating continuous"
-" functions of real time. This framework helps one create animations "
-"that use rates which do not change across platforms. The speed of the "
-"computer should correlate with the smoothness of the animation, not "
-"the speed of the animation!"
-{ $subsections
-    animate
-    reset-progress
-    progress
-}
-! A little talk about when to use progress and when to use animate
-    { $link progress } " specifically provides the length of time since "
-    { $link reset-progress } " was called, and also calls "
-    { $link reset-progress } " as its last action. This can be directly "
-    "used when one's quote runs for a specific number of iterations, instead "
-    "of a length of time. If the animation is like most, and is expected to "
-    "run for a specific length of time, " { $link animate } " should be used." ;
-ABOUT: "animations"
\ No newline at end of file
diff --git a/extra/animations/animations.factor b/extra/animations/animations.factor
deleted file mode 100644 (file)
index 8f416dc..0000000
+++ /dev/null
@@ -1,17 +0,0 @@
-! Small library for cross-platform continuous functions of real time
-
-USING: kernel shuffle system locals
-prettyprint math io namespaces threads calendar ;
-IN: animations
-
-SYMBOL: last-loop
-SYMBOL: sleep-period
-
-: reset-progress ( -- ) millis last-loop set ;
-! : my-progress ( -- progress ) millis 
-: progress ( -- time ) millis last-loop get - reset-progress ;
-: progress-peek ( -- progress ) millis last-loop get - ;
-: set-end ( duration -- end-time ) duration>milliseconds millis + ;
-: loop ( quot end -- ) dup millis > [ [ dup call ] dip loop ] [ 2drop ] if ; inline
-: animate ( quot duration -- ) reset-progress set-end loop ; inline
-: sample ( revs quot -- avg ) reset-progress dupd times progress swap / ; inline
diff --git a/extra/animations/authors.txt b/extra/animations/authors.txt
deleted file mode 100644 (file)
index 137b160..0000000
+++ /dev/null
@@ -1 +0,0 @@
-Reginald Ford
\ No newline at end of file
index 1346988fd187c7bf50a6f2222199498cbf968dfc..eec133ed1988baa7349dea332ae79bd52af710b0 100644 (file)
@@ -21,7 +21,7 @@ GENERIC: draw* ( tick-slice delegate -- )
 SYMBOL: game-loop
 
 : since-last-tick ( loop -- milliseconds )
-    last-tick>> millis swap - ;
+    last-tick>> system-millis swap - ;
 
 : tick-slice ( loop -- slice )
     [ since-last-tick ] [ tick-length>> ] bi /f 1.0 min ;
@@ -53,7 +53,7 @@ TUPLE: game-loop-error game-loop error ;
     drop ;
 
 : ?tick ( loop count -- )
-    [ millis >>last-tick drop ] [
+    [ system-millis >>last-tick drop ] [
         over [ since-last-tick ] [ tick-length>> ] bi >=
         [ [ drop increment-tick ] [ drop tick ] [ 1 - ?tick ] 2tri ]
         [ 2drop ] if
@@ -70,12 +70,12 @@ TUPLE: game-loop-error game-loop error ;
     with-variable ;
 
 : benchmark-millis ( loop -- millis )
-    millis swap benchmark-time>> - ;
+    system-millis swap benchmark-time>> - ;
 
 PRIVATE>
 
 : reset-loop-benchmark ( loop -- )
-    millis >>benchmark-time
+    system-millis >>benchmark-time
     dup tick-number>> >>benchmark-tick-number
     dup frame-number>> >>benchmark-frame-number
     drop ;
@@ -86,7 +86,7 @@ PRIVATE>
     [ frame-number>> ] [ benchmark-frame-number>> - ] [ benchmark-millis ] tri /f ;
 
 : start-loop ( loop -- )
-    millis >>last-tick
+    system-millis >>last-tick
     t >>running?
     [ reset-loop-benchmark ]
     [ [ run-loop ] curry "game loop" spawn ]
@@ -98,7 +98,7 @@ PRIVATE>
     drop ;
 
 : <game-loop> ( tick-length delegate -- loop )
-    millis f f 0 0 millis 0 0
+    system-millis f f 0 0 system-millis 0 0
     game-loop boa ;
 
 M: game-loop dispose
index 6982af63f6f2415172897b28a4270505d128b9f1..233d34e0788bc0b5e657bfcb10ffb8fb02d903ae 100644 (file)
@@ -39,9 +39,9 @@ CONSTANT: max-speed 30.0
     >>tunnel to-tunnel-start ;
 
 : update-time ( player -- seconds-passed )
-    millis swap [ last-move>> - 1000 / ] [ (>>last-move) ] 2bi ;
+    system-millis swap [ last-move>> - 1000 / ] [ (>>last-move) ] 2bi ;
 
-: moved ( player -- ) millis swap (>>last-move) ;
+: moved ( player -- ) system-millis swap (>>last-move) ;
 
 : speed-range ( -- range )
     max-speed [0,b] ;
index 3d0369128740fb471c3a19a5dcdfaafcc6171c84..76284532b4861dbab3877aaaa6985f3c305711d6 100755 (executable)
@@ -358,8 +358,8 @@ M: space-invaders update-video ( value addr cpu -- )
 
 : sync-frame ( millis -- millis )
   #! Sleep until the time for the next frame arrives.
-  1000 60 / >fixnum + system:millis - dup 0 >
-  [ milliseconds threads:sleep ] [ drop threads:yield ] if system:millis ;
+  1000 60 / >fixnum + system:system-millis - dup 0 >
+  [ milliseconds threads:sleep ] [ drop threads:yield ] if system:system-millis ;
 
 : invaders-process ( millis gadget -- )
   #! Run a space invaders gadget inside a 
@@ -377,7 +377,7 @@ M: space-invaders update-video ( value addr cpu -- )
 M: invaders-gadget graft* ( gadget -- )
   dup cpu>> init-sounds
   f over (>>quit?)
-  [ system:millis swap invaders-process ] curry
+  [ system:system-millis swap invaders-process ] curry
   "Space invaders" threads:spawn drop ;
 
 M: invaders-gadget ungraft* ( gadget -- )
index c9e235ff7953ef71350d8b78cf2e4608d842c39d..fdf6e10d5d77d75a70646bdd89ef69f1cae505ec 100644 (file)
@@ -104,10 +104,10 @@ CONSTANT: default-height 20
     dup { 0 1 } tetris-move [ move-drop ] [ lock-piece ] if ;
 
 : update ( tetris -- )
-    millis over last-update>> -
+    system-millis over last-update>> -
     over update-interval > [
         dup move-down
-        millis >>last-update
+        system-millis >>last-update
     ] when drop ;
 
 : ?update ( tetris -- )
diff --git a/unmaintained/animations/animations-docs.factor b/unmaintained/animations/animations-docs.factor
new file mode 100644 (file)
index 0000000..3e426a2
--- /dev/null
@@ -0,0 +1,67 @@
+USING: help.markup help.syntax ;
+IN: animations
+
+HELP: animate ( quot duration -- )
+
+{ $values
+    { "quot" "a quot which uses " { $link progress } }
+    { "duration" "a duration of time" }
+}
+{ $description
+    { $link animate } " calls " { $link reset-progress }
+    " , then continously calls the given quot until the"
+    " duration of time has elapsed. The quot should use "
+    { $link progress } " at least once."
+}
+{ $examples
+    { $unchecked-example 
+        "USING: animations calendar threads prettyprint ;"
+        "[ 1 sleep progress unparse write \" ms elapsed\" print ] "
+        "1/20 seconds animate ;"
+        "46 ms elapsed\n17 ms elapsed"
+    }
+    { $notes "The amount of time elapsed between these iterations will very." }
+} ;
+
+HELP: reset-progress ( -- )
+{ $description
+    "Initiates the timer. Call this before using "
+    "a loop which makes use of " { $link progress } "."
+} ;
+
+HELP: progress
+{ $values { "time" "an integer" } }
+{ $description
+    "Gives the time elapsed since the last time"
+    " this word was called, in milliseconds." 
+}
+{ $examples
+    { $unchecked-example
+        "USING: animations threads prettyprint ;"
+        "reset-progress 3 "
+        "[ 1 sleep progress unparse write \"ms elapsed\" print ] "
+        "times ;"
+        "31 ms elapsed\n18 ms elapsed\n16 ms elapsed"
+    }
+    { $notes "The amount of time elapsed between these iterations will very." }
+} ;
+
+ARTICLE: "animations" "Animations"
+"Provides a lightweight framework for properly simulating continuous"
+" functions of real time. This framework helps one create animations "
+"that use rates which do not change across platforms. The speed of the "
+"computer should correlate with the smoothness of the animation, not "
+"the speed of the animation!"
+{ $subsections
+    animate
+    reset-progress
+    progress
+}
+! A little talk about when to use progress and when to use animate
+    { $link progress } " specifically provides the length of time since "
+    { $link reset-progress } " was called, and also calls "
+    { $link reset-progress } " as its last action. This can be directly "
+    "used when one's quote runs for a specific number of iterations, instead "
+    "of a length of time. If the animation is like most, and is expected to "
+    "run for a specific length of time, " { $link animate } " should be used." ;
+ABOUT: "animations"
\ No newline at end of file
diff --git a/unmaintained/animations/animations.factor b/unmaintained/animations/animations.factor
new file mode 100644 (file)
index 0000000..8f416dc
--- /dev/null
@@ -0,0 +1,17 @@
+! Small library for cross-platform continuous functions of real time
+
+USING: kernel shuffle system locals
+prettyprint math io namespaces threads calendar ;
+IN: animations
+
+SYMBOL: last-loop
+SYMBOL: sleep-period
+
+: reset-progress ( -- ) millis last-loop set ;
+! : my-progress ( -- progress ) millis 
+: progress ( -- time ) millis last-loop get - reset-progress ;
+: progress-peek ( -- progress ) millis last-loop get - ;
+: set-end ( duration -- end-time ) duration>milliseconds millis + ;
+: loop ( quot end -- ) dup millis > [ [ dup call ] dip loop ] [ 2drop ] if ; inline
+: animate ( quot duration -- ) reset-progress set-end loop ; inline
+: sample ( revs quot -- avg ) reset-progress dupd times progress swap / ; inline
diff --git a/unmaintained/animations/authors.txt b/unmaintained/animations/authors.txt
new file mode 100644 (file)
index 0000000..137b160
--- /dev/null
@@ -0,0 +1 @@
+Reginald Ford
\ No newline at end of file
index 525b2fa43ed57d63da11314d726eb3f7c815928a..9096980097ff498dacf1a30e447e75ec9922b333 100755 (executable)
@@ -119,7 +119,7 @@ void factor_vm::init_factor(vm_parameters *p)
        if(p->image_path == NULL)
                p->image_path = default_image_path();
 
-       srand(current_micros());
+       srand(system_micros());
        init_ffi();
        init_stacks(p->ds_size,p->rs_size);
        init_callbacks(p->callback_size);
index 32ca44ae1cba251477794fd17de68f6f0c17b6f6..ff458e95dce7254365fce26fced193e740f10c47 100755 (executable)
--- a/vm/gc.cpp
+++ b/vm/gc.cpp
@@ -8,7 +8,7 @@ gc_event::gc_event(gc_op op_, factor_vm *parent) :
        cards_scanned(0),
        decks_scanned(0),
        code_blocks_scanned(0),
-       start_time(current_micros()),
+       start_time(nano_count()),
        card_scan_time(0),
        code_scan_time(0),
        data_sweep_time(0),
@@ -17,70 +17,70 @@ gc_event::gc_event(gc_op op_, factor_vm *parent) :
 {
        data_heap_before = parent->data_room();
        code_heap_before = parent->code_room();
-       start_time = current_micros();
+       start_time = nano_count();
 }
 
 void gc_event::started_card_scan()
 {
-       temp_time = current_micros();
+       temp_time = nano_count();
 }
 
 void gc_event::ended_card_scan(cell cards_scanned_, cell decks_scanned_)
 {
        cards_scanned += cards_scanned_;
        decks_scanned += decks_scanned_;
-       card_scan_time = (current_micros() - temp_time);
+       card_scan_time = (nano_count() - temp_time);
 }
 
 void gc_event::started_code_scan()
 {
-       temp_time = current_micros();
+       temp_time = nano_count();
 }
 
 void gc_event::ended_code_scan(cell code_blocks_scanned_)
 {
        code_blocks_scanned += code_blocks_scanned_;
-       code_scan_time = (current_micros() - temp_time);
+       code_scan_time = (nano_count() - temp_time);
 }
 
 void gc_event::started_data_sweep()
 {
-       temp_time = current_micros();
+       temp_time = nano_count();
 }
 
 void gc_event::ended_data_sweep()
 {
-       data_sweep_time = (current_micros() - temp_time);
+       data_sweep_time = (nano_count() - temp_time);
 }
 
 void gc_event::started_code_sweep()
 {
-       temp_time = current_micros();
+       temp_time = nano_count();
 }
 
 void gc_event::ended_code_sweep()
 {
-       code_sweep_time = (current_micros() - temp_time);
+       code_sweep_time = (nano_count() - temp_time);
 }
 
 void gc_event::started_compaction()
 {
-       temp_time = current_micros();
+       temp_time = nano_count();
 }
 
 void gc_event::ended_compaction()
 {
-       compaction_time = (current_micros() - temp_time);
+       compaction_time = (nano_count() - temp_time);
 }
 
 void gc_event::ended_gc(factor_vm *parent)
 {
        data_heap_after = parent->data_room();
        code_heap_after = parent->code_room();
-       total_time = current_micros() - start_time;
+       total_time = nano_count() - start_time;
 }
 
-gc_state::gc_state(gc_op op_, factor_vm *parent) : op(op_), start_time(current_micros())
+gc_state::gc_state(gc_op op_, factor_vm *parent) : op(op_), start_time(nano_count())
 {
        event = new gc_event(op,parent);
 }
index 15c6268bbb6ee5c0726824e97cb987bb7029b511..ba23125e802c616281ef8f10be40252b530ce328 100644 (file)
@@ -35,7 +35,7 @@ const char *default_image_path()
        return new_path;
 }
 
-u64 current_nanos()
+u64 nano_count()
 {
        struct timespec t;
        int ret;
index fa13d8fd15b67ebbd58dbd6f004c1baab2e21402..a4b21911009fbfc16243f5538931be41311d4eda 100644 (file)
@@ -85,7 +85,7 @@ Protocol *objc_getProtocol(char *name)
                return nil;
 }
 
-u64 current_nanos()
+u64 nano_count()
 {
        u64 t;
        mach_timebase_info_data_t info;
index 63d68e27873a7c7f17b1e226dd0c6a5ccf61066b..075ceff4217cb4cad133a9db87a8777f5269b414 100644 (file)
@@ -40,11 +40,11 @@ factor_vm *tls_vm()
 
 static void *null_dll;
 
-s64 current_micros()
+u64 system_micros()
 {
        struct timeval t;
        gettimeofday(&t,NULL);
-       return (s64)t.tv_sec * 1000000 + t.tv_usec;
+       return (u64)t.tv_sec * 1000000 + t.tv_usec;
 }
 
 void sleep_micros(cell usec)
@@ -52,9 +52,19 @@ void sleep_micros(cell usec)
        usleep(usec);
 }
 
-void sleep_nanos(cell nsec)
+void sleep_nanos(timespec ts)
 {
-       //nanosleep(n
+       timespec ts_rem;
+       int ret;
+       ret = nanosleep(&ts,&ts_rem);
+       while(ret == -1 && errno == EINTR)
+       {
+               memcpy(&ts, &ts_rem, sizeof(ts));
+               ret = nanosleep(&ts, &ts_rem);
+       }
+
+       if(ret == -1)
+               fatal_error("nanosleep failed", 0);
 }
 
 void factor_vm::init_ffi()
index 52a3bd8676ac7bc2874f566e41a0568c397589db..40d1255c8c074c522a63510ddb678a067e4aefac 100644 (file)
@@ -52,9 +52,10 @@ void unix_init_signals();
 void signal_handler(int signal, siginfo_t* siginfo, void* uap);
 void dump_stack_signal(int signal, siginfo_t* siginfo, void* uap);
 
-s64 current_micros();
-u64 current_nanos();
+u64 system_micros();
+u64 nano_count();
 void sleep_micros(cell usec);
+void sleep_nanos(cell nsec);
 
 void init_platform_globals();
 
index f51953e6ebf737337465103f9132990810b92244..a57db667c421b76c549ad604b0681cb735c59e70 100644 (file)
@@ -3,7 +3,7 @@
 namespace factor
 {
 
-s64 current_micros()
+u64 system_micros()
 {
        SYSTEMTIME st;
        FILETIME ft;
index f41262e54bb8d256a7dbdd62d7001d07018e9073..48da3fa5512e2d254125fa054dc220419dd3682c 100644 (file)
@@ -22,7 +22,7 @@ char *getenv(char *name);
 #define snprintf _snprintf
 #define snwprintf _snwprintf
 
-s64 current_micros();
+u64 system_micros();
 void c_to_factor_toplevel(cell quot);
 void open_console();
 
index 3feabfe8bc38de5bdfee3acf305c325b4dab945e..c46628d41e7f23d56ac42ebd7bda0cf65c5f536b 100755 (executable)
@@ -28,15 +28,15 @@ factor_vm *tls_vm()
        return vm;
 }
 
-s64 current_micros()
+u64 system_micros()
 {
        FILETIME t;
        GetSystemTimeAsFileTime(&t);
-       return (((s64)t.dwLowDateTime | (s64)t.dwHighDateTime<<32)
+       return (((u64)t.dwLowDateTime | (u64)t.dwHighDateTime<<32)
                - EPOCH_OFFSET) / 10;
 }
 
-u64 current_nanos()
+u64 nano_count()
 {
        LARGE_INTEGER count;
        LARGE_INTEGER frequency;
index fd24120b95f1a261bbd4e1e97c07c89bc2a0cb45..37591a529f15c019257635f660d2fffcede15b8f 100644 (file)
@@ -43,8 +43,8 @@ typedef wchar_t vm_char;
 inline static void init_signals() {}
 inline static void early_init() {}
 
-s64 current_micros();
-u64 current_nanos();
+u64 system_micros();
+u64 nano_count();
 long getpagesize();
 
 }
index ed877cb6450563f04e9a1d487160889282bcb99e..dc1ca8246db24328ee872acca8f175105b63c081 100644 (file)
@@ -66,8 +66,8 @@ PRIMITIVE_FORWARD(set_callstack)
 PRIMITIVE_FORWARD(exit)
 PRIMITIVE_FORWARD(data_room)
 PRIMITIVE_FORWARD(code_room)
-PRIMITIVE_FORWARD(micros)
-PRIMITIVE_FORWARD(nanos)
+PRIMITIVE_FORWARD(system_micros)
+PRIMITIVE_FORWARD(nano_count)
 PRIMITIVE_FORWARD(modify_code_heap)
 PRIMITIVE_FORWARD(dlopen)
 PRIMITIVE_FORWARD(dlsym)
@@ -203,8 +203,8 @@ const primitive_type primitives[] = {
        primitive_exit,
        primitive_data_room,
        primitive_code_room,
-       primitive_micros,
-       primitive_nanos,
+       primitive_system_micros,
+       primitive_nano_count,
        primitive_modify_code_heap,
        primitive_dlopen,
        primitive_dlsym,
index 81f155c57e9e1d23a2d6f482573719e418828d63..9203dcf1e96199447b670c55b7c6f8324d9f28be 100755 (executable)
@@ -8,14 +8,14 @@ void factor_vm::primitive_exit()
        exit(to_fixnum(dpop()));
 }
 
-void factor_vm::primitive_micros()
+void factor_vm::primitive_system_micros()
 {
-       box_unsigned_8(current_micros());
+       box_unsigned_8(system_micros());
 }
 
-void factor_vm::primitive_nanos()
+void factor_vm::primitive_nano_count()
 {
-       box_unsigned_8(current_nanos());
+       box_unsigned_8(nano_count());
 }
 
 void factor_vm::primitive_sleep()
index f96777613a9fccbdacf0e20346cf0a68de5f7221..4f2544db252aeba29115944dfa41e13718fd8e51 100755 (executable)
--- a/vm/vm.hpp
+++ b/vm/vm.hpp
@@ -117,8 +117,8 @@ struct factor_vm
 
        // run
        void primitive_exit();
-       void primitive_micros();
-       void primitive_nanos();
+       void primitive_system_micros();
+       void primitive_nano_count();
        void primitive_sleep();
        void primitive_set_slot();