1 ! Copyright (C) 2004, 2009 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: assocs continuations continuations.private kernel
4 kernel.private namespaces ;
10 startup-hooks global [ drop V{ } clone ] cache drop
11 shutdown-hooks global [ drop V{ } clone ] cache drop
13 : do-hooks ( symbol -- )
14 get [ nip call( -- ) ] assoc-each ;
16 : do-startup-hooks ( -- ) startup-hooks do-hooks ;
18 : do-shutdown-hooks ( -- ) shutdown-hooks do-hooks ;
20 : add-startup-hook ( quot name -- )
22 [ at [ drop ] [ call( -- ) ] if ]
25 : add-shutdown-hook ( quot name -- )
26 shutdown-hooks get set-at ;
28 : boot ( -- ) init-namespaces init-catchstack init-error-handler ;
30 : startup-quot ( -- quot ) OBJ-STARTUP-QUOT special-object ;
32 : set-startup-quot ( quot -- ) OBJ-STARTUP-QUOT set-special-object ;
34 : shutdown-quot ( -- quot ) OBJ-SHUTDOWN-QUOT special-object ;
36 : set-shutdown-quot ( quot -- ) OBJ-SHUTDOWN-QUOT set-special-object ;
38 [ do-shutdown-hooks ] set-shutdown-quot