medit/moo/mooutils/mooscript/mooscript-value.h

164 lines
5.0 KiB
C
Raw Normal View History

/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4; coding: utf-8 -*-
*
2006-02-24 20:03:13 -08:00
* mooscript-value.h
*
* Copyright (C) 2004-2006 by Yevgen Muntyan <muntyan@math.tamu.edu>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* See COPYING file that comes with this distribution.
*/
2006-02-24 20:03:13 -08:00
#ifndef __MOO_SCRIPT_VALUE_H__
#define __MOO_SCRIPT_VALUE_H__
#include <glib-object.h>
G_BEGIN_DECLS
2006-02-24 20:39:12 -08:00
typedef struct _MSValue MSValue;
2006-03-07 23:10:49 -08:00
typedef struct _MSValueClass MSValueClass;
2006-03-07 22:00:49 -08:00
typedef struct _MSFunc MSFunc;
typedef struct _MSContext MSContext;
2006-03-07 23:10:49 -08:00
#define MS_VALUE_TYPE(val) ((val)->klass->type)
typedef enum {
2006-02-24 20:39:12 -08:00
MS_VALUE_NONE,
MS_VALUE_INT,
MS_VALUE_STRING,
MS_VALUE_GVALUE,
2006-03-07 19:02:01 -08:00
MS_VALUE_LIST,
2006-03-07 22:00:49 -08:00
MS_VALUE_DICT,
2006-03-07 23:10:49 -08:00
MS_VALUE_FUNC,
MS_VALUE_INVALID
2006-02-24 20:39:12 -08:00
} MSValueType;
typedef enum {
2006-02-24 20:39:12 -08:00
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_LAST
2006-02-24 20:39:12 -08:00
} MSBinaryOp;
typedef enum {
2006-02-24 20:39:12 -08:00
MS_OP_UMINUS,
MS_OP_NOT,
MS_OP_LEN,
MS_UNARY_OP_LAST
2006-02-24 20:39:12 -08:00
} MSUnaryOp;
2006-03-07 23:10:49 -08:00
struct _MSValueClass {
MSValueType type;
GHashTable *methods;
};
2006-02-24 20:39:12 -08:00
struct _MSValue {
guint ref_count;
2006-03-07 23:10:49 -08:00
MSValueClass *klass;
GHashTable *methods;
2006-03-07 22:00:49 -08:00
union {
int ival;
char *str;
GValue *gval;
2006-03-07 22:00:49 -08:00
GHashTable *hash;
struct {
2006-02-24 20:39:12 -08:00
MSValue **elms;
guint n_elms;
} list;
2006-03-07 22:00:49 -08:00
struct {
MSFunc *func;
MSValue *obj;
guint meth : 1;
} func;
};
};
2006-03-07 23:10:49 -08:00
void ms_type_init (void);
void ms_value_class_add_method (MSValueClass *klass,
const char *name,
MSFunc *func);
void ms_value_add_method (MSValue *value,
const char *name,
MSFunc *func);
MSValue *ms_value_get_method (MSValue *value,
const char *name);
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);
MSValue *ms_value_none (void);
MSValue *ms_value_false (void);
MSValue *ms_value_true (void);
MSValue *ms_value_bool (gboolean val);
gboolean ms_value_is_none (MSValue *value);
MSValue *ms_value_int (int val);
MSValue *ms_value_string (const char *string);
MSValue *ms_value_string_len (const char *string,
int chars);
MSValue *ms_value_take_string (char *string);
MSValue *ms_value_gvalue (const GValue *gval);
MSValue *ms_value_list (guint n_elms);
void ms_value_list_set_elm (MSValue *list,
guint index,
MSValue *elm);
MSValue *ms_value_dict (void);
void ms_value_dict_set_elm (MSValue *dict,
const char *key,
MSValue *val);
MSValue *ms_value_dict_get_elm (MSValue *dict,
const char *key);
MSValue *ms_value_ref (MSValue *val);
void ms_value_unref (MSValue *val);
gboolean ms_value_get_bool (MSValue *val);
gboolean ms_value_get_int (MSValue *val,
int *ival);
char *ms_value_print (MSValue *val);
gboolean ms_value_equal (MSValue *a,
MSValue *b);
int ms_value_cmp (MSValue *a,
MSValue *b);
MSValue *ms_value_func (MSFunc *func);
MSValue *ms_value_meth (MSFunc *func);
MSValue *ms_value_bound_meth (MSFunc *func,
MSValue *obj);
gboolean ms_value_is_func (MSValue *val);
MSValue *ms_value_call (MSValue *func,
MSValue **args,
guint n_args,
MSContext *ctx);
2006-03-07 22:00:49 -08:00
G_END_DECLS
2006-02-24 20:03:13 -08:00
#endif /* __MOO_SCRIPT_VALUE_H__ */