From cfc9b8dd1cd074f6cfa86d4ee103990bb1188a53 Mon Sep 17 00:00:00 2001 From: jaortega Date: Sun, 3 Dec 2000 21:49:11 +0000 Subject: (cmd_weval_) added weval command (cmd_psym_) corrected bug preventing symbol table printing --- mixutils/mixvm_command.c | 56 +++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 51 insertions(+), 5 deletions(-) (limited to 'mixutils') diff --git a/mixutils/mixvm_command.c b/mixutils/mixvm_command.c index ebf66a3..19eddf0 100644 --- a/mixutils/mixvm_command.c +++ b/mixutils/mixvm_command.c @@ -31,6 +31,7 @@ #include #include +#include "mixlib/mix_eval.h" #include "mixvm_command.h" /* The names of functions that actually do the manipulation. */ @@ -59,6 +60,7 @@ DEC_FUN (cbpa_); DEC_FUN (cabp_); DEC_FUN (compile_); DEC_FUN (edit_); +DEC_FUN (weval_); DEC_FUN (quit_); /* A structure which contains information on the commands this program @@ -103,6 +105,7 @@ COMMAND commands[] = { { "cabp", cmd_cabp_, N_("Clear all breakpoints"), "cabp" }, { "compile", cmd_compile_, N_("Compile a source file"), "compile FILENAME"}, { "edit", cmd_edit_, N_("Edit a source file"), "edit FILENAME"}, + { "weval", cmd_weval_, N_("Evaluate a given W-expres sion"), "weval WEXPR"}, { "quit", cmd_quit_, N_("Quit the program"), "quit" }, { (char *)NULL, (Function *)NULL, (char *)NULL } }; @@ -184,6 +187,10 @@ find_command_ (const char *name) static mix_vm_t *vm_ = NULL; static mix_dump_context_t *dc_ = NULL; +/* the w-expression evaluator */ +static mix_eval_t *eval_ = NULL; + + static int cmd_help_ (char *arg) { @@ -239,6 +246,10 @@ cmd_load_ (char *arg) perror (NULL); return TRUE + 1; } + mix_eval_use_symbol_table (eval_, + (mix_symbol_table_t *) + mix_vm_get_symbol_table (vm_)); + fprintf (stderr, _("Program loaded. Start address: %d\n"), mix_vm_get_prog_count (vm_)); @@ -341,13 +352,13 @@ cmd_psym_ (char *arg) if ( mix_symbol_table_is_defined (table, arg) ) { mix_word_print (mix_symbol_table_value (table, arg), NULL); - puts ("\n"); + putc ('\n', stdout); } else printf (_("%s: symbol not defined\n"), arg); } else - mix_symbol_table_print (table, MIX_SYM_ROWS, stdout, FALSE); + mix_symbol_table_print (table, MIX_SYM_ROWS, stdout, TRUE); return TRUE; } @@ -789,10 +800,10 @@ cmd_edit_ (char *arg) if (!editor) { int k; - fputs ("Cannot find editor (", stderr); + fputs (_("Cannot find editor ("), stderr); for (k = 0; k < s; k++) fprintf (stderr, "%s ", envars[k]); - fputs ("undefined)\n", stderr); + fputs (_("undefined)\n"), stderr); } else { @@ -804,6 +815,36 @@ cmd_edit_ (char *arg) return TRUE; } +static int +cmd_weval_ (char *arg) +{ + if ( strlen (arg) == 0 ) + return cmd_help_ ("weval"); + + if (mix_eval_expression_with_loc (eval_, arg, + mix_vm_get_prog_count (vm_)) == + MIX_EVAL_OK) + { + mix_word_print (mix_eval_value (eval_), NULL); + putc ('\n', stdout); + } + else + { + gint pos = mix_eval_last_error_pos (eval_); + gint k, len = strlen (arg); + g_assert(pos > -1 && pos <= len); + for (k = 0; k