]> gitweb.factorcode.org Git - factor.git/blob - core/init/init.factor
calendar.format: make duration>human-readable more human readable
[factor.git] / core / init / init.factor
1 ! Copyright (C) 2004, 2009 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: assocs continuations.private kernel kernel.private
4 namespaces ;
5 IN: init
6
7 SYMBOL: startup-hooks
8 SYMBOL: shutdown-hooks
9
10 startup-hooks [ V{ } clone ] initialize
11 shutdown-hooks [ V{ } clone ] initialize
12
13 : do-hooks ( symbol -- )
14     get [ nip call( -- ) ] assoc-each ;
15
16 : do-startup-hooks ( -- ) startup-hooks do-hooks ;
17
18 : do-shutdown-hooks ( -- ) shutdown-hooks do-hooks ;
19
20 : add-startup-hook ( quot name -- )
21     startup-hooks get
22     [ at [ drop ] [ call( -- ) ] if ]
23     [ set-at ] 3bi ;
24
25 : add-shutdown-hook ( quot name -- )
26     shutdown-hooks get set-at ;
27
28 : boot ( -- ) init-namestack init-catchstack init-error-handler ;
29
30 : startup-quot ( -- quot ) OBJ-STARTUP-QUOT special-object ;
31
32 : set-startup-quot ( quot -- ) OBJ-STARTUP-QUOT set-special-object ;
33
34 : shutdown-quot ( -- quot ) OBJ-SHUTDOWN-QUOT special-object ;
35
36 : set-shutdown-quot ( quot -- ) OBJ-SHUTDOWN-QUOT set-special-object ;
37
38 [ do-shutdown-hooks ] set-shutdown-quot