diff options
Diffstat (limited to 'mixutils/mixvm_loop.c')
-rw-r--r-- | mixutils/mixvm_loop.c | 49 |
1 files changed, 24 insertions, 25 deletions
diff --git a/mixutils/mixvm_loop.c b/mixutils/mixvm_loop.c index f9672e8..023d82d 100644 --- a/mixutils/mixvm_loop.c +++ b/mixutils/mixvm_loop.c @@ -78,42 +78,41 @@ rl_gets () /* The main command loop of the virtual machine */ -void -mix_vmloop (const gchar *file, gboolean use_emacs) +static mix_config_t *config_ = NULL; + +static void +init_mixvm_ (const gchar *file, gboolean use_emacs) { static const gchar *HISTORY_FILE = "mixvm.history"; static gint HISTORY_SIZE = 100; - mix_config_t *config = mix_config_new (NULL, CONFIG_FILE_); + config_ = mix_config_new (NULL, CONFIG_FILE_); - mix_config_set_autosave (config, TRUE); - if (!mix_config_get_history_file (config)) - mix_config_set_history_file (config, HISTORY_FILE); - if (mix_config_get_history_size (config) == 0) - mix_config_set_history_size (config, HISTORY_SIZE); + mix_config_set_autosave (config_, TRUE); + if (!mix_config_get_history_file (config_)) + mix_config_set_history_file (config_, HISTORY_FILE); + if (mix_config_get_history_size (config_) == 0) + mix_config_set_history_size (config_, HISTORY_SIZE); - mixvm_cmd_init (config, (char *)file, use_emacs); + mixvm_cmd_init (config_, (char *)file, use_emacs); +} + +void +mix_vmloop (const gchar *file, gboolean use_emacs) +{ + init_mixvm_ (file, use_emacs); while ( mixvm_cmd_exec (rl_gets ()) ) ; - if (config) mix_config_delete (config); + mix_config_delete (config_); } /* run a program and exit */ void mix_vmrun (const gchar *code_file, gboolean dump) { - mix_vm_t *vm = mix_vm_new (); - if (!mix_vm_load_file (vm, code_file)) { - fprintf (stderr, _("Error loading %s file\n"), code_file); - return; - } - mix_vm_run (vm); - printf (_("** Execution time: %ld\n"), mix_vm_get_uptime (vm)); - if (dump) { - mix_dump_context_t *dc = mix_dump_context_new (MIX_DUMP_DEF_CHANNEL, - 0, 0, - MIX_DUMP_ALL_NOMEM); - mix_vm_dump (vm, dc); - mix_dump_context_delete (dc); - } - mix_vm_delete (vm); + gboolean result; + + init_mixvm_ (code_file, FALSE); + result = mixvm_cmd_exec (g_strdup ("run")); + if (result && dump) mixvm_cmd_exec (g_strdup ("pall")); + mix_config_delete (config_); } |