factor/core/init/init.factor

39 lines
1.0 KiB
Factor
Raw Normal View History

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
SYMBOL: startup-hooks
SYMBOL: shutdown-hooks
2007-09-20 18:09:08 -04:00
startup-hooks [ V{ } clone ] initialize
shutdown-hooks [ V{ } clone ] initialize
2007-09-20 18:09:08 -04:00
: do-hooks ( symbol -- )
get [ nip call( -- ) ] assoc-each ;
2007-09-20 18:09:08 -04:00
: do-startup-hooks ( -- ) startup-hooks do-hooks ;
: do-shutdown-hooks ( -- ) shutdown-hooks 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 ;
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
: startup-quot ( -- quot ) OBJ-STARTUP-QUOT special-object ;
2007-09-20 18:09:08 -04:00
: set-startup-quot ( quot -- ) OBJ-STARTUP-QUOT set-special-object ;
: shutdown-quot ( -- quot ) OBJ-SHUTDOWN-QUOT special-object ;
: set-shutdown-quot ( quot -- ) OBJ-SHUTDOWN-QUOT set-special-object ;
[ do-shutdown-hooks ] set-shutdown-quot