]> gitweb.factorcode.org Git - factor.git/commitdiff
VM: let's merge (save-image) and (save-image-and-exit) into one 3 1385/head
authorBjörn Lindqvist <bjourne@gmail.com>
Sun, 12 Jul 2015 19:08:39 +0000 (21:08 +0200)
committerBjörn Lindqvist <bjourne@gmail.com>
Sun, 12 Jul 2015 20:36:59 +0000 (22:36 +0200)
arg (save-image). it's good not to have to many similar primitives

basis/stack-checker/known-words/known-words.factor
core/bootstrap/primitives.factor
core/memory/memory.factor
vm/image.cpp
vm/primitives.hpp
vm/vm.hpp

index 48ab60795a43576fec84c34bc592c796f1a7abdf..3c04748488f7cfffee427f4413ee186674647a64 100644 (file)
@@ -291,8 +291,7 @@ M: object infer-call* \ call bad-macro-input ;
 \ (format-float) { float byte-array } { byte-array } define-primitive \ (format-float) make-foldable
 \ (fopen) { byte-array byte-array } { alien } define-primitive
 \ (identity-hashcode) { object } { fixnum } define-primitive
-\ (save-image) { byte-array byte-array } { } define-primitive
-\ (save-image-and-exit) { byte-array byte-array } { } define-primitive
+\ (save-image) { byte-array byte-array object } { } define-primitive
 \ (set-context) { object alien } { object } define-primitive
 \ (set-context-and-delete) { object alien } { } define-primitive
 \ (sleep) { integer } { } define-primitive
index 27bd5cf6b39ffc4c6729d355b03722d247f459d1..1d83b10f0dc1f1b04399f5f7fb84bec3da458038 100755 (executable)
@@ -530,8 +530,7 @@ tuple
     { "gc" "memory" "primitive_full_gc" ( -- ) }
     { "minor-gc" "memory" "primitive_minor_gc" ( -- ) }
     { "size" "memory" "primitive_size" ( obj -- n ) }
-    { "(save-image)" "memory.private" "primitive_save_image" ( path1 path2 -- ) }
-    { "(save-image-and-exit)" "memory.private" "primitive_save_image_and_exit" ( path1 path2 -- ) }
+    { "(save-image)" "memory.private" "primitive_save_image" ( path1 path2 then-die? -- ) }
     { "jit-compile" "quotations" "primitive_jit_compile" ( quot -- ) }
     { "quot-compiled?" "quotations" "primitive_quot_compiled_p" ( quot -- ? ) }
     { "quotation-code" "quotations" "primitive_quotation_code" ( quot -- start end ) }
index f9daf425e81dbac8fd603025179107192dd7fe72..aa7e33a81c734340133cdd8fa84c33beb255ae61 100644 (file)
@@ -11,8 +11,7 @@ PRIMITIVE: minor-gc ( -- )
 PRIMITIVE: size ( obj -- n )
 
 <PRIVATE
-PRIMITIVE: (save-image) ( path1 path2 -- )
-PRIMITIVE: (save-image-and-exit) ( path1 path2 -- )
+PRIMITIVE: (save-image) ( path1 path2 then-die? -- )
 PRIVATE>
 
 : instances ( quot -- seq )
@@ -23,9 +22,9 @@ PRIVATE>
     [ native-string>alien ] bi@ ;
 
 : save-image ( path -- )
-    normalize-path saving-path (save-image) ;
+    normalize-path saving-path (save-image) ;
 
 : save-image-and-exit ( path -- )
-    normalize-path saving-path (save-image-and-exit) ;
+    normalize-path saving-path t (save-image) ;
 
 : save ( -- ) image save-image ;
index 2acaea86958bff944d3ab847518bcc61be15f150..2bb653c1d3a1ea754808a7b9af9f66835be1c4d2 100644 (file)
@@ -294,27 +294,12 @@ bool factor_vm::save_image(const vm_char* saving_filename,
   return ok;
 }
 
-void factor_vm::primitive_save_image() {
-  byte_array* path2 = tagged<byte_array>(ctx->pop()).untag_check(this);
-  byte_array* path1 = tagged<byte_array>(ctx->pop()).untag_check(this);
-
-  vm_char* path1_saved = safe_strdup(path1->data<vm_char>());
-  vm_char* path2_saved = safe_strdup(path2->data<vm_char>());
-
-  /* do a full GC to push everything into tenured space */
-  primitive_compact_gc();
-
-  save_image(path1_saved, path2_saved);
-
-  free(path1_saved);
-  free(path2_saved);
-}
-
 /* Allocates memory */
-void factor_vm::primitive_save_image_and_exit() {
+void factor_vm::primitive_save_image() {
   /* We unbox this before doing anything else. This is the only point
      where we might throw an error, so we have to throw an error here since
      later steps destroy the current image. */
+  bool then_die = to_boolean(ctx->pop());
   byte_array* path2 = tagged<byte_array>(ctx->pop()).untag_check(this);
   byte_array* path1 = tagged<byte_array>(ctx->pop()).untag_check(this);
 
@@ -323,23 +308,28 @@ void factor_vm::primitive_save_image_and_exit() {
   vm_char* path1_saved = safe_strdup(path1->data<vm_char>());
   vm_char* path2_saved = safe_strdup(path2->data<vm_char>());
 
-  /* strip out special_objects data which is set on startup anyway */
-  for (cell i = 0; i < special_object_count; i++)
-    if (!save_special_p(i))
-      special_objects[i] = false_object;
+  if (then_die) {
+    /* strip out special_objects data which is set on startup anyway */
+    for (cell i = 0; i < special_object_count; i++)
+      if (!save_special_p(i))
+        special_objects[i] = false_object;
 
-  /* dont trace objects only reachable from context stacks so we don't
-     get volatile data saved in the image. */
-  active_contexts.clear();
-  code->uninitialized_blocks.clear();
+    /* dont trace objects only reachable from context stacks so we don't
+       get volatile data saved in the image. */
+    active_contexts.clear();
+    code->uninitialized_blocks.clear();
+  }
 
-  gc(collect_compact_op, 0 /* requested size */);
+  /* do a full GC to push everything remaining into tenured space */
+  primitive_compact_gc();
 
   /* Save the image */
-  if (save_image(path1_saved, path2_saved))
-    exit(0);
-  else
-    exit(1);
+  bool ret = save_image(path1_saved, path2_saved);
+  if (then_die) {
+    exit(ret ? 0 : 1);
+  }
+  free(path1_saved);
+  free(path2_saved);
 }
 
 bool factor_vm::embedded_image_p() {
index 01dd919c519cd299994c6874fda292bde9fffd7b..7bb89f36a2ddc4363ffb1c4dce8d46c80d6e57ff 100644 (file)
@@ -31,12 +31,11 @@ namespace factor {
       _(quot_compiled_p) _(quotation_code) _(reset_dispatch_stats)             \
       _(resize_array) _(resize_byte_array) _(resize_string) _(retainstack)     \
       _(retainstack_for) _(sampling_profiler) _(save_image)                    \
-      _(save_image_and_exit) _(set_context_object) _(set_datastack)            \
-      _(set_innermost_stack_frame_quot) _(set_retainstack) _(set_slot)         \
-      _(set_special_object) _(set_string_nth_fast) _(size) _(sleep)            \
-      _(special_object) _(string) _(strip_stack_traces) _(tuple) _(tuple_boa)  \
-      _(unimplemented) _(uninitialized_byte_array) _(word) _(word_code)        \
-      _(wrapper)
+      _(set_context_object) _(set_datastack) _(set_innermost_stack_frame_quot) \
+      _(set_retainstack) _(set_slot) _(set_special_object)                     \
+      _(set_string_nth_fast) _(size) _(sleep) _(special_object) _(string)      \
+      _(strip_stack_traces) _(tuple) _(tuple_boa) _(unimplemented)             \
+      _(uninitialized_byte_array) _(word) _(word_code) _(wrapper)
 
 #define EACH_ALIEN_PRIMITIVE(_)                               \
   _(signed_cell, fixnum, from_signed_cell, to_fixnum)         \
index 48e881fd0782107c00093f7ff11f9ddf72a54ac0..8529ff6e244b536d0708410d8fe309e364120afe 100644 (file)
--- a/vm/vm.hpp
+++ b/vm/vm.hpp
@@ -608,7 +608,6 @@ struct factor_vm {
   void load_code_heap(FILE* file, image_header* h, vm_parameters* p);
   bool save_image(const vm_char* saving_filename, const vm_char* filename);
   void primitive_save_image();
-  void primitive_save_image_and_exit();
   void fixup_data(cell data_offset, cell code_offset);
   void fixup_code(cell data_offset, cell code_offset);
   FILE* open_image(vm_parameters* p);