]> gitweb.factorcode.org Git - factor.git/commitdiff
Clean up startup/shutdown hook code
authorSlava Pestov <slava@slava-pestovs-macbook-pro.local>
Fri, 20 Nov 2009 06:55:16 +0000 (00:55 -0600)
committerSlava Pestov <slava@slava-pestovs-macbook-pro.local>
Fri, 20 Nov 2009 06:57:49 +0000 (00:57 -0600)
basis/bootstrap/finish-bootstrap.factor
basis/bootstrap/finish-staging.factor
basis/bootstrap/image/image.factor
basis/tools/deploy/shaker/shaker.factor
core/bootstrap/stage1.factor
core/destructors/destructors.factor
core/init/init-docs.factor
core/init/init.factor
vm/factor.cpp
vm/image.cpp
vm/objects.hpp

index 35b40df97a322e967807bbd8d9e4d5547a68f14f..70ccaedad422a1110da717d6f8fa91196527c66a 100644 (file)
@@ -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
index 348d6797c90ecc2cc572c257f068b60c720c94f7..4512d84053246094415e10c77de2463ded519df6 100644 (file)
@@ -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
index b2c7f37013f2ba45f85e8c6afca305325413f434..eb08809ec1412280a8fef3059f684cc7da687b03 100644 (file)
@@ -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
index c79065bb29b17baf8ca449199c5e62f8b19cb44f..e4ed7d72ae76fff9c269cba3f16e50c8264a9437 100755 (executable)
@@ -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
index 29d0a311a311eb5928549d0e9eacfae948c5e2cb..78658206de42af07531195fa573d21ab40a63634 100644 (file)
@@ -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
index 577da7c4eb778ea2f566ebf6c91a496284c6161d..ac3751e32ed8bf40fc96656de69ab7b935f5e701 100644 (file)
@@ -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
index edee683bded8ca8191e997eb3b09d6ccbc1016cf..0382c38dffb420ee114f50b4d3007148366a5b80 100644 (file)
@@ -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 } ;
index 16a39bbc21cfbb6d0857611ffbba6948cf99894b..40e5806fd594cdf9ccdfce2d60d17156e6cc887c 100644 (file)
@@ -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
index 9096980097ff498dacf1a30e447e75ec9922b333..39088500adbe3fcbde73bab19a426ed4c531d654 100755 (executable)
@@ -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();
 }
 
index db91b4f1ea2bc69a554283b51b51eef8579c71e7..f297cbd1377fa91162e1c5f84d46fb90425b3675 100755 (executable)
@@ -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 */
index 658f7eaa36630b5e184bc231b5d2113f0df88bb4..55b5f9063db54d5a61fa92b820f3e128561c8e51 100644 (file)
@@ -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);
 }