Skip to content

Commit

Permalink
core/basis/extra: using STARTUP-HOOK: and SHUTDOWN-HOOK:
Browse files Browse the repository at this point in the history
  • Loading branch information
mrjbq7 committed Jan 25, 2022
1 parent f099050 commit 288d7e4
Show file tree
Hide file tree
Showing 53 changed files with 99 additions and 104 deletions.
4 changes: 2 additions & 2 deletions basis/channels/remote/remote.factor
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ M: remote-channel to
M: remote-channel from
[ id>> from-message boa ] keep send-message ;

[
STARTUP-HOOK: [
H{ } clone \ remote-channels set-global
start-channel-node
] "channel-registry" add-startup-hook
]
2 changes: 1 addition & 1 deletion basis/cocoa/cocoa.factor
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ SYMBOL: frameworks

frameworks [ V{ } clone ] initialize

[ frameworks get [ load-framework ] each ] "cocoa" add-startup-hook
STARTUP-HOOK: [ frameworks get [ load-framework ] each ]

SYNTAX: FRAMEWORK: scan-token [ load-framework ] [ frameworks get push ] bi ;

Expand Down
4 changes: 2 additions & 2 deletions basis/command-line/command-line.factor
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,9 @@ SYMBOL: main-vocab-hook
main-vocab "run" set
] with-global ;

[
STARTUP-HOOK: [
H{ } user-init-errors set-global
default-cli-args
] "command-line" add-startup-hook
]

{ "debugger" "command-line" } "command-line.debugger" require-when
4 changes: 2 additions & 2 deletions basis/concurrency/distributed/distributed.factor
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ M: thread (serialize)
: stop-node ( -- )
f local-node get insecure>> send-remote-message ;

[
STARTUP-HOOK: [
H{ } clone \ registered-remote-threads set-global
H{ } clone \ thread-connections set-global
] "remote-thread-registry" add-startup-hook
]
4 changes: 2 additions & 2 deletions basis/core-foundation/fsevents/fsevents.factor
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,10 @@ SYMBOL: event-stream-callbacks
: event-stream-counter ( -- n )
\ event-stream-counter counter ;

[
STARTUP-HOOK: [
event-stream-callbacks
[ [ drop expired? ] H{ } assoc-reject-as ] change-global
] "core-foundation" add-startup-hook
]

: add-event-source-callback ( quot -- id )
event-stream-counter <alien>
Expand Down
4 changes: 2 additions & 2 deletions basis/core-foundation/run-loop/run-loop.factor
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ SYMBOL: run-loop
] change-timers drop ;

SYMBOL: thread-timer
[ f thread-timer set-global ]
"core-foundation.run-loop" add-startup-hook

STARTUP-HOOK: [ f thread-timer set-global ]

: (reset-thread-timer) ( timer -- )
sleep-time
Expand Down
2 changes: 1 addition & 1 deletion basis/core-text/core-text.factor
Original file line number Diff line number Diff line change
Expand Up @@ -172,4 +172,4 @@ SYMBOL: cached-lines
: cached-line ( font string -- line )
cached-lines get-global [ <line> ] 2cache ;

[ <cache-assoc> cached-lines set-global ] "core-text" add-startup-hook
STARTUP-HOOK: [ <cache-assoc> cached-lines set-global ]
4 changes: 2 additions & 2 deletions basis/core-text/fonts/fonts.factor
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ MEMO: (cache-font-metrics) ( name size traits -- metrics )
: cache-font-metrics ( font -- metrics )
[ name>> ] [ size>> ] [ font-traits ] tri (cache-font-metrics) ;

[
STARTUP-HOOK: [
\ (cache-font) reset-memoized
\ (cache-font-metrics) reset-memoized
] "core-text.fonts" add-startup-hook
]
5 changes: 3 additions & 2 deletions basis/cpu/x86/features/features.factor
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,9 @@ HOOK: (cpuid) cpu ( rax rcx regs -- )
MEMO: enable-popcnt? ( -- ? )
popcnt? "disable-popcnt" get not and ;

[ { sse-version enable-popcnt? } [ reset-memoized ] each ]
"cpu.x86.features" add-startup-hook
STARTUP-HOOK: [
{ sse-version enable-popcnt? } [ reset-memoized ] each
]

: sse-string ( version -- string )
{
Expand Down
7 changes: 3 additions & 4 deletions basis/environment/environment.factor
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,9 @@ HOOK: set-os-envs-pointer os ( malloc -- )
{ [ os windows? ] [ "environment.windows" require ] }
} cond

[
"FACTOR_ROOTS" os-env
[
STARTUP-HOOK: [
"FACTOR_ROOTS" os-env [
os windows? ";" ":" ? split
[ add-vocab-root ] each
] when*
] "environment" add-startup-hook
]
5 changes: 3 additions & 2 deletions basis/game/input/input.factor
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ M: f (reset-game-input) ;
: reset-game-input ( -- )
(reset-game-input) ;

[ reset-game-input ] "game-input" add-startup-hook

PRIVATE>

STARTUP-HOOK: reset-game-input

ERROR: game-input-not-open ;

: open-game-input ( -- )
Expand All @@ -48,6 +48,7 @@ ERROR: game-input-not-open ;
] unless
game-input-opened [ 1 + ] change-global
reset-mouse ;

: close-game-input ( -- )
game-input-opened [
dup zero? [ game-input-not-open ] when
Expand Down
3 changes: 1 addition & 2 deletions basis/io/backend/unix/freebsd/freebsd.factor
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,4 @@ M: freebsd init-io

freebsd set-io-backend

[ start-signal-pipe-thread ]
"io.backend.unix:signal-pipe-thread" add-startup-hook
STARTUP-HOOK: start-signal-pipe-thread
2 changes: 1 addition & 1 deletion basis/io/backend/unix/linux/linux.factor
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ M: linux init-io

linux set-io-backend

[ start-signal-pipe-thread ] "io.backend.unix:signal-pipe-thread" add-startup-hook
STARTUP-HOOK: start-signal-pipe-thread
3 changes: 1 addition & 2 deletions basis/io/backend/unix/macosx/macosx.factor
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,4 @@ M: macosx init-io

macosx set-io-backend

[ start-signal-pipe-thread ]
"io.backend.unix:signal-pipe-thread" add-startup-hook
STARTUP-HOOK: start-signal-pipe-thread
4 changes: 2 additions & 2 deletions basis/io/files/temp/temp.factor
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ SYMBOL: current-cache-directory
{ [ os unix? ] [ "io.files.temp.unix" ] }
} cond require

[
STARTUP-HOOK: [
default-temp-directory dup make-directories
current-temp-directory set-global

default-cache-directory dup make-directories
current-cache-directory set-global
] "io.files.temp" add-startup-hook
]
4 changes: 2 additions & 2 deletions basis/io/launcher/launcher.factor
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,10 @@ SYMBOL: wait-delay
5 wait-delay set-global
[ wait-loop t ] "Process wait" spawn-server drop ;

[
STARTUP-HOOK: [
H{ } clone processes set-global
start-wait-thread
] "io.launcher" add-startup-hook
]

: process-started ( process handle -- )
>>handle
Expand Down
3 changes: 1 addition & 2 deletions basis/io/sockets/sockets.factor
Original file line number Diff line number Diff line change
Expand Up @@ -382,8 +382,7 @@ CONSTANT: datagram-size 65536
MEMO: ipv6-supported? ( -- ? )
[ "::1" 0 <inet6> binary <server> dispose t ] [ drop f ] recover ;

[ \ ipv6-supported? reset-memoized ]
"io.sockets:ipv6-supported?" add-startup-hook
STARTUP-HOOK: [ \ ipv6-supported? reset-memoized ]

GENERIC: resolve-host ( addrspec -- seq )

Expand Down
2 changes: 1 addition & 1 deletion basis/io/thread/thread.factor
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ M: io-thread error-in-thread die drop rethrow ;
: stop-io-thread ( -- )
f io-thread-running? set-global ;

[ start-io-thread ] "io.thread" add-startup-hook
STARTUP-HOOK: start-io-thread
4 changes: 2 additions & 2 deletions basis/logging/server/server.factor
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ CONSTANT: keep-logs 10
"Log server" spawn-server
"log-server" set-global ;

[
STARTUP-HOOK: [
H{ } clone log-files set-global
log-server
] "logging" add-startup-hook
]
3 changes: 2 additions & 1 deletion basis/opengl/gl/extensions/extensions.factor
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ SYMBOL: +gl-function-pointers+
: reset-gl-function-pointers ( -- )
100 <hashtable> +gl-function-pointers+ set-global ;

[ reset-gl-function-pointers ] "opengl.gl" add-startup-hook
STARTUP-HOOK: reset-gl-function-pointers

reset-gl-function-pointers
reset-gl-function-number-counter

Expand Down
2 changes: 1 addition & 1 deletion basis/opengl/opengl.factor
Original file line number Diff line number Diff line change
Expand Up @@ -253,4 +253,4 @@ MACRO: set-draw-buffers ( buffers -- quot )
GL_MODELVIEW glMatrixMode
glLoadIdentity ;

[ f gl-scale-factor set-global ] "opengl" add-startup-hook
STARTUP-HOOK: [ f gl-scale-factor set-global ]
2 changes: 1 addition & 1 deletion basis/openssl/openssl.factor
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,4 @@ SINGLETON: openssl
t ssl-initialized? set-global
] unless ;

[ f ssl-initialized? set-global ] "openssl" add-startup-hook
STARTUP-HOOK: [ f ssl-initialized? set-global ]
4 changes: 2 additions & 2 deletions basis/random/mersenne-twister/mersenne-twister.factor
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,6 @@ M: mersenne-twister random-32*
: default-mersenne-twister ( -- mersenne-twister )
nano-count <mersenne-twister> ;

[
STARTUP-HOOK: [
default-mersenne-twister random-generator set-global
] "bootstrap.random" add-startup-hook
]
11 changes: 7 additions & 4 deletions basis/random/unix/unix.factor
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ M: unix-random random-bytes*

HINTS: M\ unix-random random-bytes* { fixnum unix-random } ;

[
"/dev/random" <unix-random> &dispose secure-random-generator set-global
"/dev/urandom" <unix-random> &dispose system-random-generator set-global
] "random.unix" add-startup-hook
STARTUP-HOOK: [
"/dev/random" <unix-random> &dispose
secure-random-generator set-global

"/dev/urandom" <unix-random> &dispose
system-random-generator set-global
]
4 changes: 2 additions & 2 deletions basis/random/windows/windows.factor
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ M: windows-crypto-context random-bytes*
[ first2 <windows-crypto-context> ] attempt-all
] [ 2drop f ] recover ;

[
STARTUP-HOOK: [
{
${ MS_ENHANCED_PROV PROV_RSA_FULL }
${ MS_DEF_PROV PROV_RSA_FULL }
Expand All @@ -66,4 +66,4 @@ M: windows-crypto-context random-bytes*
${ MS_STRONG_PROV PROV_RSA_FULL }
${ MS_ENH_RSA_AES_PROV PROV_RSA_AES }
} try-crypto-providers secure-random-generator set-global
] "random.windows" add-startup-hook
]
2 changes: 1 addition & 1 deletion basis/threads/threads.factor
Original file line number Diff line number Diff line change
Expand Up @@ -262,4 +262,4 @@ M: real sleep

PRIVATE>

[ init-threads ] "threads" add-startup-hook
STARTUP-HOOK: init-threads
2 changes: 1 addition & 1 deletion basis/tools/crossref/crossref.factor
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,6 @@ M: invalidate-crossref definitions-changed
drop [ null? not ] [ not ] bi or
[ f crossref set-global ] when ;

[ invalidate-crossref add-definition-observer ] "tools.crossref" add-startup-hook
STARTUP-HOOK: [ invalidate-crossref add-definition-observer ]

PRIVATE>
3 changes: 1 addition & 2 deletions basis/tools/deprecation/deprecation.factor
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ M: deprecation-observer definitions-changed
[ [ check-deprecations ] each ]
[ drop initialize-deprecation-notes ] if ;

[ deprecation-observer add-definition-observer ]
"tools.deprecation" add-startup-hook
STARTUP-HOOK: [ deprecation-observer add-definition-observer ]

initialize-deprecation-notes
4 changes: 2 additions & 2 deletions basis/ui/text/pango/pango.factor
Original file line number Diff line number Diff line change
Expand Up @@ -204,9 +204,9 @@ M: pango-renderer line-metrics
[ cached-layout metrics>> ]
if-empty ;

[
STARTUP-HOOK: [
\ (cache-font-description) reset-memoized
<cache-assoc> cached-layouts set-global
] "ui.text.pango" add-startup-hook
]

pango-renderer font-renderer set-global
4 changes: 2 additions & 2 deletions basis/ui/tools/error-list/error-list.factor
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ M: error-list-updater errors-changed

\ show-error-list H{ { +nullary+ t } } define-command

[
STARTUP-HOOK: [
f <model> 100 milliseconds <delay> error-list-model set-global
error-list-updater add-error-observer
] "ui.tools.error-list" add-startup-hook
]
4 changes: 2 additions & 2 deletions basis/ui/ui.factor
Original file line number Diff line number Diff line change
Expand Up @@ -208,10 +208,10 @@ HOOK: close-window ui-backend ( gadget -- )
M: object close-window
find-world [ ungraft ] when* ;

[
STARTUP-HOOK: [
f ui-running set-global
<flag> ui-notify-flag set-global
] "ui" add-startup-hook
]

HOOK: resize-window ui-backend ( world dim -- )
M: object resize-window 2drop ;
Expand Down
4 changes: 2 additions & 2 deletions basis/vocabs/cache/cache.factor
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ M: cache-observer vocab-changed
drop dup forgot-vocab? [ reset-vocab-cache ] [ drop ] if
reset-disk-cache ;

[
STARTUP-HOOK: [
f changed-vocabs set-global
cache-observer add-vocab-observer
] "vocabs.cache" add-startup-hook
]
4 changes: 2 additions & 2 deletions basis/vocabs/refresh/monitor/monitor.factor
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ TR: convert-separators "/\\" ".." ;
HS{ } clone changed-vocabs set-global
loaded-vocab-names [ changed-vocab ] each ;

[
STARTUP-HOOK: [
"-no-monitors" (command-line) member? [
[ drop ] add-vocab-root-hook set-global
f changed-vocabs set-global
Expand All @@ -74,4 +74,4 @@ TR: convert-separators "/\\" ".." ;
vocab-roots get [ start-vocab-monitor ] each
[ start-vocab-monitor ] add-vocab-root-hook set-global
] if
] "vocabs.refresh.monitor" add-startup-hook
]
2 changes: 1 addition & 1 deletion basis/windows/com/wrapper/wrapper.factor
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ unless
+live-wrappers+ get-global [ (allocate-wrapper) ] each
H{ } +wrapped-objects+ set-global ;

[ com-startup-hook ] "windows.com.wrapper" add-startup-hook
STARTUP-HOOK: com-startup-hook

PRIVATE>

Expand Down
2 changes: 1 addition & 1 deletion basis/windows/directx/dinput/constants/constants.factor
Original file line number Diff line number Diff line change
Expand Up @@ -832,7 +832,7 @@ MACRO: <DIDATAFORMAT> ( dwFlags dwDataSize struct rgodf-array -- alien )
define-guid-constants
define-format-constants ;

[ define-constants ] "windows.directx.dinput.constants" add-startup-hook
STARTUP-HOOK: define-constants

: uninitialize ( variable quot -- )
'[ _ when* f ] change-global ; inline
Expand Down
4 changes: 1 addition & 3 deletions basis/windows/dropfiles/dropfiles.factor
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,4 @@ IN: windows.dropfiles
: reject-files ( -- )
world get world-reject-files ;

[
f \ init-message-filter set-global
] "init-dropfiles" add-startup-hook
STARTUP-HOOK: [ f \ init-message-filter set-global ]
4 changes: 2 additions & 2 deletions basis/windows/fonts/fonts.factor
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ MEMO:: (cache-font) ( name size bold? italic? -- HFONT )
{ [ name>> ] [ size>> ] [ bold?>> ] [ italic?>> ] } cleave
(cache-font) ;

[
STARTUP-HOOK: [
\ (cache-font) reset-memoized
\ windows-fonts reset-memoized
] "windows.fonts" add-startup-hook
]

: TEXTMETRIC>metrics ( TEXTMETRIC -- metrics )
[ metrics new 0 >>width ] dip {
Expand Down
5 changes: 3 additions & 2 deletions basis/windows/gdiplus/gdiplus.factor
Original file line number Diff line number Diff line change
Expand Up @@ -1651,5 +1651,6 @@ DESTRUCTOR: stop-gdi+

SYMBOL: gdi-token

[ start-gdi+ gdi-token set-global ] "windows.gdiplus" add-startup-hook
[ gdi-token get-global [ stop-gdi+ ] when* ] "windows.gdiplus" add-shutdown-hook
STARTUP-HOOK: [ start-gdi+ gdi-token set-global ]

SHUTDOWN-HOOK: [ gdi-token get-global [ stop-gdi+ ] when* ]
3 changes: 1 addition & 2 deletions basis/windows/uniscribe/uniscribe.factor
Original file line number Diff line number Diff line change
Expand Up @@ -171,5 +171,4 @@ SYMBOL: cached-script-strings
] with-memory-dc
] unless image>> ;

[ <cache-assoc> cached-script-strings set-global ]
"windows.uniscribe" add-startup-hook
STARTUP-HOOK: [ <cache-assoc> cached-script-strings set-global ]
Loading

0 comments on commit 288d7e4

Please sign in to comment.