Interactive interpreter

master
Yevgen Muntyan 2006-03-08 02:19:44 -06:00
parent 1c1443c1ee
commit 458304c621
3 changed files with 70 additions and 13 deletions

View File

@ -268,16 +268,16 @@
</kdevdoctreeview>
<kdevfilecreate>
<filetypes>
<type icon="source" ext="g" name="GAP source" create="template" >
<type icon="source" ext="g" create="template" name="GAP source" >
<descr>A new empty GAP source file</descr>
</type>
<type icon="source_cpp" ext="cpp" name="C++ Source" create="template" >
<type icon="source_cpp" ext="cpp" create="template" name="C++ Source" >
<descr>A new empty C++ file.</descr>
</type>
<type icon="source_h" ext="h" name="C/C++ Header" create="template" >
<type icon="source_h" ext="h" create="template" name="C/C++ Header" >
<descr>A new empty header file for C/C++.</descr>
</type>
<type icon="source_c" ext="c" name="C Source" create="template" >
<type icon="source_c" ext="c" create="template" name="C Source" >
<descr>A new empty C file.</descr>
</type>
</filetypes>

View File

@ -1,4 +1,4 @@
EXTRA_PROGRAMS += medit mterm markup termbuffer testfileview testpaned testpanedfileview miniglade langparser testobject testfold mscript
EXTRA_PROGRAMS += medit mterm markup termbuffer testfileview testpaned testpanedfileview miniglade langparser testobject testfold ms
bin_PROGRAMS =
@ -99,14 +99,14 @@ endif
##############################################################################
## mscript
## ms
##
mscript_LDFLAGS = $(ldflags)
mscript_LDADD = $(ldadd)
mscript_SOURCES = tests/mscript.c
ms_LDFLAGS = $(ldflags)
ms_LDADD = $(ldadd) -lreadline
ms_SOURCES = tests/mscript.c
if !MOO_BUILD_LIB
mscript_SOURCES += $(libmoo_sources)
nodist_mscript_SOURCES = $(nodist_libmoo_sources)
ms_SOURCES += $(libmoo_sources)
nodist_ms_SOURCES = $(nodist_libmoo_sources)
endif

View File

@ -15,6 +15,9 @@
#include <gtk/gtk.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <readline/readline.h>
#include <readline/history.h>
static void usage (const char *prg)
@ -24,6 +27,60 @@ static void usage (const char *prg)
}
static int run_interactive (void)
{
MSContext *ctx;
using_history ();
ctx = ms_context_new ();
while (TRUE)
{
char *line;
MSNode *node;
MSValue *val;
line = readline (">>> ");
if (!line)
{
g_print ("\n");
return 0;
}
node = ms_script_parse (line);
add_history (line);
free (line);
if (!node)
{
g_print ("syntax error\n");
continue;
}
val = ms_top_node_eval (node, ctx);
ms_node_unref (node);
if (!val)
{
g_print ("%s\n", ms_context_get_error_msg (ctx));
ms_context_clear_error (ctx);
continue;
}
if (!ms_value_is_none (val))
{
char *s = ms_value_print (val);
g_print ("%s\n", s);
g_free (s);
}
ms_value_unref (val);
}
}
int main (int argc, char *argv[])
{
const char *file = NULL;
@ -32,11 +89,11 @@ int main (int argc, char *argv[])
MSValue *val;
MSContext *ctx;
// gtk_init (&argc, &argv);
g_type_init ();
ms_type_init ();
if (argc < 2)
usage (argv[0]);
return run_interactive ();
if (argc == 2)
file = argv[1];