Clean up startup/shutdown hook code
parent
8cbe676062
commit
24c3ddbbde
|
@ -1,19 +1,17 @@
|
|||
USING: init command-line debugger system continuations
|
||||
namespaces eval kernel vocabs.loader io destructors ;
|
||||
namespaces eval kernel vocabs.loader io ;
|
||||
|
||||
[
|
||||
boot
|
||||
do-startup-hooks
|
||||
[
|
||||
do-startup-hooks
|
||||
[
|
||||
(command-line) parse-command-line
|
||||
load-vocab-roots
|
||||
run-user-init
|
||||
"e" get [ eval( -- ) ] when*
|
||||
ignore-cli-args? not script get and
|
||||
[ run-script ] [ "run" get run ] if*
|
||||
output-stream get [ stream-flush ] when*
|
||||
0
|
||||
] [ print-error 1 ] recover
|
||||
] with-destructors exit
|
||||
] set-boot-quot
|
||||
(command-line) parse-command-line
|
||||
load-vocab-roots
|
||||
run-user-init
|
||||
"e" get [ eval( -- ) ] when*
|
||||
ignore-cli-args? not script get and
|
||||
[ run-script ] [ "run" get run ] if*
|
||||
output-stream get [ stream-flush ] when*
|
||||
0 exit
|
||||
] [ print-error 1 exit ] recover
|
||||
] set-startup-quot
|
||||
|
|
|
@ -1,12 +1,10 @@
|
|||
USING: destructors init command-line system namespaces kernel
|
||||
vocabs.loader io ;
|
||||
USING: init command-line system namespaces kernel vocabs.loader io ;
|
||||
|
||||
[
|
||||
boot
|
||||
[
|
||||
do-startup-hooks
|
||||
(command-line) parse-command-line
|
||||
"run" get run
|
||||
output-stream get [ stream-flush ] when*
|
||||
] with-destructors 0 exit
|
||||
] set-boot-quot
|
||||
do-startup-hooks
|
||||
(command-line) parse-command-line
|
||||
"run" get run
|
||||
output-stream get [ stream-flush ] when*
|
||||
0 exit
|
||||
] set-startup-quot
|
||||
|
|
|
@ -145,7 +145,7 @@ SYMBOL: architecture
|
|||
RESET
|
||||
|
||||
! Boot quotation, set in stage1.factor
|
||||
USERENV: bootstrap-boot-quot 20
|
||||
USERENV: bootstrap-startup-quot 20
|
||||
|
||||
! Bootstrap global namesapce
|
||||
USERENV: bootstrap-global 21
|
||||
|
|
|
@ -446,7 +446,7 @@ SYMBOL: deploy-vocab
|
|||
|
||||
: [print-error] ( -- word ) "print-error" "debugger" lookup ;
|
||||
|
||||
: deploy-boot-quot ( word -- )
|
||||
: deploy-startup-quot ( word -- )
|
||||
[
|
||||
[ boot ] %
|
||||
startup-hooks get values concat %
|
||||
|
@ -466,7 +466,7 @@ SYMBOL: deploy-vocab
|
|||
strip-io? [ [ flush ] % ] unless
|
||||
[ 0 exit ] %
|
||||
] [ ] make
|
||||
set-boot-quot ;
|
||||
set-startup-quot ;
|
||||
|
||||
: startup-stripper ( -- )
|
||||
t "quiet" set-global
|
||||
|
@ -521,7 +521,7 @@ SYMBOL: deploy-vocab
|
|||
strip-default-methods
|
||||
strip-compiler-classes
|
||||
f 5 setenv ! we can't use the Factor debugger or Factor I/O anymore
|
||||
deploy-vocab get vocab-main deploy-boot-quot
|
||||
deploy-vocab get vocab-main deploy-startup-quot
|
||||
find-megamorphic-caches
|
||||
stripped-word-props
|
||||
stripped-globals strip-globals
|
||||
|
|
|
@ -37,7 +37,7 @@ load-help? off
|
|||
[
|
||||
"resource:basis/bootstrap/stage2.factor"
|
||||
dup exists? [
|
||||
[ run-file ] with-destructors
|
||||
run-file
|
||||
] [
|
||||
"Cannot find " write write "." print
|
||||
"Please move " write image write " to the same directory as the Factor sources," print
|
||||
|
@ -46,4 +46,4 @@ load-help? off
|
|||
] if
|
||||
] %
|
||||
] [ ] make
|
||||
bootstrap.image.private:bootstrap-boot-quot set
|
||||
bootstrap.image.private:bootstrap-startup-quot set
|
||||
|
|
|
@ -6,8 +6,6 @@ IN: destructors
|
|||
|
||||
SYMBOL: disposables
|
||||
|
||||
[ H{ } clone disposables set-global ] "destructors" add-startup-hook
|
||||
|
||||
ERROR: already-unregistered disposable ;
|
||||
|
||||
SYMBOL: debug-leaks?
|
||||
|
@ -89,6 +87,12 @@ PRIVATE>
|
|||
] with-scope ; inline
|
||||
|
||||
[
|
||||
always-destructors get-global
|
||||
error-destructors get-global append dispose-each
|
||||
] "destructors.global" add-shutdown-hook
|
||||
H{ } clone disposables set-global
|
||||
V{ } clone always-destructors set-global
|
||||
V{ } clone error-destructors set-global
|
||||
] "destructors" add-startup-hook
|
||||
|
||||
[
|
||||
do-always-destructors
|
||||
do-error-destructors
|
||||
] "destructors" add-shutdown-hook
|
||||
|
|
|
@ -4,13 +4,13 @@ IN: init
|
|||
HELP: boot
|
||||
{ $description "Called on startup as part of the boot quotation to initialize the runtime and prepare it for running user code." } ;
|
||||
|
||||
{ boot boot-quot set-boot-quot } related-words
|
||||
{ boot startup-quot set-startup-quot } related-words
|
||||
|
||||
HELP: boot-quot
|
||||
HELP: startup-quot
|
||||
{ $values { "quot" quotation } }
|
||||
{ $description "Outputs the initial quotation called by the VM on startup." } ;
|
||||
|
||||
HELP: set-boot-quot
|
||||
HELP: set-startup-quot
|
||||
{ $values { "quot" quotation } }
|
||||
{ $description "Sets the initial quotation called by the VM on startup. This quotation must begin with a call to " { $link boot } ". The image must be saved for changes to the boot quotation to take effect." }
|
||||
{ $notes "The " { $link "tools.deploy" } " tool uses this word." } ;
|
||||
|
@ -44,8 +44,8 @@ ARTICLE: "init" "Initialization and startup"
|
|||
{ $subsections add-shutdown-hook }
|
||||
"The boot quotation can be changed:"
|
||||
{ $subsections
|
||||
boot-quot
|
||||
set-boot-quot
|
||||
startup-quot
|
||||
set-startup-quot
|
||||
}
|
||||
"When quitting Factor, shutdown hooks are called:"
|
||||
{ $subsection do-shutdown-hooks } ;
|
||||
|
|
|
@ -27,12 +27,12 @@ shutdown-hooks global [ drop V{ } clone ] cache drop
|
|||
|
||||
: boot ( -- ) init-namespaces init-catchstack init-error-handler ;
|
||||
|
||||
: boot-quot ( -- quot ) 20 getenv ;
|
||||
: startup-quot ( -- quot ) 20 getenv ;
|
||||
|
||||
: set-boot-quot ( quot -- ) 20 setenv ;
|
||||
: set-startup-quot ( quot -- ) 20 setenv ;
|
||||
|
||||
: shutdown-quot ( -- quot ) 67 getenv ;
|
||||
: shutdown-quot ( -- quot ) 22 getenv ;
|
||||
|
||||
: set-shutdown-quot ( quot -- ) 67 setenv ;
|
||||
: set-shutdown-quot ( quot -- ) 22 setenv ;
|
||||
|
||||
[ do-shutdown-hooks ] set-shutdown-quot
|
||||
|
|
|
@ -167,14 +167,14 @@ void factor_vm::start_factor(vm_parameters *p)
|
|||
if(p->fep) factorbug();
|
||||
|
||||
nest_stacks(NULL);
|
||||
c_to_factor_toplevel(special_objects[OBJ_BOOT]);
|
||||
c_to_factor_toplevel(special_objects[OBJ_STARTUP_QUOT]);
|
||||
unnest_stacks();
|
||||
}
|
||||
|
||||
void factor_vm::stop_factor()
|
||||
{
|
||||
nest_stacks(NULL);
|
||||
c_to_factor_toplevel(special_objects[OBJ_SHUTDOWN]);
|
||||
c_to_factor_toplevel(special_objects[OBJ_SHUTDOWN_QUOT]);
|
||||
unnest_stacks();
|
||||
}
|
||||
|
||||
|
|
|
@ -291,7 +291,7 @@ bool factor_vm::save_image(const vm_char *filename)
|
|||
h.bignum_neg_one = bignum_neg_one;
|
||||
|
||||
for(cell i = 0; i < special_object_count; i++)
|
||||
h.special_objects[i] = (save_env_p(i) ? special_objects[i] : false_object);
|
||||
h.special_objects[i] = (save_special_p(i) ? special_objects[i] : false_object);
|
||||
|
||||
bool ok = true;
|
||||
|
||||
|
@ -326,7 +326,7 @@ void factor_vm::primitive_save_image_and_exit()
|
|||
|
||||
/* strip out special_objects data which is set on startup anyway */
|
||||
for(cell i = 0; i < special_object_count; i++)
|
||||
if(!save_env_p(i)) special_objects[i] = false_object;
|
||||
if(!save_special_p(i)) special_objects[i] = false_object;
|
||||
|
||||
gc(collect_compact_op,
|
||||
0, /* requested size */
|
||||
|
|
|
@ -4,40 +4,40 @@ namespace factor
|
|||
static const cell special_object_count = 70;
|
||||
|
||||
enum special_object {
|
||||
OBJ_NAMESTACK, /* used by library only */
|
||||
OBJ_CATCHSTACK, /* used by library only, per-callback */
|
||||
OBJ_NAMESTACK, /* used by library only */
|
||||
OBJ_CATCHSTACK, /* used by library only, per-callback */
|
||||
|
||||
OBJ_CURRENT_CALLBACK = 2, /* used by library only, per-callback */
|
||||
OBJ_WALKER_HOOK, /* non-local exit hook, used by library only */
|
||||
OBJ_CALLCC_1, /* used to pass the value in callcc1 */
|
||||
OBJ_CURRENT_CALLBACK = 2, /* used by library only, per-callback */
|
||||
OBJ_WALKER_HOOK, /* non-local exit hook, used by library only */
|
||||
OBJ_CALLCC_1, /* used to pass the value in callcc1 */
|
||||
|
||||
OBJ_BREAK = 5, /* quotation called by throw primitive */
|
||||
OBJ_ERROR, /* a marker consed onto kernel errors */
|
||||
OBJ_BREAK = 5, /* quotation called by throw primitive */
|
||||
OBJ_ERROR, /* a marker consed onto kernel errors */
|
||||
|
||||
OBJ_CELL_SIZE = 7, /* sizeof(cell) */
|
||||
OBJ_CPU, /* CPU architecture */
|
||||
OBJ_OS, /* operating system name */
|
||||
OBJ_CELL_SIZE = 7, /* sizeof(cell) */
|
||||
OBJ_CPU, /* CPU architecture */
|
||||
OBJ_OS, /* operating system name */
|
||||
|
||||
OBJ_ARGS = 10, /* command line arguments */
|
||||
OBJ_STDIN, /* stdin FILE* handle */
|
||||
OBJ_STDOUT, /* stdout FILE* handle */
|
||||
OBJ_ARGS = 10, /* command line arguments */
|
||||
OBJ_STDIN, /* stdin FILE* handle */
|
||||
OBJ_STDOUT, /* stdout FILE* handle */
|
||||
|
||||
OBJ_IMAGE = 13, /* image path name */
|
||||
OBJ_EXECUTABLE, /* runtime executable path name */
|
||||
OBJ_IMAGE = 13, /* image path name */
|
||||
OBJ_EXECUTABLE, /* runtime executable path name */
|
||||
|
||||
OBJ_EMBEDDED = 15, /* are we embedded in another app? */
|
||||
OBJ_EVAL_CALLBACK, /* used when Factor is embedded in a C app */
|
||||
OBJ_YIELD_CALLBACK, /* used when Factor is embedded in a C app */
|
||||
OBJ_SLEEP_CALLBACK, /* used when Factor is embedded in a C app */
|
||||
OBJ_EMBEDDED = 15, /* are we embedded in another app? */
|
||||
OBJ_EVAL_CALLBACK, /* used when Factor is embedded in a C app */
|
||||
OBJ_YIELD_CALLBACK, /* used when Factor is embedded in a C app */
|
||||
OBJ_SLEEP_CALLBACK, /* used when Factor is embedded in a C app */
|
||||
|
||||
OBJ_COCOA_EXCEPTION = 19, /* Cocoa exception handler quotation */
|
||||
OBJ_COCOA_EXCEPTION = 19, /* Cocoa exception handler quotation */
|
||||
|
||||
OBJ_BOOT = 20, /* boot quotation */
|
||||
OBJ_GLOBAL, /* global namespace */
|
||||
OBJ_SHUTDOWN,
|
||||
OBJ_STARTUP_QUOT = 20, /* startup quotation */
|
||||
OBJ_GLOBAL, /* global namespace */
|
||||
OBJ_SHUTDOWN_QUOT, /* shutdown quotation */
|
||||
|
||||
/* Quotation compilation in quotations.c */
|
||||
JIT_PROLOG = 23,
|
||||
JIT_PROLOG = 23,
|
||||
JIT_PRIMITIVE_WORD,
|
||||
JIT_PRIMITIVE,
|
||||
JIT_WORD_JUMP,
|
||||
|
@ -61,14 +61,14 @@ enum special_object {
|
|||
JIT_DECLARE_WORD,
|
||||
|
||||
/* Callback stub generation in callbacks.c */
|
||||
CALLBACK_STUB = 45,
|
||||
CALLBACK_STUB = 45,
|
||||
|
||||
/* Incremented on every modify-code-heap call; invalidates call( inline
|
||||
caching */
|
||||
REDEFINITION_COUNTER = 46,
|
||||
|
||||
/* Polymorphic inline cache generation in inline_cache.c */
|
||||
PIC_LOAD = 47,
|
||||
PIC_LOAD = 47,
|
||||
PIC_TAG,
|
||||
PIC_TUPLE,
|
||||
PIC_CHECK_TAG,
|
||||
|
@ -78,27 +78,29 @@ enum special_object {
|
|||
PIC_MISS_TAIL_WORD,
|
||||
|
||||
/* Megamorphic cache generation in dispatch.c */
|
||||
MEGA_LOOKUP = 57,
|
||||
MEGA_LOOKUP = 57,
|
||||
MEGA_LOOKUP_WORD,
|
||||
MEGA_MISS_WORD,
|
||||
|
||||
OBJ_UNDEFINED = 60, /* default quotation for undefined words */
|
||||
OBJ_UNDEFINED = 60, /* default quotation for undefined words */
|
||||
|
||||
OBJ_STDERR = 61, /* stderr FILE* handle */
|
||||
OBJ_STDERR = 61, /* stderr FILE* handle */
|
||||
|
||||
OBJ_STAGE2 = 62, /* have we bootstrapped? */
|
||||
OBJ_STAGE2 = 62, /* have we bootstrapped? */
|
||||
|
||||
OBJ_CURRENT_THREAD = 63,
|
||||
OBJ_CURRENT_THREAD = 63,
|
||||
|
||||
OBJ_THREADS = 64,
|
||||
OBJ_RUN_QUEUE = 65,
|
||||
OBJ_SLEEP_QUEUE = 66,
|
||||
OBJ_THREADS = 64,
|
||||
OBJ_RUN_QUEUE = 65,
|
||||
OBJ_SLEEP_QUEUE = 66,
|
||||
};
|
||||
|
||||
#define OBJ_FIRST_SAVE OBJ_BOOT
|
||||
/* save-image-and-exit discards special objects that are filled in on startup
|
||||
anyway, to reduce image size */
|
||||
#define OBJ_FIRST_SAVE OBJ_STARTUP_QUOT
|
||||
#define OBJ_LAST_SAVE OBJ_STAGE2
|
||||
|
||||
inline static bool save_env_p(cell i)
|
||||
inline static bool save_special_p(cell i)
|
||||
{
|
||||
return (i >= OBJ_FIRST_SAVE && i <= OBJ_LAST_SAVE);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue