Renamed AS* to MS*

master
Yevgen Muntyan 2006-02-24 22:39:12 -06:00
parent f30d118e04
commit d71e3ae7a4
18 changed files with 1509 additions and 1509 deletions

View File

@ -15,51 +15,51 @@
#include "as-plugin-script.h"
static void as_plugin_context_init_api (ASPluginContext *ctx);
static void ms_plugin_context_init_api (MSPluginContext *ctx);
G_DEFINE_TYPE (ASPluginContext, _as_plugin_context, AS_TYPE_CONTEXT)
G_DEFINE_TYPE (MSPluginContext, _ms_plugin_context, MS_TYPE_CONTEXT)
static void
_as_plugin_context_init (ASPluginContext *ctx)
_ms_plugin_context_init (MSPluginContext *ctx)
{
as_plugin_context_init_api (ctx);
ms_plugin_context_init_api (ctx);
}
static void
_as_plugin_context_class_init (G_GNUC_UNUSED ASPluginContextClass *klass)
_ms_plugin_context_class_init (G_GNUC_UNUSED MSPluginContextClass *klass)
{
}
ASContext *
_as_plugin_context_new (void)
MSContext *
_ms_plugin_context_new (void)
{
return g_object_new (AS_TYPE_PLUGIN_CONTEXT, NULL);
return g_object_new (MS_TYPE_PLUGIN_CONTEXT, NULL);
}
static void
as_plugin_context_setup (ASPluginContext *ctx,
ms_plugin_context_setup (MSPluginContext *ctx,
MooEdit *doc,
char *match,
char **parens,
guint n_parens)
{
guint i;
ASValue *val;
MSValue *val;
val = as_value_string (match);
as_context_assign_positional (AS_CONTEXT (ctx), 0, val);
as_value_unref (val);
val = ms_value_string (match);
ms_context_assign_positional (MS_CONTEXT (ctx), 0, val);
ms_value_unref (val);
for (i = 0; i < n_parens; ++i)
{
val = as_value_string (parens[i]);
as_context_assign_positional (AS_CONTEXT (ctx), i + 1, val);
as_value_unref (val);
val = ms_value_string (parens[i]);
ms_context_assign_positional (MS_CONTEXT (ctx), i + 1, val);
ms_value_unref (val);
}
ctx->doc = g_object_ref (doc);
@ -67,13 +67,13 @@ as_plugin_context_setup (ASPluginContext *ctx,
static void
as_plugin_context_clear (ASPluginContext *ctx,
ms_plugin_context_clear (MSPluginContext *ctx,
guint n_parens)
{
guint i;
for (i = 0; i < n_parens + 1; ++i)
as_context_assign_positional (AS_CONTEXT (ctx), i, NULL);
ms_context_assign_positional (MS_CONTEXT (ctx), i, NULL);
g_object_ref (ctx->doc);
ctx->doc = NULL;
@ -81,40 +81,40 @@ as_plugin_context_clear (ASPluginContext *ctx,
gboolean
_as_plugin_context_exec (ASContext *ctx,
ASNode *script,
_ms_plugin_context_exec (MSContext *ctx,
MSNode *script,
MooEdit *doc,
GtkTextIter *insert,
char *match,
char **parens,
guint n_parens)
{
ASValue *val;
MSValue *val;
gboolean success;
g_return_val_if_fail (AS_IS_PLUGIN_CONTEXT (ctx), FALSE);
g_return_val_if_fail (AS_IS_NODE (script), FALSE);
g_return_val_if_fail (MS_IS_PLUGIN_CONTEXT (ctx), FALSE);
g_return_val_if_fail (MS_IS_NODE (script), FALSE);
g_return_val_if_fail (MOO_IS_EDIT (doc), FALSE);
g_return_val_if_fail (insert != NULL, FALSE);
g_return_val_if_fail (match != NULL, FALSE);
g_return_val_if_fail (!n_parens || parens, FALSE);
as_plugin_context_setup (AS_PLUGIN_CONTEXT (ctx),
ms_plugin_context_setup (MS_PLUGIN_CONTEXT (ctx),
doc, match, parens, n_parens);
val = as_node_eval (script, ctx);
val = ms_node_eval (script, ctx);
success = val != NULL;
if (val)
as_value_unref (val);
ms_value_unref (val);
if (!success)
{
g_print ("%s\n", as_context_get_error_msg (ctx));
as_context_clear_error (ctx);
g_print ("%s\n", ms_context_get_error_msg (ctx));
ms_context_clear_error (ctx);
}
as_plugin_context_clear (AS_PLUGIN_CONTEXT (ctx), n_parens);
ms_plugin_context_clear (MS_PLUGIN_CONTEXT (ctx), n_parens);
return success;
}
@ -137,13 +137,13 @@ static const char *builtin_func_names[N_BUILTIN_FUNCS] = {
"bs", "del", "ins", "up", "down", "left", "right", "sel"
};
static ASFunc *builtin_funcs[N_BUILTIN_FUNCS];
static MSFunc *builtin_funcs[N_BUILTIN_FUNCS];
static gboolean
check_one_arg (ASValue **args,
check_one_arg (MSValue **args,
guint n_args,
ASPluginContext *ctx,
MSPluginContext *ctx,
gboolean nonnegative,
int *dest,
int default_val)
@ -152,7 +152,7 @@ check_one_arg (ASValue **args,
if (n_args > 1)
{
as_context_set_error (AS_CONTEXT (ctx), AS_ERROR_TYPE,
ms_context_set_error (MS_CONTEXT (ctx), MS_ERROR_TYPE,
"number of args must be zero or one");
return FALSE;
}
@ -163,16 +163,16 @@ check_one_arg (ASValue **args,
return TRUE;
}
if (!as_value_get_int (args[0], &val))
if (!ms_value_get_int (args[0], &val))
{
as_context_set_error (AS_CONTEXT (ctx), AS_ERROR_TYPE,
ms_context_set_error (MS_CONTEXT (ctx), MS_ERROR_TYPE,
"argument must be integer");
return FALSE;
}
if (nonnegative && val < 0)
{
as_context_set_error (AS_CONTEXT (ctx), AS_ERROR_VALUE,
ms_context_set_error (MS_CONTEXT (ctx), MS_ERROR_VALUE,
"argument must be non-negative");
return FALSE;
}
@ -182,10 +182,10 @@ check_one_arg (ASValue **args,
}
static ASValue *
cfunc_bs (ASValue **args,
static MSValue *
cfunc_bs (MSValue **args,
guint n_args,
ASPluginContext *ctx)
MSPluginContext *ctx)
{
int n;
GtkTextIter start, end;
@ -195,7 +195,7 @@ cfunc_bs (ASValue **args,
return NULL;
if (!n)
return as_value_none ();
return ms_value_none ();
buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (ctx->doc));
@ -211,14 +211,14 @@ cfunc_bs (ASValue **args,
gtk_text_buffer_delete (buffer, &start, &end);
}
return as_value_none ();
return ms_value_none ();
}
static ASValue *
cfunc_del (ASValue **args,
static MSValue *
cfunc_del (MSValue **args,
guint n_args,
ASPluginContext *ctx)
MSPluginContext *ctx)
{
int n;
GtkTextIter start, end;
@ -228,7 +228,7 @@ cfunc_del (ASValue **args,
return NULL;
if (!n)
return as_value_none ();
return ms_value_none ();
buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (ctx->doc));
@ -244,7 +244,7 @@ cfunc_del (ASValue **args,
gtk_text_buffer_delete (buffer, &start, &end);
}
return as_value_none ();
return ms_value_none ();
}
@ -265,10 +265,10 @@ get_cursor (MooEdit *doc,
}
static ASValue *
cfunc_up (ASValue **args,
static MSValue *
cfunc_up (MSValue **args,
guint n_args,
ASPluginContext *ctx)
MSPluginContext *ctx)
{
int line, col, n;
@ -276,7 +276,7 @@ cfunc_up (ASValue **args,
return NULL;
if (!n)
return as_value_none ();
return ms_value_none ();
get_cursor (ctx->doc, &line, &col);
@ -285,14 +285,14 @@ cfunc_up (ASValue **args,
MAX (line - n, 0), col,
FALSE);
return as_value_none ();
return ms_value_none ();
}
static ASValue *
cfunc_down (ASValue **args,
static MSValue *
cfunc_down (MSValue **args,
guint n_args,
ASPluginContext *ctx)
MSPluginContext *ctx)
{
int line, col, n, line_count;
GtkTextBuffer *buffer;
@ -301,7 +301,7 @@ cfunc_down (ASValue **args,
return NULL;
if (!n)
return as_value_none ();
return ms_value_none ();
get_cursor (ctx->doc, &line, &col);
buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (ctx->doc));
@ -311,24 +311,24 @@ cfunc_down (ASValue **args,
MIN (line + n, line_count - 1), col,
FALSE);
return as_value_none ();
return ms_value_none ();
}
static ASValue *
cfunc_sel (ASValue *arg,
ASPluginContext *ctx)
static MSValue *
cfunc_sel (MSValue *arg,
MSPluginContext *ctx)
{
int n;
GtkTextBuffer *buffer;
GtkTextIter start, end;
if (!as_value_get_int (arg, &n))
return as_context_set_error (AS_CONTEXT (ctx), AS_ERROR_TYPE,
if (!ms_value_get_int (arg, &n))
return ms_context_set_error (MS_CONTEXT (ctx), MS_ERROR_TYPE,
"argument must be integer");
if (!n)
return as_context_set_error (AS_CONTEXT (ctx), AS_ERROR_TYPE,
return ms_context_set_error (MS_CONTEXT (ctx), MS_ERROR_TYPE,
"argument must be non zero integer");
buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (ctx->doc));
@ -339,7 +339,7 @@ cfunc_sel (ASValue *arg,
gtk_text_buffer_select_range (buffer, &end, &start);
return as_value_none ();
return ms_value_none ();
}
@ -359,10 +359,10 @@ move_cursor (MooEdit *doc,
}
static ASValue *
cfunc_left (ASValue **args,
static MSValue *
cfunc_left (MSValue **args,
guint n_args,
ASPluginContext *ctx)
MSPluginContext *ctx)
{
int n;
@ -370,14 +370,14 @@ cfunc_left (ASValue **args,
return NULL;
move_cursor (ctx->doc, -n);
return as_value_none ();
return ms_value_none ();
}
static ASValue *
cfunc_right (ASValue **args,
static MSValue *
cfunc_right (MSValue **args,
guint n_args,
ASPluginContext *ctx)
MSPluginContext *ctx)
{
int n;
@ -385,21 +385,21 @@ cfunc_right (ASValue **args,
return NULL;
move_cursor (ctx->doc, n);
return as_value_none ();
return ms_value_none ();
}
static ASValue *
cfunc_ins (ASValue **args,
static MSValue *
cfunc_ins (MSValue **args,
guint n_args,
ASPluginContext *ctx)
MSPluginContext *ctx)
{
guint i;
GtkTextIter start, end;
GtkTextBuffer *buffer;
if (!n_args)
return as_value_none ();
return ms_value_none ();
buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (ctx->doc));
@ -408,12 +408,12 @@ cfunc_ins (ASValue **args,
for (i = 0; i < n_args; ++i)
{
char *s = as_value_print (args[i]);
char *s = ms_value_print (args[i]);
gtk_text_buffer_insert (buffer, &start, s, -1);
g_free (s);
}
return as_value_none ();
return ms_value_none ();
}
@ -423,26 +423,26 @@ init_api (void)
if (builtin_funcs[0])
return;
builtin_funcs[FUNC_BS] = as_cfunc_new_var ((ASCFunc_Var) cfunc_bs);
builtin_funcs[FUNC_DEL] = as_cfunc_new_var ((ASCFunc_Var) cfunc_del);
builtin_funcs[FUNC_INS] = as_cfunc_new_var ((ASCFunc_Var) cfunc_ins);
builtin_funcs[FUNC_UP] = as_cfunc_new_var ((ASCFunc_Var) cfunc_up);
builtin_funcs[FUNC_DOWN] = as_cfunc_new_var ((ASCFunc_Var) cfunc_down);
builtin_funcs[FUNC_LEFT] = as_cfunc_new_var ((ASCFunc_Var) cfunc_left);
builtin_funcs[FUNC_RIGHT] = as_cfunc_new_var ((ASCFunc_Var) cfunc_right);
builtin_funcs[FUNC_SEL] = as_cfunc_new_1 ((ASCFunc_1) cfunc_sel);
builtin_funcs[FUNC_BS] = ms_cfunc_new_var ((MSCFunc_Var) cfunc_bs);
builtin_funcs[FUNC_DEL] = ms_cfunc_new_var ((MSCFunc_Var) cfunc_del);
builtin_funcs[FUNC_INS] = ms_cfunc_new_var ((MSCFunc_Var) cfunc_ins);
builtin_funcs[FUNC_UP] = ms_cfunc_new_var ((MSCFunc_Var) cfunc_up);
builtin_funcs[FUNC_DOWN] = ms_cfunc_new_var ((MSCFunc_Var) cfunc_down);
builtin_funcs[FUNC_LEFT] = ms_cfunc_new_var ((MSCFunc_Var) cfunc_left);
builtin_funcs[FUNC_RIGHT] = ms_cfunc_new_var ((MSCFunc_Var) cfunc_right);
builtin_funcs[FUNC_SEL] = ms_cfunc_new_1 ((MSCFunc_1) cfunc_sel);
}
static void
as_plugin_context_init_api (ASPluginContext *ctx)
ms_plugin_context_init_api (MSPluginContext *ctx)
{
guint i;
init_api ();
for (i = 0; i < N_BUILTIN_FUNCS; ++i)
as_context_set_func (AS_CONTEXT (ctx),
ms_context_set_func (MS_CONTEXT (ctx),
builtin_func_names[i],
builtin_funcs[i]);
}

View File

@ -12,8 +12,8 @@
* See COPYING file that comes with this distribution.
*/
#ifndef __AS_PLUGIN_SCRIPT_H__
#define __AS_PLUGIN_SCRIPT_H__
#ifndef __MS_PLUGIN_SCRIPT_H__
#define __MS_PLUGIN_SCRIPT_H__
#include "mooutils/mooscript/mooscript-context.h"
#include "mooutils/mooscript/mooscript-node.h"
@ -22,33 +22,33 @@
G_BEGIN_DECLS
#define AS_TYPE_PLUGIN_CONTEXT (_as_plugin_context_get_type ())
#define AS_PLUGIN_CONTEXT(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), AS_TYPE_PLUGIN_CONTEXT, ASPluginContext))
#define AS_PLUGIN_CONTEXT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), AS_TYPE_PLUGIN_CONTEXT, ASPluginContextClass))
#define AS_IS_PLUGIN_CONTEXT(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), AS_TYPE_PLUGIN_CONTEXT))
#define AS_IS_PLUGIN_CONTEXT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), AS_TYPE_PLUGIN_CONTEXT))
#define AS_PLUGIN_CONTEXT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), AS_TYPE_PLUGIN_CONTEXT, ASPluginContextClass))
#define MS_TYPE_PLUGIN_CONTEXT (_ms_plugin_context_get_type ())
#define MS_PLUGIN_CONTEXT(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), MS_TYPE_PLUGIN_CONTEXT, MSPluginContext))
#define MS_PLUGIN_CONTEXT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MS_TYPE_PLUGIN_CONTEXT, MSPluginContextClass))
#define MS_IS_PLUGIN_CONTEXT(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), MS_TYPE_PLUGIN_CONTEXT))
#define MS_IS_PLUGIN_CONTEXT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MS_TYPE_PLUGIN_CONTEXT))
#define MS_PLUGIN_CONTEXT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MS_TYPE_PLUGIN_CONTEXT, MSPluginContextClass))
typedef struct _ASPluginContext ASPluginContext;
typedef struct _ASPluginContextClass ASPluginContextClass;
typedef struct _MSPluginContext MSPluginContext;
typedef struct _MSPluginContextClass MSPluginContextClass;
struct _ASPluginContext {
ASContext context;
struct _MSPluginContext {
MSContext context;
MooEdit *doc;
};
struct _ASPluginContextClass {
ASContextClass context_class;
struct _MSPluginContextClass {
MSContextClass context_class;
};
GType _as_plugin_context_get_type (void) G_GNUC_CONST;
GType _ms_plugin_context_get_type (void) G_GNUC_CONST;
ASContext *_as_plugin_context_new (void);
MSContext *_ms_plugin_context_new (void);
gboolean _as_plugin_context_exec (ASContext *ctx,
ASNode *script,
gboolean _ms_plugin_context_exec (MSContext *ctx,
MSNode *script,
MooEdit *doc,
GtkTextIter *insert,
char *match,
@ -58,4 +58,4 @@ gboolean _as_plugin_context_exec (ASContext *ctx,
G_END_DECLS
#endif /* __AS_PLUGIN_SCRIPT_H__ */
#endif /* __MS_PLUGIN_SCRIPT_H__ */

View File

@ -17,22 +17,22 @@
#include "mooutils/mooutils-misc.h"
#include <string.h>
#define AS_ROOT "active-strings"
#define AS_ELM "as"
#define AS_PROP_PATTERN "pattern"
#define AS_PROP_LANG "lang"
#define MS_ROOT "active-strings"
#define MS_ELM "as"
#define MS_PROP_PATTERN "pattern"
#define MS_PROP_LANG "lang"
ASInfo *
_as_info_new (const char *pattern,
MSInfo *
_ms_info_new (const char *pattern,
const char *script,
const char *lang)
{
ASInfo *info;
MSInfo *info;
g_return_val_if_fail (pattern && pattern[0], NULL);
info = g_new0 (ASInfo, 1);
info = g_new0 (MSInfo, 1);
info->pattern = g_strdup (pattern);
info->script = g_strdup (script);
info->lang = lang ? g_ascii_strdown (lang, -1) : NULL;
@ -41,7 +41,7 @@ _as_info_new (const char *pattern,
void
_as_info_free (ASInfo *info)
_ms_info_free (MSInfo *info)
{
if (info)
{
@ -53,30 +53,30 @@ _as_info_free (ASInfo *info)
}
static ASInfo *
parse_as_elm (MooMarkupNode *node)
static MSInfo *
parse_ms_elm (MooMarkupNode *node)
{
const char *pattern;
const char *script;
const char *lang;
pattern = moo_markup_get_prop (node, AS_PROP_PATTERN);
lang = moo_markup_get_prop (node, AS_PROP_LANG);
pattern = moo_markup_get_prop (node, MS_PROP_PATTERN);
lang = moo_markup_get_prop (node, MS_PROP_LANG);
script = moo_markup_get_content (node);
if (!pattern || !pattern[0])
{
g_warning ("%s: '%s' attribute missing",
G_STRLOC, AS_PROP_PATTERN);
G_STRLOC, MS_PROP_PATTERN);
return NULL;
}
return _as_info_new (pattern, script, lang);
return _ms_info_new (pattern, script, lang);
}
gboolean
_as_load_file (const char *filename,
_ms_load_file (const char *filename,
GSList **list)
{
MooMarkupDoc *doc;
@ -91,25 +91,25 @@ _as_load_file (const char *filename,
if (!doc)
return FALSE;
root = moo_markup_get_root_element (doc, AS_ROOT);
root = moo_markup_get_root_element (doc, MS_ROOT);
if (!root)
root = MOO_MARKUP_NODE (doc);
for (node = root->children; node != NULL; node = node->next)
{
ASInfo *info;
MSInfo *info;
if (!MOO_MARKUP_IS_ELEMENT (node))
continue;
if (strcmp (node->name, AS_ELM))
if (strcmp (node->name, MS_ELM))
{
g_warning ("%s: unknown element '%s'", G_STRLOC, node->name);
continue;
}
info = parse_as_elm (node);
info = parse_ms_elm (node);
if (info)
*list = g_slist_prepend (*list, info);
@ -121,7 +121,7 @@ _as_load_file (const char *filename,
char *
_as_format_xml (GSList *list)
_ms_format_xml (GSList *list)
{
GString *xml;
GSList *l;
@ -131,11 +131,11 @@ _as_format_xml (GSList *list)
xml = g_string_sized_new (1024);
g_string_append (xml, "<" AS_ROOT ">\n");
g_string_append (xml, "<" MS_ROOT ">\n");
for (l = list; l != NULL; l = l->next)
{
ASInfo *info = l->data;
MSInfo *info = l->data;
char *tmp;
if (!info || !info->pattern)
@ -144,7 +144,7 @@ _as_format_xml (GSList *list)
continue;
}
tmp = g_markup_printf_escaped ("<" AS_ELM "pattern=\"%s\"", info->pattern);
tmp = g_markup_printf_escaped ("<" MS_ELM "pattern=\"%s\"", info->pattern);
g_string_append (xml, tmp);
g_free (tmp);
@ -157,7 +157,7 @@ _as_format_xml (GSList *list)
if (info->script)
{
tmp = g_markup_printf_escaped (">%s</" AS_ELM ">\n", info->script);
tmp = g_markup_printf_escaped (">%s</" MS_ELM ">\n", info->script);
g_string_append (xml, tmp);
g_free (tmp);
}
@ -167,14 +167,14 @@ _as_format_xml (GSList *list)
}
}
g_string_append (xml, "</" AS_ROOT ">\n");
g_string_append (xml, "</" MS_ROOT ">\n");
return g_string_free (xml, FALSE);
}
gboolean
_as_save (const char *filename,
_ms_save (const char *filename,
GSList *info)
{
char *xml;
@ -183,7 +183,7 @@ _as_save (const char *filename,
g_return_val_if_fail (filename != NULL, FALSE);
xml = _as_format_xml (info);
xml = _ms_format_xml (info);
if (!xml)
return moo_unlink (filename) == 0;

View File

@ -12,36 +12,36 @@
* See COPYING file that comes with this distribution.
*/
#ifndef __AS_PLUGIN_XML_H__
#define __AS_PLUGIN_XML_H__
#ifndef __MS_PLUGIN_XML_H__
#define __MS_PLUGIN_XML_H__
#include <glib.h>
G_BEGIN_DECLS
typedef struct _ASInfo ASInfo;
typedef struct _MSInfo MSInfo;
struct _ASInfo {
struct _MSInfo {
char *pattern;
char *script;
char *lang;
};
ASInfo *_as_info_new (const char *pattern,
MSInfo *_ms_info_new (const char *pattern,
const char *script,
const char *lang);
void _as_info_free (ASInfo *info);
void _ms_info_free (MSInfo *info);
gboolean _as_load_file (const char *filename,
gboolean _ms_load_file (const char *filename,
GSList **info);
gboolean _as_save (const char *filename,
gboolean _ms_save (const char *filename,
GSList *info);
char *_as_format_xml (GSList *info);
char *_ms_format_xml (GSList *info);
G_END_DECLS
#endif /* __AS_PLUGIN_XML_H__ */
#endif /* __MS_PLUGIN_XML_H__ */

View File

@ -28,29 +28,29 @@
#include "mooutils/mooscript/mooscript-parser.h"
#include <string.h>
#define AS_PLUGIN_ID "ActiveStrings"
#define AS_DATA "moo-active-strings"
#define AS_WILDCARD '?'
#define MS_PLUGIN_ID "ActiveStrings"
#define MS_DATA "moo-active-strings"
#define MS_WILDCARD '?'
#define PREFS_ROOT MOO_PLUGIN_PREFS_ROOT "/" AS_PLUGIN_ID
#define PREFS_ROOT MOO_PLUGIN_PREFS_ROOT "/" MS_PLUGIN_ID
#define FILE_PREFS_KEY PREFS_ROOT "/file"
typedef struct _ASPlugin ASPlugin;
typedef struct _ASSet ASSet;
typedef struct _ASString ASString;
typedef struct _ASStringInfo ASStringInfo;
typedef struct _ASMatch ASMatch;
typedef struct _MSPlugin MSPlugin;
typedef struct _MSSet MSSet;
typedef struct _MSString MSString;
typedef struct _MSStringInfo MSStringInfo;
typedef struct _MSMatch MSMatch;
struct _ASPlugin {
struct _MSPlugin {
MooPlugin parent;
ASContext *ctx;
MSContext *ctx;
GHashTable *lang_sets;
ASSet *any_lang;
MSSet *any_lang;
};
struct _ASStringInfo {
struct _MSStringInfo {
guint n_wildcards;
char *pattern;
guint pattern_len;
@ -58,14 +58,14 @@ struct _ASStringInfo {
char *script;
};
struct _ASString {
struct _MSString {
guint whole;
guint *parens;
guint n_parens;
};
struct _ASSet {
ASString **strings;
struct _MSSet {
MSString **strings;
char **scripts;
guint n_strings;
EggRegex *regex;
@ -76,7 +76,7 @@ struct _ASSet {
guint n_last_chars;
};
struct _ASMatch {
struct _MSMatch {
guint string_no;
/* all offsets are in chars here */
guint start_offset;
@ -86,23 +86,23 @@ struct _ASMatch {
};
typedef enum {
AS_WORD_BOUNDARY = 1 << 0,
AS_NOT_WORD_BOUNDARY = 1 << 1
} ASOptions;
MS_WORD_BOUNDARY = 1 << 0,
MS_NOT_WORD_BOUNDARY = 1 << 1
} MSOptions;
static gboolean as_plugin_init (ASPlugin *plugin);
static void as_plugin_deinit (ASPlugin *plugin);
static void as_plugin_attach (ASPlugin *plugin,
static gboolean ms_plugin_init (MSPlugin *plugin);
static void ms_plugin_deinit (MSPlugin *plugin);
static void ms_plugin_attach (MSPlugin *plugin,
MooEdit *doc);
static void as_plugin_detach (ASPlugin *plugin,
static void ms_plugin_detach (MSPlugin *plugin,
MooEdit *doc);
static void as_plugin_do_action (ASPlugin *plugin,
static void ms_plugin_do_action (MSPlugin *plugin,
MooEdit *doc,
GtkTextIter *insert,
ASSet *set,
ASMatch *match,
MSSet *set,
MSMatch *match,
char *full_text,
char **parens_text);
@ -112,26 +112,26 @@ static gboolean char_inserted_cb (MooEdit *doc,
GSList *sets);
static void process_match (MooEdit *doc,
GtkTextIter *end,
ASSet *set,
ASMatch *match);
MSSet *set,
MSMatch *match);
static ASSet *as_set_new (ASStringInfo **strings,
static MSSet *ms_set_new (MSStringInfo **strings,
guint n_strings);
static void as_set_unref (ASSet *set);
static ASSet *as_set_ref (ASSet *set);
static gboolean as_set_check_last (ASSet *set,
static void ms_set_unref (MSSet *set);
static MSSet *ms_set_ref (MSSet *set);
static gboolean ms_set_check_last (MSSet *set,
gunichar c);
static gboolean as_set_match (ASSet *set,
static gboolean ms_set_match (MSSet *set,
const char *text,
ASMatch *match);
MSMatch *match);
static void as_string_info_set_script (ASStringInfo *info,
static void ms_string_info_set_script (MSStringInfo *info,
const char *script);
static void as_string_info_free (ASStringInfo *info);
static void ms_string_info_free (MSStringInfo *info);
static void as_match_destroy (ASMatch *match);
static ASString *as_string_new (guint n_wildcards);
static void as_string_free (ASString *s);
static void ms_match_destroy (MSMatch *match);
static MSString *ms_string_new (guint n_wildcards);
static void ms_string_free (MSString *s);
static int
@ -143,11 +143,11 @@ cmp_ints (gunichar *c1, gunichar *c2)
static void
append_options (GString *pattern,
ASOptions opts)
MSOptions opts)
{
if (opts & AS_WORD_BOUNDARY)
if (opts & MS_WORD_BOUNDARY)
g_string_append (pattern, "\\b");
else if (opts & AS_NOT_WORD_BOUNDARY)
else if (opts & MS_NOT_WORD_BOUNDARY)
g_string_append (pattern, "\\B");
}
@ -164,15 +164,15 @@ append_escaped (GString *pattern,
}
static ASStringInfo *
as_string_get_info (const char *string,
ASOptions start_opts,
ASOptions end_opts,
static MSStringInfo *
ms_string_get_info (const char *string,
MSOptions start_opts,
MSOptions end_opts,
guint string_no)
{
char *wc, *p;
guint rev_len;
ASStringInfo *info = NULL;
MSStringInfo *info = NULL;
char *rev = NULL;
GString *pattern = NULL;
@ -184,17 +184,17 @@ as_string_get_info (const char *string,
rev = g_utf8_strreverse (string, -1);
rev_len = strlen (rev);
info = g_new0 (ASStringInfo, 1);
info = g_new0 (MSStringInfo, 1);
if (string[0] == AS_WILDCARD && string[1] != AS_WILDCARD)
if (string[0] == MS_WILDCARD && string[1] != MS_WILDCARD)
{
g_critical ("%s: leading '%c' symbol", G_STRLOC, AS_WILDCARD);
g_critical ("%s: leading '%c' symbol", G_STRLOC, MS_WILDCARD);
goto error;
}
if (rev[0] == AS_WILDCARD && rev[1] != AS_WILDCARD)
if (rev[0] == MS_WILDCARD && rev[1] != MS_WILDCARD)
{
g_critical ("%s: trailing '%c' symbol", G_STRLOC, AS_WILDCARD);
g_critical ("%s: trailing '%c' symbol", G_STRLOC, MS_WILDCARD);
goto error;
}
@ -208,7 +208,7 @@ as_string_get_info (const char *string,
for (p = rev; *p; )
{
wc = strchr (p, AS_WILDCARD);
wc = strchr (p, MS_WILDCARD);
if (!wc)
{
@ -216,7 +216,7 @@ as_string_get_info (const char *string,
break;
}
if (wc[1] == AS_WILDCARD)
if (wc[1] == MS_WILDCARD)
{
append_escaped (pattern, p, wc - p + 1);
p = wc + 2;
@ -242,7 +242,7 @@ as_string_get_info (const char *string,
return info;
error:
as_string_info_free (info);
ms_string_info_free (info);
g_free (rev);
if (pattern)
g_string_free (pattern, TRUE);
@ -251,7 +251,7 @@ error:
static void
as_string_info_free (ASStringInfo *info)
ms_string_info_free (MSStringInfo *info)
{
if (info)
{
@ -263,7 +263,7 @@ as_string_info_free (ASStringInfo *info)
static void
as_string_info_set_script (ASStringInfo *info,
ms_string_info_set_script (MSStringInfo *info,
const char *script)
{
g_return_if_fail (info != NULL);
@ -272,10 +272,10 @@ as_string_info_set_script (ASStringInfo *info,
}
static ASString *
as_string_new (guint n_wildcards)
static MSString *
ms_string_new (guint n_wildcards)
{
ASString *s = g_new0 (ASString, 1);
MSString *s = g_new0 (MSString, 1);
if (n_wildcards)
{
@ -288,7 +288,7 @@ as_string_new (guint n_wildcards)
static void
as_string_free (ASString *s)
ms_string_free (MSString *s)
{
if (s)
{
@ -298,25 +298,25 @@ as_string_free (ASString *s)
}
static ASSet*
as_set_new (ASStringInfo **strings,
static MSSet*
ms_set_new (MSStringInfo **strings,
guint n_strings)
{
ASSet *set = NULL;
MSSet *set = NULL;
GString *pattern;
guint i, len;
GError *error = NULL;
gunichar *last_chars;
gunichar min_last = 0, max_last = 0;
gboolean has_wildcard = FALSE;
gboolean hms_wildcard = FALSE;
g_return_val_if_fail (strings != NULL, NULL);
g_return_val_if_fail (n_strings != 0, NULL);
set = g_new0 (ASSet, 1);
set = g_new0 (MSSet, 1);
set->ref_count = 1;
set->n_strings = n_strings;
set->strings = g_new (ASString*, n_strings);
set->strings = g_new (MSString*, n_strings);
len = n_strings + 2; /* (||||) */
last_chars = g_new (gunichar, n_strings);
@ -329,10 +329,10 @@ as_set_new (ASStringInfo **strings,
len += strings[i]->pattern_len;
set->strings[i] = as_string_new (strings[i]->n_wildcards);
set->strings[i] = ms_string_new (strings[i]->n_wildcards);
if (strings[i]->n_wildcards)
has_wildcard = TRUE;
hms_wildcard = TRUE;
}
set->min_last = min_last;
@ -423,13 +423,13 @@ as_set_new (ASStringInfo **strings,
error:
g_free (last_chars);
g_string_free (pattern, TRUE);
as_set_unref (set);
ms_set_unref (set);
return NULL;
}
static void
as_match_destroy (ASMatch *match)
ms_match_destroy (MSMatch *match)
{
if (match->n_parens)
g_free (match->parens);
@ -437,9 +437,9 @@ as_match_destroy (ASMatch *match)
static gboolean
as_set_match (ASSet *set,
ms_set_match (MSSet *set,
const char *text,
ASMatch *match)
MSMatch *match)
{
char *reversed;
int start_pos, end_pos;
@ -509,7 +509,7 @@ out:
static gboolean
as_set_check_last (ASSet *set,
ms_set_check_last (MSSet *set,
gunichar c)
{
guint i;
@ -526,7 +526,7 @@ as_set_check_last (ASSet *set,
static void
as_set_unref (ASSet *set)
ms_set_unref (MSSet *set)
{
guint i;
@ -537,7 +537,7 @@ as_set_unref (ASSet *set)
{
for (i = 0; i < set->n_strings; ++i)
{
as_string_free (set->strings[i]);
ms_string_free (set->strings[i]);
g_free (set->scripts[i]);
}
@ -550,7 +550,7 @@ as_set_unref (ASSet *set)
}
static ASSet *as_set_ref (ASSet *set)
static MSSet *ms_set_ref (MSSet *set)
{
g_return_val_if_fail (set != NULL, NULL);
set->ref_count++;
@ -559,9 +559,9 @@ static ASSet *as_set_ref (ASSet *set)
static void
as_string_info_array_free (GPtrArray *ar)
ms_string_info_array_free (GPtrArray *ar)
{
g_ptr_array_foreach (ar, (GFunc) as_string_info_free, NULL);
g_ptr_array_foreach (ar, (GFunc) ms_string_info_free, NULL);
g_ptr_array_free (ar, TRUE);
}
@ -569,13 +569,13 @@ as_string_info_array_free (GPtrArray *ar)
static void
add_lang_sets (const char *lang,
GPtrArray *strings,
ASPlugin *plugin)
MSPlugin *plugin)
{
ASSet *set;
MSSet *set;
g_return_if_fail (strings && strings->len);
set = as_set_new ((ASStringInfo**) strings->pdata, strings->len);
set = ms_set_new ((MSStringInfo**) strings->pdata, strings->len);
if (set)
g_hash_table_insert (plugin->lang_sets, g_strdup (lang), set);
@ -600,7 +600,7 @@ is_nonblank_string (const char *string)
static void
as_plugin_load_info (ASPlugin *plugin,
ms_plugin_load_info (MSPlugin *plugin,
GSList *list)
{
GPtrArray *any_lang;
@ -612,13 +612,13 @@ as_plugin_load_info (ASPlugin *plugin,
any_lang = g_ptr_array_new ();
lang_strings = g_hash_table_new_full (g_str_hash, g_str_equal, g_free,
(GDestroyNotify) as_string_info_array_free);
(GDestroyNotify) ms_string_info_array_free);
for (l = list; l != NULL; l = l->next)
{
ASInfo *info = l->data;
ASStringInfo *sinfo;
GPtrArray *ar;
MSStringInfo *sinfo;
MSInfo *info = l->data;
if (info->lang)
{
@ -635,7 +635,7 @@ as_plugin_load_info (ASPlugin *plugin,
ar = any_lang;
}
sinfo = as_string_get_info (info->pattern, 0, 0, ar->len);
sinfo = ms_string_get_info (info->pattern, 0, 0, ar->len);
if (!sinfo)
{
@ -645,11 +645,11 @@ as_plugin_load_info (ASPlugin *plugin,
if (is_nonblank_string (info->script))
{
ASNode *script = as_script_parse (info->script);
MSNode *script = ms_script_parse (info->script);
if (script)
{
as_string_info_set_script (sinfo, info->script);
ms_string_info_set_script (sinfo, info->script);
g_object_unref (script);
}
}
@ -658,18 +658,18 @@ as_plugin_load_info (ASPlugin *plugin,
}
if (any_lang->len)
plugin->any_lang = as_set_new ((ASStringInfo**) any_lang->pdata,
plugin->any_lang = ms_set_new ((MSStringInfo**) any_lang->pdata,
any_lang->len);
g_hash_table_foreach (lang_strings, (GHFunc) add_lang_sets, plugin);
as_string_info_array_free (any_lang);
ms_string_info_array_free (any_lang);
g_hash_table_destroy (lang_strings);
}
static void
as_plugin_load (ASPlugin *plugin)
ms_plugin_load (MSPlugin *plugin)
{
const char *file;
GSList *info = NULL;
@ -679,33 +679,33 @@ as_plugin_load (ASPlugin *plugin)
file = moo_prefs_get_filename (FILE_PREFS_KEY);
if (file)
_as_load_file (file, &info);
_ms_load_file (file, &info);
if (info)
as_plugin_load_info (plugin, info);
ms_plugin_load_info (plugin, info);
g_slist_foreach (info, (GFunc) _as_info_free, NULL);
g_slist_foreach (info, (GFunc) _ms_info_free, NULL);
g_slist_free (info);
}
static gboolean
as_plugin_init (ASPlugin *plugin)
ms_plugin_init (MSPlugin *plugin)
{
plugin->lang_sets = g_hash_table_new_full (g_str_hash, g_str_equal, g_free,
(GDestroyNotify) as_set_unref);
plugin->ctx = _as_plugin_context_new ();
(GDestroyNotify) ms_set_unref);
plugin->ctx = _ms_plugin_context_new ();
as_plugin_load (plugin);
ms_plugin_load (plugin);
return TRUE;
}
static void
as_plugin_deinit (ASPlugin *plugin)
ms_plugin_deinit (MSPlugin *plugin)
{
as_set_unref (plugin->any_lang);
ms_set_unref (plugin->any_lang);
g_hash_table_destroy (plugin->lang_sets);
g_object_unref (plugin->ctx);
plugin->any_lang = NULL;
@ -717,29 +717,29 @@ as_plugin_deinit (ASPlugin *plugin)
static void
free_sets_list (GSList *list)
{
g_slist_foreach (list, (GFunc) as_set_unref, NULL);
g_slist_foreach (list, (GFunc) ms_set_unref, NULL);
g_slist_free (list);
}
static GSList *
as_plugin_get_doc_sets (ASPlugin *plugin,
ms_plugin_get_doc_sets (MSPlugin *plugin,
MooEdit *doc)
{
char *lang = NULL;
GSList *list = NULL;
if (plugin->any_lang)
list = g_slist_prepend (list, as_set_ref (plugin->any_lang));
list = g_slist_prepend (list, ms_set_ref (plugin->any_lang));
moo_edit_config_get (doc->config, "lang", &lang, NULL);
if (lang)
{
ASSet *set = g_hash_table_lookup (plugin->lang_sets, lang);
MSSet *set = g_hash_table_lookup (plugin->lang_sets, lang);
if (set)
list = g_slist_prepend (list, as_set_ref (set));
list = g_slist_prepend (list, ms_set_ref (set));
}
g_free (lang);
@ -748,14 +748,14 @@ as_plugin_get_doc_sets (ASPlugin *plugin,
static void
as_plugin_connect_doc (ASPlugin *plugin,
ms_plugin_connect_doc (MSPlugin *plugin,
MooEdit *doc)
{
GSList *sets = as_plugin_get_doc_sets (plugin, doc);
GSList *sets = ms_plugin_get_doc_sets (plugin, doc);
if (sets)
{
g_object_set_data_full (G_OBJECT (doc), AS_DATA, sets,
g_object_set_data_full (G_OBJECT (doc), MS_DATA, sets,
(GDestroyNotify) free_sets_list);
g_signal_connect (doc, "char-inserted",
G_CALLBACK (char_inserted_cb), sets);
@ -764,15 +764,15 @@ as_plugin_connect_doc (ASPlugin *plugin,
static void
as_plugin_disconnect_doc (G_GNUC_UNUSED ASPlugin *plugin,
ms_plugin_disconnect_doc (G_GNUC_UNUSED MSPlugin *plugin,
MooEdit *doc)
{
GSList *sets = g_object_get_data (G_OBJECT (doc), AS_DATA);
GSList *sets = g_object_get_data (G_OBJECT (doc), MS_DATA);
if (sets)
{
g_signal_handlers_disconnect_by_func (doc, (gpointer) char_inserted_cb, sets);
g_object_set_data (G_OBJECT (doc), AS_DATA, NULL);
g_object_set_data (G_OBJECT (doc), MS_DATA, NULL);
}
}
@ -781,28 +781,28 @@ static void
lang_changed (MooEdit *doc,
G_GNUC_UNUSED guint var_id,
G_GNUC_UNUSED GParamSpec *pspec,
ASPlugin *plugin)
MSPlugin *plugin)
{
as_plugin_disconnect_doc (plugin, doc);
as_plugin_connect_doc (plugin, doc);
ms_plugin_disconnect_doc (plugin, doc);
ms_plugin_connect_doc (plugin, doc);
}
static void
as_plugin_attach (ASPlugin *plugin,
ms_plugin_attach (MSPlugin *plugin,
MooEdit *doc)
{
as_plugin_connect_doc (plugin, doc);
ms_plugin_connect_doc (plugin, doc);
g_signal_connect (doc, "config_notify::lang",
G_CALLBACK (lang_changed), plugin);
}
static void
as_plugin_detach (ASPlugin *plugin,
ms_plugin_detach (MSPlugin *plugin,
MooEdit *doc)
{
as_plugin_disconnect_doc (plugin, doc);
ms_plugin_disconnect_doc (plugin, doc);
g_signal_handlers_disconnect_by_func (doc, (gpointer) lang_changed, plugin);
}
@ -816,16 +816,16 @@ char_inserted_cb (MooEdit *doc,
GtkTextIter iter;
char *slice;
gboolean found;
ASMatch match;
MSMatch match;
GSList *l;
g_return_val_if_fail (sets != NULL, FALSE);
for (l = sets; l != NULL; l = l->next)
{
ASSet *set = l->data;
MSSet *set = l->data;
if (!as_set_check_last (set, character))
if (!ms_set_check_last (set, character))
continue;
iter = *where;
@ -833,14 +833,14 @@ char_inserted_cb (MooEdit *doc,
/* get extra char here */
slice = gtk_text_iter_get_slice (&iter, where);
found = as_set_match (set, slice, &match);
found = ms_set_match (set, slice, &match);
g_free (slice);
if (!found)
continue;
process_match (doc, where, set, &match);
as_match_destroy (&match);
ms_match_destroy (&match);
return TRUE;
}
@ -851,14 +851,14 @@ char_inserted_cb (MooEdit *doc,
static void
process_match (MooEdit *doc,
GtkTextIter *end,
ASSet *set,
ASMatch *match)
MSSet *set,
MSMatch *match)
{
GtkTextIter start;
char *full_text = NULL;
char **parens_text = NULL;
guint i;
ASPlugin *plugin;
MSPlugin *plugin;
start = *end;
gtk_text_iter_backward_chars (&start, match->end_offset);
@ -890,9 +890,9 @@ process_match (MooEdit *doc,
g_print ("\n");
plugin = moo_plugin_lookup (AS_PLUGIN_ID);
plugin = moo_plugin_lookup (MS_PLUGIN_ID);
g_return_if_fail (plugin != NULL);
as_plugin_do_action (plugin, doc, end, set, match,
ms_plugin_do_action (plugin, doc, end, set, match,
full_text, parens_text);
g_free (full_text);
@ -901,21 +901,21 @@ process_match (MooEdit *doc,
static void
as_plugin_do_action (ASPlugin *plugin,
ms_plugin_do_action (MSPlugin *plugin,
MooEdit *doc,
GtkTextIter *insert,
ASSet *set,
ASMatch *match,
MSSet *set,
MSMatch *match,
char *full_text,
char **parens_text)
{
ASNode *script;
MSNode *script;
const char *code = set->scripts[match->string_no];
if (!code)
return;
script = as_script_parse (code);
script = ms_script_parse (code);
if (!script)
{
@ -923,26 +923,26 @@ as_plugin_do_action (ASPlugin *plugin,
return;
}
_as_plugin_context_exec (plugin->ctx, script, doc, insert,
_ms_plugin_context_exec (plugin->ctx, script, doc, insert,
full_text, parens_text, match->n_parens);
g_object_unref (script);
}
MOO_PLUGIN_DEFINE_INFO (as, AS_PLUGIN_ID,
MOO_PLUGIN_DEFINE_INFO (ms, MS_PLUGIN_ID,
"Active Strings", "Very active",
"Yevgen Muntyan <muntyan@tamu.edu>",
MOO_VERSION);
MOO_PLUGIN_DEFINE_FULL (AS, as,
as_plugin_init, as_plugin_deinit,
MOO_PLUGIN_DEFINE_FULL (MS, ms,
ms_plugin_init, ms_plugin_deinit,
NULL, NULL,
as_plugin_attach, as_plugin_detach,
ms_plugin_attach, ms_plugin_detach,
NULL, 0, 0);
gboolean
_moo_active_strings_plugin_init (void)
{
return moo_plugin_register (as_plugin_get_type ());
return moo_plugin_register (ms_plugin_get_type ());
}

View File

@ -17,70 +17,70 @@
#define N_POS_VARS 20
G_DEFINE_TYPE (ASContext, as_context, G_TYPE_OBJECT)
G_DEFINE_TYPE (MSContext, ms_context, G_TYPE_OBJECT)
static void
default_print_func (const char *string,
G_GNUC_UNUSED ASContext *ctx)
G_GNUC_UNUSED MSContext *ctx)
{
g_print ("%s", string);
}
static ASValue*
print_func (ASValue **args,
static MSValue*
print_func (MSValue **args,
guint n_args,
ASContext *ctx)
MSContext *ctx)
{
guint i;
for (i = 0; i < n_args; ++i)
{
char *s = as_value_print (args[i]);
char *s = ms_value_print (args[i]);
ctx->print_func (s, ctx);
g_free (s);
}
ctx->print_func ("\n", ctx);
return as_value_none ();
return ms_value_none ();
}
static void
add_builtin_funcs (ASContext *ctx)
add_builtin_funcs (MSContext *ctx)
{
guint i;
ASFunc *func;
MSFunc *func;
for (i = 0; i < AS_BINARY_OP_LAST; ++i)
for (i = 0; i < MS_BINARY_OP_LMST; ++i)
{
func = as_cfunc_new_2 (as_binary_op_cfunc (i));
as_context_set_func (ctx, as_binary_op_name (i), func);
func = ms_cfunc_new_2 (ms_binary_op_cfunc (i));
ms_context_set_func (ctx, ms_binary_op_name (i), func);
g_object_unref (func);
}
for (i = 0; i < AS_UNARY_OP_LAST; ++i)
for (i = 0; i < MS_UNARY_OP_LMST; ++i)
{
func = as_cfunc_new_1 (as_unary_op_cfunc (i));
as_context_set_func (ctx, as_unary_op_name (i), func);
func = ms_cfunc_new_1 (ms_unary_op_cfunc (i));
ms_context_set_func (ctx, ms_unary_op_name (i), func);
g_object_unref (func);
}
func = as_cfunc_new_var (print_func);
as_context_set_func (ctx, "print", func);
func = ms_cfunc_new_var (print_func);
ms_context_set_func (ctx, "print", func);
g_object_unref (func);
}
static void
as_context_init (ASContext *ctx)
ms_context_init (MSContext *ctx)
{
ctx->funcs = g_hash_table_new_full (g_str_hash, g_str_equal,
g_free, g_object_unref);
ctx->named_vars = g_hash_table_new_full (g_str_hash, g_str_equal, g_free,
(GDestroyNotify) as_variable_unref);
ctx->positional_vars = g_new0 (ASValue*, N_POS_VARS);
(GDestroyNotify) ms_variable_unref);
ctx->positional_vars = g_new0 (MSValue*, N_POS_VARS);
ctx->print_func = default_print_func;
add_builtin_funcs (ctx);
@ -88,87 +88,87 @@ as_context_init (ASContext *ctx)
static void
as_context_finalize (GObject *object)
ms_context_finalize (GObject *object)
{
guint i;
ASContext *ctx = AS_CONTEXT (object);
MSContext *ctx = MS_CONTEXT (object);
g_hash_table_destroy (ctx->funcs);
g_hash_table_destroy (ctx->named_vars);
for (i = 0; i < N_POS_VARS; ++i)
if (ctx->positional_vars[i])
as_value_unref (ctx->positional_vars[i]);
ms_value_unref (ctx->positional_vars[i]);
g_free (ctx->positional_vars);
g_free (ctx->error_msg);
G_OBJECT_CLASS(as_context_parent_class)->finalize (object);
G_OBJECT_CLASS(ms_context_parent_class)->finalize (object);
}
static void
as_context_class_init (ASContextClass *klass)
ms_context_class_init (MSContextClass *klass)
{
G_OBJECT_CLASS(klass)->finalize = as_context_finalize;
G_OBJECT_CLASS(klass)->finalize = ms_context_finalize;
}
ASContext *
as_context_new (void)
MSContext *
ms_context_new (void)
{
ASContext *ctx = g_object_new (AS_TYPE_CONTEXT, NULL);
MSContext *ctx = g_object_new (MS_TYPE_CONTEXT, NULL);
return ctx;
}
ASValue *
as_context_eval_positional (ASContext *ctx,
MSValue *
ms_context_eval_positional (MSContext *ctx,
guint num)
{
g_return_val_if_fail (AS_IS_CONTEXT (ctx), NULL);
g_return_val_if_fail (MS_IS_CONTEXT (ctx), NULL);
g_return_val_if_fail (num < N_POS_VARS, NULL);
return ctx->positional_vars[num] ?
as_value_ref (ctx->positional_vars[num]) : as_value_none ();
ms_value_ref (ctx->positional_vars[num]) : ms_value_none ();
}
ASValue *
as_context_eval_named (ASContext *ctx,
MSValue *
ms_context_eval_named (MSContext *ctx,
const char *name)
{
ASVariable *var;
MSVariable *var;
g_return_val_if_fail (AS_IS_CONTEXT (ctx), NULL);
g_return_val_if_fail (MS_IS_CONTEXT (ctx), NULL);
g_return_val_if_fail (name != NULL, NULL);
var = as_context_lookup_var (ctx, name);
var = ms_context_lookup_var (ctx, name);
if (!var)
return as_value_none ();
return ms_value_none ();
if (var->value)
return as_value_ref (var->value);
return ms_value_ref (var->value);
return as_func_call (var->func, NULL, 0, ctx);
return ms_func_call (var->func, NULL, 0, ctx);
}
gboolean
as_context_assign_positional (ASContext *ctx,
ms_context_assign_positional (MSContext *ctx,
guint num,
ASValue *value)
MSValue *value)
{
g_return_val_if_fail (AS_IS_CONTEXT (ctx), FALSE);
g_return_val_if_fail (MS_IS_CONTEXT (ctx), FALSE);
g_return_val_if_fail (num < N_POS_VARS, FALSE);
if (value != ctx->positional_vars[num])
{
if (ctx->positional_vars[num])
as_value_unref (ctx->positional_vars[num]);
ms_value_unref (ctx->positional_vars[num]);
ctx->positional_vars[num] = value;
if (value)
as_value_ref (value);
ms_value_ref (value);
}
return TRUE;
@ -176,16 +176,16 @@ as_context_assign_positional (ASContext *ctx,
gboolean
as_context_assign_named (ASContext *ctx,
ms_context_assign_named (MSContext *ctx,
const char *name,
ASValue *value)
MSValue *value)
{
ASVariable *var;
MSVariable *var;
g_return_val_if_fail (AS_IS_CONTEXT (ctx), FALSE);
g_return_val_if_fail (MS_IS_CONTEXT (ctx), FALSE);
g_return_val_if_fail (name != NULL, FALSE);
var = as_context_lookup_var (ctx, name);
var = ms_context_lookup_var (ctx, name);
if (value)
{
@ -199,44 +199,44 @@ as_context_assign_named (ASContext *ctx,
if (var->value != value)
{
as_value_unref (var->value);
var->value = as_value_ref (value);
ms_value_unref (var->value);
var->value = ms_value_ref (value);
}
}
else
{
var = as_variable_new_value (value);
as_context_set_var (ctx, name, var);
as_variable_unref (var);
var = ms_variable_new_value (value);
ms_context_set_var (ctx, name, var);
ms_variable_unref (var);
}
}
else if (var)
{
as_context_set_var (ctx, name, NULL);
ms_context_set_var (ctx, name, NULL);
}
return TRUE;
}
ASVariable *
as_context_lookup_var (ASContext *ctx,
MSVariable *
ms_context_lookup_var (MSContext *ctx,
const char *name)
{
g_return_val_if_fail (AS_IS_CONTEXT (ctx), NULL);
g_return_val_if_fail (MS_IS_CONTEXT (ctx), NULL);
g_return_val_if_fail (name != NULL, NULL);
return g_hash_table_lookup (ctx->named_vars, name);
}
gboolean
as_context_set_var (ASContext *ctx,
ms_context_set_var (MSContext *ctx,
const char *name,
ASVariable *var)
MSVariable *var)
{
ASVariable *old;
MSVariable *old;
g_return_val_if_fail (AS_IS_CONTEXT (ctx), FALSE);
g_return_val_if_fail (MS_IS_CONTEXT (ctx), FALSE);
g_return_val_if_fail (name != NULL, FALSE);
old = g_hash_table_lookup (ctx->named_vars, name);
@ -245,7 +245,7 @@ as_context_set_var (ASContext *ctx,
{
if (var)
g_hash_table_insert (ctx->named_vars, g_strdup (name),
as_variable_ref (var));
ms_variable_ref (var));
else
g_hash_table_remove (ctx->named_vars, name);
}
@ -254,26 +254,26 @@ as_context_set_var (ASContext *ctx,
}
ASFunc *
as_context_lookup_func (ASContext *ctx,
MSFunc *
ms_context_lookup_func (MSContext *ctx,
const char *name)
{
g_return_val_if_fail (AS_IS_CONTEXT (ctx), FALSE);
g_return_val_if_fail (MS_IS_CONTEXT (ctx), FALSE);
g_return_val_if_fail (name != NULL, FALSE);
return g_hash_table_lookup (ctx->funcs, name);
}
gboolean
as_context_set_func (ASContext *ctx,
ms_context_set_func (MSContext *ctx,
const char *name,
ASFunc *func)
MSFunc *func)
{
ASFunc *old;
MSFunc *old;
g_return_val_if_fail (AS_IS_CONTEXT (ctx), FALSE);
g_return_val_if_fail (MS_IS_CONTEXT (ctx), FALSE);
g_return_val_if_fail (name != NULL, FALSE);
g_return_val_if_fail (!func || AS_IS_FUNC (func), FALSE);
g_return_val_if_fail (!func || MS_IS_FUNC (func), FALSE);
old = g_hash_table_lookup (ctx->funcs, name);
@ -290,19 +290,19 @@ as_context_set_func (ASContext *ctx,
}
ASValue *
as_context_set_error (ASContext *ctx,
ASError error,
MSValue *
ms_context_set_error (MSContext *ctx,
MSError error,
const char *message)
{
const char *errname;
g_return_val_if_fail (AS_IS_CONTEXT (ctx), NULL);
g_return_val_if_fail (MS_IS_CONTEXT (ctx), NULL);
g_return_val_if_fail (!ctx->error && error, NULL);
g_return_val_if_fail (!ctx->error_msg, NULL);
ctx->error = error;
errname = as_context_get_error_msg (ctx);
errname = ms_context_get_error_msg (ctx);
if (message && *message)
ctx->error_msg = g_strdup_printf ("%s: %s", errname, message);
@ -314,35 +314,35 @@ as_context_set_error (ASContext *ctx,
static void
as_context_format_error_valist (ASContext *ctx,
ASError error,
ms_context_format_error_valist (MSContext *ctx,
MSError error,
const char *format,
va_list args)
{
char *buffer = NULL;
g_vasprintf (&buffer, format, args);
as_context_set_error (ctx, error, buffer);
ms_context_set_error (ctx, error, buffer);
g_free (buffer);
}
ASValue *
as_context_format_error (ASContext *ctx,
ASError error,
MSValue *
ms_context_format_error (MSContext *ctx,
MSError error,
const char *format,
...)
{
va_list args;
g_return_val_if_fail (AS_IS_CONTEXT (ctx), NULL);
g_return_val_if_fail (MS_IS_CONTEXT (ctx), NULL);
g_return_val_if_fail (!ctx->error && error, NULL);
g_return_val_if_fail (!ctx->error_msg, NULL);
if (!format || !format[0])
as_context_set_error (ctx, error, NULL);
ms_context_set_error (ctx, error, NULL);
va_start (args, format);
as_context_format_error_valist (ctx, error, format, args);
ms_context_format_error_valist (ctx, error, format, args);
va_end (args);
return NULL;
@ -350,24 +350,24 @@ as_context_format_error (ASContext *ctx,
void
as_context_clear_error (ASContext *ctx)
ms_context_clear_error (MSContext *ctx)
{
g_return_if_fail (AS_IS_CONTEXT (ctx));
ctx->error = AS_ERROR_NONE;
g_return_if_fail (MS_IS_CONTEXT (ctx));
ctx->error = MS_ERROR_NONE;
g_free (ctx->error_msg);
ctx->error_msg = NULL;
}
const char *
as_context_get_error_msg (ASContext *ctx)
ms_context_get_error_msg (MSContext *ctx)
{
static const char *msgs[AS_ERROR_LAST] = {
static const char *msgs[MS_ERROR_LMST] = {
NULL, "Type error", "Value error", "Name error"
};
g_return_val_if_fail (AS_IS_CONTEXT (ctx), NULL);
g_return_val_if_fail (ctx->error < AS_ERROR_LAST, NULL);
g_return_val_if_fail (MS_IS_CONTEXT (ctx), NULL);
g_return_val_if_fail (ctx->error < MS_ERROR_LMST, NULL);
if (ctx->error_msg)
return ctx->error_msg;
@ -376,45 +376,45 @@ as_context_get_error_msg (ASContext *ctx)
}
static ASVariable *
as_variable_new (void)
static MSVariable *
ms_variable_new (void)
{
ASVariable *var = g_new0 (ASVariable, 1);
MSVariable *var = g_new0 (MSVariable, 1);
var->ref_count = 1;
return var;
}
ASVariable *
as_variable_new_value (ASValue *value)
MSVariable *
ms_variable_new_value (MSValue *value)
{
ASVariable *var;
MSVariable *var;
g_return_val_if_fail (value != NULL, NULL);
var = as_variable_new ();
var->value = as_value_ref (value);
var = ms_variable_new ();
var->value = ms_value_ref (value);
return var;
}
ASVariable *
as_variable_new_func (ASFunc *func)
MSVariable *
ms_variable_new_func (MSFunc *func)
{
ASVariable *var;
MSVariable *var;
g_return_val_if_fail (AS_IS_FUNC (func), NULL);
g_return_val_if_fail (MS_IS_FUNC (func), NULL);
var = as_variable_new ();
var = ms_variable_new ();
var->func = g_object_ref (func);
return var;
}
ASVariable *
as_variable_ref (ASVariable *var)
MSVariable *
ms_variable_ref (MSVariable *var)
{
g_return_val_if_fail (var != NULL, NULL);
var->ref_count++;
@ -423,14 +423,14 @@ as_variable_ref (ASVariable *var)
void
as_variable_unref (ASVariable *var)
ms_variable_unref (MSVariable *var)
{
g_return_if_fail (var != NULL);
if (!--var->ref_count)
{
if (var->value)
as_value_unref (var->value);
ms_value_unref (var->value);
if (var->func)
g_object_unref (var->func);
g_free (var);

View File

@ -20,93 +20,93 @@
G_BEGIN_DECLS
#define AS_TYPE_CONTEXT (as_context_get_type ())
#define AS_CONTEXT(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), AS_TYPE_CONTEXT, ASContext))
#define AS_CONTEXT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), AS_TYPE_CONTEXT, ASContextClass))
#define AS_IS_CONTEXT(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), AS_TYPE_CONTEXT))
#define AS_IS_CONTEXT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), AS_TYPE_CONTEXT))
#define AS_CONTEXT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), AS_TYPE_CONTEXT, ASContextClass))
#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 _ASContextClass ASContextClass;
typedef struct _ASVariable ASVariable;
typedef struct _MSContextClass MSContextClass;
typedef struct _MSVariable MSVariable;
struct _ASVariable {
struct _MSVariable {
guint ref_count;
ASValue *value;
ASFunc *func; /* called with no arguments */
MSValue *value;
MSFunc *func; /* called with no arguments */
};
typedef enum {
AS_ERROR_NONE = 0,
AS_ERROR_TYPE,
AS_ERROR_VALUE,
AS_ERROR_NAME,
AS_ERROR_LAST
} ASError;
MS_ERROR_NONE = 0,
MS_ERROR_TYPE,
MS_ERROR_VALUE,
MS_ERROR_NAME,
MS_ERROR_LMST
} MSError;
typedef void (*ASPrintFunc) (const char *string,
ASContext *ctx);
typedef void (*MSPrintFunc) (const char *string,
MSContext *ctx);
struct _ASContext {
struct _MSContext {
GObject object;
GHashTable *funcs;
GHashTable *named_vars;
ASValue **positional_vars;
MSValue **positional_vars;
ASError error;
MSError error;
char *error_msg;
ASPrintFunc print_func;
MSPrintFunc print_func;
};
struct _ASContextClass {
struct _MSContextClass {
GObjectClass object_class;
};
GType as_context_get_type (void) G_GNUC_CONST;
GType ms_context_get_type (void) G_GNUC_CONST;
ASVariable *as_variable_new_value (ASValue *value);
ASVariable *as_variable_new_func (ASFunc *func);
ASVariable *as_variable_ref (ASVariable *var);
void as_variable_unref (ASVariable *var);
MSVariable *ms_variable_new_value (MSValue *value);
MSVariable *ms_variable_new_func (MSFunc *func);
MSVariable *ms_variable_ref (MSVariable *var);
void ms_variable_unref (MSVariable *var);
ASContext *as_context_new (void);
MSContext *ms_context_new (void);
ASValue *as_context_eval_positional (ASContext *ctx,
MSValue *ms_context_eval_positional (MSContext *ctx,
guint num);
ASValue *as_context_eval_named (ASContext *ctx,
MSValue *ms_context_eval_named (MSContext *ctx,
const char *name);
gboolean as_context_assign_positional (ASContext *ctx,
gboolean ms_context_assign_positional (MSContext *ctx,
guint num,
ASValue *value);
gboolean as_context_assign_named (ASContext *ctx,
MSValue *value);
gboolean ms_context_assign_named (MSContext *ctx,
const char *name,
ASValue *value);
MSValue *value);
ASVariable *as_context_lookup_var (ASContext *ctx,
MSVariable *ms_context_lookup_var (MSContext *ctx,
const char *name);
gboolean as_context_set_var (ASContext *ctx,
gboolean ms_context_set_var (MSContext *ctx,
const char *name,
ASVariable *var);
MSVariable *var);
ASFunc *as_context_lookup_func (ASContext *ctx,
MSFunc *ms_context_lookup_func (MSContext *ctx,
const char *name);
gboolean as_context_set_func (ASContext *ctx,
gboolean ms_context_set_func (MSContext *ctx,
const char *name,
ASFunc *func);
MSFunc *func);
ASValue *as_context_set_error (ASContext *ctx,
ASError error,
MSValue *ms_context_set_error (MSContext *ctx,
MSError error,
const char *message);
ASValue *as_context_format_error (ASContext *ctx,
ASError error,
MSValue *ms_context_format_error (MSContext *ctx,
MSError error,
const char *format,
...);
const char *as_context_get_error_msg (ASContext *ctx);
void as_context_clear_error (ASContext *ctx);
const char *ms_context_get_error_msg (MSContext *ctx);
void ms_context_clear_error (MSContext *ctx);
G_END_DECLS

View File

@ -15,19 +15,19 @@
#include "mooscript-func.h"
ASValue *
as_func_call (ASFunc *func,
ASValue **args,
MSValue *
ms_func_call (MSFunc *func,
MSValue **args,
guint n_args,
ASContext *ctx)
MSContext *ctx)
{
ASFuncCall call;
MSFuncCall call;
g_return_val_if_fail (AS_IS_FUNC (func), NULL);
g_return_val_if_fail (MS_IS_FUNC (func), NULL);
g_return_val_if_fail (!n_args || args, NULL);
g_return_val_if_fail (ctx != NULL, NULL);
call = AS_FUNC_GET_CLASS(func)->call;
call = MS_FUNC_GET_CLASS(func)->call;
g_return_val_if_fail (call != NULL, NULL);
return call (func, args, n_args, ctx);
@ -35,48 +35,48 @@ as_func_call (ASFunc *func,
/******************************************************************/
/* ASFunc
/* MSFunc
*/
G_DEFINE_TYPE (ASFunc, as_func, G_TYPE_OBJECT)
G_DEFINE_TYPE (MSFunc, ms_func, G_TYPE_OBJECT)
static void
as_func_init (G_GNUC_UNUSED ASFunc *func)
ms_func_init (G_GNUC_UNUSED MSFunc *func)
{
}
static void
as_func_class_init (G_GNUC_UNUSED ASFuncClass *klass)
ms_func_class_init (G_GNUC_UNUSED MSFuncClass *klass)
{
}
/******************************************************************/
/* ASCFunc
/* MSCFunc
*/
G_DEFINE_TYPE (ASCFunc, as_cfunc, AS_TYPE_FUNC)
G_DEFINE_TYPE (MSCFunc, ms_cfunc, MS_TYPE_FUNC)
static void
as_cfunc_init (ASCFunc *func)
ms_cfunc_init (MSCFunc *func)
{
func->n_args = -1;
}
static ASValue *
as_cfunc_call (ASFunc *func_,
ASValue **args,
static MSValue *
ms_cfunc_call (MSFunc *func_,
MSValue **args,
guint n_args,
ASContext *ctx)
MSContext *ctx)
{
ASCFunc_Var func_var;
ASCFunc_0 func_0;
ASCFunc_1 func_1;
ASCFunc_2 func_2;
ASCFunc_3 func_3;
ASCFunc *func = AS_CFUNC (func_);
MSCFunc_Var func_var;
MSCFunc_0 func_0;
MSCFunc_1 func_1;
MSCFunc_2 func_2;
MSCFunc_3 func_3;
MSCFunc *func = MS_CFUNC (func_);
if (func->n_args >= 0 && func->n_args != (int) n_args)
{
@ -86,23 +86,23 @@ as_cfunc_call (ASFunc *func_,
if (func->n_args < 0)
{
func_var = (ASCFunc_Var) func->cfunc;
func_var = (MSCFunc_Var) func->cfunc;
return func_var (args, n_args, ctx);
}
switch (func->n_args)
{
case 0:
func_0 = (ASCFunc_0) func->cfunc;
func_0 = (MSCFunc_0) func->cfunc;
return func_0 (ctx);
case 1:
func_1 = (ASCFunc_1) func->cfunc;
func_1 = (MSCFunc_1) func->cfunc;
return func_1 (args[0], ctx);
case 2:
func_2 = (ASCFunc_2) func->cfunc;
func_2 = (MSCFunc_2) func->cfunc;
return func_2 (args[0], args[1], ctx);
case 3:
func_3 = (ASCFunc_3) func->cfunc;
func_3 = (MSCFunc_3) func->cfunc;
return func_3 (args[0], args[1], args[2], ctx);
}
@ -112,58 +112,58 @@ as_cfunc_call (ASFunc *func_,
static void
as_cfunc_class_init (ASCFuncClass *klass)
ms_cfunc_class_init (MSCFuncClass *klass)
{
AS_FUNC_CLASS(klass)->call = as_cfunc_call;
MS_FUNC_CLASS(klass)->call = ms_cfunc_call;
}
static ASFunc *
as_cfunc_new (int n_args,
static MSFunc *
ms_cfunc_new (int n_args,
GCallback cfunc)
{
ASCFunc *func;
MSCFunc *func;
g_return_val_if_fail (cfunc != NULL, NULL);
func = g_object_new (AS_TYPE_CFUNC, NULL);
func = g_object_new (MS_TYPE_CFUNC, NULL);
func->n_args = n_args;
func->cfunc = cfunc;
return AS_FUNC (func);
return MS_FUNC (func);
}
ASFunc *
as_cfunc_new_var (ASCFunc_Var cfunc)
MSFunc *
ms_cfunc_new_var (MSCFunc_Var cfunc)
{
return as_cfunc_new (-1, G_CALLBACK (cfunc));
return ms_cfunc_new (-1, G_CALLBACK (cfunc));
}
ASFunc *
as_cfunc_new_0 (ASCFunc_0 cfunc)
MSFunc *
ms_cfunc_new_0 (MSCFunc_0 cfunc)
{
return as_cfunc_new (0, G_CALLBACK (cfunc));
return ms_cfunc_new (0, G_CALLBACK (cfunc));
}
ASFunc *
as_cfunc_new_1 (ASCFunc_1 cfunc)
MSFunc *
ms_cfunc_new_1 (MSCFunc_1 cfunc)
{
return as_cfunc_new (1, G_CALLBACK (cfunc));
return ms_cfunc_new (1, G_CALLBACK (cfunc));
}
ASFunc *
as_cfunc_new_2 (ASCFunc_2 cfunc)
MSFunc *
ms_cfunc_new_2 (MSCFunc_2 cfunc)
{
return as_cfunc_new (2, G_CALLBACK (cfunc));
return ms_cfunc_new (2, G_CALLBACK (cfunc));
}
ASFunc *
as_cfunc_new_3 (ASCFunc_3 cfunc)
MSFunc *
ms_cfunc_new_3 (MSCFunc_3 cfunc)
{
return as_cfunc_new (3, G_CALLBACK (cfunc));
return ms_cfunc_new (3, G_CALLBACK (cfunc));
}

View File

@ -20,80 +20,80 @@
G_BEGIN_DECLS
#define AS_TYPE_FUNC (as_func_get_type ())
#define AS_FUNC(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), AS_TYPE_FUNC, ASFunc))
#define AS_FUNC_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), AS_TYPE_FUNC, ASFuncClass))
#define AS_IS_FUNC(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), AS_TYPE_FUNC))
#define AS_IS_FUNC_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), AS_TYPE_FUNC))
#define AS_FUNC_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), AS_TYPE_FUNC, ASFuncClass))
#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))
#define AS_TYPE_CFUNC (as_cfunc_get_type ())
#define AS_CFUNC(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), AS_TYPE_CFUNC, ASCFunc))
#define AS_CFUNC_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), AS_TYPE_CFUNC, ASCFuncClass))
#define AS_IS_CFUNC(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), AS_TYPE_CFUNC))
#define AS_IS_CFUNC_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), AS_TYPE_CFUNC))
#define AS_CFUNC_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), AS_TYPE_CFUNC, ASCFuncClass))
#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 _ASContext ASContext;
typedef struct _MSContext MSContext;
typedef struct _ASFunc ASFunc;
typedef struct _ASFuncClass ASFuncClass;
typedef struct _ASCFunc ASCFunc;
typedef struct _ASCFuncClass ASCFuncClass;
typedef struct _MSFunc MSFunc;
typedef struct _MSFuncClass MSFuncClass;
typedef struct _MSCFunc MSCFunc;
typedef struct _MSCFuncClass MSCFuncClass;
struct _ASFunc {
struct _MSFunc {
GObject object;
};
typedef ASValue* (*ASFuncCall) (ASFunc *func,
ASValue **args,
typedef MSValue* (*MSFuncCall) (MSFunc *func,
MSValue **args,
guint n_args,
ASContext *ctx);
MSContext *ctx);
struct _ASFuncClass {
struct _MSFuncClass {
GObjectClass object_class;
ASFuncCall call;
MSFuncCall call;
};
typedef ASValue* (*ASCFunc_Var) (ASValue **args,
typedef MSValue* (*MSCFunc_Var) (MSValue **args,
guint n_args,
ASContext *ctx);
typedef ASValue* (*ASCFunc_0) (ASContext *ctx);
typedef ASValue* (*ASCFunc_1) (ASValue *arg1,
ASContext *ctx);
typedef ASValue* (*ASCFunc_2) (ASValue *arg1,
ASValue *arg2,
ASContext *ctx);
typedef ASValue* (*ASCFunc_3) (ASValue *arg1,
ASValue *arg2,
ASValue *arg3,
ASContext *ctx);
MSContext *ctx);
typedef MSValue* (*MSCFunc_0) (MSContext *ctx);
typedef MSValue* (*MSCFunc_1) (MSValue *arg1,
MSContext *ctx);
typedef MSValue* (*MSCFunc_2) (MSValue *arg1,
MSValue *arg2,
MSContext *ctx);
typedef MSValue* (*MSCFunc_3) (MSValue *arg1,
MSValue *arg2,
MSValue *arg3,
MSContext *ctx);
struct _ASCFunc {
ASFunc func;
struct _MSCFunc {
MSFunc func;
int n_args;
void (*cfunc) (void);
};
struct _ASCFuncClass {
ASFuncClass func_class;
struct _MSCFuncClass {
MSFuncClass func_class;
};
GType as_func_get_type (void) G_GNUC_CONST;
GType as_cfunc_get_type (void) G_GNUC_CONST;
GType ms_func_get_type (void) G_GNUC_CONST;
GType ms_cfunc_get_type (void) G_GNUC_CONST;
ASValue *as_func_call (ASFunc *func,
ASValue **args,
MSValue *ms_func_call (MSFunc *func,
MSValue **args,
guint n_args,
ASContext *ctx);
MSContext *ctx);
ASFunc *as_cfunc_new_var (ASCFunc_Var cfunc);
ASFunc *as_cfunc_new_0 (ASCFunc_0 cfunc);
ASFunc *as_cfunc_new_1 (ASCFunc_1 cfunc);
ASFunc *as_cfunc_new_2 (ASCFunc_2 cfunc);
ASFunc *as_cfunc_new_3 (ASCFunc_3 cfunc);
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);
G_END_DECLS

File diff suppressed because it is too large Load Diff

View File

@ -20,245 +20,245 @@
G_BEGIN_DECLS
#define AS_TYPE_NODE (as_node_get_type ())
#define AS_NODE(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), AS_TYPE_NODE, ASNode))
#define AS_NODE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), AS_TYPE_NODE, ASNodeClass))
#define AS_IS_NODE(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), AS_TYPE_NODE))
#define AS_IS_NODE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), AS_TYPE_NODE))
#define AS_NODE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), AS_TYPE_NODE, ASNodeClass))
#define MS_TYPE_NODE (ms_node_get_type ())
#define MS_NODE(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), MS_TYPE_NODE, MSNode))
#define MS_NODE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MS_TYPE_NODE, MSNodeClass))
#define MS_IS_NODE(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), MS_TYPE_NODE))
#define MS_IS_NODE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MS_TYPE_NODE))
#define MS_NODE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MS_TYPE_NODE, MSNodeClass))
#define AS_TYPE_NODE_LIST (as_node_list_get_type ())
#define AS_NODE_LIST(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), AS_TYPE_NODE_LIST, ASNodeList))
#define AS_NODE_LIST_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), AS_TYPE_NODE_LIST, ASNodeListClass))
#define AS_IS_NODE_LIST(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), AS_TYPE_NODE_LIST))
#define AS_IS_NODE_LIST_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), AS_TYPE_NODE_LIST))
#define AS_NODE_LIST_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), AS_TYPE_NODE_LIST, ASNodeListClass))
#define MS_TYPE_NODE_LIST (ms_node_list_get_type ())
#define MS_NODE_LIST(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), MS_TYPE_NODE_LIST, MSNodeList))
#define MS_NODE_LIST_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MS_TYPE_NODE_LIST, MSNodeListClass))
#define MS_IS_NODE_LIST(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), MS_TYPE_NODE_LIST))
#define MS_IS_NODE_LIST_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MS_TYPE_NODE_LIST))
#define MS_NODE_LIST_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MS_TYPE_NODE_LIST, MSNodeListClass))
#define AS_TYPE_NODE_VAR (as_node_var_get_type ())
#define AS_NODE_VAR(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), AS_TYPE_NODE_VAR, ASNodeVar))
#define AS_NODE_VAR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), AS_TYPE_NODE_VAR, ASNodeVarClass))
#define AS_IS_NODE_VAR(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), AS_TYPE_NODE_VAR))
#define AS_IS_NODE_VAR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), AS_TYPE_NODE_VAR))
#define AS_NODE_VAR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), AS_TYPE_NODE_VAR, ASNodeVarClass))
#define MS_TYPE_NODE_VAR (ms_node_var_get_type ())
#define MS_NODE_VAR(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), MS_TYPE_NODE_VAR, MSNodeVar))
#define MS_NODE_VAR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MS_TYPE_NODE_VAR, MSNodeVarClass))
#define MS_IS_NODE_VAR(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), MS_TYPE_NODE_VAR))
#define MS_IS_NODE_VAR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MS_TYPE_NODE_VAR))
#define MS_NODE_VAR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MS_TYPE_NODE_VAR, MSNodeVarClass))
#define AS_TYPE_NODE_COMMAND (as_node_command_get_type ())
#define AS_NODE_COMMAND(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), AS_TYPE_NODE_COMMAND, ASNodeCommand))
#define AS_NODE_COMMAND_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), AS_TYPE_NODE_COMMAND, ASNodeCommandClass))
#define AS_IS_NODE_COMMAND(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), AS_TYPE_NODE_COMMAND))
#define AS_IS_NODE_COMMAND_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), AS_TYPE_NODE_COMMAND))
#define AS_NODE_COMMAND_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), AS_TYPE_NODE_COMMAND, ASNodeCommandClass))
#define MS_TYPE_NODE_COMMAND (ms_node_command_get_type ())
#define MS_NODE_COMMAND(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), MS_TYPE_NODE_COMMAND, MSNodeCommand))
#define MS_NODE_COMMAND_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MS_TYPE_NODE_COMMAND, MSNodeCommandClass))
#define MS_IS_NODE_COMMAND(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), MS_TYPE_NODE_COMMAND))
#define MS_IS_NODE_COMMAND_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MS_TYPE_NODE_COMMAND))
#define MS_NODE_COMMAND_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MS_TYPE_NODE_COMMAND, MSNodeCommandClass))
#define AS_TYPE_NODE_IF_ELSE (as_node_if_else_get_type ())
#define AS_NODE_IF_ELSE(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), AS_TYPE_NODE_IF_ELSE, ASNodeIfElse))
#define AS_NODE_IF_ELSE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), AS_TYPE_NODE_IF_ELSE, ASNodeIfElseClass))
#define AS_IS_NODE_IF_ELSE(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), AS_TYPE_NODE_IF_ELSE))
#define AS_IS_NODE_IF_ELSE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), AS_TYPE_NODE_IF_ELSE))
#define AS_NODE_IF_ELSE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), AS_TYPE_NODE_IF_ELSE, ASNodeIfElseClass))
#define MS_TYPE_NODE_IF_ELSE (ms_node_if_else_get_type ())
#define MS_NODE_IF_ELSE(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), MS_TYPE_NODE_IF_ELSE, MSNodeIfElse))
#define MS_NODE_IF_ELSE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MS_TYPE_NODE_IF_ELSE, MSNodeIfElseClass))
#define MS_IS_NODE_IF_ELSE(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), MS_TYPE_NODE_IF_ELSE))
#define MS_IS_NODE_IF_ELSE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MS_TYPE_NODE_IF_ELSE))
#define MS_NODE_IF_ELSE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MS_TYPE_NODE_IF_ELSE, MSNodeIfElseClass))
#define AS_TYPE_NODE_LOOP (as_node_loop_get_type ())
#define AS_NODE_LOOP(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), AS_TYPE_NODE_LOOP, ASNodeLoop))
#define AS_NODE_LOOP_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), AS_TYPE_NODE_LOOP, ASNodeLoopClass))
#define AS_IS_NODE_LOOP(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), AS_TYPE_NODE_LOOP))
#define AS_IS_NODE_LOOP_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), AS_TYPE_NODE_LOOP))
#define AS_NODE_LOOP_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), AS_TYPE_NODE_LOOP, ASNodeLoopClass))
#define MS_TYPE_NODE_LOOP (ms_node_loop_get_type ())
#define MS_NODE_LOOP(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), MS_TYPE_NODE_LOOP, MSNodeLoop))
#define MS_NODE_LOOP_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MS_TYPE_NODE_LOOP, MSNodeLoopClass))
#define MS_IS_NODE_LOOP(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), MS_TYPE_NODE_LOOP))
#define MS_IS_NODE_LOOP_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MS_TYPE_NODE_LOOP))
#define MS_NODE_LOOP_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MS_TYPE_NODE_LOOP, MSNodeLoopClass))
#define AS_TYPE_NODE_ASSIGN (as_node_assign_get_type ())
#define AS_NODE_ASSIGN(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), AS_TYPE_NODE_ASSIGN, ASNodeAssign))
#define AS_NODE_ASSIGN_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), AS_TYPE_NODE_ASSIGN, ASNodeAssignClass))
#define AS_IS_NODE_ASSIGN(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), AS_TYPE_NODE_ASSIGN))
#define AS_IS_NODE_ASSIGN_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), AS_TYPE_NODE_ASSIGN))
#define AS_NODE_ASSIGN_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), AS_TYPE_NODE_ASSIGN, ASNodeAssignClass))
#define MS_TYPE_NODE_ASSIGN (ms_node_assign_get_type ())
#define MS_NODE_ASSIGN(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), MS_TYPE_NODE_ASSIGN, MSNodeAssign))
#define MS_NODE_ASSIGN_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MS_TYPE_NODE_ASSIGN, MSNodeAssignClass))
#define MS_IS_NODE_ASSIGN(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), MS_TYPE_NODE_ASSIGN))
#define MS_IS_NODE_ASSIGN_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MS_TYPE_NODE_ASSIGN))
#define MS_NODE_ASSIGN_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MS_TYPE_NODE_ASSIGN, MSNodeAssignClass))
#define AS_TYPE_NODE_VALUE (as_node_value_get_type ())
#define AS_NODE_VALUE(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), AS_TYPE_NODE_VALUE, ASNodeValue))
#define AS_NODE_VALUE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), AS_TYPE_NODE_VALUE, ASNodeValueClass))
#define AS_IS_NODE_VALUE(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), AS_TYPE_NODE_VALUE))
#define AS_IS_NODE_VALUE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), AS_TYPE_NODE_VALUE))
#define AS_NODE_VALUE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), AS_TYPE_NODE_VALUE, ASNodeValueClass))
#define MS_TYPE_NODE_VALUE (ms_node_value_get_type ())
#define MS_NODE_VALUE(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), MS_TYPE_NODE_VALUE, MSNodeValue))
#define MS_NODE_VALUE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MS_TYPE_NODE_VALUE, MSNodeValueClass))
#define MS_IS_NODE_VALUE(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), MS_TYPE_NODE_VALUE))
#define MS_IS_NODE_VALUE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MS_TYPE_NODE_VALUE))
#define MS_NODE_VALUE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MS_TYPE_NODE_VALUE, MSNodeValueClass))
#define AS_TYPE_NODE_VAL_LIST (as_node_val_list_get_type ())
#define AS_NODE_VAL_LIST(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), AS_TYPE_NODE_VAL_LIST, ASNodeValList))
#define AS_NODE_VAL_LIST_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), AS_TYPE_NODE_VAL_LIST, ASNodeValListClass))
#define AS_IS_NODE_VAL_LIST(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), AS_TYPE_NODE_VAL_LIST))
#define AS_IS_NODE_VAL_LIST_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), AS_TYPE_NODE_VAL_LIST))
#define AS_NODE_VAL_LIST_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), AS_TYPE_NODE_VAL_LIST, ASNodeValListClass))
#define MS_TYPE_NODE_VAL_LIST (ms_node_val_list_get_type ())
#define MS_NODE_VAL_LIST(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), MS_TYPE_NODE_VAL_LIST, MSNodeValList))
#define MS_NODE_VAL_LIST_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MS_TYPE_NODE_VAL_LIST, MSNodeValListClass))
#define MS_IS_NODE_VAL_LIST(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), MS_TYPE_NODE_VAL_LIST))
#define MS_IS_NODE_VAL_LIST_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MS_TYPE_NODE_VAL_LIST))
#define MS_NODE_VAL_LIST_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MS_TYPE_NODE_VAL_LIST, MSNodeValListClass))
typedef struct _ASNode ASNode;
typedef struct _ASNodeClass ASNodeClass;
typedef struct _ASNodeList ASNodeList;
typedef struct _ASNodeListClass ASNodeListClass;
typedef struct _ASNodeVar ASNodeVar;
typedef struct _ASNodeVarClass ASNodeVarClass;
typedef struct _ASNodeCommand ASNodeCommand;
typedef struct _ASNodeCommandClass ASNodeCommandClass;
typedef struct _ASNodeIfElse ASNodeIfElse;
typedef struct _ASNodeIfElseClass ASNodeIfElseClass;
typedef struct _ASNodeLoop ASNodeLoop;
typedef struct _ASNodeLoopClass ASNodeLoopClass;
typedef struct _ASNodeAssign ASNodeAssign;
typedef struct _ASNodeAssignClass ASNodeAssignClass;
typedef struct _ASNodeValue ASNodeValue;
typedef struct _ASNodeValueClass ASNodeValueClass;
typedef struct _ASNodeValList ASNodeValList;
typedef struct _ASNodeValListClass ASNodeValListClass;
typedef struct _MSNode MSNode;
typedef struct _MSNodeClass MSNodeClass;
typedef struct _MSNodeList MSNodeList;
typedef struct _MSNodeListClass MSNodeListClass;
typedef struct _MSNodeVar MSNodeVar;
typedef struct _MSNodeVarClass MSNodeVarClass;
typedef struct _MSNodeCommand MSNodeCommand;
typedef struct _MSNodeCommandClass MSNodeCommandClass;
typedef struct _MSNodeIfElse MSNodeIfElse;
typedef struct _MSNodeIfElseClass MSNodeIfElseClass;
typedef struct _MSNodeLoop MSNodeLoop;
typedef struct _MSNodeLoopClass MSNodeLoopClass;
typedef struct _MSNodeAssign MSNodeAssign;
typedef struct _MSNodeAssignClass MSNodeAssignClass;
typedef struct _MSNodeValue MSNodeValue;
typedef struct _MSNodeValueClass MSNodeValueClass;
typedef struct _MSNodeValList MSNodeValList;
typedef struct _MSNodeValListClass MSNodeValListClass;
typedef ASValue* (*ASNodeEval) (ASNode *node, ASContext *ctx);
typedef MSValue* (*MSNodeEval) (MSNode *node, MSContext *ctx);
struct _ASNode {
struct _MSNode {
GObject object;
};
struct _ASNodeClass {
struct _MSNodeClass {
GObjectClass object_class;
ASNodeEval eval;
MSNodeEval eval;
};
struct _ASNodeList {
ASNode node;
ASNode **nodes;
struct _MSNodeList {
MSNode node;
MSNode **nodes;
guint n_nodes;
guint n_nodes_allocd__;
};
struct _ASNodeListClass {
ASNodeClass node_class;
struct _MSNodeListClass {
MSNodeClass node_class;
};
typedef enum {
AS_VAR_POSITIONAL,
AS_VAR_NAMED
} ASNodeVarType;
MS_VAR_POSITIONAL,
MS_VAR_NAMED
} MSNodeVarType;
struct _ASNodeVar {
ASNode node;
ASNodeVarType type;
struct _MSNodeVar {
MSNode node;
MSNodeVarType type;
union {
guint num;
char *name;
};
};
struct _ASNodeVarClass {
ASNodeClass node_class;
struct _MSNodeVarClass {
MSNodeClass node_class;
};
struct _ASNodeCommand {
ASNode node;
struct _MSNodeCommand {
MSNode node;
char *name;
ASNodeList *args;
MSNodeList *args;
};
struct _ASNodeCommandClass {
ASNodeClass node_class;
struct _MSNodeCommandClass {
MSNodeClass node_class;
};
typedef enum {
AS_LOOP_TIMES,
AS_LOOP_WHILE
} ASLoopType;
MS_LOOP_TIMES,
MS_LOOP_WHILE
} MSLoopType;
struct _ASNodeLoop {
ASNode node;
ASLoopType type;
ASNode *condition;
ASNode *what;
struct _MSNodeLoop {
MSNode node;
MSLoopType type;
MSNode *condition;
MSNode *what;
};
struct _ASNodeLoopClass {
ASNodeClass node_class;
struct _MSNodeLoopClass {
MSNodeClass node_class;
};
struct _ASNodeIfElse {
ASNode node;
ASNode *condition;
ASNode *then_;
ASNode *else_;
struct _MSNodeIfElse {
MSNode node;
MSNode *condition;
MSNode *then_;
MSNode *else_;
};
struct _ASNodeIfElseClass {
ASNodeClass node_class;
struct _MSNodeIfElseClass {
MSNodeClass node_class;
};
struct _ASNodeAssign {
ASNode node;
ASNodeVar *var;
ASNode *val;
struct _MSNodeAssign {
MSNode node;
MSNodeVar *var;
MSNode *val;
};
struct _ASNodeAssignClass {
ASNodeClass node_class;
struct _MSNodeAssignClass {
MSNodeClass node_class;
};
struct _ASNodeValue {
ASNode node;
ASValue *value;
struct _MSNodeValue {
MSNode node;
MSValue *value;
};
struct _ASNodeValueClass {
ASNodeClass node_class;
struct _MSNodeValueClass {
MSNodeClass node_class;
};
struct _ASNodeValList {
ASNode node;
ASNodeList *elms;
struct _MSNodeValList {
MSNode node;
MSNodeList *elms;
};
struct _ASNodeValListClass {
ASNodeClass node_class;
struct _MSNodeValListClass {
MSNodeClass node_class;
};
GType as_node_get_type (void) G_GNUC_CONST;
GType as_node_list_get_type (void) G_GNUC_CONST;
GType as_node_var_get_type (void) G_GNUC_CONST;
GType as_node_command_get_type (void) G_GNUC_CONST;
GType as_node_if_else_get_type (void) G_GNUC_CONST;
GType as_node_loop_get_type (void) G_GNUC_CONST;
GType as_node_assign_get_type (void) G_GNUC_CONST;
GType as_node_val_list_get_type (void) G_GNUC_CONST;
GType as_node_value_get_type (void) G_GNUC_CONST;
GType ms_node_get_type (void) G_GNUC_CONST;
GType ms_node_list_get_type (void) G_GNUC_CONST;
GType ms_node_var_get_type (void) G_GNUC_CONST;
GType ms_node_command_get_type (void) G_GNUC_CONST;
GType ms_node_if_else_get_type (void) G_GNUC_CONST;
GType ms_node_loop_get_type (void) G_GNUC_CONST;
GType ms_node_assign_get_type (void) G_GNUC_CONST;
GType ms_node_val_list_get_type (void) G_GNUC_CONST;
GType ms_node_value_get_type (void) G_GNUC_CONST;
ASValue *as_node_eval (ASNode *node,
ASContext *ctx);
MSValue *ms_node_eval (MSNode *node,
MSContext *ctx);
ASNodeList *as_node_list_new (void);
void as_node_list_add (ASNodeList *list,
ASNode *node);
MSNodeList *ms_node_list_new (void);
void ms_node_list_add (MSNodeList *list,
MSNode *node);
ASNodeCommand *as_node_command_new (const char *name,
ASNodeList *args);
ASNodeCommand *as_node_binary_op_new (ASBinaryOp op,
ASNode *lval,
ASNode *rval);
ASNodeCommand *as_node_unary_op_new (ASUnaryOp op,
ASNode *val);
MSNodeCommand *ms_node_command_new (const char *name,
MSNodeList *args);
MSNodeCommand *ms_node_binary_op_new (MSBinaryOp op,
MSNode *lval,
MSNode *rval);
MSNodeCommand *ms_node_unary_op_new (MSUnaryOp op,
MSNode *val);
ASNodeIfElse *as_node_if_else_new (ASNode *condition,
ASNode *then_,
ASNode *else_);
MSNodeIfElse *ms_node_if_else_new (MSNode *condition,
MSNode *then_,
MSNode *else_);
ASNodeLoop *as_node_loop_new (ASLoopType type,
ASNode *times_or_cond,
ASNode *what);
MSNodeLoop *ms_node_loop_new (MSLoopType type,
MSNode *times_or_cond,
MSNode *what);
ASNodeAssign *as_node_assign_new (ASNodeVar *var,
ASNode *val);
MSNodeAssign *ms_node_assign_new (MSNodeVar *var,
MSNode *val);
ASNodeValue *as_node_value_new (ASValue *value);
ASNodeValList *as_node_val_list_new (ASNodeList *list);
MSNodeValue *ms_node_value_new (MSValue *value);
MSNodeValList *ms_node_val_list_new (MSNodeList *list);
ASNodeVar *as_node_var_new_positional (guint n);
ASNodeVar *as_node_var_new_named (const char *name);
MSNodeVar *ms_node_var_new_positional (guint n);
MSNodeVar *ms_node_var_new_named (const char *name);
G_END_DECLS

View File

@ -38,14 +38,14 @@ typedef struct {
guint len;
guint ptr;
GHashTable *hash;
} ASLex;
} MSLex;
struct _ASParser {
ASLex *lex;
struct _MSParser {
MSLex *lex;
gboolean failed;
GSList *nodes;
ASNode *script;
MSNode *script;
};
@ -57,7 +57,7 @@ struct _ASParser {
static int
as_lex_error (ASParser *parser)
ms_lex_error (MSParser *parser)
{
parser->failed = TRUE;
return -1;
@ -65,7 +65,7 @@ as_lex_error (ASParser *parser)
static char *
as_lex_add_string (ASLex *lex,
ms_lex_add_string (MSLex *lex,
const char *string,
guint len)
{
@ -86,8 +86,8 @@ as_lex_add_string (ASLex *lex,
static int
as_lex_parse_string (ASLex *lex,
ASParser *parser)
ms_lex_parse_string (MSLex *lex,
MSParser *parser)
{
guint first, last;
guchar quote, second;
@ -111,7 +111,7 @@ as_lex_parse_string (ASLex *lex,
if (c == quote)
{
_as_script_yylval.str = as_lex_add_string (lex, string->str, string->len);
_ms_script_yylval.str = ms_lex_add_string (lex, string->str, string->len);
lex->ptr = last + 1;
token = LITERAL;
goto out;
@ -156,7 +156,7 @@ as_lex_parse_string (ASLex *lex,
}
g_warning ("unterminated string literal");
token = as_lex_error (parser);
token = ms_lex_error (parser);
out:
g_string_free (string, TRUE);
@ -165,8 +165,8 @@ out:
static int
as_lex_parse_number (ASLex *lex,
ASParser *parser)
ms_lex_parse_number (MSLex *lex,
MSParser *parser)
{
int value = 0;
@ -181,7 +181,7 @@ as_lex_parse_number (ASLex *lex,
if (value > 1000000)
{
g_warning ("number is too big");
return as_lex_error (parser);
return ms_lex_error (parser);
}
value = (value * 10) + (c - '0');
@ -190,23 +190,23 @@ as_lex_parse_number (ASLex *lex,
else if (IS_WORD (c))
{
g_warning ("number followed by word char");
return as_lex_error (parser);
return ms_lex_error (parser);
}
else
{
_as_script_yylval.ival = value;
_ms_script_yylval.ival = value;
return NUMBER;
}
}
g_critical ("oops");
return as_lex_error (parser);
return ms_lex_error (parser);
}
static int
as_lex_parse_word (ASLex *lex,
G_GNUC_UNUSED ASParser *parser)
ms_lex_parse_word (MSLex *lex,
G_GNUC_UNUSED MSParser *parser)
{
guint last, i;
const char *string;
@ -230,7 +230,7 @@ as_lex_parse_word (ASLex *lex,
for (last = lex->ptr + 1; last < lex->len && IS_WORD (lex->input[last]); ++last) ;
_as_script_yylval.str = as_lex_add_string (lex, string, last - lex->ptr);
_ms_script_yylval.str = ms_lex_add_string (lex, string, last - lex->ptr);
lex->ptr = last;
return IDENTIFIER;
@ -238,9 +238,9 @@ as_lex_parse_word (ASLex *lex,
int
_as_script_yylex (ASParser *parser)
_ms_script_yylex (MSParser *parser)
{
ASLex *lex = parser->lex;
MSLex *lex = parser->lex;
guchar c;
while (lex->ptr < lex->len && IS_SPACE(lex->input[lex->ptr]))
@ -254,17 +254,17 @@ _as_script_yylex (ASParser *parser)
if (c & 0x80)
{
g_warning ("got unicode character");
return as_lex_error (parser);
return ms_lex_error (parser);
}
if (IS_QUOTE (c))
return as_lex_parse_string (lex, parser);
return ms_lex_parse_string (lex, parser);
if (IS_DIGIT (c))
return as_lex_parse_number (lex, parser);
return ms_lex_parse_number (lex, parser);
if (IS_LETTER (c) || c == '_')
return as_lex_parse_word (lex, parser);
return ms_lex_parse_word (lex, parser);
lex->ptr++;
return c;
@ -272,7 +272,7 @@ _as_script_yylex (ASParser *parser)
void
_as_script_yyerror (ASParser *parser,
_ms_script_yyerror (MSParser *parser,
const char *string)
{
g_print ("error: %s\n", string);
@ -280,11 +280,11 @@ _as_script_yyerror (ASParser *parser,
}
static ASLex *
as_lex_new (const char *string,
static MSLex *
ms_lex_new (const char *string,
int len)
{
ASLex *lex = g_new0 (ASLex, 1);
MSLex *lex = g_new0 (MSLex, 1);
if (len < 0)
len = strlen (string);
@ -298,7 +298,7 @@ as_lex_new (const char *string,
static void
as_lex_free (ASLex *lex)
ms_lex_free (MSLex *lex)
{
if (lex)
{
@ -308,18 +308,18 @@ as_lex_free (ASLex *lex)
}
static ASParser *
as_parser_new (void)
static MSParser *
ms_parser_new (void)
{
ASParser *parser = g_new0 (ASParser, 1);
MSParser *parser = g_new0 (MSParser, 1);
return parser;
}
static void
as_parser_cleanup (ASParser *parser)
ms_parser_cleanup (MSParser *parser)
{
as_lex_free (parser->lex);
ms_lex_free (parser->lex);
parser->lex = NULL;
g_slist_foreach (parser->nodes, (GFunc) g_object_unref, NULL);
g_slist_free (parser->nodes);
@ -329,71 +329,71 @@ as_parser_cleanup (ASParser *parser)
static void
as_parser_free (ASParser *parser)
ms_parser_free (MSParser *parser)
{
if (parser)
{
as_parser_cleanup (parser);
ms_parser_cleanup (parser);
g_free (parser);
}
}
static ASNode *
as_parser_parse (ASParser *parser,
static MSNode *
ms_parser_parse (MSParser *parser,
const char *string,
int len)
{
as_parser_cleanup (parser);
parser->lex = as_lex_new (string, len);
ms_parser_cleanup (parser);
parser->lex = ms_lex_new (string, len);
_as_script_yyparse (parser);
_ms_script_yyparse (parser);
return parser->failed ? NULL : parser->script;
}
ASNode *
as_script_parse (const char *string)
MSNode *
ms_script_parse (const char *string)
{
ASParser *parser;
ASNode *script;
MSParser *parser;
MSNode *script;
g_return_val_if_fail (string != NULL, FALSE);
if (!string[0])
return NULL;
parser = as_parser_new ();
script = as_parser_parse (parser, string, -1);
parser = ms_parser_new ();
script = ms_parser_parse (parser, string, -1);
if (script)
g_object_ref (script);
as_parser_free (parser);
ms_parser_free (parser);
return script;
}
static void
parser_add_node (ASParser *parser,
parser_add_node (MSParser *parser,
gpointer node)
{
g_return_if_fail (AS_IS_NODE (node));
g_return_if_fail (MS_IS_NODE (node));
parser->nodes = g_slist_prepend (parser->nodes, node);
}
void
_as_parser_set_top_node (ASParser *parser,
ASNode *node)
_ms_parser_set_top_node (MSParser *parser,
MSNode *node)
{
g_assert (parser != NULL);
g_assert (parser->script == NULL);
if (!node)
{
node = (ASNode*) as_node_list_new ();
node = (MSNode*) ms_node_list_new ();
parser_add_node (parser, node);
}
@ -401,213 +401,213 @@ _as_parser_set_top_node (ASParser *parser,
}
ASNode *
_as_parser_node_list_add (ASParser *parser,
ASNodeList *list,
ASNode *node)
MSNode *
_ms_parser_node_list_add (MSParser *parser,
MSNodeList *list,
MSNode *node)
{
if (!node)
return NULL;
if (!list)
{
list = as_node_list_new ();
list = ms_node_list_new ();
parser_add_node (parser, list);
}
as_node_list_add (list, node);
return AS_NODE (list);
ms_node_list_add (list, node);
return MS_NODE (list);
}
ASNode *
_as_parser_node_command (ASParser *parser,
MSNode *
_ms_parser_node_command (MSParser *parser,
const char *name,
ASNodeList *list)
MSNodeList *list)
{
ASNodeCommand *cmd;
MSNodeCommand *cmd;
g_return_val_if_fail (name != NULL, NULL);
g_return_val_if_fail (!list || AS_IS_NODE_LIST (list), NULL);
g_return_val_if_fail (!list || MS_IS_NODE_LIST (list), NULL);
cmd = as_node_command_new (name, list);
cmd = ms_node_command_new (name, list);
parser_add_node (parser, cmd);
return AS_NODE (cmd);
return MS_NODE (cmd);
}
ASNode *
_as_parser_node_if_else (ASParser *parser,
ASNode *condition,
ASNode *then_,
ASNode *else_)
MSNode *
_ms_parser_node_if_else (MSParser *parser,
MSNode *condition,
MSNode *then_,
MSNode *else_)
{
ASNodeIfElse *node;
MSNodeIfElse *node;
g_return_val_if_fail (AS_IS_NODE (condition), NULL);
g_return_val_if_fail (AS_IS_NODE (then_), NULL);
g_return_val_if_fail (!else_ || AS_IS_NODE (else_), NULL);
g_return_val_if_fail (MS_IS_NODE (condition), NULL);
g_return_val_if_fail (MS_IS_NODE (then_), NULL);
g_return_val_if_fail (!else_ || MS_IS_NODE (else_), NULL);
node = as_node_if_else_new (condition, then_, else_);
node = ms_node_if_else_new (condition, then_, else_);
parser_add_node (parser, node);
return AS_NODE (node);
return MS_NODE (node);
}
static ASNode *
as_parser_loop (ASParser *parser,
ASLoopType type,
ASNode *times,
ASNode *what)
static MSNode *
ms_parser_loop (MSParser *parser,
MSLoopType type,
MSNode *times,
MSNode *what)
{
ASNodeLoop *loop;
MSNodeLoop *loop;
g_return_val_if_fail (AS_IS_NODE (times), NULL);
g_return_val_if_fail (AS_IS_NODE (what), NULL);
g_return_val_if_fail (MS_IS_NODE (times), NULL);
g_return_val_if_fail (MS_IS_NODE (what), NULL);
loop = as_node_loop_new (type, times, what);
loop = ms_node_loop_new (type, times, what);
parser_add_node (parser, loop);
return AS_NODE (loop);
return MS_NODE (loop);
}
ASNode *
_as_parser_node_repeat (ASParser *parser,
ASNode *times,
ASNode *what)
MSNode *
_ms_parser_node_repeat (MSParser *parser,
MSNode *times,
MSNode *what)
{
return as_parser_loop (parser, AS_LOOP_TIMES, times, what);
return ms_parser_loop (parser, MS_LOOP_TIMES, times, what);
}
ASNode *
_as_parser_node_while (ASParser *parser,
ASNode *cond,
ASNode *what)
MSNode *
_ms_parser_node_while (MSParser *parser,
MSNode *cond,
MSNode *what)
{
return as_parser_loop (parser, AS_LOOP_WHILE, cond, what);
return ms_parser_loop (parser, MS_LOOP_WHILE, cond, what);
}
ASNode *
_as_parser_node_assignment (ASParser *parser,
ASNodeVar *var,
ASNode *val)
MSNode *
_ms_parser_node_assignment (MSParser *parser,
MSNodeVar *var,
MSNode *val)
{
ASNodeAssign *node;
MSNodeAssign *node;
g_return_val_if_fail (AS_IS_NODE_VAR (var), NULL);
g_return_val_if_fail (AS_IS_NODE (val), NULL);
g_return_val_if_fail (MS_IS_NODE_VAR (var), NULL);
g_return_val_if_fail (MS_IS_NODE (val), NULL);
node = as_node_assign_new (var, val);
node = ms_node_assign_new (var, val);
parser_add_node (parser, node);
return AS_NODE (node);
return MS_NODE (node);
}
ASNode *
_as_parser_node_binary_op (ASParser *parser,
ASBinaryOp op,
ASNode *lval,
ASNode *rval)
MSNode *
_ms_parser_node_binary_op (MSParser *parser,
MSBinaryOp op,
MSNode *lval,
MSNode *rval)
{
ASNodeCommand *cmd;
MSNodeCommand *cmd;
g_return_val_if_fail (AS_IS_NODE (lval), NULL);
g_return_val_if_fail (AS_IS_NODE (rval), NULL);
g_return_val_if_fail (MS_IS_NODE (lval), NULL);
g_return_val_if_fail (MS_IS_NODE (rval), NULL);
cmd = as_node_binary_op_new (op, lval, rval);
cmd = ms_node_binary_op_new (op, lval, rval);
parser_add_node (parser, cmd);
return AS_NODE (cmd);
return MS_NODE (cmd);
}
ASNode *
_as_parser_node_unary_op (ASParser *parser,
ASUnaryOp op,
ASNode *val)
MSNode *
_ms_parser_node_unary_op (MSParser *parser,
MSUnaryOp op,
MSNode *val)
{
ASNodeCommand *cmd;
MSNodeCommand *cmd;
g_return_val_if_fail (AS_IS_NODE (val), NULL);
g_return_val_if_fail (MS_IS_NODE (val), NULL);
cmd = as_node_unary_op_new (op, val);
cmd = ms_node_unary_op_new (op, val);
parser_add_node (parser, cmd);
return AS_NODE (cmd);
return MS_NODE (cmd);
}
ASNode *
_as_parser_node_int (ASParser *parser,
MSNode *
_ms_parser_node_int (MSParser *parser,
int n)
{
ASNodeValue *node;
ASValue *value;
MSNodeValue *node;
MSValue *value;
value = as_value_int (n);
node = as_node_value_new (value);
as_value_unref (value);
value = ms_value_int (n);
node = ms_node_value_new (value);
ms_value_unref (value);
parser_add_node (parser, node);
return AS_NODE (node);
return MS_NODE (node);
}
ASNode *
_as_parser_node_string (ASParser *parser,
MSNode *
_ms_parser_node_string (MSParser *parser,
const char *string)
{
ASNodeValue *node;
ASValue *value;
MSNodeValue *node;
MSValue *value;
value = as_value_string (string);
node = as_node_value_new (value);
as_value_unref (value);
value = ms_value_string (string);
node = ms_node_value_new (value);
ms_value_unref (value);
parser_add_node (parser, node);
return AS_NODE (node);
return MS_NODE (node);
}
ASNode *
_as_parser_node_var_pos (ASParser *parser,
MSNode *
_ms_parser_node_var_pos (MSParser *parser,
int n)
{
ASNodeVar *node;
MSNodeVar *node;
node = as_node_var_new_positional (n);
node = ms_node_var_new_positional (n);
parser_add_node (parser, node);
return AS_NODE (node);
return MS_NODE (node);
}
ASNode *
_as_parser_node_var_named (ASParser *parser,
MSNode *
_ms_parser_node_var_named (MSParser *parser,
const char *name)
{
ASNodeVar *node;
MSNodeVar *node;
node = as_node_var_new_named (name);
node = ms_node_var_new_named (name);
parser_add_node (parser, node);
return AS_NODE (node);
return MS_NODE (node);
}
ASNode *
_as_parser_node_value_list (ASParser *parser,
ASNodeList *list)
MSNode *
_ms_parser_node_value_list (MSParser *parser,
MSNodeList *list)
{
ASNodeValList *node;
MSNodeValList *node;
node = as_node_val_list_new (list);
node = ms_node_val_list_new (list);
parser_add_node (parser, node);
return AS_NODE (node);
return MS_NODE (node);
}

View File

@ -22,55 +22,55 @@
G_BEGIN_DECLS
typedef struct _ASParser ASParser;
typedef struct _MSParser MSParser;
ASNode *as_script_parse (const char *string);
MSNode *ms_script_parse (const char *string);
int _as_script_yyparse (ASParser *parser);
int _as_script_yylex (ASParser *parser);
void _as_script_yyerror (ASParser *parser,
int _ms_script_yyparse (MSParser *parser);
int _ms_script_yylex (MSParser *parser);
void _ms_script_yyerror (MSParser *parser,
const char *string);
void _as_parser_set_top_node (ASParser *parser,
ASNode *node);
void _ms_parser_set_top_node (MSParser *parser,
MSNode *node);
ASNode *_as_parser_node_list_add (ASParser *parser,
ASNodeList *list,
ASNode *node);
ASNode *_as_parser_node_command (ASParser *parser,
MSNode *_ms_parser_node_list_add (MSParser *parser,
MSNodeList *list,
MSNode *node);
MSNode *_ms_parser_node_command (MSParser *parser,
const char *name,
ASNodeList *list);
ASNode *_as_parser_node_if_else (ASParser *parser,
ASNode *condition,
ASNode *then_,
ASNode *else_);
ASNode *_as_parser_node_repeat (ASParser *parser,
ASNode *times,
ASNode *what);
ASNode *_as_parser_node_while (ASParser *parser,
ASNode *times,
ASNode *what);
ASNode *_as_parser_node_assignment (ASParser *parser,
ASNodeVar *var,
ASNode *val);
ASNode *_as_parser_node_binary_op (ASParser *parser,
ASBinaryOp op,
ASNode *lval,
ASNode *rval);
ASNode *_as_parser_node_unary_op (ASParser *parser,
ASUnaryOp op,
ASNode *val);
ASNode *_as_parser_node_int (ASParser *parser,
MSNodeList *list);
MSNode *_ms_parser_node_if_else (MSParser *parser,
MSNode *condition,
MSNode *then_,
MSNode *else_);
MSNode *_ms_parser_node_repeat (MSParser *parser,
MSNode *times,
MSNode *what);
MSNode *_ms_parser_node_while (MSParser *parser,
MSNode *times,
MSNode *what);
MSNode *_ms_parser_node_assignment (MSParser *parser,
MSNodeVar *var,
MSNode *val);
MSNode *_ms_parser_node_binary_op (MSParser *parser,
MSBinaryOp op,
MSNode *lval,
MSNode *rval);
MSNode *_ms_parser_node_unary_op (MSParser *parser,
MSUnaryOp op,
MSNode *val);
MSNode *_ms_parser_node_int (MSParser *parser,
int n);
ASNode *_as_parser_node_string (ASParser *parser,
MSNode *_ms_parser_node_string (MSParser *parser,
const char *string);
ASNode *_as_parser_node_value_list (ASParser *parser,
ASNodeList *list);
ASNode *_as_parser_node_var_pos (ASParser *parser,
MSNode *_ms_parser_node_value_list (MSParser *parser,
MSNodeList *list);
MSNode *_ms_parser_node_var_pos (MSParser *parser,
int n);
ASNode *_as_parser_node_var_named (ASParser *parser,
MSNode *_ms_parser_node_var_named (MSParser *parser,
const char *name);

View File

@ -17,102 +17,102 @@
#include <string.h>
static ASValue *AS_None;
static ASValue *AS_True;
static ASValue *AS_False;
static MSValue *MS_None;
static MSValue *MS_True;
static MSValue *MS_False;
static ASValue *
as_value_new (ASValueType type)
static MSValue *
ms_value_new (MSValueType type)
{
ASValue *val = g_new0 (ASValue, 1);
MSValue *val = g_new0 (MSValue, 1);
val->ref_count = 1;
val->type = type;
return val;
}
ASValue *
as_value_none (void)
MSValue *
ms_value_none (void)
{
if (!AS_None)
return AS_None = as_value_new (AS_VALUE_NONE);
if (!MS_None)
return MS_None = ms_value_new (MS_VALUE_NONE);
else
return as_value_ref (AS_None);
return ms_value_ref (MS_None);
}
ASValue *
as_value_false (void)
MSValue *
ms_value_false (void)
{
if (!AS_False)
return AS_False = as_value_int (FALSE);
if (!MS_False)
return MS_False = ms_value_int (FALSE);
else
return as_value_ref (AS_False);
return ms_value_ref (MS_False);
}
ASValue *
as_value_true (void)
MSValue *
ms_value_true (void)
{
if (!AS_True)
return AS_True = as_value_int (TRUE);
if (!MS_True)
return MS_True = ms_value_int (TRUE);
else
return as_value_ref (AS_True);
return ms_value_ref (MS_True);
}
ASValue *
as_value_bool (gboolean val)
MSValue *
ms_value_bool (gboolean val)
{
return val ? as_value_true () : as_value_false ();
return val ? ms_value_true () : ms_value_false ();
}
ASValue *
as_value_int (int ival)
MSValue *
ms_value_int (int ival)
{
ASValue *val = as_value_new (AS_VALUE_INT);
MSValue *val = ms_value_new (MS_VALUE_INT);
val->ival = ival;
return val;
}
ASValue *
as_value_string (const char *string)
MSValue *
ms_value_string (const char *string)
{
return as_value_take_string (g_strdup (string));
return ms_value_take_string (g_strdup (string));
}
ASValue *
as_value_take_string (char *string)
MSValue *
ms_value_take_string (char *string)
{
ASValue *val;
MSValue *val;
g_return_val_if_fail (string != NULL, NULL);
val = as_value_new (AS_VALUE_STRING);
val = ms_value_new (MS_VALUE_STRING);
val->str = string;
return val;
}
ASValue *
as_value_object (gpointer object)
MSValue *
ms_value_object (gpointer object)
{
ASValue *val;
MSValue *val;
g_return_val_if_fail (G_IS_OBJECT (object), NULL);
val = as_value_new (AS_VALUE_OBJECT);
val = ms_value_new (MS_VALUE_OBJECT);
val->ptr = g_object_ref (object);
return val;
}
ASValue *
as_value_gvalue (GValue *gval)
MSValue *
ms_value_gvalue (GValue *gval)
{
ASValue *val;
MSValue *val;
g_return_val_if_fail (G_IS_VALUE (gval), NULL);
val = as_value_new (AS_VALUE_GVALUE);
val = ms_value_new (MS_VALUE_GVALUE);
val->gval = g_new (GValue, 1);
val->gval->g_type = 0;
@ -123,43 +123,43 @@ as_value_gvalue (GValue *gval)
}
ASValue *
as_value_list (guint n_elms)
MSValue *
ms_value_list (guint n_elms)
{
ASValue *val;
MSValue *val;
guint i;
val = as_value_new (AS_VALUE_LIST);
val->list.elms = g_new (ASValue*, n_elms);
val = ms_value_new (MS_VALUE_LIST);
val->list.elms = g_new (MSValue*, n_elms);
val->list.n_elms = n_elms;
for (i = 0; i < n_elms; ++i)
val->list.elms[i] = as_value_none ();
val->list.elms[i] = ms_value_none ();
return val;
}
void
as_value_list_set_elm (ASValue *list,
ms_value_list_set_elm (MSValue *list,
guint index,
ASValue *elm)
MSValue *elm)
{
g_return_if_fail (list != NULL);
g_return_if_fail (elm != NULL);
g_return_if_fail (list->type == AS_VALUE_LIST);
g_return_if_fail (list->type == MS_VALUE_LIST);
g_return_if_fail (index < list->list.n_elms);
if (list->list.elms[index] != elm)
{
as_value_unref (list->list.elms[index]);
list->list.elms[index] = as_value_ref (elm);
ms_value_unref (list->list.elms[index]);
list->list.elms[index] = ms_value_ref (elm);
}
}
ASValue *
as_value_ref (ASValue *val)
MSValue *
ms_value_ref (MSValue *val)
{
g_return_val_if_fail (val != NULL, NULL);
val->ref_count++;
@ -168,7 +168,7 @@ as_value_ref (ASValue *val)
void
as_value_unref (ASValue *val)
ms_value_unref (MSValue *val)
{
guint i;
@ -179,34 +179,34 @@ as_value_unref (ASValue *val)
switch (val->type)
{
case AS_VALUE_STRING:
case MS_VALUE_STRING:
g_free (val->str);
break;
case AS_VALUE_NONE:
if (val == AS_None)
AS_None = NULL;
case MS_VALUE_NONE:
if (val == MS_None)
MS_None = NULL;
break;
case AS_VALUE_INT:
if (val == AS_False)
AS_False = NULL;
else if (val == AS_True)
AS_True = NULL;
case MS_VALUE_INT:
if (val == MS_False)
MS_False = NULL;
else if (val == MS_True)
MS_True = NULL;
break;
case AS_VALUE_OBJECT:
case MS_VALUE_OBJECT:
g_object_unref (val->ptr);
break;
case AS_VALUE_GVALUE:
case MS_VALUE_GVALUE:
g_value_unset (val->gval);
g_free (val->gval);
break;
case AS_VALUE_LIST:
case MS_VALUE_LIST:
for (i = 0; i < val->list.n_elms; ++i)
as_value_unref (val->list.elms[i]);
ms_value_unref (val->list.elms[i]);
g_free (val->list.elms);
break;
}
@ -216,48 +216,48 @@ as_value_unref (ASValue *val)
const char *
as_binary_op_name (ASBinaryOp op)
ms_binary_op_name (MSBinaryOp op)
{
static const char *names[AS_BINARY_OP_LAST] = {
static const char *names[MS_BINARY_OP_LMST] = {
"@PLUS", "@MINUS", "@MULT", "@DIV", "@AND", "@OR",
"@EQ", "@NEQ", "@LT", "@GT", "@LE", "@GE", "@FORMAT"
};
g_return_val_if_fail (op < AS_BINARY_OP_LAST, NULL);
g_return_val_if_fail (op < MS_BINARY_OP_LMST, NULL);
return names[op];
}
const char *
as_unary_op_name (ASUnaryOp op)
ms_unary_op_name (MSUnaryOp op)
{
static const char *names[AS_UNARY_OP_LAST] = {
static const char *names[MS_UNARY_OP_LMST] = {
"@UMINUS", "@NOT", "@LEN"
};
g_return_val_if_fail (op < AS_UNARY_OP_LAST, NULL);
g_return_val_if_fail (op < MS_UNARY_OP_LMST, NULL);
return names[op];
}
gboolean
as_value_get_bool (ASValue *val)
ms_value_get_bool (MSValue *val)
{
g_return_val_if_fail (val != NULL, FALSE);
switch (val->type)
{
case AS_VALUE_STRING:
case MS_VALUE_STRING:
return val->str[0] != 0;
case AS_VALUE_INT:
case MS_VALUE_INT:
return val->ival != 0;
case AS_VALUE_NONE:
case MS_VALUE_NONE:
return FALSE;
case AS_VALUE_OBJECT:
case MS_VALUE_OBJECT:
return val->ptr != NULL;
case AS_VALUE_LIST:
case MS_VALUE_LIST:
return val->list.n_elms != 0;
case AS_VALUE_GVALUE:
case MS_VALUE_GVALUE:
switch (G_TYPE_FUNDAMENTAL (G_VALUE_TYPE (val->gval)))
{
case G_TYPE_NONE:
@ -307,7 +307,7 @@ as_value_get_bool (ASValue *val)
gboolean
as_value_get_int (ASValue *val,
ms_value_get_int (MSValue *val,
int *ival)
{
g_return_val_if_fail (val != NULL, FALSE);
@ -315,15 +315,15 @@ as_value_get_int (ASValue *val,
switch (val->type)
{
case AS_VALUE_INT:
case MS_VALUE_INT:
*ival = val->ival;
return TRUE;
case AS_VALUE_NONE:
case MS_VALUE_NONE:
*ival = 0;
return TRUE;
case AS_VALUE_GVALUE:
case MS_VALUE_GVALUE:
switch (G_TYPE_FUNDAMENTAL (G_VALUE_TYPE (val->gval)))
{
case G_TYPE_NONE:
@ -376,7 +376,7 @@ as_value_get_int (ASValue *val,
static char *
print_list (ASValue **elms,
print_list (MSValue **elms,
guint n_elms)
{
guint i;
@ -389,7 +389,7 @@ print_list (ASValue **elms,
char *s;
if (i)
g_string_append (string, ", ");
s = as_value_print (elms[i]);
s = ms_value_print (elms[i]);
g_string_append (string, s);
g_free (s);
}
@ -400,23 +400,23 @@ print_list (ASValue **elms,
char *
as_value_print (ASValue *val)
ms_value_print (MSValue *val)
{
g_return_val_if_fail (val != NULL, NULL);
switch (val->type)
{
case AS_VALUE_STRING:
case MS_VALUE_STRING:
return g_strdup (val->str);
case AS_VALUE_INT:
case MS_VALUE_INT:
return g_strdup_printf ("%d", val->ival);
case AS_VALUE_NONE:
case MS_VALUE_NONE:
return g_strdup ("None");
case AS_VALUE_OBJECT:
case MS_VALUE_OBJECT:
return g_strdup_printf ("Object %p", val->ptr);
case AS_VALUE_LIST:
case MS_VALUE_LIST:
return print_list (val->list.elms, val->list.n_elms);
case AS_VALUE_GVALUE:
case MS_VALUE_GVALUE:
switch (G_TYPE_FUNDAMENTAL (G_VALUE_TYPE (val->gval)))
{
case G_TYPE_NONE:
@ -465,46 +465,46 @@ as_value_print (ASValue *val)
}
static ASValue *
func_plus (ASValue *a, ASValue *b, ASContext *ctx)
static MSValue *
func_plus (MSValue *a, MSValue *b, MSContext *ctx)
{
if (a->type == AS_VALUE_INT && b->type == AS_VALUE_INT)
return as_value_int (a->ival + b->ival);
else if (a->type == AS_VALUE_STRING && b->type == AS_VALUE_STRING)
return as_value_take_string (g_strdup_printf ("%s%s", a->str, b->str));
if (a->type == MS_VALUE_INT && b->type == MS_VALUE_INT)
return ms_value_int (a->ival + b->ival);
else if (a->type == MS_VALUE_STRING && b->type == MS_VALUE_STRING)
return ms_value_take_string (g_strdup_printf ("%s%s", a->str, b->str));
return as_context_set_error (ctx, AS_ERROR_TYPE,
return ms_context_set_error (ctx, MS_ERROR_TYPE,
"invalid PLUS");
}
static ASValue *
func_minus (ASValue *a, ASValue *b, ASContext *ctx)
static MSValue *
func_minus (MSValue *a, MSValue *b, MSContext *ctx)
{
if (a->type == AS_VALUE_INT && b->type == AS_VALUE_INT)
return as_value_int (a->ival - b->ival);
return as_context_set_error (ctx, AS_ERROR_TYPE,
if (a->type == MS_VALUE_INT && b->type == MS_VALUE_INT)
return ms_value_int (a->ival - b->ival);
return ms_context_set_error (ctx, MS_ERROR_TYPE,
"invalid MINUS");
}
static ASValue *
func_mult (ASValue *a, ASValue *b, ASContext *ctx)
static MSValue *
func_mult (MSValue *a, MSValue *b, MSContext *ctx)
{
if (a->type == AS_VALUE_INT && b->type == AS_VALUE_INT)
return as_value_int (a->ival * b->ival);
if (a->type == MS_VALUE_INT && b->type == MS_VALUE_INT)
return ms_value_int (a->ival * b->ival);
if (a->type == AS_VALUE_STRING && b->type == AS_VALUE_INT)
if (a->type == MS_VALUE_STRING && b->type == MS_VALUE_INT)
{
char *s;
guint len;
int i;
if (b->ival < 0)
return as_context_set_error (ctx, AS_ERROR_TYPE,
return ms_context_set_error (ctx, MS_ERROR_TYPE,
"string * negative int");
if (b->ival == 0)
return as_value_string ("");
return ms_value_string ("");
len = strlen (a->str);
s = g_new (char, len * b->ival + 1);
@ -513,55 +513,55 @@ func_mult (ASValue *a, ASValue *b, ASContext *ctx)
for (i = 0; i < b->ival; ++i)
memcpy (&s[i*len], a->str, len);
return as_value_take_string (s);
return ms_value_take_string (s);
}
return as_context_set_error (ctx, AS_ERROR_TYPE,
return ms_context_set_error (ctx, MS_ERROR_TYPE,
"invalid MULT");
}
static ASValue *
func_div (ASValue *a, ASValue *b, ASContext *ctx)
static MSValue *
func_div (MSValue *a, MSValue *b, MSContext *ctx)
{
if (a->type == AS_VALUE_INT && b->type == AS_VALUE_INT)
if (a->type == MS_VALUE_INT && b->type == MS_VALUE_INT)
{
if (b->ival)
return as_value_int (a->ival / b->ival);
return ms_value_int (a->ival / b->ival);
else
return as_context_set_error (ctx, AS_ERROR_VALUE,
return ms_context_set_error (ctx, MS_ERROR_VALUE,
"division by zero");
}
return as_context_set_error (ctx, AS_ERROR_TYPE,
return ms_context_set_error (ctx, MS_ERROR_TYPE,
"invalid DIV");
}
static ASValue *
func_and (ASValue *a, ASValue *b)
static MSValue *
func_and (MSValue *a, MSValue *b)
{
if (as_value_get_bool (a) && as_value_get_bool (b))
return as_value_ref (b);
if (ms_value_get_bool (a) && ms_value_get_bool (b))
return ms_value_ref (b);
else
return as_value_false ();
return ms_value_false ();
}
static ASValue *
func_or (ASValue *a, ASValue *b)
static MSValue *
func_or (MSValue *a, MSValue *b)
{
if (as_value_get_bool (a))
return as_value_ref (a);
else if (as_value_get_bool (b))
return as_value_ref (b);
if (ms_value_get_bool (a))
return ms_value_ref (a);
else if (ms_value_get_bool (b))
return ms_value_ref (b);
else
return as_value_false ();
return ms_value_false ();
}
static gboolean
list_equal (ASValue *a, ASValue *b)
list_equal (MSValue *a, MSValue *b)
{
guint i;
@ -569,7 +569,7 @@ list_equal (ASValue *a, ASValue *b)
return FALSE;
for (i = 0; i < a->list.n_elms; ++i)
if (!as_value_equal (a->list.elms[i], b->list.elms[i]))
if (!ms_value_equal (a->list.elms[i], b->list.elms[i]))
return FALSE;
return TRUE;
@ -577,7 +577,7 @@ list_equal (ASValue *a, ASValue *b)
gboolean
as_value_equal (ASValue *a, ASValue *b)
ms_value_equal (MSValue *a, MSValue *b)
{
if (a == b)
return TRUE;
@ -587,17 +587,17 @@ as_value_equal (ASValue *a, ASValue *b)
switch (a->type)
{
case AS_VALUE_INT:
case MS_VALUE_INT:
return a->ival == b->ival;
case AS_VALUE_NONE:
case MS_VALUE_NONE:
return TRUE;
case AS_VALUE_STRING:
case MS_VALUE_STRING:
return !strcmp (a->str, b->str);
case AS_VALUE_OBJECT:
case MS_VALUE_OBJECT:
return a->ptr == b->ptr;
case AS_VALUE_LIST:
case MS_VALUE_LIST:
return list_equal (a, b);
case AS_VALUE_GVALUE:
case MS_VALUE_GVALUE:
g_return_val_if_reached (FALSE);
}
@ -608,13 +608,13 @@ as_value_equal (ASValue *a, ASValue *b)
#define CMP(a, b) ((a) < (b) ? -1 : ((a) > (b) ? 1 : 0))
static int
list_cmp (ASValue *a, ASValue *b)
list_cmp (MSValue *a, MSValue *b)
{
guint i;
for (i = 0; i < a->list.n_elms && i < b->list.n_elms; ++i)
{
int c = as_value_cmp (a->list.elms[i], b->list.elms[i]);
int c = ms_value_cmp (a->list.elms[i], b->list.elms[i]);
if (c)
return c;
@ -625,7 +625,7 @@ list_cmp (ASValue *a, ASValue *b)
int
as_value_cmp (ASValue *a, ASValue *b)
ms_value_cmp (MSValue *a, MSValue *b)
{
if (a == b)
return 0;
@ -635,17 +635,17 @@ as_value_cmp (ASValue *a, ASValue *b)
switch (a->type)
{
case AS_VALUE_INT:
case MS_VALUE_INT:
return CMP (a->ival, b->ival);
case AS_VALUE_NONE:
case MS_VALUE_NONE:
return 0;
case AS_VALUE_STRING:
case MS_VALUE_STRING:
return strcmp (a->str, b->str);
case AS_VALUE_OBJECT:
case MS_VALUE_OBJECT:
return CMP (a->ptr, b->ptr);
case AS_VALUE_LIST:
case MS_VALUE_LIST:
return list_cmp (a, b);
case AS_VALUE_GVALUE:
case MS_VALUE_GVALUE:
g_return_val_if_reached (CMP (a, b));
}
@ -653,85 +653,85 @@ as_value_cmp (ASValue *a, ASValue *b)
}
static ASValue *
func_eq (ASValue *a, ASValue *b)
static MSValue *
func_eq (MSValue *a, MSValue *b)
{
return as_value_bool (as_value_equal (a, b));
return ms_value_bool (ms_value_equal (a, b));
}
static ASValue *
func_neq (ASValue *a, ASValue *b)
static MSValue *
func_neq (MSValue *a, MSValue *b)
{
return as_value_bool (!as_value_equal (a, b));
return ms_value_bool (!ms_value_equal (a, b));
}
static ASValue *
func_lt (ASValue *a, ASValue *b)
static MSValue *
func_lt (MSValue *a, MSValue *b)
{
return as_value_bool (as_value_cmp (a, b) < 0);
return ms_value_bool (ms_value_cmp (a, b) < 0);
}
static ASValue *
func_gt (ASValue *a, ASValue *b)
static MSValue *
func_gt (MSValue *a, MSValue *b)
{
return as_value_bool (as_value_cmp (a, b) > 0);
return ms_value_bool (ms_value_cmp (a, b) > 0);
}
static ASValue *
func_le (ASValue *a, ASValue *b)
static MSValue *
func_le (MSValue *a, MSValue *b)
{
return as_value_bool (as_value_cmp (a, b) <= 0);
return ms_value_bool (ms_value_cmp (a, b) <= 0);
}
static ASValue *
func_ge (ASValue *a, ASValue *b)
static MSValue *
func_ge (MSValue *a, MSValue *b)
{
return as_value_bool (as_value_cmp (a, b) >= 0);
return ms_value_bool (ms_value_cmp (a, b) >= 0);
}
static char *
format_value (char format,
ASValue *value,
ASContext *ctx)
MSValue *value,
MSContext *ctx)
{
int ival;
switch (format)
{
case 's':
return as_value_print (value);
return ms_value_print (value);
case 'd':
if (!as_value_get_int (value, &ival))
if (!ms_value_get_int (value, &ival))
{
as_context_set_error (ctx, AS_ERROR_TYPE, NULL);
ms_context_set_error (ctx, MS_ERROR_TYPE, NULL);
return NULL;
}
return g_strdup_printf ("%d", ival);
default:
as_context_set_error (ctx, AS_ERROR_VALUE, "invalid format");
ms_context_set_error (ctx, MS_ERROR_VALUE, "invalid format");
return NULL;
}
}
static ASValue *
func_format (ASValue *format, ASValue *tuple, ASContext *ctx)
static MSValue *
func_format (MSValue *format, MSValue *tuple, MSContext *ctx)
{
GString *ret;
guint n_items, items_written;
char *str, *p, *s;
ASValue *val;
MSValue *val;
if (format->type != AS_VALUE_STRING)
return as_context_set_error (ctx, AS_ERROR_TYPE, "invalid '%'");
if (format->type != MS_VALUE_STRING)
return ms_context_set_error (ctx, MS_ERROR_TYPE, "invalid '%'");
if (tuple->type == AS_VALUE_LIST)
if (tuple->type == MS_VALUE_LIST)
n_items = tuple->list.n_elms;
else
n_items = 1;
@ -759,13 +759,13 @@ func_format (ASValue *format, ASValue *tuple, ASContext *ctx)
case 'd':
if (items_written == n_items)
{
as_context_set_error (ctx, AS_ERROR_VALUE,
ms_context_set_error (ctx, MS_ERROR_VALUE,
"invalid conversion");
g_string_free (ret, TRUE);
return NULL;
}
if (tuple->type == AS_VALUE_LIST)
if (tuple->type == MS_VALUE_LIST)
val = tuple->list.elms[items_written];
else
val = tuple;
@ -786,7 +786,7 @@ func_format (ASValue *format, ASValue *tuple, ASContext *ctx)
break;
default:
as_context_set_error (ctx, AS_ERROR_VALUE,
ms_context_set_error (ctx, MS_ERROR_VALUE,
"invalid conversion");
g_string_free (ret, TRUE);
return NULL;
@ -801,66 +801,66 @@ func_format (ASValue *format, ASValue *tuple, ASContext *ctx)
if (str < p)
g_string_append (ret, str);
return as_value_take_string (g_string_free (ret, FALSE));
return ms_value_take_string (g_string_free (ret, FALSE));
}
gpointer
as_binary_op_cfunc (ASBinaryOp op)
ms_binary_op_cfunc (MSBinaryOp op)
{
static gpointer funcs[AS_BINARY_OP_LAST] = {
static gpointer funcs[MS_BINARY_OP_LMST] = {
func_plus, func_minus, func_mult, func_div,
func_and, func_or,
func_eq, func_neq, func_lt, func_gt, func_le, func_ge,
func_format
};
g_return_val_if_fail (op < AS_BINARY_OP_LAST, NULL);
g_return_val_if_fail (op < MS_BINARY_OP_LMST, NULL);
return funcs[op];
}
static ASValue *
func_uminus (ASValue *val,
ASContext *ctx)
static MSValue *
func_uminus (MSValue *val,
MSContext *ctx)
{
if (val->type == AS_VALUE_INT)
return as_value_int (-val->ival);
return as_context_set_error (ctx, AS_ERROR_TYPE, NULL);
if (val->type == MS_VALUE_INT)
return ms_value_int (-val->ival);
return ms_context_set_error (ctx, MS_ERROR_TYPE, NULL);
}
static ASValue *
func_not (ASValue *val)
static MSValue *
func_not (MSValue *val)
{
return !as_value_get_bool (val) ?
as_value_true () : as_value_false ();
return !ms_value_get_bool (val) ?
ms_value_true () : ms_value_false ();
}
static ASValue *
func_len (ASValue *val,
ASContext *ctx)
static MSValue *
func_len (MSValue *val,
MSContext *ctx)
{
switch (val->type)
{
case AS_VALUE_STRING:
return as_value_int (strlen (val->str));
case AS_VALUE_LIST:
return as_value_int (val->list.n_elms);
case MS_VALUE_STRING:
return ms_value_int (strlen (val->str));
case MS_VALUE_LIST:
return ms_value_int (val->list.n_elms);
default:
return as_context_set_error (ctx, AS_ERROR_TYPE, NULL);
return ms_context_set_error (ctx, MS_ERROR_TYPE, NULL);
}
}
gpointer
as_unary_op_cfunc (ASUnaryOp op)
ms_unary_op_cfunc (MSUnaryOp op)
{
static gpointer funcs[AS_UNARY_OP_LAST] = {
static gpointer funcs[MS_UNARY_OP_LMST] = {
func_uminus, func_not, func_len
};
g_return_val_if_fail (op < AS_UNARY_OP_LAST, NULL);
g_return_val_if_fail (op < MS_UNARY_OP_LMST, NULL);
return funcs[op];
}

View File

@ -20,90 +20,90 @@
G_BEGIN_DECLS
typedef struct _ASValue ASValue;
typedef struct _MSValue MSValue;
typedef enum {
AS_VALUE_NONE,
AS_VALUE_INT,
AS_VALUE_STRING,
AS_VALUE_OBJECT,
AS_VALUE_GVALUE,
AS_VALUE_LIST
} ASValueType;
MS_VALUE_NONE,
MS_VALUE_INT,
MS_VALUE_STRING,
MS_VALUE_OBJECT,
MS_VALUE_GVALUE,
MS_VALUE_LIST
} MSValueType;
typedef enum {
AS_OP_PLUS,
AS_OP_MINUS,
AS_OP_MULT,
AS_OP_DIV,
AS_OP_AND,
AS_OP_OR,
AS_OP_EQ,
AS_OP_NEQ,
AS_OP_LT,
AS_OP_GT,
AS_OP_LE,
AS_OP_GE,
AS_OP_FORMAT,
AS_BINARY_OP_LAST
} ASBinaryOp;
MS_OP_PLUS,
MS_OP_MINUS,
MS_OP_MULT,
MS_OP_DIV,
MS_OP_AND,
MS_OP_OR,
MS_OP_EQ,
MS_OP_NEQ,
MS_OP_LT,
MS_OP_GT,
MS_OP_LE,
MS_OP_GE,
MS_OP_FORMAT,
MS_BINARY_OP_LMST
} MSBinaryOp;
typedef enum {
AS_OP_UMINUS,
AS_OP_NOT,
AS_OP_LEN,
AS_UNARY_OP_LAST
} ASUnaryOp;
MS_OP_UMINUS,
MS_OP_NOT,
MS_OP_LEN,
MS_UNARY_OP_LMST
} MSUnaryOp;
struct _ASValue {
struct _MSValue {
guint ref_count;
ASValueType type;
MSValueType type;
union {
int ival;
char *str;
gpointer ptr;
GValue *gval;
struct {
ASValue **elms;
MSValue **elms;
guint n_elms;
} list;
};
};
const char *as_binary_op_name (ASBinaryOp op);
gpointer as_binary_op_cfunc (ASBinaryOp op);
const char *as_unary_op_name (ASUnaryOp op);
gpointer as_unary_op_cfunc (ASUnaryOp op);
const char *ms_binary_op_name (MSBinaryOp op);
gpointer ms_binary_op_cfunc (MSBinaryOp op);
const char *ms_unary_op_name (MSUnaryOp op);
gpointer ms_unary_op_cfunc (MSUnaryOp op);
ASValue *as_value_none (void);
ASValue *as_value_false (void);
ASValue *as_value_true (void);
ASValue *as_value_bool (gboolean val);
MSValue *ms_value_none (void);
MSValue *ms_value_false (void);
MSValue *ms_value_true (void);
MSValue *ms_value_bool (gboolean val);
ASValue *as_value_int (int val);
ASValue *as_value_string (const char *string);
ASValue *as_value_take_string (char *string);
ASValue *as_value_object (gpointer object);
ASValue *as_value_gvalue (GValue *gval);
MSValue *ms_value_int (int val);
MSValue *ms_value_string (const char *string);
MSValue *ms_value_take_string (char *string);
MSValue *ms_value_object (gpointer object);
MSValue *ms_value_gvalue (GValue *gval);
ASValue *as_value_list (guint n_elms);
void as_value_list_set_elm (ASValue *list,
MSValue *ms_value_list (guint n_elms);
void ms_value_list_set_elm (MSValue *list,
guint index,
ASValue *elm);
MSValue *elm);
ASValue *as_value_ref (ASValue *val);
void as_value_unref (ASValue *val);
MSValue *ms_value_ref (MSValue *val);
void ms_value_unref (MSValue *val);
gboolean as_value_get_bool (ASValue *val);
gboolean as_value_get_int (ASValue *val,
gboolean ms_value_get_bool (MSValue *val);
gboolean ms_value_get_int (MSValue *val,
int *ival);
char *as_value_print (ASValue *val);
char *ms_value_print (MSValue *val);
gboolean as_value_equal (ASValue *a,
ASValue *b);
int as_value_cmp (ASValue *a,
ASValue *b);
gboolean ms_value_equal (MSValue *a,
MSValue *b);
int ms_value_cmp (MSValue *a,
MSValue *b);
G_END_DECLS

View File

@ -49,13 +49,13 @@
#define YYLSP_NEEDED 0
/* Substitute the variable and function names. */
#define yyparse _as_script_yyparse
#define yylex _as_script_yylex
#define yyerror _as_script_yyerror
#define yylval _as_script_yylval
#define yychar _as_script_yychar
#define yydebug _as_script_yydebug
#define yynerrs _as_script_yynerrs
#define yyparse _ms_script_yyparse
#define yylex _ms_script_yylex
#define yyerror _ms_script_yyerror
#define yylval _ms_script_yylval
#define yychar _ms_script_yychar
#define yydebug _ms_script_yydebug
#define yynerrs _ms_script_yynerrs
/* Tokens. */
@ -113,21 +113,21 @@
#include "mooscript-parser.h"
#include "mooscript-yacc.h"
#define NODE_LIST_ADD(list, node) _as_parser_node_list_add (parser, AS_NODE_LIST (list), node)
#define NODE_COMMAND(id, node) _as_parser_node_command (parser, id, AS_NODE_LIST (node))
#define NODE_IF_ELSE(cond, then_, else_) _as_parser_node_if_else (parser, cond, then_, else_)
#define NODE_REPEAT(times, what) _as_parser_node_repeat (parser, times, what)
#define NODE_WHILE(cond, what) _as_parser_node_while (parser, cond, what)
#define NODE_ASSIGNMENT(var, val) _as_parser_node_assignment (parser, AS_NODE_VAR (var), val)
#define BINARY_OP(op, lval, rval) _as_parser_node_binary_op (parser, op, lval, rval)
#define UNARY_OP(op, val) _as_parser_node_unary_op (parser, op, val)
#define NODE_NUMBER(n) _as_parser_node_int (parser, n)
#define NODE_STRING(n) _as_parser_node_string (parser, n)
#define NODE_VALUE_LIST(list) _as_parser_node_value_list (parser, AS_NODE_LIST (list))
#define VAR_POSITIONAL(n) _as_parser_node_var_pos (parser, n)
#define VAR_NAMED(string) _as_parser_node_var_named (parser, string)
#define NODE_LIST_ADD(list, node) _ms_parser_node_list_add (parser, MS_NODE_LIST (list), node)
#define NODE_COMMAND(id, node) _ms_parser_node_command (parser, id, MS_NODE_LIST (node))
#define NODE_IF_ELSE(cond, then_, else_) _ms_parser_node_if_else (parser, cond, then_, else_)
#define NODE_REPEAT(times, what) _ms_parser_node_repeat (parser, times, what)
#define NODE_WHILE(cond, what) _ms_parser_node_while (parser, cond, what)
#define NODE_MSSIGNMENT(var, val) _ms_parser_node_assignment (parser, MS_NODE_VAR (var), val)
#define BINARY_OP(op, lval, rval) _ms_parser_node_binary_op (parser, op, lval, rval)
#define UNARY_OP(op, val) _ms_parser_node_unary_op (parser, op, val)
#define NODE_NUMBER(n) _ms_parser_node_int (parser, n)
#define NODE_STRING(n) _ms_parser_node_string (parser, n)
#define NODE_VALUE_LIST(list) _ms_parser_node_value_list (parser, MS_NODE_LIST (list))
#define VAR_POSITIONAL(n) _ms_parser_node_var_pos (parser, n)
#define VAR_NAMED(string) _ms_parser_node_var_named (parser, string)
#define SET_TOP_NODE(node) _as_parser_set_top_node (parser, node)
#define SET_TOP_NODE(node) _ms_parser_set_top_node (parser, node)
/* Enabling traces. */
@ -153,7 +153,7 @@
typedef union YYSTYPE {
int ival;
const char *str;
ASNode *node;
MSNode *node;
} YYSTYPE;
/* Line 196 of yacc.c. */
#line 160 "/home/muntyan/projects/moo/moo/mooutils/mooscript/mooscript-yacc.c"
@ -992,7 +992,7 @@ int yyparse ();
# endif
#else /* ! YYPARSE_PARAM */
#if defined (__STDC__) || defined (__cplusplus)
int yyparse (ASParser *parser);
int yyparse (MSParser *parser);
#else
int yyparse ();
#endif
@ -1025,11 +1025,11 @@ int yyparse (YYPARSE_PARAM)
#else /* ! YYPARSE_PARAM */
#if defined (__STDC__) || defined (__cplusplus)
int
yyparse (ASParser *parser)
yyparse (MSParser *parser)
#else
int
yyparse (parser)
ASParser *parser;
MSParser *parser;
#endif
#endif
{
@ -1352,67 +1352,67 @@ yyreduce:
case 26:
#line 106 "/home/muntyan/projects/moo/moo/mooutils/mooscript/mooscript-yacc.y"
{ (yyval.node) = NODE_ASSIGNMENT ((yyvsp[-2].node), (yyvsp[0].node)); ;}
{ (yyval.node) = NODE_MSSIGNMENT ((yyvsp[-2].node), (yyvsp[0].node)); ;}
break;
case 28:
#line 110 "/home/muntyan/projects/moo/moo/mooutils/mooscript/mooscript-yacc.y"
{ (yyval.node) = BINARY_OP (AS_OP_PLUS, (yyvsp[-2].node), (yyvsp[0].node)); ;}
{ (yyval.node) = BINARY_OP (MS_OP_PLUS, (yyvsp[-2].node), (yyvsp[0].node)); ;}
break;
case 29:
#line 111 "/home/muntyan/projects/moo/moo/mooutils/mooscript/mooscript-yacc.y"
{ (yyval.node) = BINARY_OP (AS_OP_MINUS, (yyvsp[-2].node), (yyvsp[0].node)); ;}
{ (yyval.node) = BINARY_OP (MS_OP_MINUS, (yyvsp[-2].node), (yyvsp[0].node)); ;}
break;
case 30:
#line 112 "/home/muntyan/projects/moo/moo/mooutils/mooscript/mooscript-yacc.y"
{ (yyval.node) = BINARY_OP (AS_OP_DIV, (yyvsp[-2].node), (yyvsp[0].node)); ;}
{ (yyval.node) = BINARY_OP (MS_OP_DIV, (yyvsp[-2].node), (yyvsp[0].node)); ;}
break;
case 31:
#line 113 "/home/muntyan/projects/moo/moo/mooutils/mooscript/mooscript-yacc.y"
{ (yyval.node) = BINARY_OP (AS_OP_MULT, (yyvsp[-2].node), (yyvsp[0].node)); ;}
{ (yyval.node) = BINARY_OP (MS_OP_MULT, (yyvsp[-2].node), (yyvsp[0].node)); ;}
break;
case 32:
#line 115 "/home/muntyan/projects/moo/moo/mooutils/mooscript/mooscript-yacc.y"
{ (yyval.node) = BINARY_OP (AS_OP_AND, (yyvsp[-2].node), (yyvsp[0].node)); ;}
{ (yyval.node) = BINARY_OP (MS_OP_AND, (yyvsp[-2].node), (yyvsp[0].node)); ;}
break;
case 33:
#line 116 "/home/muntyan/projects/moo/moo/mooutils/mooscript/mooscript-yacc.y"
{ (yyval.node) = BINARY_OP (AS_OP_OR, (yyvsp[-2].node), (yyvsp[0].node)); ;}
{ (yyval.node) = BINARY_OP (MS_OP_OR, (yyvsp[-2].node), (yyvsp[0].node)); ;}
break;
case 34:
#line 118 "/home/muntyan/projects/moo/moo/mooutils/mooscript/mooscript-yacc.y"
{ (yyval.node) = BINARY_OP (AS_OP_EQ, (yyvsp[-2].node), (yyvsp[0].node)); ;}
{ (yyval.node) = BINARY_OP (MS_OP_EQ, (yyvsp[-2].node), (yyvsp[0].node)); ;}
break;
case 35:
#line 119 "/home/muntyan/projects/moo/moo/mooutils/mooscript/mooscript-yacc.y"
{ (yyval.node) = BINARY_OP (AS_OP_NEQ, (yyvsp[-2].node), (yyvsp[0].node)); ;}
{ (yyval.node) = BINARY_OP (MS_OP_NEQ, (yyvsp[-2].node), (yyvsp[0].node)); ;}
break;
case 36:
#line 120 "/home/muntyan/projects/moo/moo/mooutils/mooscript/mooscript-yacc.y"
{ (yyval.node) = BINARY_OP (AS_OP_LT, (yyvsp[-2].node), (yyvsp[0].node)); ;}
{ (yyval.node) = BINARY_OP (MS_OP_LT, (yyvsp[-2].node), (yyvsp[0].node)); ;}
break;
case 37:
#line 121 "/home/muntyan/projects/moo/moo/mooutils/mooscript/mooscript-yacc.y"
{ (yyval.node) = BINARY_OP (AS_OP_GT, (yyvsp[-2].node), (yyvsp[0].node)); ;}
{ (yyval.node) = BINARY_OP (MS_OP_GT, (yyvsp[-2].node), (yyvsp[0].node)); ;}
break;
case 38:
#line 122 "/home/muntyan/projects/moo/moo/mooutils/mooscript/mooscript-yacc.y"
{ (yyval.node) = BINARY_OP (AS_OP_LE, (yyvsp[-2].node), (yyvsp[0].node)); ;}
{ (yyval.node) = BINARY_OP (MS_OP_LE, (yyvsp[-2].node), (yyvsp[0].node)); ;}
break;
case 39:
#line 123 "/home/muntyan/projects/moo/moo/mooutils/mooscript/mooscript-yacc.y"
{ (yyval.node) = BINARY_OP (AS_OP_GE, (yyvsp[-2].node), (yyvsp[0].node)); ;}
{ (yyval.node) = BINARY_OP (MS_OP_GE, (yyvsp[-2].node), (yyvsp[0].node)); ;}
break;
case 40:
@ -1437,22 +1437,22 @@ yyreduce:
case 45:
#line 132 "/home/muntyan/projects/moo/moo/mooutils/mooscript/mooscript-yacc.y"
{ (yyval.node) = BINARY_OP (AS_OP_FORMAT, (yyvsp[-2].node), (yyvsp[0].node)); ;}
{ (yyval.node) = BINARY_OP (MS_OP_FORMAT, (yyvsp[-2].node), (yyvsp[0].node)); ;}
break;
case 46:
#line 133 "/home/muntyan/projects/moo/moo/mooutils/mooscript/mooscript-yacc.y"
{ (yyval.node) = UNARY_OP (AS_OP_LEN, (yyvsp[0].node)); ;}
{ (yyval.node) = UNARY_OP (MS_OP_LEN, (yyvsp[0].node)); ;}
break;
case 47:
#line 134 "/home/muntyan/projects/moo/moo/mooutils/mooscript/mooscript-yacc.y"
{ (yyval.node) = UNARY_OP (AS_OP_NOT, (yyvsp[0].node)); ;}
{ (yyval.node) = UNARY_OP (MS_OP_NOT, (yyvsp[0].node)); ;}
break;
case 48:
#line 135 "/home/muntyan/projects/moo/moo/mooutils/mooscript/mooscript-yacc.y"
{ (yyval.node) = UNARY_OP (AS_OP_UMINUS, (yyvsp[0].node)); ;}
{ (yyval.node) = UNARY_OP (MS_OP_UMINUS, (yyvsp[0].node)); ;}
break;
case 49:

View File

@ -77,7 +77,7 @@
typedef union YYSTYPE {
int ival;
const char *str;
ASNode *node;
MSNode *node;
} YYSTYPE;
/* Line 1447 of yacc.c. */
#line 84 "/home/muntyan/projects/moo/moo/mooutils/mooscript/mooscript-yacc.h"
@ -86,7 +86,7 @@ typedef union YYSTYPE {
# define YYSTYPE_IS_TRIVIAL 1
#endif
extern YYSTYPE _as_script_yylval;
extern YYSTYPE _ms_script_yylval;

View File

@ -2,29 +2,29 @@
#include "mooscript-parser.h"
#include "mooscript-yacc.h"
#define NODE_LIST_ADD(list, node) _as_parser_node_list_add (parser, AS_NODE_LIST (list), node)
#define NODE_COMMAND(id, node) _as_parser_node_command (parser, id, AS_NODE_LIST (node))
#define NODE_IF_ELSE(cond, then_, else_) _as_parser_node_if_else (parser, cond, then_, else_)
#define NODE_REPEAT(times, what) _as_parser_node_repeat (parser, times, what)
#define NODE_WHILE(cond, what) _as_parser_node_while (parser, cond, what)
#define NODE_ASSIGNMENT(var, val) _as_parser_node_assignment (parser, AS_NODE_VAR (var), val)
#define BINARY_OP(op, lval, rval) _as_parser_node_binary_op (parser, op, lval, rval)
#define UNARY_OP(op, val) _as_parser_node_unary_op (parser, op, val)
#define NODE_NUMBER(n) _as_parser_node_int (parser, n)
#define NODE_STRING(n) _as_parser_node_string (parser, n)
#define NODE_VALUE_LIST(list) _as_parser_node_value_list (parser, AS_NODE_LIST (list))
#define VAR_POSITIONAL(n) _as_parser_node_var_pos (parser, n)
#define VAR_NAMED(string) _as_parser_node_var_named (parser, string)
#define NODE_LIST_ADD(list, node) _ms_parser_node_list_add (parser, MS_NODE_LIST (list), node)
#define NODE_COMMAND(id, node) _ms_parser_node_command (parser, id, MS_NODE_LIST (node))
#define NODE_IF_ELSE(cond, then_, else_) _ms_parser_node_if_else (parser, cond, then_, else_)
#define NODE_REPEAT(times, what) _ms_parser_node_repeat (parser, times, what)
#define NODE_WHILE(cond, what) _ms_parser_node_while (parser, cond, what)
#define NODE_MSSIGNMENT(var, val) _ms_parser_node_assignment (parser, MS_NODE_VAR (var), val)
#define BINARY_OP(op, lval, rval) _ms_parser_node_binary_op (parser, op, lval, rval)
#define UNARY_OP(op, val) _ms_parser_node_unary_op (parser, op, val)
#define NODE_NUMBER(n) _ms_parser_node_int (parser, n)
#define NODE_STRING(n) _ms_parser_node_string (parser, n)
#define NODE_VALUE_LIST(list) _ms_parser_node_value_list (parser, MS_NODE_LIST (list))
#define VAR_POSITIONAL(n) _ms_parser_node_var_pos (parser, n)
#define VAR_NAMED(string) _ms_parser_node_var_named (parser, string)
#define SET_TOP_NODE(node) _as_parser_set_top_node (parser, node)
#define SET_TOP_NODE(node) _ms_parser_set_top_node (parser, node)
%}
%name-prefix="_as_script_yy"
%name-prefix="_ms_script_yy"
%union {
int ival;
const char *str;
ASNode *node;
MSNode *node;
}
%token <str> IDENTIFIER
@ -41,8 +41,8 @@
%token AND OR NOT
%token UMINUS
%lex-param {ASParser *parser}
%parse-param {ASParser *parser}
%lex-param {MSParser *parser}
%parse-param {MSParser *parser}
%expect 1
%left '-' '+'
@ -103,24 +103,24 @@ loop: REPEAT simple_expr non_empty_stmt { $$ = NODE_REPEAT ($2, $3); }
;
assignment:
variable '=' expr { $$ = NODE_ASSIGNMENT ($1, $3); }
variable '=' expr { $$ = NODE_MSSIGNMENT ($1, $3); }
;
expr: simple_expr
| expr '+' expr { $$ = BINARY_OP (AS_OP_PLUS, $1, $3); }
| expr '-' expr { $$ = BINARY_OP (AS_OP_MINUS, $1, $3); }
| expr '/' expr { $$ = BINARY_OP (AS_OP_DIV, $1, $3); }
| expr '*' expr { $$ = BINARY_OP (AS_OP_MULT, $1, $3); }
| expr '+' expr { $$ = BINARY_OP (MS_OP_PLUS, $1, $3); }
| expr '-' expr { $$ = BINARY_OP (MS_OP_MINUS, $1, $3); }
| expr '/' expr { $$ = BINARY_OP (MS_OP_DIV, $1, $3); }
| expr '*' expr { $$ = BINARY_OP (MS_OP_MULT, $1, $3); }
| expr AND expr { $$ = BINARY_OP (AS_OP_AND, $1, $3); }
| expr OR expr { $$ = BINARY_OP (AS_OP_OR, $1, $3); }
| expr AND expr { $$ = BINARY_OP (MS_OP_AND, $1, $3); }
| expr OR expr { $$ = BINARY_OP (MS_OP_OR, $1, $3); }
| expr EQ expr { $$ = BINARY_OP (AS_OP_EQ, $1, $3); }
| expr NEQ expr { $$ = BINARY_OP (AS_OP_NEQ, $1, $3); }
| expr '<' expr { $$ = BINARY_OP (AS_OP_LT, $1, $3); }
| expr '>' expr { $$ = BINARY_OP (AS_OP_GT, $1, $3); }
| expr LE expr { $$ = BINARY_OP (AS_OP_LE, $1, $3); }
| expr GE expr { $$ = BINARY_OP (AS_OP_GE, $1, $3); }
| expr EQ expr { $$ = BINARY_OP (MS_OP_EQ, $1, $3); }
| expr NEQ expr { $$ = BINARY_OP (MS_OP_NEQ, $1, $3); }
| expr '<' expr { $$ = BINARY_OP (MS_OP_LT, $1, $3); }
| expr '>' expr { $$ = BINARY_OP (MS_OP_GT, $1, $3); }
| expr LE expr { $$ = BINARY_OP (MS_OP_LE, $1, $3); }
| expr GE expr { $$ = BINARY_OP (MS_OP_GE, $1, $3); }
;
simple_expr:
@ -129,10 +129,10 @@ simple_expr:
| variable
| '(' stmt_or_program ')' { $$ = $2; }
| '[' list_elms ']' { $$ = NODE_VALUE_LIST ($2); }
| simple_expr '%' simple_expr { $$ = BINARY_OP (AS_OP_FORMAT, $1, $3); }
| '#' simple_expr { $$ = UNARY_OP (AS_OP_LEN, $2); }
| NOT simple_expr { $$ = UNARY_OP (AS_OP_NOT, $2); }
| '-' simple_expr %prec UMINUS { $$ = UNARY_OP (AS_OP_UMINUS, $2); }
| simple_expr '%' simple_expr { $$ = BINARY_OP (MS_OP_FORMAT, $1, $3); }
| '#' simple_expr { $$ = UNARY_OP (MS_OP_LEN, $2); }
| NOT simple_expr { $$ = UNARY_OP (MS_OP_NOT, $2); }
| '-' simple_expr %prec UMINUS { $$ = UNARY_OP (MS_OP_UMINUS, $2); }
;
list_elms: /* empty */ { $$ = NULL; }