Clean up startup/shutdown hook code

db4
Slava Pestov 2009-11-20 00:55:16 -06:00
parent 8cbe676062
commit 24c3ddbbde
11 changed files with 85 additions and 83 deletions

View File

@ -1,9 +1,8 @@
USING: init command-line debugger system continuations USING: init command-line debugger system continuations
namespaces eval kernel vocabs.loader io destructors ; namespaces eval kernel vocabs.loader io ;
[ [
boot boot
[
do-startup-hooks do-startup-hooks
[ [
(command-line) parse-command-line (command-line) parse-command-line
@ -13,7 +12,6 @@ namespaces eval kernel vocabs.loader io destructors ;
ignore-cli-args? not script get and ignore-cli-args? not script get and
[ run-script ] [ "run" get run ] if* [ run-script ] [ "run" get run ] if*
output-stream get [ stream-flush ] when* output-stream get [ stream-flush ] when*
0 0 exit
] [ print-error 1 ] recover ] [ print-error 1 exit ] recover
] with-destructors exit ] set-startup-quot
] set-boot-quot

View File

@ -1,12 +1,10 @@
USING: destructors init command-line system namespaces kernel USING: init command-line system namespaces kernel vocabs.loader io ;
vocabs.loader io ;
[ [
boot boot
[
do-startup-hooks do-startup-hooks
(command-line) parse-command-line (command-line) parse-command-line
"run" get run "run" get run
output-stream get [ stream-flush ] when* output-stream get [ stream-flush ] when*
] with-destructors 0 exit 0 exit
] set-boot-quot ] set-startup-quot

View File

@ -145,7 +145,7 @@ SYMBOL: architecture
RESET RESET
! Boot quotation, set in stage1.factor ! Boot quotation, set in stage1.factor
USERENV: bootstrap-boot-quot 20 USERENV: bootstrap-startup-quot 20
! Bootstrap global namesapce ! Bootstrap global namesapce
USERENV: bootstrap-global 21 USERENV: bootstrap-global 21

View File

@ -446,7 +446,7 @@ SYMBOL: deploy-vocab
: [print-error] ( -- word ) "print-error" "debugger" lookup ; : [print-error] ( -- word ) "print-error" "debugger" lookup ;
: deploy-boot-quot ( word -- ) : deploy-startup-quot ( word -- )
[ [
[ boot ] % [ boot ] %
startup-hooks get values concat % startup-hooks get values concat %
@ -466,7 +466,7 @@ SYMBOL: deploy-vocab
strip-io? [ [ flush ] % ] unless strip-io? [ [ flush ] % ] unless
[ 0 exit ] % [ 0 exit ] %
] [ ] make ] [ ] make
set-boot-quot ; set-startup-quot ;
: startup-stripper ( -- ) : startup-stripper ( -- )
t "quiet" set-global t "quiet" set-global
@ -521,7 +521,7 @@ SYMBOL: deploy-vocab
strip-default-methods strip-default-methods
strip-compiler-classes strip-compiler-classes
f 5 setenv ! we can't use the Factor debugger or Factor I/O anymore 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 find-megamorphic-caches
stripped-word-props stripped-word-props
stripped-globals strip-globals stripped-globals strip-globals

View File

@ -37,7 +37,7 @@ load-help? off
[ [
"resource:basis/bootstrap/stage2.factor" "resource:basis/bootstrap/stage2.factor"
dup exists? [ dup exists? [
[ run-file ] with-destructors run-file
] [ ] [
"Cannot find " write write "." print "Cannot find " write write "." print
"Please move " write image write " to the same directory as the Factor sources," print "Please move " write image write " to the same directory as the Factor sources," print
@ -46,4 +46,4 @@ load-help? off
] if ] if
] % ] %
] [ ] make ] [ ] make
bootstrap.image.private:bootstrap-boot-quot set bootstrap.image.private:bootstrap-startup-quot set

View File

@ -6,8 +6,6 @@ IN: destructors
SYMBOL: disposables SYMBOL: disposables
[ H{ } clone disposables set-global ] "destructors" add-startup-hook
ERROR: already-unregistered disposable ; ERROR: already-unregistered disposable ;
SYMBOL: debug-leaks? SYMBOL: debug-leaks?
@ -89,6 +87,12 @@ PRIVATE>
] with-scope ; inline ] with-scope ; inline
[ [
always-destructors get-global H{ } clone disposables set-global
error-destructors get-global append dispose-each V{ } clone always-destructors set-global
] "destructors.global" add-shutdown-hook V{ } clone error-destructors set-global
] "destructors" add-startup-hook
[
do-always-destructors
do-error-destructors
] "destructors" add-shutdown-hook

View File

@ -4,13 +4,13 @@ IN: init
HELP: boot HELP: boot
{ $description "Called on startup as part of the boot quotation to initialize the runtime and prepare it for running user code." } ; { $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 } } { $values { "quot" quotation } }
{ $description "Outputs the initial quotation called by the VM on startup." } ; { $description "Outputs the initial quotation called by the VM on startup." } ;
HELP: set-boot-quot HELP: set-startup-quot
{ $values { "quot" quotation } } { $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." } { $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." } ; { $notes "The " { $link "tools.deploy" } " tool uses this word." } ;
@ -44,8 +44,8 @@ ARTICLE: "init" "Initialization and startup"
{ $subsections add-shutdown-hook } { $subsections add-shutdown-hook }
"The boot quotation can be changed:" "The boot quotation can be changed:"
{ $subsections { $subsections
boot-quot startup-quot
set-boot-quot set-startup-quot
} }
"When quitting Factor, shutdown hooks are called:" "When quitting Factor, shutdown hooks are called:"
{ $subsection do-shutdown-hooks } ; { $subsection do-shutdown-hooks } ;

View File

@ -27,12 +27,12 @@ shutdown-hooks global [ drop V{ } clone ] cache drop
: boot ( -- ) init-namespaces init-catchstack init-error-handler ; : 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 [ do-shutdown-hooks ] set-shutdown-quot

View File

@ -167,14 +167,14 @@ void factor_vm::start_factor(vm_parameters *p)
if(p->fep) factorbug(); if(p->fep) factorbug();
nest_stacks(NULL); nest_stacks(NULL);
c_to_factor_toplevel(special_objects[OBJ_BOOT]); c_to_factor_toplevel(special_objects[OBJ_STARTUP_QUOT]);
unnest_stacks(); unnest_stacks();
} }
void factor_vm::stop_factor() void factor_vm::stop_factor()
{ {
nest_stacks(NULL); nest_stacks(NULL);
c_to_factor_toplevel(special_objects[OBJ_SHUTDOWN]); c_to_factor_toplevel(special_objects[OBJ_SHUTDOWN_QUOT]);
unnest_stacks(); unnest_stacks();
} }

View File

@ -291,7 +291,7 @@ bool factor_vm::save_image(const vm_char *filename)
h.bignum_neg_one = bignum_neg_one; h.bignum_neg_one = bignum_neg_one;
for(cell i = 0; i < special_object_count; i++) 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; 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 */ /* strip out special_objects data which is set on startup anyway */
for(cell i = 0; i < special_object_count; i++) 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, gc(collect_compact_op,
0, /* requested size */ 0, /* requested size */

View File

@ -32,9 +32,9 @@ enum special_object {
OBJ_COCOA_EXCEPTION = 19, /* Cocoa exception handler quotation */ OBJ_COCOA_EXCEPTION = 19, /* Cocoa exception handler quotation */
OBJ_BOOT = 20, /* boot quotation */ OBJ_STARTUP_QUOT = 20, /* startup quotation */
OBJ_GLOBAL, /* global namespace */ OBJ_GLOBAL, /* global namespace */
OBJ_SHUTDOWN, OBJ_SHUTDOWN_QUOT, /* shutdown quotation */
/* Quotation compilation in quotations.c */ /* Quotation compilation in quotations.c */
JIT_PROLOG = 23, JIT_PROLOG = 23,
@ -95,10 +95,12 @@ enum special_object {
OBJ_SLEEP_QUEUE = 66, 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 #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); return (i >= OBJ_FIRST_SAVE && i <= OBJ_LAST_SAVE);
} }