diff --git a/vm/factor.cpp b/vm/factor.cpp index 3052335882..f554292570 100644 --- a/vm/factor.cpp +++ b/vm/factor.cpp @@ -4,92 +4,6 @@ namespace factor { void init_globals() { init_mvm(); } -void factor_vm::default_parameters(vm_parameters* p) { - p->embedded_image = false; - p->image_path = NULL; - - p->datastack_size = 32 * sizeof(cell); - p->retainstack_size = 32 * sizeof(cell); - -#if defined(FACTOR_PPC) - p->callstack_size = 256 * sizeof(cell); -#else - p->callstack_size = 128 * sizeof(cell); -#endif - - p->code_size = 64; - p->young_size = sizeof(cell) / 4; - p->aging_size = sizeof(cell) / 2; - p->tenured_size = 24 * sizeof(cell); - - p->max_pic_size = 3; - - p->fep = false; - p->signals = true; - -#ifdef WINDOWS - p->console = GetConsoleWindow() != NULL; -#else - p->console = true; -#endif - - p->callback_size = 256; -} - -bool factor_vm::factor_arg(const vm_char* str, const vm_char* arg, - cell* value) { - int val; - if (SSCANF(str, arg, &val) > 0) { - *value = val; - return true; - } - return false; -} - -void factor_vm::init_parameters_from_args(vm_parameters* p, int argc, - vm_char** argv) { - default_parameters(p); - p->executable_path = argv[0]; - - int i = 0; - - for (i = 1; i < argc; i++) { - vm_char* arg = argv[i]; - if (STRCMP(arg, STRING_LITERAL("--")) == 0) - break; - else if (factor_arg(arg, STRING_LITERAL("-datastack=%d"), - &p->datastack_size)) - ; - else if (factor_arg(arg, STRING_LITERAL("-retainstack=%d"), - &p->retainstack_size)) - ; - else if (factor_arg(arg, STRING_LITERAL("-callstack=%d"), - &p->callstack_size)) - ; - else if (factor_arg(arg, STRING_LITERAL("-young=%d"), &p->young_size)) - ; - else if (factor_arg(arg, STRING_LITERAL("-aging=%d"), &p->aging_size)) - ; - else if (factor_arg(arg, STRING_LITERAL("-tenured=%d"), &p->tenured_size)) - ; - else if (factor_arg(arg, STRING_LITERAL("-codeheap=%d"), &p->code_size)) - ; - else if (factor_arg(arg, STRING_LITERAL("-pic=%d"), &p->max_pic_size)) - ; - else if (factor_arg(arg, STRING_LITERAL("-callbacks=%d"), - &p->callback_size)) - ; - else if (STRNCMP(arg, STRING_LITERAL("-i="), 3) == 0) - p->image_path = arg + 3; - else if (STRCMP(arg, STRING_LITERAL("-fep")) == 0) - p->fep = true; - else if (STRCMP(arg, STRING_LITERAL("-nosignals")) == 0) - p->signals = false; - else if (STRCMP(arg, STRING_LITERAL("-console")) == 0) - p->console = true; - } -} - /* Compile code in boot image so that we can execute the startup quotation */ /* Allocates memory */ void factor_vm::prepare_boot_image() { @@ -235,7 +149,7 @@ void factor_vm::factor_sleep(long us) { void factor_vm::start_standalone_factor(int argc, vm_char** argv) { vm_parameters p; - init_parameters_from_args(&p, argc, argv); + p.init_from_args(argc, argv); init_factor(&p); pass_args_to_factor(argc, argv); @@ -256,7 +170,8 @@ factor_vm* new_factor_vm() { VM_C_API void start_standalone_factor(int argc, vm_char** argv) { factor_vm* newvm = new_factor_vm(); - return newvm->start_standalone_factor(argc, argv); + newvm->start_standalone_factor(argc, argv); + delete newvm; } } diff --git a/vm/factor.hpp b/vm/factor.hpp index 3e2c097368..d042d3a165 100644 --- a/vm/factor.hpp +++ b/vm/factor.hpp @@ -4,6 +4,9 @@ VM_C_API void init_globals(); factor_vm* new_factor_vm(); VM_C_API void start_standalone_factor(int argc, vm_char** argv); +// image +bool factor_arg(const vm_char* str, const vm_char* arg, cell* value); + // objects cell object_size(cell tagged); diff --git a/vm/image.cpp b/vm/image.cpp index 60b4967ac9..f04097b46c 100644 --- a/vm/image.cpp +++ b/vm/image.cpp @@ -2,6 +2,88 @@ namespace factor { +bool factor_arg(const vm_char* str, const vm_char* arg, cell* value) { + int val; + if (SSCANF(str, arg, &val) > 0) { + *value = val; + return true; + } + return false; +} + +vm_parameters::vm_parameters() { + embedded_image = false; + image_path = NULL; + + datastack_size = 32 * sizeof(cell); + retainstack_size = 32 * sizeof(cell); + +#if defined(FACTOR_PPC) + callstack_size = 256 * sizeof(cell); +#else + callstack_size = 128 * sizeof(cell); +#endif + + code_size = 64; + young_size = sizeof(cell) / 4; + aging_size = sizeof(cell) / 2; + tenured_size = 24 * sizeof(cell); + + max_pic_size = 3; + + fep = false; + signals = true; + +#ifdef WINDOWS + console = GetConsoleWindow() != NULL; +#else + console = true; +#endif + + callback_size = 256; +} + +void vm_parameters::init_from_args(int argc, vm_char** argv) { + executable_path = argv[0]; + + int i = 0; + + for (i = 1; i < argc; i++) { + vm_char* arg = argv[i]; + if (STRCMP(arg, STRING_LITERAL("--")) == 0) + break; + else if (factor_arg(arg, STRING_LITERAL("-datastack=%d"), + &datastack_size)) + ; + else if (factor_arg(arg, STRING_LITERAL("-retainstack=%d"), + &retainstack_size)) + ; + else if (factor_arg(arg, STRING_LITERAL("-callstack=%d"), + &callstack_size)) + ; + else if (factor_arg(arg, STRING_LITERAL("-young=%d"), &young_size)) + ; + else if (factor_arg(arg, STRING_LITERAL("-aging=%d"), &aging_size)) + ; + else if (factor_arg(arg, STRING_LITERAL("-tenured=%d"), &tenured_size)) + ; + else if (factor_arg(arg, STRING_LITERAL("-codeheap=%d"), &code_size)) + ; + else if (factor_arg(arg, STRING_LITERAL("-pic=%d"), &max_pic_size)) + ; + else if (factor_arg(arg, STRING_LITERAL("-callbacks=%d"), &callback_size)) + ; + else if (STRNCMP(arg, STRING_LITERAL("-i="), 3) == 0) + image_path = arg + 3; + else if (STRCMP(arg, STRING_LITERAL("-fep")) == 0) + fep = true; + else if (STRCMP(arg, STRING_LITERAL("-nosignals")) == 0) + signals = false; + else if (STRCMP(arg, STRING_LITERAL("-console")) == 0) + console = true; + } +} + void factor_vm::load_data_heap(FILE* file, image_header* h, vm_parameters* p) { p->tenured_size = std::max((h->data_size * 3) / 2, p->tenured_size); diff --git a/vm/image.hpp b/vm/image.hpp index c43e8e9fc7..36709b2ec1 100644 --- a/vm/image.hpp +++ b/vm/image.hpp @@ -43,6 +43,9 @@ struct vm_parameters { bool signals; cell max_pic_size; cell callback_size; + + vm_parameters(); + void init_from_args(int argc, vm_char** argv); }; } diff --git a/vm/vm.hpp b/vm/vm.hpp index d21172ea1b..f737fcd763 100644 --- a/vm/vm.hpp +++ b/vm/vm.hpp @@ -694,9 +694,6 @@ struct factor_vm { void set_fpu_state(cell state); // factor - void default_parameters(vm_parameters* p); - bool factor_arg(const vm_char* str, const vm_char* arg, cell* value); - void init_parameters_from_args(vm_parameters* p, int argc, vm_char** argv); void prepare_boot_image(); void init_factor(vm_parameters* p); void pass_args_to_factor(int argc, vm_char** argv);