2009-03-17 03:19:50 -04:00
|
|
|
! Copyright (C) 2004, 2009 Slava Pestov.
|
2007-09-20 18:09:08 -04:00
|
|
|
! See http://factorcode.org/license.txt for BSD license.
|
2013-03-05 13:34:47 -05:00
|
|
|
USING: assocs continuations continuations.private kernel
|
|
|
|
kernel.private namespaces ;
|
2007-09-20 18:09:08 -04:00
|
|
|
IN: init
|
|
|
|
|
2009-10-19 22:17:02 -04:00
|
|
|
SYMBOL: startup-hooks
|
|
|
|
SYMBOL: shutdown-hooks
|
2007-09-20 18:09:08 -04:00
|
|
|
|
2015-07-09 22:06:19 -04:00
|
|
|
startup-hooks [ V{ } clone ] initialize
|
|
|
|
shutdown-hooks [ V{ } clone ] initialize
|
2007-09-20 18:09:08 -04:00
|
|
|
|
2009-10-20 00:28:18 -04:00
|
|
|
: do-hooks ( symbol -- )
|
|
|
|
get [ nip call( -- ) ] assoc-each ;
|
2007-09-20 18:09:08 -04:00
|
|
|
|
2009-10-20 00:28:18 -04:00
|
|
|
: do-startup-hooks ( -- ) startup-hooks do-hooks ;
|
2009-10-19 22:17:02 -04:00
|
|
|
|
2009-10-20 00:28:18 -04:00
|
|
|
: do-shutdown-hooks ( -- ) shutdown-hooks do-hooks ;
|
2009-10-19 22:17:02 -04:00
|
|
|
|
|
|
|
: 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 ;
|
2007-09-20 18:09:08 -04:00
|
|
|
|
2009-05-01 09:21:31 -04:00
|
|
|
: boot ( -- ) init-namespaces init-catchstack init-error-handler ;
|
2007-09-20 18:09:08 -04:00
|
|
|
|
2011-11-02 15:54:31 -04:00
|
|
|
: startup-quot ( -- quot ) OBJ-STARTUP-QUOT special-object ;
|
2007-09-20 18:09:08 -04:00
|
|
|
|
2011-11-02 15:54:31 -04:00
|
|
|
: set-startup-quot ( quot -- ) OBJ-STARTUP-QUOT set-special-object ;
|
2009-10-20 00:28:18 -04:00
|
|
|
|
2011-11-02 15:54:31 -04:00
|
|
|
: shutdown-quot ( -- quot ) OBJ-SHUTDOWN-QUOT special-object ;
|
2009-10-20 00:28:18 -04:00
|
|
|
|
2011-11-02 15:54:31 -04:00
|
|
|
: set-shutdown-quot ( quot -- ) OBJ-SHUTDOWN-QUOT set-special-object ;
|
2009-10-20 00:28:18 -04:00
|
|
|
|
|
|
|
[ do-shutdown-hooks ] set-shutdown-quot
|