Objectified MSContext

This commit is contained in:
Yevgen Muntyan 2007-07-12 05:12:15 -05:00
parent fed8af5f27
commit 2ad1088945
23 changed files with 737 additions and 1181 deletions

View File

@ -83,12 +83,14 @@
#include <mooutils/mooutils-misc.h>
#include <mooutils/moowindow.h>
#ifdef __OBJC__
#include <mooscript/mooscript-context.h>
#include <mooscript/mooscript-func.h>
#include <mooscript/mooscript-node.h>
#include <mooscript/mooscript-parser.h>
#include <mooscript/mooscript-value.h>
#include <mooscript/mooscript-zenity.h>
#endif
#include <moofileview/moofileview.h>

View File

@ -104,6 +104,7 @@ endif
EXTRA_DIST = \
$(languagespecs_DATA) \
moo.xml.in
moo.xml.in \
styles.rng
CLEANFILES = \
moo.xml

View File

@ -51,7 +51,7 @@ set_variable (const char *name,
ms_value = ms_value_from_gvalue (value);
g_return_if_fail (ms_value != NULL);
ms_context_assign_variable (ctx, name, ms_value);
[ctx assignVariable:name :ms_value];
ms_value_unref (ms_value);
}
@ -68,8 +68,8 @@ moo_command_script_run (MooCommand *cmd_base,
g_return_if_fail (cmd->priv->script != NULL);
script_ctx = moo_edit_script_context_new (moo_command_context_get_doc (ctx),
moo_command_context_get_window (ctx));
script_ctx = [MooEditScriptContext new:moo_command_context_get_doc (ctx)
:moo_command_context_get_window (ctx)];
g_return_if_fail (script_ctx != NULL);
moo_command_context_foreach (ctx, set_variable, script_ctx);
@ -87,12 +87,12 @@ moo_command_script_run (MooCommand *cmd_base,
if (!ret)
{
g_print ("%s\n", ms_context_get_error_msg (script_ctx));
ms_context_clear_error (script_ctx);
g_print ("%s\n", [script_ctx getErrorMsg]);
[script_ctx clearError];
}
ms_value_unref (ret);
g_object_unref (script_ctx);
[script_ctx release];
}

View File

@ -21,34 +21,16 @@
G_BEGIN_DECLS
#define MOO_TYPE_EDIT_SCRIPT_CONTEXT (moo_edit_script_context_get_type ())
#define MOO_EDIT_SCRIPT_CONTEXT(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), MOO_TYPE_EDIT_SCRIPT_CONTEXT, MooEditScriptContext))
#define MOO_EDIT_SCRIPT_CONTEXT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MOO_TYPE_EDIT_SCRIPT_CONTEXT, MooEditScriptContextClass))
#define MOO_IS_EDIT_SCRIPT_CONTEXT(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), MOO_TYPE_EDIT_SCRIPT_CONTEXT))
#define MOO_IS_EDIT_SCRIPT_CONTEXT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MOO_TYPE_EDIT_SCRIPT_CONTEXT))
#define MOO_EDIT_SCRIPT_CONTEXT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MOO_TYPE_EDIT_SCRIPT_CONTEXT, MooEditScriptContextClass))
typedef struct _MooEditScriptContext MooEditScriptContext;
typedef struct _MooEditScriptContextClass MooEditScriptContextClass;
struct _MooEditScriptContext {
MSContext base;
@interface MooEditScriptContext : MSContext {
@private
GtkTextView *doc;
};
struct _MooEditScriptContextClass {
MSContextClass base_class;
};
GType moo_edit_script_context_get_type (void) G_GNUC_CONST;
MSContext *moo_edit_script_context_new (GtkTextView *doc,
GtkWindow *window);
void moo_edit_script_context_set_doc (MooEditScriptContext *ctx,
GtkTextView *doc);
+ (MooEditScriptContext*) new:(GtkTextView*) doc
:(GtkWindow*) window;
- (void) setDoc:(GtkTextView*) doc;
- (GtkTextView*) doc;
@end
G_END_DECLS

View File

@ -26,83 +26,36 @@
#define MS_VAR_EXT "ext"
static void add_text_api (MSContext *ctx);
static void add_editor_api (MSContext *ctx);
@interface MooEditScriptContext (MooEditScriptContextPrivate)
- (void) addTextApi;
- (void) addEditorApi;
@end
G_DEFINE_TYPE (MooEditScriptContext, moo_edit_script_context, MS_TYPE_CONTEXT)
@implementation MooEditScriptContext : MSContext
enum {
PROP_0,
PROP_DOC
};
static void
moo_edit_script_context_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
+ (MooEditScriptContext*) new:(GtkTextView*) doc
:(GtkWindow*) window
{
MooEditScriptContext *ctx = MOO_EDIT_SCRIPT_CONTEXT (object);
MooEditScriptContext *ctx;
switch (prop_id)
{
case PROP_DOC:
moo_edit_script_context_set_doc (ctx, g_value_get_object (value));
break;
ctx = [[self alloc] init];
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
[ctx setDoc:doc];
if (window)
[ctx setWindow:window];
return ctx;
}
static void
moo_edit_script_context_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
- init
{
MooEditScriptContext *ctx = MOO_EDIT_SCRIPT_CONTEXT (object);
switch (prop_id)
{
case PROP_DOC:
g_value_set_object (value, ctx->doc);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
[super init];
[self addTextApi];
[self addEditorApi];
return self;
}
}
static void
moo_edit_script_context_class_init (MooEditScriptContextClass *klass)
{
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
gobject_class->set_property = moo_edit_script_context_set_property;
gobject_class->get_property = moo_edit_script_context_get_property;
g_object_class_install_property (gobject_class,
PROP_DOC,
g_param_spec_object ("doc", "doc", "doc",
GTK_TYPE_TEXT_VIEW,
G_PARAM_READWRITE));
}
static void
moo_edit_script_context_init (MooEditScriptContext *ctx)
{
add_text_api (MS_CONTEXT (ctx));
add_editor_api (MS_CONTEXT (ctx));
}
static void
get_extension (const char *string,
@ -127,34 +80,31 @@ get_extension (const char *string,
}
}
void
moo_edit_script_context_set_doc (MooEditScriptContext *ctx,
GtkTextView *doc)
- (void) setDoc:(GtkTextView*) new_doc
{
MSValue *val;
GtkWidget *window = NULL;
g_return_if_fail (MOO_IS_EDIT_SCRIPT_CONTEXT (ctx));
g_return_if_fail (!doc || GTK_IS_TEXT_VIEW (doc));
g_return_if_fail (!new_doc || GTK_IS_TEXT_VIEW (new_doc));
if (doc)
if (new_doc)
{
window = gtk_widget_get_toplevel (GTK_WIDGET (doc));
window = gtk_widget_get_toplevel (GTK_WIDGET (new_doc));
if (!GTK_IS_WINDOW (window))
window = NULL;
}
g_object_set (ctx, "window", window, NULL);
[self setWindow:window];
val = ms_value_dict ();
if (MOO_IS_EDIT (doc))
if (MOO_IS_EDIT (new_doc))
{
char *filename = NULL, *basename = NULL;
char *dirname = NULL, *base = NULL, *ext = NULL;
filename = moo_edit_get_filename (MOO_EDIT (doc));
filename = moo_edit_get_filename (MOO_EDIT (new_doc));
if (filename)
{
@ -187,120 +137,18 @@ moo_edit_script_context_set_doc (MooEditScriptContext *ctx,
ms_value_dict_set_string (val, MS_VAR_EXT, NULL);
}
ms_context_assign_variable (MS_CONTEXT (ctx), MS_VAR_DOC, val);
[self assignVariable:MS_VAR_DOC :val];
ms_value_unref (val);
ctx->doc = doc;
g_object_notify (G_OBJECT (ctx), "doc");
doc = new_doc;
}
MSContext *
moo_edit_script_context_new (GtkTextView *doc,
GtkWindow *window)
- (GtkTextView*) doc
{
g_return_val_if_fail (!window || GTK_IS_WINDOW (window), NULL);
g_return_val_if_fail (!doc || GTK_IS_TEXT_VIEW (doc), NULL);
if (window)
return g_object_new (MOO_TYPE_EDIT_SCRIPT_CONTEXT,
"window", window,
"doc", doc,
NULL);
else
return g_object_new (MOO_TYPE_EDIT_SCRIPT_CONTEXT,
"doc", doc,
NULL);
return doc;
}
#if 0
// MSContext *
// moo_text_context_new (GtkTextView *doc)
// {
// GtkWidget *window;
// MSContext *ctx;
//
// g_return_val_if_fail (GTK_IS_TEXT_VIEW (doc), NULL);
//
// if (MOO_IS_EDIT (doc))
// return moo_edit_script_context_new (MOO_EDIT (doc), NULL);
//
// window = gtk_widget_get_toplevel (GTK_WIDGET (doc));
//
// ctx = g_object_new (MS_TYPE_CONTEXT,
// "window", GTK_IS_WINDOW (window) ? window : NULL,
// NULL);
//
// moo_edit_script_context_init_text_api (ctx);
//
// return ctx;
// }
//
//
// static void
// moo_edit_set_shell_vars (MooCommand *cmd,
// MooEdit *doc,
// MooEditWindow *window)
// {
// if (doc)
// {
// char *dirname = NULL, *base = NULL, *ext = NULL;
//
// if (moo_edit_get_filename (doc))
// dirname = g_path_get_dirname (moo_edit_get_filename (doc));
//
// if (moo_edit_get_basename (doc))
// get_extension (moo_edit_get_basename (doc), &base, &ext);
//
// moo_command_set_shell_var (cmd, MS_VAR_FILE,
// moo_edit_get_filename (doc));
// moo_command_set_shell_var (cmd, MS_VAR_NAME,
// moo_edit_get_basename (doc));
// moo_command_set_shell_var (cmd, MS_VAR_BASE, base);
// moo_command_set_shell_var (cmd, MS_VAR_EXT, ext);
// moo_command_set_shell_var (cmd, MS_VAR_DIR, dirname);
//
// g_free (base);
// g_free (ext);
// g_free (dirname);
// }
// else
// {
// moo_command_set_shell_var (cmd, MS_VAR_FILE, NULL);
// moo_command_set_shell_var (cmd, MS_VAR_BASE, NULL);
// moo_command_set_shell_var (cmd, MS_VAR_EXT, NULL);
// moo_command_set_shell_var (cmd, MS_VAR_DIR, NULL);
// }
// }
//
//
// void
// moo_edit_setup_command (MooCommand *cmd,
// MooEdit *doc,
// MooEditWindow *window)
// {
// MSContext *ctx;
//
// g_return_if_fail (MOO_IS_COMMAND (cmd));
// g_return_if_fail (!window || MOO_IS_EDIT_WINDOW (window));
// g_return_if_fail (!doc || MOO_IS_EDIT (doc));
//
// if (!doc && window)
// doc = moo_edit_window_get_active_doc (window);
//
// ctx = moo_edit_script_context_new (doc, window);
//
// moo_command_set_context (cmd, ctx);
//
// if (ctx->py_dict)
// moo_command_set_py_dict (cmd, ctx->py_dict);
//
// g_object_unref (ctx);
//
// moo_edit_set_shell_vars (cmd, doc, window);
// }
#endif
@end
/******************************************************************/
@ -341,13 +189,12 @@ static MSFunc *builtin_funcs[N_BUILTIN_FUNCS];
#define CHECK_DOC(ctx,doc) \
G_STMT_START { \
doc = MOO_EDIT_SCRIPT_CONTEXT(ctx)->doc; \
doc = [(MooEditScriptContext*)ctx doc]; \
\
if (!doc) \
{ \
ms_context_set_error (MS_CONTEXT (ctx), \
MS_ERROR_TYPE, \
"Document not set"); \
[ctx setError:MS_ERROR_TYPE \
:"Document not set"]; \
return NULL; \
} \
} G_STMT_END
@ -365,8 +212,8 @@ check_one_arg (MSValue **args,
if (n_args > 1)
{
ms_context_set_error (ctx, MS_ERROR_TYPE,
"number of args must be zero or one");
[ctx setError:MS_ERROR_TYPE
:"number of args must be zero or one"];
return FALSE;
}
@ -378,15 +225,15 @@ check_one_arg (MSValue **args,
if (!ms_value_get_int (args[0], &val))
{
ms_context_set_error (ctx, MS_ERROR_TYPE,
"argument must be integer");
[ctx setError:MS_ERROR_TYPE
:"argument must be integer"];
return FALSE;
}
if (nonnegative && val < 0)
{
ms_context_set_error (ctx, MS_ERROR_VALUE,
"argument must be non-negative");
[ctx setError:MS_ERROR_TYPE
:"argument must be non-negative"];
return FALSE;
}
@ -612,8 +459,8 @@ cfunc_select (MSValue *arg,
CHECK_DOC (ctx, doc);
if (!ms_value_get_int (arg, &n))
return ms_context_set_error (MS_CONTEXT (ctx), MS_ERROR_TYPE,
"argument must be integer");
return [ctx setError:MS_ERROR_TYPE
:"argument must be an integer"];
buffer = gtk_text_view_get_buffer (doc);
gtk_text_buffer_get_iter_at_mark (buffer, &start,
@ -726,12 +573,12 @@ cfunc_insert_placeholder (MSValue **args,
CHECK_DOC (ctx, doc);
if (n_args > 1)
return ms_context_set_error (ctx, MS_ERROR_TYPE,
"number of args must be zero or one");
return [ctx setError:MS_ERROR_TYPE
:"number of args must be zero or one"];
if (!MOO_IS_TEXT_VIEW (doc))
return ms_context_set_error (ctx, MS_ERROR_TYPE,
"document does not support placeholders");
return [ctx setError:MS_ERROR_TYPE
:"document does not support placeholders"];
if (n_args)
text = ms_value_print (args[0]);
@ -785,33 +632,20 @@ init_text_api (void)
if (builtin_funcs[0])
return;
builtin_funcs[FUNC_BACKSPACE] = ms_cfunc_new_var (cfunc_backspace);
builtin_funcs[FUNC_DELETE] = ms_cfunc_new_var (cfunc_delete);
builtin_funcs[FUNC_INSERT] = ms_cfunc_new_var (cfunc_insert);
builtin_funcs[FUNC_INSERT_PLACEHOLDER] = ms_cfunc_new_var (cfunc_insert_placeholder);
builtin_funcs[FUNC_UP] = ms_cfunc_new_var (cfunc_up);
builtin_funcs[FUNC_DOWN] = ms_cfunc_new_var (cfunc_down);
builtin_funcs[FUNC_LEFT] = ms_cfunc_new_var (cfunc_left);
builtin_funcs[FUNC_RIGHT] = ms_cfunc_new_var (cfunc_right);
builtin_funcs[FUNC_SELECT] = ms_cfunc_new_1 (cfunc_select);
builtin_funcs[FUNC_SELECTION] = ms_cfunc_new_0 (cfunc_selection);
builtin_funcs[FUNC_NEWLINE] = ms_cfunc_new_var (cfunc_newline);
builtin_funcs[FUNC_CUT] = ms_cfunc_new_0 (cfunc_cut);
builtin_funcs[FUNC_COPY] = ms_cfunc_new_0 (cfunc_copy);
builtin_funcs[FUNC_PASTE] = ms_cfunc_new_0 (cfunc_paste);
}
static void
add_text_api (MSContext *ctx)
{
guint i;
init_text_api ();
for (i = 0; i < N_BUILTIN_FUNCS; ++i)
ms_context_set_func (ctx, builtin_func_names[i],
builtin_funcs[i]);
builtin_funcs[FUNC_BACKSPACE] = [MSCFunc newVar:cfunc_backspace];
builtin_funcs[FUNC_DELETE] = [MSCFunc newVar:cfunc_delete];
builtin_funcs[FUNC_INSERT] = [MSCFunc newVar:cfunc_insert];
builtin_funcs[FUNC_INSERT_PLACEHOLDER] = [MSCFunc newVar:cfunc_insert_placeholder];
builtin_funcs[FUNC_UP] = [MSCFunc newVar:cfunc_up];
builtin_funcs[FUNC_DOWN] = [MSCFunc newVar:cfunc_down];
builtin_funcs[FUNC_LEFT] = [MSCFunc newVar:cfunc_left];
builtin_funcs[FUNC_RIGHT] = [MSCFunc newVar:cfunc_right];
builtin_funcs[FUNC_SELECT] = [MSCFunc new1:cfunc_select];
builtin_funcs[FUNC_SELECTION] = [MSCFunc new0:cfunc_selection];
builtin_funcs[FUNC_NEWLINE] = [MSCFunc newVar:cfunc_newline];
builtin_funcs[FUNC_CUT] = [MSCFunc new0:cfunc_cut];
builtin_funcs[FUNC_COPY] = [MSCFunc new0:cfunc_copy];
builtin_funcs[FUNC_PASTE] = [MSCFunc new0:cfunc_paste];
}
@ -842,16 +676,16 @@ cfunc_open (MSValue *arg,
MooEditWindow *window;
char *filename;
g_return_val_if_fail (MOO_IS_EDIT_SCRIPT_CONTEXT (ctx), NULL);
g_return_val_if_fail (ctx != nil, NULL);
doc = MOO_EDIT_SCRIPT_CONTEXT(ctx)->doc;
doc = [(MooEditScriptContext*)ctx doc];
editor = MOO_IS_EDIT (doc) ? MOO_EDIT (doc)->priv->editor : moo_editor_instance ();
g_return_val_if_fail (MOO_IS_EDITOR (editor), NULL);
window = MOO_IS_EDIT_WINDOW (ctx->window) ? MOO_EDIT_WINDOW (ctx->window) : NULL;
window = MOO_IS_EDIT_WINDOW ([ctx window]) ? MOO_EDIT_WINDOW ([ctx window]) : NULL;
filename = ms_value_print (arg);
new_doc = moo_editor_open_file (editor, window, ctx->window, filename, NULL);
new_doc = moo_editor_open_file (editor, window, [ctx window], filename, NULL);
g_free (filename);
return ms_value_bool (new_doc != NULL);
@ -864,18 +698,33 @@ init_editor_api (void)
if (builtin_editor_funcs[0])
return;
builtin_editor_funcs[FUNC_OPEN] = ms_cfunc_new_1 (cfunc_open);
builtin_editor_funcs[FUNC_OPEN] = [MSCFunc new1:cfunc_open];
}
static void
add_editor_api (MSContext *ctx)
@implementation MooEditScriptContext (MooEditScriptContextPrivate)
- (void) addTextApi
{
guint i;
init_text_api ();
for (i = 0; i < N_BUILTIN_FUNCS; ++i)
[self setFunc:builtin_func_names[i] :builtin_funcs[i]];
}
- (void) addEditorApi
{
guint i;
init_editor_api ();
for (i = 0; i < N_BUILTIN_EDITOR_FUNCS; ++i)
ms_context_set_func (ctx, builtin_editor_func_names[i],
builtin_editor_funcs[i]);
[self setFunc:builtin_editor_func_names[i] :builtin_editor_funcs[i]];
}
@end
/* -*- objc -*- */

View File

@ -6,6 +6,7 @@ mooscript_yacc: $(srcdir)/mooscript.y
bison -o $(srcdir)/mooscript-yacc.m -d $(srcdir)/mooscript.y
mooscript.lo: mooscript-yacc.lo
mooscript-context-private.lo: mooscript-context.lo
mooscript_headers = \
mooscript-context.h \

View File

@ -29,11 +29,12 @@ print_func (MSValue **args,
for (i = 0; i < n_args; ++i)
{
char *s = ms_value_print (args[i]);
_ms_context_print (ctx, s);
[ctx print:s];
g_free (s);
}
_ms_context_print (ctx, "\n");
[ctx print:"\n"];
return ms_value_none ();
}
@ -51,7 +52,7 @@ len_func (MSValue *val,
case MS_VALUE_DICT:
return ms_value_int (g_hash_table_size (val->u.hash));
default:
return ms_context_set_error (ctx, MS_ERROR_TYPE, NULL);
return [ctx setError:MS_ERROR_TYPE];
}
}
@ -59,7 +60,7 @@ len_func (MSValue *val,
static MSValue*
abort_func (MSContext *ctx)
{
return ms_context_format_error (ctx, MS_ERROR_RUNTIME, "Aborted");
return [ctx formatError:MS_ERROR_RUNTIME :"Aborted"];
}
@ -86,9 +87,9 @@ int_func (MSValue *arg,
if (!ms_value_get_int (arg, &ival))
{
char *str = ms_value_repr (arg);
ms_context_format_error (ctx, MS_ERROR_TYPE,
"could not convert %s to int",
str);
[ctx formatError:MS_ERROR_TYPE
:"could not convert %s to int",
str];
g_free (str);
return NULL;
}
@ -110,8 +111,8 @@ include_func (MSValue *arg,
if (!g_file_get_contents (file, &script, NULL, &error))
{
ms_context_format_error (ctx, MS_ERROR_RUNTIME,
"%s", error->message);
[ctx formatError:MS_ERROR_RUNTIME
:"%s", error->message];
goto error;
}
@ -119,8 +120,8 @@ include_func (MSValue *arg,
if (!node)
{
ms_context_format_error (ctx, MS_ERROR_RUNTIME,
"%s", error->message);
[ctx formatError:MS_ERROR_RUNTIME
:"%s", error->message];
goto error;
}
@ -154,8 +155,8 @@ prefs_get_func (MSValue *arg,
if (!key || !key[0])
{
ms_context_format_error (ctx, MS_ERROR_VALUE,
"empty prefs key");
[ctx formatError:MS_ERROR_VALUE
:"empty prefs key"];
goto out;
}
@ -189,8 +190,8 @@ prefs_set_func (MSValue *arg1,
if (!key || !key[0])
{
ms_context_format_error (ctx, MS_ERROR_VALUE,
"empty prefs key");
[ctx formatError:MS_ERROR_VALUE
:"empty prefs key"];
goto out;
}
@ -220,15 +221,15 @@ exec_func (MSValue *arg,
if (!cmd || !cmd[0])
{
ms_context_format_error (ctx, MS_ERROR_VALUE,
"empty command");
[ctx formatError:MS_ERROR_VALUE
:"empty command"];
goto out;
}
if (!g_spawn_command_line_sync (cmd, &cmd_out, NULL, NULL, &error))
{
ms_context_format_error (ctx, MS_ERROR_RUNTIME,
"%s", error->message);
[ctx formatError:MS_ERROR_RUNTIME
:"%s", error->message];
g_error_free (error);
goto out;
}
@ -270,15 +271,15 @@ exec_async_func (MSValue *arg,
if (!cmd || !cmd[0])
{
ms_context_format_error (ctx, MS_ERROR_VALUE,
"empty command");
[ctx formatError:MS_ERROR_VALUE
:"empty command"];
goto out;
}
if (!g_spawn_command_line_async (cmd, &error))
{
ms_context_format_error (ctx, MS_ERROR_RUNTIME,
"%s", error->message);
[ctx formatError:MS_ERROR_RUNTIME
:"%s", error->message];
g_error_free (error);
goto out;
}
@ -313,17 +314,17 @@ file_exists_func (MSValue *arg,
#define ADD_FUNC(type_,func_,name_) \
G_STMT_START { \
MSFunc *msfunc__; \
msfunc__ = type_ (func_); \
ms_context_set_func (ctx, name_, msfunc__); \
g_object_unref (msfunc__); \
msfunc__ = [MSCFunc type_:func_]; \
[ctx setFunc:name_ :msfunc__]; \
[msfunc__ release]; \
} G_STMT_END
#define ADD_FUNC_OBJ(factory_,name_) \
G_STMT_START { \
MSFunc *msfunc__; \
msfunc__ = factory_ (); \
ms_context_set_func (ctx, name_, msfunc__); \
g_object_unref (msfunc__); \
[ctx setFunc:name_ :msfunc__]; \
[msfunc__ release]; \
} G_STMT_END
#define ADD_CONSTANT(func_,name_) \
@ -331,9 +332,9 @@ G_STMT_START { \
MSVariable *var_; \
MSValue *val_; \
val_ = func_ (); \
var_ = ms_variable_new_value (val_); \
ms_context_set_var (ctx, name_, var_); \
ms_variable_unref (var_); \
var_ = [MSVariable new:val_]; \
[ctx setVar:name_ :var_]; \
[var_ release]; \
ms_value_unref (val_); \
} G_STMT_END;
@ -347,29 +348,29 @@ _ms_context_add_builtin (MSContext *ctx)
ADD_CONSTANT (ms_value_false, "false");
for (i = 0; i < MS_BINARY_OP_LAST; ++i)
ADD_FUNC (ms_cfunc_new_2,
ADD_FUNC (new2,
_ms_binary_op_cfunc (i),
_ms_binary_op_name (i));
for (i = 0; i < MS_UNARY_OP_LAST; ++i)
ADD_FUNC (ms_cfunc_new_1,
ADD_FUNC (new1,
_ms_unary_op_cfunc (i),
_ms_unary_op_name (i));
ADD_FUNC (ms_cfunc_new_1, str_func, "Str");
ADD_FUNC (ms_cfunc_new_1, int_func, "Int");
ADD_FUNC (ms_cfunc_new_1, len_func, "Len");
ADD_FUNC (new1, str_func, "Str");
ADD_FUNC (new1, int_func, "Int");
ADD_FUNC (new1, len_func, "Len");
ADD_FUNC (ms_cfunc_new_var, print_func, "Print");
ADD_FUNC (ms_cfunc_new_1, include_func, "Include");
ADD_FUNC (ms_cfunc_new_0, abort_func, "Abort");
ADD_FUNC (newVar, print_func, "Print");
ADD_FUNC (new1, include_func, "Include");
ADD_FUNC (new0, abort_func, "Abort");
ADD_FUNC (ms_cfunc_new_1, exec_func, "Exec");
ADD_FUNC (ms_cfunc_new_1, exec_async_func, "ExecAsync");
ADD_FUNC (ms_cfunc_new_1, file_exists_func, "FileExists");
ADD_FUNC (new1, exec_func, "Exec");
ADD_FUNC (new1, exec_async_func, "ExecAsync");
ADD_FUNC (new1, file_exists_func, "FileExists");
ADD_FUNC (ms_cfunc_new_1, prefs_get_func, "PrefsGet");
ADD_FUNC (ms_cfunc_new_2, prefs_set_func, "PrefsSet");
ADD_FUNC (new1, prefs_get_func, "PrefsGet");
ADD_FUNC (new2, prefs_set_func, "PrefsSet");
ADD_FUNC_OBJ (ms_zenity_text, "Text");
ADD_FUNC_OBJ (ms_zenity_entry, "Entry");
@ -395,13 +396,13 @@ add_meth (MSValueClass *klass,
MSFunc *func)
{
_ms_value_class_add_method (klass, name, func);
g_object_unref (func);
[func release];
}
#define add_meth0(type, name, cfunc) \
add_meth (&types[type], name, ms_cfunc_new_1 (cfunc))
add_meth (&types[type], name, [MSCFunc new1:cfunc])
#define add_meth1(type, name, cfunc) \
add_meth (&types[type], name, ms_cfunc_new_2 (cfunc))
add_meth (&types[type], name, [MSCFunc new2:cfunc])
static void
@ -486,8 +487,8 @@ list_max_func (MSValue *val,
MSValue *max;
if (!val->u.list.n_elms)
return ms_context_format_error (ctx, MS_ERROR_VALUE,
"requested MAX of empty list");
return [ctx formatError:MS_ERROR_VALUE
:"requested MAX of empty list"];
max = val->u.list.elms[0];
@ -506,8 +507,8 @@ list_min_func (MSValue *val,
MSValue *min;
if (!val->u.list.n_elms)
return ms_context_format_error (ctx, MS_ERROR_VALUE,
"requested MIN of empty list");
return [ctx formatError:MS_ERROR_VALUE
:"requested MIN of empty list"];
min = val->u.list.elms[0];

View File

@ -19,26 +19,29 @@
G_BEGIN_DECLS
@interface MSContext (MSContextPrivate)
- (MSVariable*) lookupVar:(CSTR)name;
- (void) print:(CSTR) string;
- (void) setReturn:(MSValue*) val;
- (MSValue*) getReturn;
- (void) setBreak;
- (void) setContinue;
- (void) unsetReturn;
- (void) unsetBreak;
- (void) unsetContinue;
- (BOOL) returnSet;
- (BOOL) breakSet;
- (BOOL) continueSet;
- (BOOL) errorSet;
@end
void _ms_context_add_builtin (MSContext *ctx);
void _ms_context_print (MSContext *ctx,
const char *string);
void _ms_context_set_return (MSContext *ctx,
MSValue *val);
MSValue *_ms_context_get_return (MSContext *ctx);
void _ms_context_set_break (MSContext *ctx);
void _ms_context_set_continue (MSContext *ctx);
void _ms_context_unset_return (MSContext *ctx);
void _ms_context_unset_break (MSContext *ctx);
void _ms_context_unset_continue (MSContext *ctx);
gboolean _ms_context_return_set (MSContext *ctx);
gboolean _ms_context_break_set (MSContext *ctx);
gboolean _ms_context_continue_set (MSContext *ctx);
gboolean _ms_context_error_set (MSContext *ctx);
G_END_DECLS

View File

@ -14,28 +14,28 @@
#ifndef MOO_SCRIPT_CONTEXT_H
#define MOO_SCRIPT_CONTEXT_H
#include <mooutils/moocobject.h>
#include <mooscript/mooscript-func.h>
G_BEGIN_DECLS
#define MS_TYPE_CONTEXT (ms_context_get_type ())
#define MS_CONTEXT(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), MS_TYPE_CONTEXT, MSContext))
#define MS_CONTEXT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MS_TYPE_CONTEXT, MSContextClass))
#define MS_IS_CONTEXT(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), MS_TYPE_CONTEXT))
#define MS_IS_CONTEXT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MS_TYPE_CONTEXT))
#define MS_CONTEXT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MS_TYPE_CONTEXT, MSContextClass))
typedef struct _MSContextPrivate MSContextPrivate;
typedef struct _MSContextClass MSContextClass;
typedef struct _MSVariable MSVariable;
struct _MSVariable {
guint ref_count;
@interface MSVariable : MooCObject {
@private
MSValue *value;
MSFunc *func; /* called with no arguments */
};
+ (MSVariable*) new:(MSValue*) value;
- (void) setValue:(MSValue*) value;
- (MSValue*) value;
- (void) setFunc:(MSFunc*) func;
- (MSFunc*) func;
@end
typedef enum {
MS_ERROR_NONE = 0,
MS_ERROR_TYPE,
@ -45,59 +45,43 @@ typedef enum {
MS_ERROR_LAST
} MSError;
struct _MSContext {
GObject object;
@interface MSContext : MooCObject {
@private
MSContextPrivate *priv;
gpointer window;
};
}
struct _MSContextClass {
GObjectClass object_class;
+ (MSContext*) new;
+ (MSContext*) new:(gpointer) window;
MSValue* (*get_env_var) (MSContext *ctx,
const char *name);
};
- (void) setWindow:(gpointer) window;
- (gpointer) window;
- (MSValue*) evalVariable:(CSTR) name;
- (BOOL) assignVariable:(CSTR) name
:(MSValue*) value;
- (BOOL) assignPositional:(guint) n
:(MSValue*) value;
- (BOOL) assignString:(CSTR) name
:(CSTR) value;
GType ms_context_get_type (void) G_GNUC_CONST;
- (MSValue*) getEnvVariable:(CSTR) name;
MSVariable *ms_variable_new_value (MSValue *value);
MSVariable *ms_variable_ref (MSVariable *var);
void ms_variable_unref (MSVariable *var);
- (BOOL) setVar:(CSTR) name
:(MSVariable*) var;
MSValue *ms_context_eval_variable (MSContext *ctx,
const char *name);
gboolean ms_context_assign_variable (MSContext *ctx,
const char *name,
MSValue *value);
gboolean ms_context_assign_positional (MSContext *ctx,
guint n,
MSValue *value);
gboolean ms_context_assign_string (MSContext *ctx,
const char *name,
const char *value);
- (BOOL) setFunc:(CSTR) name
:(MSFunc*) func;
MSValue *ms_context_get_env_variable (MSContext *ctx,
const char *name);
- (MSValue*) setError:(MSError) error;
- (MSValue*) setError:(MSError) error
:(CSTR) message;
- (MSValue*) formatError:(MSError) error
:(CSTR) format,
...;
gboolean ms_context_set_var (MSContext *ctx,
const char *name,
MSVariable *var);
gboolean ms_context_set_func (MSContext *ctx,
const char *name,
MSFunc *func);
MSValue *ms_context_set_error (MSContext *ctx,
MSError error,
const char *message);
MSValue *ms_context_format_error (MSContext *ctx,
MSError error,
const char *format,
...);
const char *ms_context_get_error_msg (MSContext *ctx);
void ms_context_clear_error (MSContext *ctx);
- (CSTR) getErrorMsg;
- (void) clearError;
@end
G_END_DECLS

View File

@ -15,6 +15,7 @@
#include "mooscript-parser.h"
#include "mooscript-func-private.h"
#include "mooutils/moomarshals.h"
#include "mooutils/mooutils-misc.h"
#include <glib/gprintf.h>
#include <gtk/gtkwindow.h>
@ -28,103 +29,15 @@ struct _MSContextPrivate {
MSError error;
char *error_msg;
MSPrintFunc print_func;
gpointer window;
MSValue *return_val;
guint break_set : 1;
guint continue_set : 1;
guint return_set : 1;
int argc;
char **argv;
char *name;
};
enum {
PROP_0,
PROP_WINDOW,
PROP_NAME,
PROP_ARGV
};
enum {
GET_ENV_VAR,
N_SIGNALS
};
static guint signals[N_SIGNALS];
G_DEFINE_TYPE (MSContext, ms_context, G_TYPE_OBJECT)
#if GLIB_CHECK_VERSION(2,10,0)
#define ms_variable_alloc() g_slice_new0 (MSVariable)
#define ms_variable_free(v) g_slice_free (MSVariable, v)
#else
#define ms_variable_alloc() g_new0 (MSVariable, 1)
#define ms_variable_free(v) g_free (v)
#endif
static void
ms_context_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
MSContext *ctx = MS_CONTEXT (object);
switch (prop_id)
{
case PROP_WINDOW:
ctx->window = g_value_get_object (value);
g_object_notify (object, "window");
break;
case PROP_NAME:
g_free (ctx->priv->name);
ctx->window = g_strdup (g_value_get_string (value));
g_object_notify (object, "name");
break;
case PROP_ARGV:
g_strfreev (ctx->priv->argv);
ctx->priv->argv = g_strdupv (g_value_get_pointer (value));
ctx->priv->argc = ctx->priv->argv ? g_strv_length (ctx->priv->argv) : 0;
g_object_notify (object, "argv");
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
}
static void
ms_context_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
MSContext *ctx = MS_CONTEXT (object);
switch (prop_id)
{
case PROP_WINDOW:
g_value_set_object (value, ctx->window);
break;
case PROP_NAME:
g_value_set_string (value, ctx->priv->name);
break;
case PROP_ARGV:
g_value_set_pointer (value, ctx->priv->argv);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
}
@implementation MSContext : MooCObject
static void
default_print_func (const char *string,
@ -133,304 +46,227 @@ default_print_func (const char *string,
g_print ("%s", string);
}
static GObject *
ms_context_constructor (GType type,
guint n_props,
GObjectConstructParam *props)
static void
variable_unref (MSVariable *var)
{
if (var)
[var release];
}
- init
{
[super init];
priv = _moo_new0 (MSContextPrivate);
priv->vars = g_hash_table_new_full (g_str_hash, g_str_equal, g_free,
(GDestroyNotify) variable_unref);
priv->print_func = default_print_func;
_ms_context_add_builtin (self);
return self;
}
- (void) dealloc
{
g_hash_table_destroy (priv->vars);
g_free (priv->error_msg);
ms_value_unref (priv->return_val);
_moo_free (MSContextPrivate, priv);
[super dealloc];
}
- (gpointer) window
{
return priv->window;
}
- (void) setWindow:(gpointer) window
{
priv->window = window;
}
+ (MSContext*) new:(gpointer) window
{
GObject *obj;
MSContext *ctx;
obj = G_OBJECT_CLASS(ms_context_parent_class)->constructor (type, n_props, props);
ctx = MS_CONTEXT (obj);
ctx = [[self alloc] init];
[ctx setWindow:window];
if (!ctx->priv->name)
{
if (ctx->priv->argv && ctx->priv->argc)
ctx->priv->name = g_strdup (ctx->priv->argv[0]);
else
ctx->priv->name = g_strdup ("script");
return ctx;
}
if (!ctx->priv->argv || !ctx->priv->argc)
+ (MSContext*) new
{
g_strfreev (ctx->priv->argv);
ctx->priv->argv = g_new0 (char*, 2);
ctx->priv->argv[0] = g_strdup (ctx->priv->name);
ctx->priv->argc = 1;
return [self new:NULL];
}
return obj;
}
static void
ms_context_init (MSContext *ctx)
+ initialize
{
ctx->priv = G_TYPE_INSTANCE_GET_PRIVATE (ctx, MS_TYPE_CONTEXT, MSContextPrivate);
ctx->priv->vars = g_hash_table_new_full (g_str_hash, g_str_equal, g_free,
(GDestroyNotify) ms_variable_unref);
ctx->priv->print_func = default_print_func;
_ms_context_add_builtin (ctx);
}
static void
ms_context_finalize (GObject *object)
{
MSContext *ctx = MS_CONTEXT (object);
g_hash_table_destroy (ctx->priv->vars);
g_free (ctx->priv->error_msg);
ms_value_unref (ctx->priv->return_val);
g_free (ctx->priv->name);
g_strfreev (ctx->priv->argv);
G_OBJECT_CLASS(ms_context_parent_class)->finalize (object);
}
static void
ms_context_class_init (MSContextClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->finalize = ms_context_finalize;
object_class->set_property = ms_context_set_property;
object_class->get_property = ms_context_get_property;
object_class->constructor = ms_context_constructor;
g_type_class_add_private (klass, sizeof (MSContextPrivate));
ms_type_init ();
g_object_class_install_property (object_class,
PROP_WINDOW,
g_param_spec_object ("window",
"window",
"window",
GTK_TYPE_WINDOW,
G_PARAM_READWRITE));
signals[GET_ENV_VAR] =
g_signal_new ("get-env-var",
G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (MSContextClass, get_env_var),
NULL, NULL,
_moo_marshal_BOXED__STRING,
MS_TYPE_VALUE, 1,
G_TYPE_STRING | G_SIGNAL_TYPE_STATIC_SCOPE);
return self;
}
static MSVariable *
ms_context_lookup_var (MSContext *ctx,
const char *name)
{
g_return_val_if_fail (MS_IS_CONTEXT (ctx), NULL);
g_return_val_if_fail (name != NULL, NULL);
return g_hash_table_lookup (ctx->priv->vars, name);
}
MSValue *
ms_context_eval_variable (MSContext *ctx,
const char *name)
- (MSValue*) evalVariable:(CSTR) name
{
MSVariable *var;
g_return_val_if_fail (MS_IS_CONTEXT (ctx), NULL);
g_return_val_if_fail (name != NULL, NULL);
var = ms_context_lookup_var (ctx, name);
var = [self lookupVar:name];
if (!var)
return ms_context_format_error (ctx, MS_ERROR_NAME,
"no variable named '%s'",
name);
return [self formatError:MS_ERROR_NAME
:"no variable named '%s'",
name];
if (var->value)
return ms_value_ref (var->value);
if ([var value])
return ms_value_ref ([var value]);
return _ms_func_call (var->func, NULL, 0, ctx);
return [[var func] call:NULL :0 :self];
}
gboolean
ms_context_assign_variable (MSContext *ctx,
const char *name,
MSValue *value)
- (BOOL) assignVariable:(CSTR) name
:(MSValue*) value
{
MSVariable *var;
g_return_val_if_fail (MS_IS_CONTEXT (ctx), FALSE);
g_return_val_if_fail (name != NULL, FALSE);
g_return_val_if_fail (name != NULL, NO);
var = ms_context_lookup_var (ctx, name);
var = [self lookupVar:name];
if (value)
{
if (var)
{
if (var->func)
{
g_object_unref (var->func);
var->func = NULL;
}
if (var->value != value)
{
ms_value_unref (var->value);
var->value = ms_value_ref (value);
}
[var setValue:value];
}
else
{
var = ms_variable_new_value (value);
ms_context_set_var (ctx, name, var);
ms_variable_unref (var);
var = [MSVariable new:value];
[self setVar:name :var];
[var release];
}
}
else if (var)
{
ms_context_set_var (ctx, name, NULL);
[self setVar:name :NULL];
}
return TRUE;
return YES;
}
- (BOOL) assignPositional:(guint) n
:(MSValue*) value
{
char *name;
gboolean result;
gboolean
ms_context_assign_string (MSContext *ctx,
const char *name,
const char *str_value)
name = g_strdup_printf ("_%u", n);
result = [self assignVariable:name :value];
g_free (name);
return result;
}
- (BOOL) assignString:(CSTR) name
:(CSTR) str_value
{
MSValue *value = NULL;
gboolean retval;
g_return_val_if_fail (MS_IS_CONTEXT (ctx), FALSE);
g_return_val_if_fail (name != NULL, FALSE);
g_return_val_if_fail (name != NULL, NO);
if (str_value)
value = ms_value_string (str_value);
retval = ms_context_assign_variable (ctx, name, value);
retval = [self assignVariable:name :value];
ms_value_unref (value);
return retval;
}
gboolean
ms_context_assign_positional (MSContext *ctx,
guint n,
MSValue *value)
- (MSValue*) getEnvVariable:(CSTR) name
{
char *name;
gboolean result;
g_return_val_if_fail (MS_IS_CONTEXT (ctx), FALSE);
name = g_strdup_printf ("_%u", n);
result = ms_context_assign_variable (ctx, name, value);
g_free (name);
return result;
MOO_UNUSED_VAR (name);
return NULL;
}
gboolean
ms_context_set_var (MSContext *ctx,
const char *name,
MSVariable *var)
- (BOOL) setVar:(CSTR) name
:(MSVariable*) var
{
MSVariable *old;
g_return_val_if_fail (MS_IS_CONTEXT (ctx), FALSE);
g_return_val_if_fail (name != NULL, FALSE);
g_return_val_if_fail (name != NULL, NO);
old = g_hash_table_lookup (ctx->priv->vars, name);
old = g_hash_table_lookup (priv->vars, name);
if (var != old)
{
if (var)
g_hash_table_insert (ctx->priv->vars,
g_hash_table_insert (priv->vars,
g_strdup (name),
ms_variable_ref (var));
[var retain]);
else
g_hash_table_remove (ctx->priv->vars, name);
g_hash_table_remove (priv->vars, name);
}
return TRUE;
return YES;
}
gboolean
ms_context_set_func (MSContext *ctx,
const char *name,
MSFunc *func)
- (BOOL) setFunc:(CSTR) name
:(MSFunc*) func
{
MSValue *vfunc;
gboolean ret;
g_return_val_if_fail (MS_IS_CONTEXT (ctx), FALSE);
g_return_val_if_fail (name != NULL, FALSE);
g_return_val_if_fail (!func || MS_IS_FUNC (func), FALSE);
g_return_val_if_fail (name != NULL, NO);
vfunc = ms_value_func (func);
ret = ms_context_assign_variable (ctx, name, vfunc);
ret = [self assignVariable:name :vfunc];
ms_value_unref (vfunc);
return ret;
}
MSValue *
ms_context_set_error (MSContext *ctx,
MSError error,
const char *message)
- (MSValue*) setError:(MSError) error
{
return [self setError:error :NULL];
}
- (MSValue*) setError:(MSError) error
:(CSTR) message
{
const char *errname;
g_return_val_if_fail (MS_IS_CONTEXT (ctx), NULL);
g_return_val_if_fail (!ctx->priv->error && error, NULL);
g_return_val_if_fail (!ctx->priv->error_msg, NULL);
g_return_val_if_fail (!priv->error && error, NULL);
g_return_val_if_fail (!priv->error_msg, NULL);
ctx->priv->error = error;
errname = ms_context_get_error_msg (ctx);
priv->error = error;
errname = [self getErrorMsg];
if (message && *message)
ctx->priv->error_msg = g_strdup_printf ("%s: %s", errname, message);
priv->error_msg = g_strdup_printf ("%s: %s", errname, message);
else
ctx->priv->error_msg = g_strdup (message);
priv->error_msg = g_strdup (message);
return NULL;
}
MSValue *
ms_context_format_error (MSContext *ctx,
MSError error,
const char *format,
...)
- (MSValue*) formatError:(MSError) error
:(CSTR) format,
...
{
va_list args;
char *string;
g_return_val_if_fail (MS_IS_CONTEXT (ctx), NULL);
g_return_val_if_fail (!ctx->priv->error && error, NULL);
g_return_val_if_fail (!ctx->priv->error_msg, NULL);
g_return_val_if_fail (!priv->error && error, NULL);
g_return_val_if_fail (!priv->error_msg, NULL);
if (!format || !format[0])
{
ms_context_set_error (ctx, error, NULL);
[self setError:error :NULL];
return NULL;
}
@ -438,241 +274,195 @@ ms_context_format_error (MSContext *ctx,
string = _ms_vaprintf (format, args);
va_end (args);
ms_context_set_error (ctx, error, string);
[self setError:error :string];
g_free (string);
return NULL;
}
void
ms_context_clear_error (MSContext *ctx)
{
g_return_if_fail (MS_IS_CONTEXT (ctx));
ctx->priv->error = MS_ERROR_NONE;
g_free (ctx->priv->error_msg);
ctx->priv->error_msg = NULL;
}
const char *
ms_context_get_error_msg (MSContext *ctx)
- (CSTR) getErrorMsg
{
static const char *msgs[MS_ERROR_LAST] = {
NULL, "Type error", "Value error", "Name error",
"Runtime error"
};
g_return_val_if_fail (MS_IS_CONTEXT (ctx), NULL);
g_return_val_if_fail (ctx->priv->error < MS_ERROR_LAST, NULL);
g_return_val_if_fail (ctx->priv->error != MS_ERROR_NONE, "ERROR");
g_return_val_if_fail (priv->error < MS_ERROR_LAST, NULL);
g_return_val_if_fail (priv->error != MS_ERROR_NONE, "ERROR");
if (ctx->priv->error_msg)
return ctx->priv->error_msg;
if (priv->error_msg)
return priv->error_msg;
else
return msgs[ctx->priv->error];
return msgs[priv->error];
}
static MSVariable *
ms_variable_new (void)
- (void) clearError
{
MSVariable *var = ms_variable_alloc ();
var->ref_count = 1;
return var;
priv->error = MS_ERROR_NONE;
g_free (priv->error_msg);
priv->error_msg = NULL;
}
@end
@implementation MSContext (MSContextPrivate)
- (MSVariable*) lookupVar:(CSTR)name
{
g_return_val_if_fail (name != NULL, NULL);
return g_hash_table_lookup (priv->vars, name);
}
MSVariable *
ms_variable_new_value (MSValue *value)
- (void) setReturn:(MSValue*) val
{
g_return_if_fail (!priv->return_set);
priv->return_set = YES;
priv->return_val = val ? ms_value_ref (val) : ms_value_none ();
}
- (MSValue*) getReturn
{
g_return_val_if_fail (priv->return_set, NULL);
return ms_value_ref (priv->return_val);
}
- (void) unsetReturn
{
g_return_if_fail (priv->return_set);
priv->return_set = NO;
ms_value_unref (priv->return_val);
priv->return_val = NULL;
}
- (BOOL) returnSet
{
return priv->return_set;
}
- (void) setBreak
{
g_return_if_fail (!priv->break_set);
priv->break_set = YES;
}
- (void) setContinue
{
g_return_if_fail (!priv->continue_set);
priv->continue_set = YES;
}
- (void) unsetBreak
{
g_return_if_fail (priv->break_set);
priv->break_set = NO;
}
- (void) unsetContinue
{
g_return_if_fail (priv->continue_set);
priv->continue_set = NO;
}
- (BOOL) breakSet
{
return priv->break_set;
}
- (BOOL) continueSet
{
return priv->continue_set;
}
- (BOOL) errorSet;
{
return priv->error != 0;
}
- (void) print:(CSTR) string
{
priv->print_func (string, self);
}
@end
@implementation MSVariable : MooCObject
+ (MSVariable*) new:(MSValue*) value
{
MSVariable *var;
g_return_val_if_fail (value != NULL, NULL);
g_return_val_if_fail (value != NULL, nil);
var = ms_variable_new ();
var = [[self alloc] init];
var->value = ms_value_ref (value);
return var;
}
#if 0
MSVariable *
ms_variable_new_func (MSFunc *func)
- (void) dealloc
{
MSVariable *var;
g_return_val_if_fail (MS_IS_FUNC (func), NULL);
var = ms_variable_new ();
var->func = g_object_ref (func);
return var;
}
#endif
MSVariable *
ms_variable_ref (MSVariable *var)
{
g_return_val_if_fail (var != NULL, NULL);
var->ref_count++;
return var;
if (value)
ms_value_unref (value);
if (func)
[func release];
[super dealloc];
}
void
ms_variable_unref (MSVariable *var)
- (void) setValue:(MSValue*) new_value
{
g_return_if_fail (var != NULL);
if (!--var->ref_count)
if (value != new_value)
{
ms_value_unref (var->value);
if (var->func)
g_object_unref (var->func);
ms_variable_free (var);
if (value)
ms_value_unref (value);
if (new_value)
ms_value_ref (new_value);
value = new_value;
}
if (func)
{
[func release];
func = NULL;
}
}
void
_ms_context_set_return (MSContext *ctx,
MSValue *val)
- (void) setFunc:(MSFunc*) new_func
{
g_assert (MS_IS_CONTEXT (ctx));
g_return_if_fail (!ctx->priv->return_set);
ctx->priv->return_set = TRUE;
ctx->priv->return_val = val ? ms_value_ref (val) : ms_value_none ();
if (func != new_func)
{
if (func)
[func release];
if (new_func)
[new_func retain];
func = new_func;
}
MSValue *
_ms_context_get_return (MSContext *ctx)
if (value)
{
g_assert (MS_IS_CONTEXT (ctx));
g_return_val_if_fail (ctx->priv->return_set, NULL);
return ms_value_ref (ctx->priv->return_val);
ms_value_unref (value);
value = NULL;
}
}
void
_ms_context_set_break (MSContext *ctx)
- (MSValue*) value
{
g_assert (MS_IS_CONTEXT (ctx));
g_return_if_fail (!ctx->priv->break_set);
ctx->priv->break_set = TRUE;
return value;
}
void
_ms_context_set_continue (MSContext *ctx)
- (MSFunc*) func
{
g_assert (MS_IS_CONTEXT (ctx));
g_return_if_fail (!ctx->priv->continue_set);
ctx->priv->continue_set = TRUE;
return func;
}
void
_ms_context_unset_return (MSContext *ctx)
{
g_assert (MS_IS_CONTEXT (ctx));
g_return_if_fail (ctx->priv->return_set);
ctx->priv->return_set = FALSE;
ms_value_unref (ctx->priv->return_val);
ctx->priv->return_val = NULL;
}
@end
void
_ms_context_unset_break (MSContext *ctx)
{
g_assert (MS_IS_CONTEXT (ctx));
g_return_if_fail (ctx->priv->break_set);
ctx->priv->break_set = FALSE;
}
void
_ms_context_unset_continue (MSContext *ctx)
{
g_assert (MS_IS_CONTEXT (ctx));
g_return_if_fail (ctx->priv->continue_set);
ctx->priv->continue_set = FALSE;
}
gboolean
_ms_context_return_set (MSContext *ctx)
{
g_assert (MS_IS_CONTEXT (ctx));
return ctx->priv->return_set;
}
gboolean
_ms_context_break_set (MSContext *ctx)
{
g_assert (MS_IS_CONTEXT (ctx));
return ctx->priv->break_set;
}
gboolean
_ms_context_continue_set (MSContext *ctx)
{
g_assert (MS_IS_CONTEXT (ctx));
return ctx->priv->continue_set;
}
gboolean
_ms_context_error_set (MSContext *ctx)
{
g_assert (MS_IS_CONTEXT (ctx));
return ctx->priv->error != 0;
}
#if 0
MSValue *
ms_context_run_script (MSContext *ctx,
const char *script)
{
MSNode *node;
MSValue *result;
g_return_val_if_fail (MS_IS_CONTEXT (ctx), NULL);
g_return_val_if_fail (script != NULL, NULL);
node = ms_script_parse (script);
g_return_val_if_fail (node != NULL, NULL);
result = ms_top_node_eval (node, ctx);
ms_node_unref (node);
return result;
}
#endif
MSValue *
ms_context_get_env_variable (MSContext *ctx,
const char *name)
{
MSValue *val = NULL;
g_return_val_if_fail (MS_IS_CONTEXT (ctx), NULL);
g_return_val_if_fail (name != NULL, NULL);
g_signal_emit (ctx, signals[GET_ENV_VAR], 0, name, &val);
return val;
}
void
_ms_context_print (MSContext *ctx,
const char *string)
{
g_assert (MS_IS_CONTEXT (ctx));
ctx->priv->print_func (string, ctx);
}
/* -*- objc -*- */

View File

@ -15,42 +15,18 @@
#define MOO_SCRIPT_FUNC_H
#include <mooscript/mooscript-value.h>
#include <mooutils/moocobject.h>
G_BEGIN_DECLS
#define MS_TYPE_FUNC (ms_func_get_type ())
#define MS_FUNC(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), MS_TYPE_FUNC, MSFunc))
#define MS_FUNC_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MS_TYPE_FUNC, MSFuncClass))
#define MS_IS_FUNC(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), MS_TYPE_FUNC))
#define MS_IS_FUNC_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MS_TYPE_FUNC))
#define MS_FUNC_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MS_TYPE_FUNC, MSFuncClass))
@class MSContext;
#define MS_TYPE_CFUNC (ms_cfunc_get_type ())
#define MS_CFUNC(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), MS_TYPE_CFUNC, MSCFunc))
#define MS_CFUNC_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MS_TYPE_CFUNC, MSCFuncClass))
#define MS_IS_CFUNC(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), MS_TYPE_CFUNC))
#define MS_IS_CFUNC_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MS_TYPE_CFUNC))
#define MS_CFUNC_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MS_TYPE_CFUNC, MSCFuncClass))
typedef struct _MSContext MSContext;
typedef struct _MSFuncClass MSFuncClass;
typedef struct _MSCFunc MSCFunc;
typedef struct _MSCFuncClass MSCFuncClass;
struct _MSFunc {
GObject object;
};
typedef MSValue* (*MSFuncCall) (MSFunc *func,
MSValue **args,
guint n_args,
MSContext *ctx);
struct _MSFuncClass {
GObjectClass object_class;
MSFuncCall call;
};
@interface MSFunc : MooCObject
- (MSValue*) call:(MSValue**)args
:(guint) n_args
:(MSContext*) ctx;
@end
typedef MSValue* (*MSCFunc_Var) (MSValue **args,
@ -72,26 +48,19 @@ typedef MSValue* (*MSCFunc_4) (MSValue *arg1,
MSValue *arg4,
MSContext *ctx);
struct _MSCFunc {
MSFunc func;
@interface MSCFunc : MSFunc {
@private
int n_args;
void (*cfunc) (void);
};
}
struct _MSCFuncClass {
MSFuncClass func_class;
};
GType ms_func_get_type (void) G_GNUC_CONST;
GType ms_cfunc_get_type (void) G_GNUC_CONST;
MSFunc *ms_cfunc_new_var (MSCFunc_Var cfunc);
MSFunc *ms_cfunc_new_0 (MSCFunc_0 cfunc);
MSFunc *ms_cfunc_new_1 (MSCFunc_1 cfunc);
MSFunc *ms_cfunc_new_2 (MSCFunc_2 cfunc);
MSFunc *ms_cfunc_new_3 (MSCFunc_3 cfunc);
MSFunc *ms_cfunc_new_4 (MSCFunc_4 cfunc);
+ (MSFunc*) newVar:(MSCFunc_Var) cfunc;
+ (MSFunc*) new0 :(MSCFunc_0) cfunc;
+ (MSFunc*) new1 :(MSCFunc_1) cfunc;
+ (MSFunc*) new2 :(MSCFunc_2) cfunc;
+ (MSFunc*) new3 :(MSCFunc_3) cfunc;
+ (MSFunc*) new4 :(MSCFunc_4) cfunc;
@end
G_END_DECLS

View File

@ -15,62 +15,32 @@
#include "mooscript-func-private.h"
MSValue *
_ms_func_call (MSFunc *func,
MSValue **args,
guint n_args,
MSContext *ctx)
{
MSFuncCall call;
@implementation MSFunc : MooCObject
g_return_val_if_fail (MS_IS_FUNC (func), NULL);
- (MSValue*) call:(MSValue**)args
:(guint) n_args
:(MSContext*) ctx
{
g_return_val_if_fail (!n_args || args, NULL);
g_return_val_if_fail (ctx != NULL, NULL);
call = MS_FUNC_GET_CLASS(func)->call;
g_return_val_if_fail (call != NULL, NULL);
return call (func, args, n_args, ctx);
g_return_val_if_reached (NULL);
}
@end
/******************************************************************/
/* MSFunc
*/
G_DEFINE_TYPE (MSFunc, ms_func, G_TYPE_OBJECT)
@implementation MSCFunc : MSFunc
static void
ms_func_init (G_GNUC_UNUSED MSFunc *func)
- init
{
[super init];
n_args = -1;
return self;
}
static void
ms_func_class_init (G_GNUC_UNUSED MSFuncClass *klass)
{
ms_type_init ();
}
/******************************************************************/
/* MSCFunc
*/
G_DEFINE_TYPE (MSCFunc, ms_cfunc, MS_TYPE_FUNC)
static void
ms_cfunc_init (MSCFunc *func)
{
func->n_args = -1;
}
static MSValue *
ms_cfunc_call (MSFunc *func_,
MSValue **args,
guint n_args,
MSContext *ctx)
- (MSValue*) call:(MSValue**) call_args
:(guint) n_call_args
:(MSContext*) ctx
{
MSCFunc_Var func_var;
MSCFunc_0 func_0;
@ -78,106 +48,90 @@ ms_cfunc_call (MSFunc *func_,
MSCFunc_2 func_2;
MSCFunc_3 func_3;
MSCFunc_4 func_4;
MSCFunc *func = MS_CFUNC (func_);
if (func->n_args >= 0 && func->n_args != (int) n_args)
if (n_args >= 0 && n_args != (int) n_call_args)
{
ms_context_format_error (ctx, MS_ERROR_TYPE,
"function takes %d arguments, but %d given",
func->n_args, n_args);
[ctx formatError:MS_ERROR_TYPE
:"function takes %d arguments, but %d given",
n_args, n_call_args];
return NULL;
}
if (func->n_args < 0)
if (n_args < 0)
{
func_var = (MSCFunc_Var) func->cfunc;
return func_var (args, n_args, ctx);
func_var = (MSCFunc_Var) cfunc;
return func_var (call_args, n_call_args, ctx);
}
switch (func->n_args)
switch (n_args)
{
case 0:
func_0 = (MSCFunc_0) func->cfunc;
func_0 = (MSCFunc_0) cfunc;
return func_0 (ctx);
case 1:
func_1 = (MSCFunc_1) func->cfunc;
return func_1 (args[0], ctx);
func_1 = (MSCFunc_1) cfunc;
return func_1 (call_args[0], ctx);
case 2:
func_2 = (MSCFunc_2) func->cfunc;
return func_2 (args[0], args[1], ctx);
func_2 = (MSCFunc_2) cfunc;
return func_2 (call_args[0], call_args[1], ctx);
case 3:
func_3 = (MSCFunc_3) func->cfunc;
return func_3 (args[0], args[1], args[2], ctx);
func_3 = (MSCFunc_3) cfunc;
return func_3 (call_args[0], call_args[1], call_args[2], ctx);
case 4:
func_4 = (MSCFunc_4) func->cfunc;
return func_4 (args[0], args[1], args[2], args[3], ctx);
func_4 = (MSCFunc_4) cfunc;
return func_4 (call_args[0], call_args[1], call_args[2], call_args[3], ctx);
}
g_warning ("don't know how to call function with %d arguments", func->n_args);
g_warning ("don't know how to call function with %d arguments", n_args);
return NULL;
}
static void
ms_cfunc_class_init (MSCFuncClass *klass)
{
MS_FUNC_CLASS(klass)->call = ms_cfunc_call;
}
static MSFunc *
ms_cfunc_new (int n_args,
GCallback cfunc)
+ (MSFunc*) new:(int) n_args
:(GCallback) cfunc
{
MSCFunc *func;
g_return_val_if_fail (cfunc != NULL, NULL);
func = g_object_new (MS_TYPE_CFUNC, NULL);
func = [[self alloc] init];
func->n_args = n_args;
func->cfunc = cfunc;
return MS_FUNC (func);
return func;
}
MSFunc *
ms_cfunc_new_var (MSCFunc_Var cfunc)
+ (MSFunc*) newVar:(MSCFunc_Var) cfunc
{
return ms_cfunc_new (-1, G_CALLBACK (cfunc));
return [self new:-1 :G_CALLBACK (cfunc)];
}
MSFunc *
ms_cfunc_new_0 (MSCFunc_0 cfunc)
+ (MSFunc*) new0 :(MSCFunc_0) cfunc
{
return ms_cfunc_new (0, G_CALLBACK (cfunc));
return [self new:0 :G_CALLBACK (cfunc)];
}
MSFunc *
ms_cfunc_new_1 (MSCFunc_1 cfunc)
+ (MSFunc*) new1 :(MSCFunc_1) cfunc
{
return ms_cfunc_new (1, G_CALLBACK (cfunc));
return [self new:1 :G_CALLBACK (cfunc)];
}
MSFunc *
ms_cfunc_new_2 (MSCFunc_2 cfunc)
+ (MSFunc*) new2 :(MSCFunc_2) cfunc
{
return ms_cfunc_new (2, G_CALLBACK (cfunc));
return [self new:2 :G_CALLBACK (cfunc)];
}
MSFunc *
ms_cfunc_new_3 (MSCFunc_3 cfunc)
+ (MSFunc*) new3 :(MSCFunc_3) cfunc
{
return ms_cfunc_new (3, G_CALLBACK (cfunc));
return [self new:3 :G_CALLBACK (cfunc)];
}
MSFunc *
ms_cfunc_new_4 (MSCFunc_4 cfunc)
+ (MSFunc*) new4 :(MSCFunc_4) cfunc
{
return ms_cfunc_new (4, G_CALLBACK (cfunc));
return [self new:4 :G_CALLBACK (cfunc)];
}
@end
/* -*- objc -*- */

View File

@ -35,7 +35,7 @@ _ms_node_eval (MSNode *node,
MSContext *ctx)
{
g_return_val_if_fail (node != NULL, NULL);
g_return_val_if_fail (MS_IS_CONTEXT (ctx), NULL);
g_return_val_if_fail (ctx != nil, NULL);
g_return_val_if_fail (node->eval != NULL, NULL);
return node->eval (node, ctx);
}
@ -48,17 +48,17 @@ ms_top_node_eval (MSNode *node,
MSValue *ret;
g_return_val_if_fail (node != NULL, NULL);
g_return_val_if_fail (MS_IS_CONTEXT (ctx), NULL);
g_return_val_if_fail (ctx != nil, NULL);
g_return_val_if_fail (node->eval != NULL, NULL);
ret = _ms_node_eval (node, ctx);
if (_ms_context_return_set (ctx))
_ms_context_unset_return (ctx);
if (_ms_context_break_set (ctx))
_ms_context_unset_break (ctx);
if (_ms_context_continue_set (ctx))
_ms_context_unset_continue (ctx);
if ([ctx returnSet])
[ctx unsetReturn];
if ([ctx breakSet])
[ctx unsetBreak];
if ([ctx continueSet])
[ctx unsetContinue];
return ret;
}
@ -131,14 +131,14 @@ ms_node_list_eval (MSNode *node,
if (!ret)
return NULL;
if (_ms_context_return_set (ctx))
if ([ctx returnSet])
{
ms_value_unref (ret);
ret = _ms_context_get_return (ctx);
ret = [ctx getReturn];
break;
}
if (_ms_context_break_set (ctx) || _ms_context_continue_set (ctx))
if ([ctx breakSet] || [ctx continueSet])
break;
if (i + 1 < list->n_nodes)
@ -219,17 +219,17 @@ ms_node_env_var_eval (MSNode *node,
if (MS_VALUE_TYPE (name) != MS_VALUE_STRING || !name->u.str)
{
ms_context_format_error (ctx, MS_ERROR_TYPE,
"in $(%v): variable name must be a string",
name);
[ctx formatError:MS_ERROR_TYPE
:"in $(%v): variable name must be a string",
name];
ms_value_unref (name);
return NULL;
}
ret = ms_context_get_env_variable (ctx, name->u.str);
ret = [ctx getEnvVariable:name->u.str];
ms_value_unref (name);
if (ret || _ms_context_error_set (ctx))
if (ret || [ctx errorSet])
return ret;
return var->dflt ? _ms_node_eval (var->dflt, ctx) : ms_value_none ();
@ -273,7 +273,7 @@ ms_node_var_eval (MSNode *node,
MSContext *ctx)
{
MSNodeVar *var = MS_NODE_VAR (node);
return ms_context_eval_variable (ctx, var->name);
return [ctx evalVariable:var->name];
}
@ -325,9 +325,9 @@ ms_node_function_eval (MSNode *node_,
if (!_ms_value_is_func (func))
{
ms_context_format_error (ctx, MS_ERROR_TYPE,
"object <%r> is not a function",
func);
[ctx formatError:MS_ERROR_TYPE
:"object <%r> is not a function",
func];
ms_value_unref (func);
return NULL;
}
@ -497,10 +497,10 @@ ms_node_if_else_eval (MSNode *node_,
ret = _ms_node_eval (node_action, ctx);
if (_ms_context_return_set (ctx))
if ([ctx returnSet])
{
ms_value_unref (ret);
ret = _ms_context_get_return (ctx);
ret = [ctx getReturn];
}
return ret;
@ -603,21 +603,21 @@ ms_loop_while (MSContext *ctx,
if (!ret)
return NULL;
if (_ms_context_return_set (ctx))
if ([ctx returnSet])
{
ms_value_unref (ret);
ret = _ms_context_get_return (ctx);
ret = [ctx getReturn];
break;
}
if (_ms_context_break_set (ctx))
if ([ctx breakSet])
{
_ms_context_unset_break (ctx);
[ctx unsetBreak];
break;
}
if (_ms_context_continue_set (ctx))
_ms_context_unset_continue (ctx);
if ([ctx continueSet])
[ctx unsetContinue];
}
else
{
@ -655,21 +655,21 @@ ms_loop_do_while (MSContext *ctx,
if (!ret)
return NULL;
if (_ms_context_return_set (ctx))
if ([ctx returnSet])
{
ms_value_unref (ret);
ret = _ms_context_get_return (ctx);
ret = [ctx getReturn];
break;
}
if (_ms_context_break_set (ctx))
if ([ctx breakSet])
{
_ms_context_unset_break (ctx);
[ctx unsetBreak];
break;
}
if (_ms_context_continue_set (ctx))
_ms_context_unset_continue (ctx);
if ([ctx continueSet])
[ctx unsetContinue];
cond = _ms_node_eval (condition, ctx);
@ -757,9 +757,9 @@ ms_node_for_eval (MSNode *node,
g_return_val_if_fail (loop->list != NULL, NULL);
if (!MS_IS_NODE_VAR (loop->variable))
return ms_context_format_error (ctx, MS_ERROR_TYPE,
"illegal loop variable <%r>",
loop->variable);
return [ctx formatError:MS_ERROR_TYPE
:"illegal loop variable <%r>",
loop->variable];
vallist = _ms_node_eval (loop->list, ctx);
@ -767,15 +767,15 @@ ms_node_for_eval (MSNode *node,
return NULL;
if (MS_VALUE_TYPE (vallist) != MS_VALUE_LIST)
return ms_context_format_error (ctx, MS_ERROR_TYPE,
"illegal loop list <%r>",
vallist);
return [ctx formatError:MS_ERROR_TYPE
:"illegal loop list <%r>",
vallist];
var = MS_NODE_VAR (loop->variable);
for (i = 0; i < vallist->u.list.n_elms; ++i)
{
if (!ms_context_assign_variable (ctx, var->name, vallist->u.list.elms[i]))
if (![ctx assignVariable:var->name :vallist->u.list.elms[i]])
goto error;
ms_value_unref (ret);
@ -788,21 +788,21 @@ ms_node_for_eval (MSNode *node,
if (!ret)
goto error;
if (_ms_context_return_set (ctx))
if ([ctx returnSet])
{
ms_value_unref (ret);
ret = _ms_context_get_return (ctx);
ret = [ctx getReturn];
break;
}
if (_ms_context_break_set (ctx))
if ([ctx breakSet])
{
_ms_context_unset_break (ctx);
[ctx unsetBreak];
break;
}
if (_ms_context_continue_set (ctx))
_ms_context_unset_continue (ctx);
if ([ctx continueSet])
[ctx unsetContinue];
}
if (!ret)
@ -868,7 +868,7 @@ ms_node_assign_eval (MSNode *node_,
if (!value)
return NULL;
if (!ms_context_assign_variable (ctx, node->var->name, value))
if (![ctx assignVariable:node->var->name :value])
{
ms_value_unref (value);
return NULL;
@ -977,9 +977,9 @@ ms_node_val_range_eval (MSNodeValList *node,
if (!ms_value_get_int (vfirst, &first) || !ms_value_get_int (vlast, &last))
{
ms_context_format_error (ctx, MS_ERROR_TYPE,
"illegal list bounds <%r> and <%r>",
vfirst, vlast);
[ctx formatError:MS_ERROR_TYPE
:"illegal list bounds <%r> and <%r>",
vfirst, vlast];
ms_value_unref (vfirst);
ms_value_unref (vlast);
return NULL;
@ -1127,8 +1127,9 @@ ms_node_get_item_eval (MSNode *node_,
if (!val)
{
ms_context_format_error (ctx, MS_ERROR_VALUE,
"no key '%s'", key->u.str);
[ctx formatError:MS_ERROR_VALUE
:"no key '%s'",
key->u.str];
goto error;
}
@ -1136,25 +1137,25 @@ ms_node_get_item_eval (MSNode *node_,
}
else
{
ms_context_format_error (ctx, MS_ERROR_VALUE,
"invalid dict key <%r>",
key);
[ctx formatError:MS_ERROR_VALUE
:"invalid dict key <%r>",
key];
goto error;
}
}
if (!ms_value_get_int (key, &index))
{
ms_context_format_error (ctx, MS_ERROR_VALUE,
"invalid list index <%r>",
key);
[ctx formatError:MS_ERROR_VALUE
:"invalid list index <%r>",
key];
goto error;
}
if (index < 0)
{
ms_context_format_error (ctx, MS_ERROR_VALUE,
"index out of range");
[ctx formatError:MS_ERROR_VALUE
:"index out of range"];
goto error;
}
@ -1169,16 +1170,16 @@ ms_node_get_item_eval (MSNode *node_,
break;
default:
ms_context_format_error (ctx, MS_ERROR_VALUE,
"<%r> is not subscriptable",
obj);
[ctx formatError:MS_ERROR_VALUE
:"<%r> is not subscriptable",
obj];
goto error;
}
if ((guint) index >= len)
{
ms_context_format_error (ctx, MS_ERROR_VALUE,
"index out of range");
[ctx formatError:MS_ERROR_VALUE
:"index out of range"];
goto error;
}
@ -1274,24 +1275,25 @@ ms_node_set_item_eval (MSNode *node_,
}
else
{
ms_context_format_error (ctx, MS_ERROR_VALUE,
"invalid dict key <%r>",
key);
[ctx formatError:MS_ERROR_VALUE
:"invalid dict key <%r>",
key];
goto error;
}
}
if (!ms_value_get_int (key, &index))
{
ms_context_format_error (ctx, MS_ERROR_VALUE,
"invalid list index <%r>", key);
[ctx formatError:MS_ERROR_VALUE
:"invalid list index <%r>",
key];
goto error;
}
if (index < 0)
{
ms_context_format_error (ctx, MS_ERROR_VALUE,
"index out of range");
[ctx formatError:MS_ERROR_VALUE
:"index out of range"];
goto error;
}
@ -1302,16 +1304,16 @@ ms_node_set_item_eval (MSNode *node_,
break;
default:
ms_context_format_error (ctx, MS_ERROR_VALUE,
"invalid list assignment for <%r>",
obj);
[ctx formatError:MS_ERROR_VALUE
:"invalid list assignment for <%r>",
obj];
goto error;
}
if ((guint) index >= len)
{
ms_context_format_error (ctx, MS_ERROR_VALUE,
"index out of range");
[ctx formatError:MS_ERROR_VALUE
:"index out of range"];
goto error;
}
@ -1390,7 +1392,7 @@ ms_node_return_eval (MSNode *node_,
ret = ms_value_none ();
}
_ms_context_set_return (ctx, ret);
[ctx setReturn:ret];
return ret;
}
@ -1425,10 +1427,10 @@ ms_node_break_eval (MSNode *node_,
switch (node->type)
{
case MS_BREAK_BREAK:
_ms_context_set_break (ctx);
[ctx setBreak];
break;
case MS_BREAK_CONTINUE:
_ms_context_set_continue (ctx);
[ctx setContinue];
break;
default:
g_assert_not_reached ();
@ -1487,8 +1489,9 @@ ms_node_dict_elm_eval (MSNode *node_,
ms_value_unref (obj);
if (!val)
return ms_context_format_error (ctx, MS_ERROR_VALUE,
"no key '%s'", node->key);
return [ctx formatError:MS_ERROR_VALUE
:"no key '%s'",
node->key];
else
return val;
}
@ -1547,9 +1550,9 @@ ms_node_dict_assign_eval (MSNode *node_,
if (MS_VALUE_TYPE (obj) != MS_VALUE_DICT)
{
ms_context_format_error (ctx, MS_ERROR_TYPE,
"<%r> is not a dict object",
obj);
[ctx formatError:MS_ERROR_TYPE
:"<%r> is not a dict object",
obj];
goto error;
}
@ -1682,3 +1685,5 @@ _ms_node_dict_new (MSNodeList *entries)
return node;
}
/* -*- objc -*- */

View File

@ -22,7 +22,7 @@ G_BEGIN_DECLS
#define MS_VALUE_TYPE(val) (ms_value_type (val))
typedef struct _MSValue MSValue;
typedef struct _MSFunc MSFunc;
@class MSFunc;
typedef enum {
MS_VALUE_NONE,

View File

@ -400,7 +400,7 @@ ms_value_unref (MSValue *val)
break;
case MS_VALUE_FUNC:
g_object_unref (val->u.func.func);
[val->u.func.func release];
ms_value_unref (val->u.func.obj);
break;
@ -927,8 +927,7 @@ func_plus (MSValue *a, MSValue *b, MSContext *ctx)
else if (MS_VALUE_TYPE (a) == MS_VALUE_STRING && MS_VALUE_TYPE (b) == MS_VALUE_STRING)
return ms_value_take_string (g_strdup_printf ("%s%s", a->u.str, b->u.str));
return ms_context_set_error (ctx, MS_ERROR_TYPE,
"invalid PLUS");
return [ctx setError:MS_ERROR_TYPE :"invalid PLUS"];
}
@ -937,8 +936,7 @@ func_minus (MSValue *a, MSValue *b, MSContext *ctx)
{
if (MS_VALUE_TYPE (a) == MS_VALUE_INT && MS_VALUE_TYPE (b) == MS_VALUE_INT)
return ms_value_int (a->u.ival - b->u.ival);
return ms_context_set_error (ctx, MS_ERROR_TYPE,
"invalid MINUS");
return [ctx setError:MS_ERROR_TYPE :"invalid MINUS"];
}
@ -955,8 +953,7 @@ func_mult (MSValue *a, MSValue *b, MSContext *ctx)
int i;
if (b->u.ival < 0)
return ms_context_set_error (ctx, MS_ERROR_TYPE,
"string * negative int");
return [ctx setError:MS_ERROR_TYPE :"string * negative int"];
if (b->u.ival == 0)
return ms_value_string ("");
@ -970,8 +967,7 @@ func_mult (MSValue *a, MSValue *b, MSContext *ctx)
return ms_value_take_string (s);
}
return ms_context_set_error (ctx, MS_ERROR_TYPE,
"invalid MULT");
return [ctx setError:MS_ERROR_TYPE :"invalid MULT"];
}
@ -983,12 +979,10 @@ func_div (MSValue *a, MSValue *b, MSContext *ctx)
if (b->u.ival)
return ms_value_int (a->u.ival / b->u.ival);
else
return ms_context_set_error (ctx, MS_ERROR_VALUE,
"division by zero");
return [ctx setError:MS_ERROR_VALUE: "division by zero"];
}
return ms_context_set_error (ctx, MS_ERROR_TYPE,
"invalid DIV");
return [ctx setError:MS_ERROR_TYPE :"invalid DIV"];
}
@ -1293,9 +1287,9 @@ func_in (MSValue *val,
case MS_VALUE_STRING:
return string_in (list, val);
default:
ms_context_format_error (ctx, MS_ERROR_TYPE,
"invalid left hand side '%v' of operator in",
list);
[ctx formatError:MS_ERROR_TYPE
:"invalid left hand side '%v' of operator in",
list];
return NULL;
}
}
@ -1316,14 +1310,14 @@ format_value (char format,
case 'd':
if (!ms_value_get_int (value, &ival))
{
ms_context_set_error (ctx, MS_ERROR_TYPE, NULL);
[ctx setError:MS_ERROR_TYPE];
return NULL;
}
return g_strdup_printf ("%d", ival);
default:
ms_context_set_error (ctx, MS_ERROR_VALUE, "invalid format");
[ctx setError:MS_ERROR_VALUE :"invalid format"];
return NULL;
}
}
@ -1338,7 +1332,7 @@ func_format (MSValue *format, MSValue *tuple, MSContext *ctx)
MSValue *val;
if (MS_VALUE_TYPE (format) != MS_VALUE_STRING)
return ms_context_set_error (ctx, MS_ERROR_TYPE, "invalid '%'");
return [ctx setError:MS_ERROR_TYPE :"invalid '%'"];
if (MS_VALUE_TYPE (tuple) == MS_VALUE_LIST)
n_items = tuple->u.list.n_elms;
@ -1368,8 +1362,7 @@ func_format (MSValue *format, MSValue *tuple, MSContext *ctx)
case 'd':
if (items_written == n_items)
{
ms_context_set_error (ctx, MS_ERROR_VALUE,
"invalid conversion");
[ctx setError:MS_ERROR_VALUE :"invalid conversion"];
g_string_free (ret, TRUE);
return NULL;
}
@ -1395,8 +1388,7 @@ func_format (MSValue *format, MSValue *tuple, MSContext *ctx)
break;
default:
ms_context_set_error (ctx, MS_ERROR_VALUE,
"invalid conversion");
[ctx setError:MS_ERROR_VALUE :"invalid conversion"];
g_string_free (ret, TRUE);
return NULL;
}
@ -1435,7 +1427,7 @@ func_uminus (MSValue *val,
{
if (MS_VALUE_TYPE (val) == MS_VALUE_INT)
return ms_value_int (-val->u.ival);
return ms_context_set_error (ctx, MS_ERROR_TYPE, NULL);
return [ctx setError:MS_ERROR_TYPE];
}
@ -1459,7 +1451,7 @@ func_len (MSValue *val,
case MS_VALUE_LIST:
return ms_value_int (val->u.list.n_elms);
default:
return ms_context_set_error (ctx, MS_ERROR_TYPE, NULL);
return [ctx setError:MS_ERROR_TYPE];
}
}
@ -1480,9 +1472,9 @@ MSValue *
ms_value_func (MSFunc *func)
{
MSValue *val;
g_return_val_if_fail (MS_IS_FUNC (func), NULL);
g_return_val_if_fail (func != nil, NULL);
val = ms_value_new (&types[MS_VALUE_FUNC]);
val->u.func.func = g_object_ref (func);
val->u.func.func = [func retain];
return val;
}
@ -1491,7 +1483,7 @@ static MSValue *
ms_value_meth (MSFunc *func)
{
MSValue *val;
g_return_val_if_fail (MS_IS_FUNC (func), NULL);
g_return_val_if_fail (func != nil, NULL);
val = ms_value_func (func);
val->u.func.meth = TRUE;
return val;
@ -1503,7 +1495,7 @@ ms_value_bound_meth (MSFunc *func,
MSValue *obj)
{
MSValue *val;
g_return_val_if_fail (MS_IS_FUNC (func), NULL);
g_return_val_if_fail (func != nil, NULL);
g_return_val_if_fail (obj != NULL, NULL);
val = ms_value_meth (func);
val->u.func.obj = ms_value_ref (obj);
@ -1531,11 +1523,11 @@ _ms_value_call (MSValue *func,
g_return_val_if_fail (func != NULL, NULL);
g_return_val_if_fail (!n_args || args, NULL);
g_return_val_if_fail (MS_IS_CONTEXT (ctx), NULL);
g_return_val_if_fail (ctx != nil, NULL);
g_return_val_if_fail (MS_VALUE_TYPE (func) == MS_VALUE_FUNC, NULL);
if (!func->u.func.meth || !func->u.func.obj)
return _ms_func_call (func->u.func.func, args, n_args, ctx);
return [func->u.func.func call:args :n_args :ctx];
real_args = ms_value_array_alloc (n_args + 1);
real_args[0] = ms_value_ref (func->u.func.obj);
@ -1543,7 +1535,7 @@ _ms_value_call (MSValue *func,
for (i = 0; i < n_args; ++i)
real_args[i+1] = ms_value_ref (args[i]);
ret = _ms_func_call (func->u.func.func, real_args, n_args + 1, ctx);
ret = [func->u.func.func call:real_args :n_args + 1 :ctx];
for (i = 0; i < n_args + 1; ++i)
ms_value_unref (real_args[i]);
@ -1571,6 +1563,12 @@ ms_type_init (void)
}
static void
func_release (MSFunc *func)
{
[func release];
}
void
_ms_value_class_add_method (MSValueClass *klass,
const char *name,
@ -1578,14 +1576,13 @@ _ms_value_class_add_method (MSValueClass *klass,
{
g_return_if_fail (klass != NULL && klass->type < MS_VALUE_INVALID);
g_return_if_fail (name != NULL);
g_return_if_fail (MS_IS_FUNC (func));
g_return_if_fail (func != nil);
if (!klass->methods)
klass->methods = g_hash_table_new_full (g_str_hash, g_str_equal,
g_free, g_object_unref);
klass->methods = g_hash_table_new_full (g_str_hash, g_str_equal, g_free,
(GDestroyNotify) func_release);
g_object_ref (func);
g_hash_table_insert (klass->methods, g_strdup (name), func);
g_hash_table_insert (klass->methods, g_strdup (name), [func retain]);
}
@ -1597,13 +1594,13 @@ ms_value_add_method (MSValue *val,
{
g_return_if_fail (val != NULL);
g_return_if_fail (name != NULL);
g_return_if_fail (MS_IS_FUNC (func));
g_return_if_fail (func != nil);
if (!val->methods)
val->methods = g_hash_table_new_full (g_str_hash, g_str_equal,
g_free, g_object_unref);
g_free, func_release);
g_object_ref (func);
[func retain];
g_hash_table_insert (val->methods, g_strdup (name), func);
}
#endif
@ -1754,3 +1751,5 @@ _ms_value_get_type (void)
return type;
}
/* -*- objc -*- */

View File

@ -21,8 +21,8 @@
#define CHECK_GTK(ctx) \
G_STMT_START { \
if (!gtk_init_check (NULL, NULL)) \
return ms_context_format_error (ctx, MS_ERROR_RUNTIME, \
"could not open display"); \
return [ctx formatError:MS_ERROR_RUNTIME \
:"could not open display"]; \
} G_STMT_END
@ -47,7 +47,7 @@ entry_func (MSValue **args,
hide_text = ms_value_get_bool (args[2]);
dialog = gtk_dialog_new_with_buttons (NULL,
ctx->window,
[ctx window],
GTK_DIALOG_MODAL | GTK_DIALOG_NO_SEPARATOR,
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
GTK_STOCK_OK, GTK_RESPONSE_OK,
@ -86,7 +86,7 @@ entry_func (MSValue **args,
MSFunc *
ms_zenity_entry (void)
{
return ms_cfunc_new_var (entry_func);
return [MSCFunc newVar:entry_func];
}
@ -110,7 +110,7 @@ history_entry_func (MSValue **args,
dialog_text = ms_value_print (args[2]);
dialog = gtk_dialog_new_with_buttons (NULL,
ctx->window,
[ctx window],
GTK_DIALOG_MODAL | GTK_DIALOG_NO_SEPARATOR,
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
GTK_STOCK_OK, GTK_RESPONSE_OK,
@ -164,7 +164,7 @@ history_entry_func (MSValue **args,
MSFunc *
ms_zenity_history_entry (void)
{
return ms_cfunc_new_var (history_entry_func);
return [MSCFunc newVar:history_entry_func];
}
@ -187,7 +187,7 @@ text_func (MSValue **args,
dialog_text = ms_value_print (args[1]);
dialog = gtk_dialog_new_with_buttons (NULL,
ctx->window,
[ctx window],
GTK_DIALOG_MODAL | GTK_DIALOG_NO_SEPARATOR,
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
GTK_STOCK_OK, GTK_RESPONSE_OK,
@ -246,7 +246,7 @@ text_func (MSValue **args,
MSFunc *
ms_zenity_text (void)
{
return ms_cfunc_new_var (text_func);
return [MSCFunc newVar:text_func];
}
@ -266,7 +266,7 @@ message_dialog (MSValue **args,
if (n_args > 0)
dialog_text = ms_value_print (args[0]);
dialog = gtk_message_dialog_new (ctx->window,
dialog = gtk_message_dialog_new ([ctx window],
GTK_DIALOG_MODAL,
type, GTK_BUTTONS_NONE,
"%s", dialog_text ? dialog_text : "");
@ -316,7 +316,7 @@ info_func (MSValue **args,
MSFunc *
ms_zenity_info (void)
{
return ms_cfunc_new_var (info_func);
return [MSCFunc newVar:info_func];
}
@ -331,7 +331,7 @@ error_func (MSValue **args,
MSFunc *
ms_zenity_error (void)
{
return ms_cfunc_new_var (error_func);
return [MSCFunc newVar:error_func];
}
@ -346,7 +346,7 @@ question_func (MSValue **args,
MSFunc *
ms_zenity_question (void)
{
return ms_cfunc_new_var (question_func);
return [MSCFunc newVar:question_func];
}
@ -361,7 +361,7 @@ warning_func (MSValue **args,
MSFunc *
ms_zenity_warning (void)
{
return ms_cfunc_new_var (warning_func);
return [MSCFunc newVar:warning_func];
}
@ -384,7 +384,7 @@ file_selector_func (MSValue **args,
if (n_args > 1)
start = ms_value_print (args[1]);
dialog = moo_file_dialog_new (type, ctx->window, multiple, title, start, NULL);
dialog = moo_file_dialog_new (type, [ctx window], multiple, title, start, NULL);
g_free (title);
g_free (start);
@ -436,7 +436,7 @@ choose_file_func (MSValue **args,
MSFunc *
ms_zenity_choose_file (void)
{
return ms_cfunc_new_var (choose_file_func);
return [MSCFunc newVar:choose_file_func];
}
@ -453,7 +453,7 @@ choose_files_func (MSValue **args,
MSFunc *
ms_zenity_choose_files (void)
{
return ms_cfunc_new_var (choose_files_func);
return [MSCFunc newVar:choose_files_func];
}
@ -470,7 +470,7 @@ choose_dir_func (MSValue **args,
MSFunc *
ms_zenity_choose_dir (void)
{
return ms_cfunc_new_var (choose_dir_func);
return [MSCFunc newVar:choose_dir_func];
}
@ -487,5 +487,7 @@ choose_file_save_func (MSValue **args,
MSFunc *
ms_zenity_choose_file_save (void)
{
return ms_cfunc_new_var (choose_file_save_func);
return [MSCFunc newVar:choose_file_save_func];
}
/* -*- objc -*- */

View File

@ -91,3 +91,10 @@ moo/mooutils/newgtk/gmappedfile.c
moo/mooutils/newgtk/gtkcolorbutton.c
moo/mooutils/newgtk/gtkfontbutton.c
moo/mooedit/language-specs/moo.xml.in
moo/mooedit/gtksourceview/gtksourcecontextengine-mangled.c
moo/mooedit/gtksourceview/gtksourcelanguage-parser-2-mangled.c
moo/mooedit/gtksourceview/gtksourcelanguagemanager-mangled.c
moo/mooedit/gtksourceview/gtksourcestyle-mangled.c
moo/mooedit/gtksourceview/gtksourcestylemanager-mangled.c
moo/mooedit/gtksourceview/gtksourcestylescheme-mangled.c
moo/mooedit/gtksourceview/gtksourcestylescheme-noxml-mangled.c

View File

@ -25,7 +25,7 @@ moo/mooedit/medit-ui.xml
moo/mooedit/mooedit-ui.xml
moo/mooedit/mooeditor.c
moo/mooedit/moocommand-exe-unix.c
moo/mooedit/moocommand-script.c
moo/mooedit/moocommand-script.m
moo/mooedit/mooeditdialogs.c
moo/mooedit/mooeditwindow.c
moo/mooedit/mootextstylescheme.c

View File

@ -116,3 +116,10 @@ moo/mooedit/gtksourceview/upstream/gtksourcestylemanager.c
moo/mooedit/gtksourceview/upstream/gtksourcestylescheme.c
moo/mooedit/gtksourceview/upstream/gtksourcestyle.c
moo/mooedit/gtksourceview/upstream/gtksourcestylescheme-noxml.c
moo/mooedit/gtksourceview/gtksourcecontextengine-mangled.c
moo/mooedit/gtksourceview/gtksourcelanguage-parser-2-mangled.c
moo/mooedit/gtksourceview/gtksourcelanguagemanager-mangled.c
moo/mooedit/gtksourceview/gtksourcestyle-mangled.c
moo/mooedit/gtksourceview/gtksourcestylemanager-mangled.c
moo/mooedit/gtksourceview/gtksourcestylescheme-mangled.c
moo/mooedit/gtksourceview/gtksourcestylescheme-noxml-mangled.c

View File

@ -6,7 +6,7 @@ msgid ""
msgstr ""
"Project-Id-Version: moo\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2007-07-12 00:33-0500\n"
"POT-Creation-Date: 2007-07-12 04:52-0500\n"
"PO-Revision-Date: 2007-07-06 00:51+0100\n"
"Last-Translator: Christian Dywan <christian@twotoasts.de>\n"
"MIME-Version: 1.0\n"
@ -543,7 +543,7 @@ msgstr "Ins Dokument einfügen"
msgid "Output|New document"
msgstr "Neues Dokument"
#: ../moo/mooedit/moocommand-script.c:241
#: ../moo/mooedit/moocommand-script.m:241
msgid "MooScript"
msgstr "MooSkript"

View File

@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: moo\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2007-07-12 00:33-0500\n"
"POT-Creation-Date: 2007-07-12 04:52-0500\n"
"PO-Revision-Date: 2007-06-16 21:04-0600\n"
"Last-Translator: Collilieux <mccnews@free.fr>\n"
"MIME-Version: 1.0\n"
@ -541,7 +541,7 @@ msgstr "Insére dans le document"
msgid "Output|New document"
msgstr "Nouveau document"
#: ../moo/mooedit/moocommand-script.c:241
#: ../moo/mooedit/moocommand-script.m:241
msgid "MooScript"
msgstr "Mooscript"

View File

@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: moo\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2007-07-12 00:33-0500\n"
"POT-Creation-Date: 2007-07-12 04:52-0500\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: Yevgen Muntyan <muntyan@tamu.edu>\n"
"MIME-Version: 1.0\n"
@ -543,7 +543,7 @@ msgstr ""
msgid "Output|New document"
msgstr "Новый документ"
#: ../moo/mooedit/moocommand-script.c:241
#: ../moo/mooedit/moocommand-script.m:241
msgid "MooScript"
msgstr ""

View File

@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: moo\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2007-07-12 00:33-0500\n"
"POT-Creation-Date: 2007-07-12 04:52-0500\n"
"PO-Revision-Date: 2007-06-16 21:04-0600\n"
"Last-Translator: Chaosye <chao-7410@163.com>\n"
"MIME-Version: 1.0\n"
@ -541,7 +541,7 @@ msgstr "输入到文档"
msgid "Output|New document"
msgstr "新建文档"
#: ../moo/mooedit/moocommand-script.c:241
#: ../moo/mooedit/moocommand-script.m:241
msgid "MooScript"
msgstr "Mooscript"