From 6b6e56a179e1d7d08ac533827142e69055ad68ab Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Mon, 19 Oct 2009 22:17:02 -0400 Subject: [PATCH] change add-init-hook to add-startup-hook, new add-shutdown-hook word --- basis/alarms/alarms.factor | 2 +- basis/bootstrap/finish-bootstrap.factor | 2 +- basis/bootstrap/finish-staging.factor | 2 +- basis/calendar/model/model.factor | 2 +- basis/channels/remote/remote.factor | 2 +- basis/cocoa/application/application.factor | 2 +- basis/cocoa/cocoa.factor | 2 +- basis/cocoa/messages/messages.factor | 8 +++--- basis/command-line/command-line.factor | 2 +- .../core-foundation/fsevents/fsevents.factor | 2 +- basis/core-text/core-text.factor | 2 +- basis/core-text/fonts/fonts.factor | 2 +- basis/cpu/x86/features/features.factor | 2 +- basis/cpu/x86/x86.factor | 2 +- basis/environment/environment.factor | 2 +- basis/game/input/input.factor | 2 +- basis/io/launcher/launcher.factor | 2 +- basis/io/sockets/unix/unix.factor | 3 +- basis/io/thread/thread.factor | 2 +- basis/logging/server/server.factor | 2 +- basis/opengl/gl/extensions/extensions.factor | 2 +- basis/openssl/openssl.factor | 2 +- basis/pango/cairo/cairo.factor | 2 +- basis/pango/fonts/fonts.factor | 2 +- .../mersenne-twister/mersenne-twister.factor | 2 +- basis/random/unix/unix.factor | 15 ++++++++-- basis/random/windows/windows.factor | 8 +++++- basis/threads/threads-docs.factor | 2 +- basis/threads/threads.factor | 2 +- basis/tools/crossref/crossref.factor | 4 +-- basis/tools/deploy/shaker/shaker.factor | 28 +++++++++---------- basis/tools/deploy/shaker/strip-cocoa.factor | 4 +-- basis/tools/deprecation/deprecation.factor | 2 +- basis/tools/errors/model/model.factor | 2 +- basis/ui/backend/cocoa/cocoa.factor | 6 ++-- basis/ui/backend/cocoa/tools/tools.factor | 2 +- basis/ui/ui.factor | 2 +- basis/vocabs/cache/cache.factor | 2 +- basis/vocabs/refresh/monitor/monitor.factor | 2 +- basis/windows/com/wrapper/wrapper.factor | 4 +-- .../windows/dinput/constants/constants.factor | 2 +- basis/windows/fonts/fonts.factor | 2 +- basis/windows/uniscribe/uniscribe.factor | 5 +++- basis/windows/winsock/winsock.factor | 5 +++- core/alien/alien.factor | 2 +- core/alien/strings/strings.factor | 3 +- core/compiler/units/units.factor | 4 +-- core/destructors/destructors.factor | 2 +- core/init/init-docs.factor | 24 +++++++++++----- core/init/init.factor | 24 +++++++++++----- core/io/backend/backend.factor | 4 +-- core/io/files/files.factor | 2 +- core/source-files/errors/errors.factor | 4 +-- extra/site-watcher/site-watcher.factor | 2 +- 54 files changed, 134 insertions(+), 93 deletions(-) diff --git a/basis/alarms/alarms.factor b/basis/alarms/alarms.factor index 9943d39ad1..c29371d26f 100644 --- a/basis/alarms/alarms.factor +++ b/basis/alarms/alarms.factor @@ -75,7 +75,7 @@ ERROR: bad-alarm-frequency frequency ; [ alarm-thread-loop t ] "Alarms" spawn-server alarm-thread set-global ; -[ init-alarms ] "alarms" add-init-hook +[ init-alarms ] "alarms" add-startup-hook PRIVATE> diff --git a/basis/bootstrap/finish-bootstrap.factor b/basis/bootstrap/finish-bootstrap.factor index ab08aa87a9..65115fc2df 100644 --- a/basis/bootstrap/finish-bootstrap.factor +++ b/basis/bootstrap/finish-bootstrap.factor @@ -3,7 +3,7 @@ namespaces eval kernel vocabs.loader io ; [ boot - do-init-hooks + do-startup-hooks [ (command-line) parse-command-line load-vocab-roots diff --git a/basis/bootstrap/finish-staging.factor b/basis/bootstrap/finish-staging.factor index 49f504fd41..e75f0fa5c5 100644 --- a/basis/bootstrap/finish-staging.factor +++ b/basis/bootstrap/finish-staging.factor @@ -3,7 +3,7 @@ io ; [ boot - do-init-hooks + do-startup-hooks (command-line) parse-command-line "run" get run output-stream get [ stream-flush ] when* diff --git a/basis/calendar/model/model.factor b/basis/calendar/model/model.factor index 8665cc22ce..38ad986952 100644 --- a/basis/calendar/model/model.factor +++ b/basis/calendar/model/model.factor @@ -16,4 +16,4 @@ SYMBOL: time ] "Time model update" spawn drop ; f time set-global -[ time-thread ] "calendar.model" add-init-hook +[ time-thread ] "calendar.model" add-startup-hook diff --git a/basis/channels/remote/remote.factor b/basis/channels/remote/remote.factor index 6e10b23407..bf2438ac19 100644 --- a/basis/channels/remote/remote.factor +++ b/basis/channels/remote/remote.factor @@ -64,4 +64,4 @@ M: remote-channel from ( remote-channel -- value ) [ H{ } clone \ remote-channels set-global start-channel-node -] "channel-registry" add-init-hook +] "channel-registry" add-startup-hook diff --git a/basis/cocoa/application/application.factor b/basis/cocoa/application/application.factor index cbf8636a75..83213b47ba 100644 --- a/basis/cocoa/application/application.factor +++ b/basis/cocoa/application/application.factor @@ -49,7 +49,7 @@ TUPLE: objc-error alien reason ; M: objc-error summary ( error -- ) drop "Objective C exception" ; -[ [ objc-error ] 19 setenv ] "cocoa.application" add-init-hook +[ [ objc-error ] 19 setenv ] "cocoa.application" add-startup-hook : running.app? ( -- ? ) #! Test if we're running a .app. diff --git a/basis/cocoa/cocoa.factor b/basis/cocoa/cocoa.factor index ec5db31940..7f9d3f6814 100644 --- a/basis/cocoa/cocoa.factor +++ b/basis/cocoa/cocoa.factor @@ -27,7 +27,7 @@ SYMBOL: frameworks frameworks [ V{ } clone ] initialize -[ frameworks get [ load-framework ] each ] "cocoa" add-init-hook +[ frameworks get [ load-framework ] each ] "cocoa" add-startup-hook SYNTAX: FRAMEWORK: scan [ load-framework ] [ frameworks get push ] bi ; diff --git a/basis/cocoa/messages/messages.factor b/basis/cocoa/messages/messages.factor index c0d8939a7a..85cff72749 100755 --- a/basis/cocoa/messages/messages.factor +++ b/basis/cocoa/messages/messages.factor @@ -74,13 +74,13 @@ MACRO: (send) ( selector super? -- quot ) : super-send ( receiver args... selector -- return... ) t (send) ; inline ! Runtime introspection -SYMBOL: class-init-hooks +SYMBOL: class-startup-hooks -class-init-hooks [ H{ } clone ] initialize +class-startup-hooks [ H{ } clone ] initialize : (objc-class) ( name word -- class ) 2dup execute dup [ 2nip ] [ - drop over class-init-hooks get at [ call( -- ) ] when* + drop over class-startup-hooks get at [ call( -- ) ] when* 2dup execute dup [ 2nip ] [ 2drop "No such class: " prepend throw ] if @@ -218,7 +218,7 @@ ERROR: no-objc-type name ; : class-exists? ( string -- class ) objc_getClass >boolean ; : define-objc-class-word ( quot name -- ) - [ class-init-hooks get set-at ] + [ class-startup-hooks get set-at ] [ [ "cocoa.classes" create ] [ '[ _ objc-class ] ] bi (( -- class )) define-declared diff --git a/basis/command-line/command-line.factor b/basis/command-line/command-line.factor index 19421359a3..f1748d3708 100644 --- a/basis/command-line/command-line.factor +++ b/basis/command-line/command-line.factor @@ -69,4 +69,4 @@ SYMBOL: main-vocab-hook : ignore-cli-args? ( -- ? ) os macosx? "run" get "ui" = and ; -[ default-cli-args ] "command-line" add-init-hook +[ default-cli-args ] "command-line" add-startup-hook diff --git a/basis/core-foundation/fsevents/fsevents.factor b/basis/core-foundation/fsevents/fsevents.factor index 6f5484fb77..e7a7962e6e 100755 --- a/basis/core-foundation/fsevents/fsevents.factor +++ b/basis/core-foundation/fsevents/fsevents.factor @@ -156,7 +156,7 @@ SYMBOL: event-stream-callbacks [ event-stream-callbacks [ [ drop expired? not ] assoc-filter H{ } assoc-like ] change-global -] "core-foundation" add-init-hook +] "core-foundation" add-startup-hook : add-event-source-callback ( quot -- id ) event-stream-counter diff --git a/basis/core-text/core-text.factor b/basis/core-text/core-text.factor index 3459b368f7..d672815cbe 100644 --- a/basis/core-text/core-text.factor +++ b/basis/core-text/core-text.factor @@ -150,4 +150,4 @@ SYMBOL: cached-lines : cached-line ( font string -- line ) cached-lines get [ ] 2cache ; -[ cached-lines set-global ] "core-text" add-init-hook +[ cached-lines set-global ] "core-text" add-startup-hook diff --git a/basis/core-text/fonts/fonts.factor b/basis/core-text/fonts/fonts.factor index 5c57034632..63b9a0f6e1 100644 --- a/basis/core-text/fonts/fonts.factor +++ b/basis/core-text/fonts/fonts.factor @@ -127,4 +127,4 @@ MEMO: (cache-font-metrics) ( font -- metrics ) [ \ (cache-font) reset-memoized \ (cache-font-metrics) reset-memoized -] "core-text.fonts" add-init-hook +] "core-text.fonts" add-startup-hook diff --git a/basis/cpu/x86/features/features.factor b/basis/cpu/x86/features/features.factor index b21aa762d8..38364805eb 100644 --- a/basis/cpu/x86/features/features.factor +++ b/basis/cpu/x86/features/features.factor @@ -17,7 +17,7 @@ MEMO: sse-version ( -- n ) sse_version "sse-version" get string>number [ min ] when* ; -[ \ sse-version reset-memoized ] "cpu.x86.features" add-init-hook +[ \ sse-version reset-memoized ] "cpu.x86.features" add-startup-hook : sse? ( -- ? ) sse-version 10 >= ; : sse2? ( -- ? ) sse-version 20 >= ; diff --git a/basis/cpu/x86/x86.factor b/basis/cpu/x86/x86.factor index 5db2641907..e6c95fcbff 100644 --- a/basis/cpu/x86/x86.factor +++ b/basis/cpu/x86/x86.factor @@ -1362,7 +1362,7 @@ enable-fixnum-log2 flush 1 exit ] when - ] "cpu.x86" add-init-hook ; + ] "cpu.x86" add-startup-hook ; : enable-sse2 ( version -- ) 20 >= [ diff --git a/basis/environment/environment.factor b/basis/environment/environment.factor index e60a52c995..ccdbd66d96 100644 --- a/basis/environment/environment.factor +++ b/basis/environment/environment.factor @@ -32,4 +32,4 @@ HOOK: (set-os-envs) os ( seq -- ) os windows? ";" ":" ? split [ add-vocab-root ] each ] when* -] "environment" add-init-hook +] "environment" add-startup-hook diff --git a/basis/game/input/input.factor b/basis/game/input/input.factor index 377a89a884..25283df4bf 100755 --- a/basis/game/input/input.factor +++ b/basis/game/input/input.factor @@ -35,7 +35,7 @@ M: f (reset-game-input) ; : reset-game-input ( -- ) (reset-game-input) ; -[ reset-game-input ] "game-input" add-init-hook +[ reset-game-input ] "game-input" add-startup-hook PRIVATE> diff --git a/basis/io/launcher/launcher.factor b/basis/io/launcher/launcher.factor index 34325780c0..d1a41a1f09 100755 --- a/basis/io/launcher/launcher.factor +++ b/basis/io/launcher/launcher.factor @@ -75,7 +75,7 @@ SYMBOL: wait-flag [ H{ } clone processes set-global start-wait-thread -] "io.launcher" add-init-hook +] "io.launcher" add-startup-hook : process-started ( process handle -- ) >>handle diff --git a/basis/io/sockets/unix/unix.factor b/basis/io/sockets/unix/unix.factor index fa46a71ca0..583fd8fba9 100755 --- a/basis/io/sockets/unix/unix.factor +++ b/basis/io/sockets/unix/unix.factor @@ -113,7 +113,8 @@ SYMBOL: receive-buffer CONSTANT: packet-size 65536 -[ packet-size malloc receive-buffer set-global ] "io.sockets.unix" add-init-hook +[ packet-size malloc receive-buffer set-global ] "io.sockets.unix" add-startup-hook +[ receive-buffer get-global free ] "io.sockets.unix" add-shutdown-hook :: do-receive ( port -- packet sockaddr ) port addr>> empty-sockaddr/size :> len :> sockaddr diff --git a/basis/io/thread/thread.factor b/basis/io/thread/thread.factor index 88db135f44..994dcd9c50 100644 --- a/basis/io/thread/thread.factor +++ b/basis/io/thread/thread.factor @@ -17,4 +17,4 @@ SYMBOL: io-thread-running? [ t io-thread-running? set-global start-io-thread -] "io.thread" add-init-hook +] "io.thread" add-startup-hook diff --git a/basis/logging/server/server.factor b/basis/logging/server/server.factor index 848ad5d40e..f5539b2813 100644 --- a/basis/logging/server/server.factor +++ b/basis/logging/server/server.factor @@ -106,4 +106,4 @@ CONSTANT: keep-logs 10 [ H{ } clone log-files set-global log-server -] "logging" add-init-hook +] "logging" add-startup-hook diff --git a/basis/opengl/gl/extensions/extensions.factor b/basis/opengl/gl/extensions/extensions.factor index 6292a683e3..540fba40f0 100644 --- a/basis/opengl/gl/extensions/extensions.factor +++ b/basis/opengl/gl/extensions/extensions.factor @@ -19,7 +19,7 @@ SYMBOL: +gl-function-pointers+ : reset-gl-function-pointers ( -- ) 100 +gl-function-pointers+ set-global ; -[ reset-gl-function-pointers ] "opengl.gl" add-init-hook +[ reset-gl-function-pointers ] "opengl.gl" add-startup-hook reset-gl-function-pointers reset-gl-function-number-counter diff --git a/basis/openssl/openssl.factor b/basis/openssl/openssl.factor index 8f14c60e14..76806f9523 100644 --- a/basis/openssl/openssl.factor +++ b/basis/openssl/openssl.factor @@ -34,4 +34,4 @@ SYMBOL: ssl-initialized? t ssl-initialized? set-global ] unless ; -[ f ssl-initialized? set-global ] "openssl" add-init-hook +[ f ssl-initialized? set-global ] "openssl" add-startup-hook diff --git a/basis/pango/cairo/cairo.factor b/basis/pango/cairo/cairo.factor index 6fd8d57893..d6baaffe2e 100644 --- a/basis/pango/cairo/cairo.factor +++ b/basis/pango/cairo/cairo.factor @@ -240,4 +240,4 @@ SYMBOL: cached-layouts : cached-line ( font string -- line ) cached-layout layout>> first-line ; -[ cached-layouts set-global ] "pango.cairo" add-init-hook +[ cached-layouts set-global ] "pango.cairo" add-startup-hook diff --git a/basis/pango/fonts/fonts.factor b/basis/pango/fonts/fonts.factor index 280ddd20d6..31a51e3f12 100644 --- a/basis/pango/fonts/fonts.factor +++ b/basis/pango/fonts/fonts.factor @@ -111,4 +111,4 @@ MEMO: (cache-font-description) ( font -- description ) : cache-font-description ( font -- description ) strip-font-colors (cache-font-description) ; -[ \ (cache-font-description) reset-memoized ] "pango.fonts" add-init-hook +[ \ (cache-font-description) reset-memoized ] "pango.fonts" add-startup-hook diff --git a/basis/random/mersenne-twister/mersenne-twister.factor b/basis/random/mersenne-twister/mersenne-twister.factor index a0e40e5c38..90489d3052 100644 --- a/basis/random/mersenne-twister/mersenne-twister.factor +++ b/basis/random/mersenne-twister/mersenne-twister.factor @@ -79,5 +79,5 @@ M: mersenne-twister random-32* ( mt -- r ) [ default-mersenne-twister random-generator set-global -] "bootstrap.random" add-init-hook +] "bootstrap.random" add-startup-hook diff --git a/basis/random/unix/unix.factor b/basis/random/unix/unix.factor index 599cd5e0ad..b15b9ab8b9 100644 --- a/basis/random/unix/unix.factor +++ b/basis/random/unix/unix.factor @@ -1,7 +1,7 @@ ! Copyright (C) 2008 Doug Coleman ! See http://factorcode.org/license.txt for BSD license. USING: alien.c-types io io.files kernel namespaces random -io.encodings.binary init accessors system ; +io.encodings.binary init accessors system destructors ; IN: random.unix TUPLE: unix-random reader ; @@ -9,6 +9,8 @@ TUPLE: unix-random reader ; : ( path -- random ) binary unix-random boa ; +M: unix-random dispose reader>> dispose ; + M: unix-random random-bytes* ( n tuple -- byte-array ) reader>> stream-read ; @@ -16,10 +18,17 @@ os openbsd? [ [ "/dev/srandom" secure-random-generator set-global "/dev/arandom" system-random-generator set-global - ] "random.unix" add-init-hook + ] "random.unix" add-startup-hook ] [ [ "/dev/random" secure-random-generator set-global "/dev/urandom" system-random-generator set-global - ] "random.unix" add-init-hook + ] "random.unix" add-startup-hook ] if + +[ + [ + secure-random-generator get-global &dispose drop + system-random-generator get-global &dispose drop + ] with-destructors +] "random.unix" add-shutdown-hook diff --git a/basis/random/windows/windows.factor b/basis/random/windows/windows.factor index d959b191c9..c948fc01e4 100644 --- a/basis/random/windows/windows.factor +++ b/basis/random/windows/windows.factor @@ -65,5 +65,11 @@ M: windows-rng random-bytes* ( n tuple -- bytes ) [ MS_STRONG_PROV PROV_RSA_FULL ] [ drop MS_ENH_RSA_AES_PROV PROV_RSA_AES ] recover secure-random-generator set-global +] "random.windows" add-startup-hook -] "random.windows" add-init-hook +[ + [ + system-random-generator get-global &dispose drop + secure-random-generator get-global &dispose drop + ] with-destructors +] "random.windows" add-shutdown-hook diff --git a/basis/threads/threads-docs.factor b/basis/threads/threads-docs.factor index 8956051b25..85952ccd91 100644 --- a/basis/threads/threads-docs.factor +++ b/basis/threads/threads-docs.factor @@ -16,7 +16,7 @@ ARTICLE: "threads-start/stop" "Starting and stopping threads" } "Threads stop either when the quotation given to " { $link spawn } " returns, or when the following word is called:" { $subsections stop } -"If the image is saved and started again, all runnable threads are stopped. Vocabularies wishing to have a background thread always running should use " { $link add-init-hook } "." ; +"If the image is saved and started again, all runnable threads are stopped. Vocabularies wishing to have a background thread always running should use " { $link add-startup-hook } "." ; ARTICLE: "threads-yield" "Yielding and suspending threads" "Yielding to other threads:" diff --git a/basis/threads/threads.factor b/basis/threads/threads.factor index dec44625f7..b7e0e1b87f 100644 --- a/basis/threads/threads.factor +++ b/basis/threads/threads.factor @@ -225,4 +225,4 @@ GENERIC: error-in-thread ( error thread -- ) PRIVATE> -[ init-threads ] "threads" add-init-hook +[ init-threads ] "threads" add-startup-hook diff --git a/basis/tools/crossref/crossref.factor b/basis/tools/crossref/crossref.factor index beaf1c0673..f5d4b55129 100644 --- a/basis/tools/crossref/crossref.factor +++ b/basis/tools/crossref/crossref.factor @@ -135,6 +135,6 @@ SINGLETON: invalidate-crossref M: invalidate-crossref definitions-changed 2drop crossref global delete-at ; -[ invalidate-crossref add-definition-observer ] "tools.crossref" add-init-hook +[ invalidate-crossref add-definition-observer ] "tools.crossref" add-startup-hook -PRIVATE> \ No newline at end of file +PRIVATE> diff --git a/basis/tools/deploy/shaker/shaker.factor b/basis/tools/deploy/shaker/shaker.factor index 0c703cae13..470194ed9d 100755 --- a/basis/tools/deploy/shaker/shaker.factor +++ b/basis/tools/deploy/shaker/shaker.factor @@ -23,9 +23,9 @@ IN: tools.deploy.shaker : add-command-line-hook ( -- ) [ (command-line) command-line set-global ] "command-line" - init-hooks get set-at ; + startup-hooks get set-at ; -: strip-init-hooks ( -- ) +: strip-startup-hooks ( -- ) "Stripping startup hooks" show { "alien.strings" @@ -34,17 +34,17 @@ IN: tools.deploy.shaker "environment" "libc" } - [ init-hooks get delete-at ] each + [ startup-hooks get delete-at ] each deploy-threads? get [ - "threads" init-hooks get delete-at + "threads" startup-hooks get delete-at ] unless native-io? [ - "io.thread" init-hooks get delete-at + "io.thread" startup-hooks get delete-at ] unless strip-io? [ - "io.files" init-hooks get delete-at - "io.backend" init-hooks get delete-at - "io.thread" init-hooks get delete-at + "io.files" startup-hooks get delete-at + "io.backend" startup-hooks get delete-at + "io.thread" startup-hooks get delete-at ] when strip-dictionary? [ { @@ -52,7 +52,7 @@ IN: tools.deploy.shaker "vocabs" "vocabs.cache" "source-files.errors" - } [ init-hooks get delete-at ] each + } [ startup-hooks get delete-at ] each ] when ; : strip-debugger ( -- ) @@ -293,7 +293,7 @@ IN: tools.deploy.shaker continuations:error-continuation continuations:error-thread continuations:restarts - init:init-hooks + init:startup-hooks source-files:source-files input-stream output-stream @@ -448,7 +448,7 @@ SYMBOL: deploy-vocab : deploy-boot-quot ( word -- ) [ [ boot ] % - init-hooks get values concat % + startup-hooks get values concat % strip-debugger? [ , ] [ ! Don't reference 'try' directly since we don't want ! to pull in the debugger and prettyprinter into every @@ -467,7 +467,7 @@ SYMBOL: deploy-vocab ] [ ] make set-boot-quot ; -: init-stripper ( -- ) +: startup-stripper ( -- ) t "quiet" set-global f output-stream set-global ; @@ -506,7 +506,7 @@ SYMBOL: deploy-vocab [ clear-megamorphic-cache ] each ; : strip ( -- ) - init-stripper + startup-stripper strip-libc strip-destructors strip-call @@ -514,7 +514,7 @@ SYMBOL: deploy-vocab strip-debugger strip-specialized-arrays compute-next-methods - strip-init-hooks + strip-startup-hooks add-command-line-hook strip-c-io strip-default-methods diff --git a/basis/tools/deploy/shaker/strip-cocoa.factor b/basis/tools/deploy/shaker/strip-cocoa.factor index 133308b732..d5c5bd54da 100644 --- a/basis/tools/deploy/shaker/strip-cocoa.factor +++ b/basis/tools/deploy/shaker/strip-cocoa.factor @@ -17,7 +17,7 @@ IN: cocoa.application : objc-error ( error -- ) die ; -[ [ die ] 19 setenv ] "cocoa.application" add-init-hook +[ [ die ] 19 setenv ] "cocoa.application" add-startup-hook H{ } clone \ pool [ global [ @@ -46,4 +46,4 @@ H{ } clone \ pool [ \ make-prepare-send reset-memoized \ reset-memoized -\ (send) def>> second clear-assoc \ No newline at end of file +\ (send) def>> second clear-assoc diff --git a/basis/tools/deprecation/deprecation.factor b/basis/tools/deprecation/deprecation.factor index 0ee60b06b5..8dbfda3011 100644 --- a/basis/tools/deprecation/deprecation.factor +++ b/basis/tools/deprecation/deprecation.factor @@ -73,6 +73,6 @@ M: deprecation-observer definitions-changed [ drop initialize-deprecation-notes ] if ; [ \ deprecation-observer add-definition-observer ] -"tools.deprecation" add-init-hook +"tools.deprecation" add-startup-hook initialize-deprecation-notes diff --git a/basis/tools/errors/model/model.factor b/basis/tools/errors/model/model.factor index c874363fe6..b41d236fd7 100644 --- a/basis/tools/errors/model/model.factor +++ b/basis/tools/errors/model/model.factor @@ -14,5 +14,5 @@ SINGLETON: updater M: updater errors-changed drop f (error-list-model) get-global set-model ; -[ updater add-error-observer ] "ui.tools.error-list" add-init-hook +[ updater add-error-observer ] "ui.tools.error-list" add-startup-hook diff --git a/basis/ui/backend/cocoa/cocoa.factor b/basis/ui/backend/cocoa/cocoa.factor index 0213b8433c..84e55ed134 100755 --- a/basis/ui/backend/cocoa/cocoa.factor +++ b/basis/ui/backend/cocoa/cocoa.factor @@ -225,9 +225,9 @@ CLASS: { : install-app-delegate ( -- ) NSApp FactorApplicationDelegate install-delegate ; -SYMBOL: cocoa-init-hook +SYMBOL: cocoa-startup-hook -cocoa-init-hook [ +cocoa-startup-hook [ [ "MiniFactor.nib" load-nib install-app-delegate ] ] initialize @@ -235,7 +235,7 @@ M: cocoa-ui-backend (with-ui) "UI" assert.app [ [ init-clipboard - cocoa-init-hook get call( -- ) + cocoa-startup-hook get call( -- ) start-ui f io-thread-running? set-global init-thread-timer diff --git a/basis/ui/backend/cocoa/tools/tools.factor b/basis/ui/backend/cocoa/tools/tools.factor index b8c01f0bd9..ddcf79208d 100644 --- a/basis/ui/backend/cocoa/tools/tools.factor +++ b/basis/ui/backend/cocoa/tools/tools.factor @@ -100,4 +100,4 @@ FUNCTION: void NSUpdateDynamicServices ; install-app-delegate "Factor.nib" load-nib register-services -] cocoa-init-hook set-global +] cocoa-startup-hook set-global diff --git a/basis/ui/ui.factor b/basis/ui/ui.factor index aa3c549cf0..c75f5956b3 100644 --- a/basis/ui/ui.factor +++ b/basis/ui/ui.factor @@ -236,7 +236,7 @@ M: object close-window [ f \ ui-running set-global ui-notify-flag set-global -] "ui" add-init-hook +] "ui" add-startup-hook : with-ui ( quot -- ) ui-running? [ call( -- ) ] [ '[ init-ui @ ] (with-ui) ] if ; diff --git a/basis/vocabs/cache/cache.factor b/basis/vocabs/cache/cache.factor index 24ccd391f1..1f62f02dde 100644 --- a/basis/vocabs/cache/cache.factor +++ b/basis/vocabs/cache/cache.factor @@ -18,4 +18,4 @@ M: cache-observer vocabs-changed drop reset-cache ; [ f changed-vocabs set-global cache-observer add-vocab-observer -] "vocabs.cache" add-init-hook \ No newline at end of file +] "vocabs.cache" add-startup-hook diff --git a/basis/vocabs/refresh/monitor/monitor.factor b/basis/vocabs/refresh/monitor/monitor.factor index 1445b9f882..1bf73862e6 100644 --- a/basis/vocabs/refresh/monitor/monitor.factor +++ b/basis/vocabs/refresh/monitor/monitor.factor @@ -56,4 +56,4 @@ TR: convert-separators "/\\" ".." ; [ "-no-monitors" (command-line) member? [ start-monitor-thread ] unless -] "vocabs.refresh.monitor" add-init-hook +] "vocabs.refresh.monitor" add-startup-hook diff --git a/basis/windows/com/wrapper/wrapper.factor b/basis/windows/com/wrapper/wrapper.factor index 27672df833..c007a8c400 100755 --- a/basis/windows/com/wrapper/wrapper.factor +++ b/basis/windows/com/wrapper/wrapper.factor @@ -141,11 +141,11 @@ unless dup callbacks>> (callbacks>vtbls) >>vtbls f >>disposed drop ; -: (init-hook) ( -- ) +: com-startup-hook ( -- ) +live-wrappers+ get-global [ (allocate-wrapper) ] each H{ } +wrapped-objects+ set-global ; -[ (init-hook) ] "windows.com.wrapper" add-init-hook +[ com-startup-hook ] "windows.com.wrapper" add-startup-hook PRIVATE> diff --git a/basis/windows/dinput/constants/constants.factor b/basis/windows/dinput/constants/constants.factor index 3c0509c49d..ab37f96c2a 100755 --- a/basis/windows/dinput/constants/constants.factor +++ b/basis/windows/dinput/constants/constants.factor @@ -832,7 +832,7 @@ M: array array-base-type first ; define-guid-constants define-format-constants ; -[ define-constants ] "windows.dinput.constants" add-init-hook +[ define-constants ] "windows.dinput.constants" add-startup-hook : uninitialize ( variable quot -- ) '[ _ when* f ] change-global ; inline diff --git a/basis/windows/fonts/fonts.factor b/basis/windows/fonts/fonts.factor index 9e113e8c3b..65a08ce3c7 100755 --- a/basis/windows/fonts/fonts.factor +++ b/basis/windows/fonts/fonts.factor @@ -37,7 +37,7 @@ MEMO:: (cache-font) ( font -- HFONT ) : cache-font ( font -- HFONT ) strip-font-colors (cache-font) ; -[ \ (cache-font) reset-memoized ] "windows.fonts" add-init-hook +[ \ (cache-font) reset-memoized ] "windows.fonts" add-startup-hook : TEXTMETRIC>metrics ( TEXTMETRIC -- metrics ) [ metrics new 0 >>width ] dip { diff --git a/basis/windows/uniscribe/uniscribe.factor b/basis/windows/uniscribe/uniscribe.factor index 9555927ab1..1651e8b3d8 100755 --- a/basis/windows/uniscribe/uniscribe.factor +++ b/basis/windows/uniscribe/uniscribe.factor @@ -114,4 +114,7 @@ SYMBOL: cached-script-strings cached-script-strings get-global [ ] 2cache ; [ cached-script-strings set-global ] -"windows.uniscribe" add-init-hook +"windows.uniscribe" add-startup-hook + +[ cached-script-strings get-global dispose ] +"windows.uniscribe" add-shutdown-hook diff --git a/basis/windows/winsock/winsock.factor b/basis/windows/winsock/winsock.factor index 7bd86c8e47..b8d1f099d2 100755 --- a/basis/windows/winsock/winsock.factor +++ b/basis/windows/winsock/winsock.factor @@ -442,4 +442,7 @@ CONSTANT: WSAID_CONNECTEX GUID: {25a207b9-ddf3-4660-8ee9-76e58c74063e} : init-winsock ( -- ) HEX: 0202 WSAStartup winsock-return-check ; -[ init-winsock ] "windows.winsock" add-init-hook +: shutdown-winsock ( -- ) WSACleanup winsock-return-check ; + +[ init-winsock ] "windows.winsock" add-startup-hook +[ shutdown-winsock ] "windows.winsock" add-shutdown-hook diff --git a/core/alien/alien.factor b/core/alien/alien.factor index 3f2b5f95bf..368f0b25e7 100644 --- a/core/alien/alien.factor +++ b/core/alien/alien.factor @@ -72,7 +72,7 @@ ERROR: alien-invoke-error library symbol ; ! cleared on startup. SYMBOL: callbacks -[ H{ } clone callbacks set-global ] "alien" add-init-hook +[ H{ } clone callbacks set-global ] "alien" add-startup-hook symbol [ string>symbol* ] map ; [ 8 getenv utf8 alien>string string>cpu \ cpu set-global 9 getenv utf8 alien>string string>os \ os set-global -] "alien.strings" add-init-hook - +] "alien.strings" add-startup-hook diff --git a/core/compiler/units/units.factor b/core/compiler/units/units.factor index f1f9131f08..ac1c9627ac 100644 --- a/core/compiler/units/units.factor +++ b/core/compiler/units/units.factor @@ -59,11 +59,11 @@ SYMBOL: definition-observers GENERIC: definitions-changed ( assoc obj -- ) [ V{ } clone definition-observers set-global ] -"compiler.units" add-init-hook +"compiler.units" add-startup-hook ! This goes here because vocabs cannot depend on init [ V{ } clone vocab-observers set-global ] -"vocabs" add-init-hook +"vocabs" add-startup-hook : add-definition-observer ( obj -- ) definition-observers get push ; diff --git a/core/destructors/destructors.factor b/core/destructors/destructors.factor index 3e57f498af..7b10a75212 100644 --- a/core/destructors/destructors.factor +++ b/core/destructors/destructors.factor @@ -6,7 +6,7 @@ IN: destructors SYMBOL: disposables -[ H{ } clone disposables set-global ] "destructors" add-init-hook +[ H{ } clone disposables set-global ] "destructors" add-startup-hook ERROR: already-unregistered disposable ; diff --git a/core/init/init-docs.factor b/core/init/init-docs.factor index e76b6e8fee..edee683bde 100644 --- a/core/init/init-docs.factor +++ b/core/init/init-docs.factor @@ -15,29 +15,39 @@ HELP: set-boot-quot { $description "Sets the initial quotation called by the VM on startup. This quotation must begin with a call to " { $link boot } ". The image must be saved for changes to the boot quotation to take effect." } { $notes "The " { $link "tools.deploy" } " tool uses this word." } ; -HELP: init-hooks +HELP: startup-hooks { $var-description "An association list mapping string identifiers to quotations to be run on startup." } ; -HELP: do-init-hooks +HELP: shutdown-hooks +{ $var-description "An association list mapping string identifiers to quotations to be run on shutdown." } ; + +HELP: do-startup-hooks { $description "Calls all initialization hook quotations." } ; -HELP: add-init-hook +HELP: do-shutdown-hooks +{ $description "Calls all shutdown hook quotations." } ; + +HELP: add-startup-hook { $values { "quot" quotation } { "name" string } } { $description "Registers a startup hook. The hook will always run when Factor is started. If the hook was not already defined, this word also calls it immediately." } ; -{ init-hooks do-init-hooks add-init-hook } related-words +{ startup-hooks do-startup-hooks add-startup-hook add-shutdown-hook do-shutdown-hooks shutdown-hooks } related-words ARTICLE: "init" "Initialization and startup" "When Factor starts, the first thing it does is call a word:" { $subsections boot } "Next, initialization hooks are called:" -{ $subsections do-init-hooks } +{ $subsections do-startup-hooks } "Initialization hooks can be defined:" -{ $subsections add-init-hook } +{ $subsections add-startup-hook } +"Corresponding shutdown hooks may also be defined:" +{ $subsections add-shutdown-hook } "The boot quotation can be changed:" { $subsections boot-quot set-boot-quot -} ; +} +"When quitting Factor, shutdown hooks are called:" +{ $subsection do-shutdown-hooks } ; ABOUT: "init" diff --git a/core/init/init.factor b/core/init/init.factor index 5d8e88b85f..540768ee63 100644 --- a/core/init/init.factor +++ b/core/init/init.factor @@ -4,16 +4,26 @@ USING: continuations continuations.private kernel kernel.private sequences assocs namespaces namespaces.private ; IN: init -SYMBOL: init-hooks +SYMBOL: startup-hooks +SYMBOL: shutdown-hooks -init-hooks global [ drop V{ } clone ] cache drop +startup-hooks global [ drop V{ } clone ] cache drop +shutdown-hooks global [ drop V{ } clone ] cache drop -: do-init-hooks ( -- ) - init-hooks get [ nip call( -- ) ] assoc-each ; +: do-hooks ( assoc -- ) + [ nip call( -- ) ] assoc-each ; -: add-init-hook ( quot name -- ) - dup init-hooks get at [ over call( -- ) ] unless - init-hooks get set-at ; +: do-startup-hooks ( -- ) startup-hooks get do-hooks ; + +: do-shutdown-hooks ( -- ) shutdown-hooks get do-hooks ; + +: add-startup-hook ( quot name -- ) + startup-hooks get + [ at [ drop ] [ call( -- ) ] if ] + [ set-at ] 3bi ; + +: add-shutdown-hook ( quot name -- ) + shutdown-hooks get set-at ; : boot ( -- ) init-namespaces init-catchstack init-error-handler ; diff --git a/core/io/backend/backend.factor b/core/io/backend/backend.factor index 494ccbff22..ee50500754 100644 --- a/core/io/backend/backend.factor +++ b/core/io/backend/backend.factor @@ -29,9 +29,9 @@ M: object normalize-directory normalize-path ; : set-io-backend ( io-backend -- ) io-backend set-global init-io init-stdio - "io.files" init-hooks get at call( -- ) ; + "io.files" startup-hooks get at call( -- ) ; ! Note that we have 'alien' in our using list so that the alien ! init hook runs before this one. [ init-io embedded? [ init-stdio ] unless ] -"io.backend" add-init-hook +"io.backend" add-startup-hook diff --git a/core/io/files/files.factor b/core/io/files/files.factor index 6779c6d094..9824fba18c 100644 --- a/core/io/files/files.factor +++ b/core/io/files/files.factor @@ -60,4 +60,4 @@ PRIVATE> 13 getenv alien>native-string cwd prepend-path \ image set-global 14 getenv alien>native-string cwd prepend-path \ vm set-global image parent-directory "resource-path" set-global -] "io.files" add-init-hook +] "io.files" add-startup-hook diff --git a/core/source-files/errors/errors.factor b/core/source-files/errors/errors.factor index 93078c162b..f5c41285ee 100644 --- a/core/source-files/errors/errors.factor +++ b/core/source-files/errors/errors.factor @@ -67,7 +67,7 @@ GENERIC: errors-changed ( observer -- ) SYMBOL: error-observers -[ V{ } clone error-observers set-global ] "source-files.errors" add-init-hook +[ V{ } clone error-observers set-global ] "source-files.errors" add-startup-hook : add-error-observer ( observer -- ) error-observers get push ; @@ -86,4 +86,4 @@ SYMBOL: error-observers error-types get [ second forget-quot>> dup [ call( definition -- ) ] [ 2drop ] if - ] with each ; \ No newline at end of file + ] with each ; diff --git a/extra/site-watcher/site-watcher.factor b/extra/site-watcher/site-watcher.factor index 535c8cd626..dcae438679 100644 --- a/extra/site-watcher/site-watcher.factor +++ b/extra/site-watcher/site-watcher.factor @@ -10,7 +10,7 @@ SYMBOL: site-watcher-frequency 5 minutes site-watcher-frequency set-global SYMBOL: running-site-watcher -[ f running-site-watcher set-global ] "site-watcher" add-init-hook +[ f running-site-watcher set-global ] "site-watcher" add-startup-hook