summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--mixutils/mixvm_command.c56
1 files changed, 51 insertions, 5 deletions
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 <mixlib/mix_vm.h>
#include <mixlib/mix_vm_dump.h>
+#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<pos; ++k) fputc (arg[k], stderr);
+ fputc ('\n', stderr);
+ for (k = 0; k<pos; ++k) fputc (' ', stderr);
+ for (k = pos; k < len; ++k) fputc (arg[k], stderr);
+ fprintf (stderr, _("\nEvaluation error: %s\n"),
+ mix_eval_last_error_string (eval_));
+ }
+
+ return TRUE;
+}
+
+
/* external interface */
void
@@ -816,7 +857,9 @@ mixvm_cmd_init (char *arg)
dc_ = mix_dump_context_new (MIX_DUMP_DEF_CHANNEL,
MIX_SHORT_ZERO, MIX_SHORT_ZERO,
MIX_DUMP_ALL);
- if ( vm_ == NULL || dc_ == NULL )
+ eval_ = mix_eval_new ();
+
+ if ( vm_ == NULL || dc_ == NULL || eval_ == NULL)
g_error (_("Failed initialisation (no memory resources)"));
if (arg)
cmd_load_ (arg);
@@ -846,6 +889,9 @@ mixvm_cmd_exec (char *line)
if (line[i])
line[i++] = '\0';
+ if (word == NULL || strlen (word) == 0)
+ return TRUE;
+
command = find_command_ (word);
if (!command)