| libxexpr Reference Manual | ||||
|---|---|---|---|---|
| Top | Description | ||||
#include <libxexpr/xexpr.h>
XexprInvocation;
XexprFunction;
typedef XexprConstant;
XexprBinding;
enum XexprType;
XexprEnvironment;
Xexpr;
XexprExtension;
XexprConstant * xexpr_new_string (const char *s,
gssize len);
XexprConstant * xexpr_new_string_take_ownership (char *s);
XexprConstant * xexpr_new_integer (long int integer);
XexprConstant * xexpr_new_number (double number);
XexprConstant * xexpr_new_invocation (const char *ns,
const char *function,
GSList *bindings,
GSList *constants);
XexprConstant * xexpr_new_invocation_take_ownership (char *ns,
char *function,
GSList *bindings,
GSList *constants);
XexprConstant * xexpr_new_function_take_ownership (GSList *args,
GSList *constants);
XexprConstant * xexpr_new_function (GSList *args,
GSList *constants);
XexprConstant * xexpr_constant_dup (XexprConstant *constant);
void xexpr_constant_free (XexprConstant *constant);
void xexpr_binding_free (XexprBinding *binding);
XexprConstant * xexpr_bindings_get (GSList *bindings,
const char *id);
gboolean xexpr_bindings_set (GSList *bindings,
const char *id,
XexprConstant *value);
GSList * xexpr_bindings_new (GSList *bindings,
const char *id,
XexprConstant *value);
GSList * xexpr_bindings_dup (GSList *bindings);
Xexpr * xexpr_new (void);
Xexpr * xexpr_sub (Xexpr *xexpr);
void xexpr_var_new (Xexpr *xexpr,
const char *id,
XexprConstant *value);
void xexpr_var_set (Xexpr *xexpr,
const char *id,
XexprConstant *value);
XexprConstant * xexpr_var_get (Xexpr *xexpr,
const char *id);
void xexpr_start_tracing (Xexpr *xexpr,
const char *id);
gboolean xexpr_is_tracing (Xexpr *xexpr,
const char *id);
void xexpr_free (Xexpr *xexpr);
XexprEnvironment * xexpr_get_environment (Xexpr *xexpr);
void xexpr_environment_foreach (XexprEnvironment *environment,
GTraverseFunc func,
gpointer user_data);
typedef struct {
char *ns;
char *function;
GSList *bindings;
GSList *constants;
} XexprInvocation;
A structure describing the invocation of a function.
typedef struct {
GSList *args;
GSList *constants;
} XexprFunction;
A structure describing the definition of a function.
typedef struct xexpr_constant XexprConstant;
A structure describing an XEXPR expression
typedef struct {
char *id;
XexprConstant *value;
} XexprBinding;
A structure describing the binding of a value to a name.
char * |
the bound name |
XexprConstant * |
the expresion bound to id
|
typedef enum {
XEXPR_TYPE_INVOCATION=1,
XEXPR_TYPE_FUNCTION,
XEXPR_TYPE_STRING,
XEXPR_TYPE_INTEGER,
XEXPR_TYPE_NUMBER
} XexprType;
Enum values for the type, to specify the type of expression.
typedef struct {
char *function;
struct xexpr_environment *outer;
GSList *bindings;
} XexprEnvironment;
A structure describing an XEXPR environment
char * |
the name of the function to which the environment belongs,
or NULL if this is the outermost environment
|
struct xexpr_environment * |
the next environment in the chain from innermost to outermost,
or NULL if this is the outermost environment
|
GSList * |
(element-type XexprBinding): the variables set in this environment |
typedef struct {
GSList *constants;
XexprEnvironment *environment;
} Xexpr;
A structure describing an XEXPR expression
GSList * |
(element-type XexprConstant): the constants that make up this expression |
XexprEnvironment * |
the innermost environment |
typedef struct {
char *ns;
XexprConstant *(*function_evaluate)(Xexpr *xexpr,const char *ns,
const char *id,GSList *bindings,GSList *args,GError **err);
} XexprExtension;
A structure describing an XEXPR extension
char * |
the namespace of the extension |
|
evaluates functions defined in the extension |
XexprConstant * xexpr_new_string (const char *s,
gssize len);
Create a new XexprConstant that consists of the given string.
XexprConstant * xexpr_new_string_take_ownership (char *s);
Create a new XexprConstant that consists of the given string.
XexprConstant * xexpr_new_integer (long int integer);
Create a new XexprConstant that consists of the given integer.
|
the integer |
Returns : |
the new XexprConstant. transfer full. |
XexprConstant * xexpr_new_number (double number);
Create a new XexprConstant that consists of the given floating-point number.
|
the number |
Returns : |
the new XexprConstant. transfer full. |
XexprConstant * xexpr_new_invocation (const char *ns,
const char *function,
GSList *bindings,
GSList *constants);
Create a new XexprConstant that invokes function with pre-bound arguments
bindings and with constants as further arguments. Functions with named
parameters will use the pre-bound arguments first if present, otherwise
the other arguments will be bound to the unbound parameters as needed.
ns should be NULL, the empty string or XEXPR_NS for XEXPR functions.
|
the namespace to which function belongs, or NULL. transfer none. |
|
the name of the function to be invoked. transfer none. |
|
transfer none) (element-type XexprBinding. transfer none. element-type XexprBinding. |
|
transfer none) (element-type XexprConstant. transfer none. element-type XexprConstant. |
Returns : |
the new XexprConstant. transfer full. |
XexprConstant * xexpr_new_invocation_take_ownership (char *ns,
char *function,
GSList *bindings,
GSList *constants);
Create a new XexprConstant that invokes function with pre-bound arguments
bindings and with constants as further arguments. Functions with named
parameters will use the pre-bound arguments first if present, otherwise
the other arguments will be bound to the unbound parameters as needed.
ns should be NULL, the empty string or XEXPR_NS for XEXPR functions.
|
the namespace to which function belongs, or NULL. transfer full. |
|
the name of the function to be invoked. transfer full. |
|
transfer full) (element-type XexprBinding. transfer full. element-type XexprBinding. |
|
transfer full) (element-type XexprConstant. transfer full. element-type XexprConstant. |
Returns : |
the new XexprConstant. transfer full. |
XexprConstant * xexpr_new_function_take_ownership (GSList *args, GSList *constants);
Create a new XexprConstant that defines an unnamed function. Creating a
function definition is the first step in defining a function. The second
step is to bind the definition to a name, eg., using xexpr_var_new().
XexprConstant * xexpr_new_function (GSList *args, GSList *constants);
Create a new XexprConstant that defines an unnamed function. Creating a
function definition is the first step in defining a function. The second
step is to bind the definition to a name, eg., using xexpr_var_new().
XexprConstant * xexpr_constant_dup (XexprConstant *constant);
Duplicate constant.
|
an XexprConstant to duplicate |
Returns : |
the new XexprConstant. transfer full. |
void xexpr_constant_free (XexprConstant *constant);
Frees the memory allocated for the XexprConstant.
|
an XexprConstant |
void xexpr_binding_free (XexprBinding *binding);
Frees the memory allocated for the XexprBinding.
|
an XexprBinding |
XexprConstant * xexpr_bindings_get (GSList *bindings, const char *id);
Look for a binding of symbol id in bindings and return the value if
found.
gboolean xexpr_bindings_set (GSList *bindings, const char *id, XexprConstant *value);
Update an existing binding of symbol id in bindings with the new value
value. If no existing binding is found, return FALSE.
GSList * xexpr_bindings_new (GSList *bindings, const char *id, XexprConstant *value);
Update an existing binding of symbol id or create a new one in bindings
with the new value value.
Xexpr * xexpr_sub (Xexpr *xexpr);
Creates a new Xexpr, copying options from xexpr.
|
an Xexpr to copy the initial options from |
Returns : |
the new Xexpr |
void xexpr_var_new (Xexpr *xexpr,
const char *id,
XexprConstant *value);
Update an existing binding of symbol id in the innermost environment of
xexpr or create a new one with the new value value.
|
an Xexpr |
|
a symbol to set or create |
|
the new value. transfer none. |
void xexpr_var_set (Xexpr *xexpr,
const char *id,
XexprConstant *value);
Update the active binding of symbol id in xexpr if such exists or create
create a new one in the outermost environment with the new value value.
|
an Xexpr |
|
a symbol to set or create |
|
the new value. transfer none. |
XexprConstant * xexpr_var_get (Xexpr *xexpr,
const char *id);
Look for a definition of symbol id in xexpr and return its value. If
no definition exists, return NULL.
|
an Xexpr |
|
a symbol to look up |
Returns : |
the bound value, or NULL if not found.. transfer none. |
void xexpr_start_tracing (Xexpr *xexpr,
const char *id);
Adds id to the set of symbols to trace.
When variables with the name of a traced symbol are created or changed, the evaluator will output a suitable tracing message and a stack dump.
Example 1. Example Tracing Output
Created new variable x in frame #0
#0 test1 (x = <nil/>)
#1 eq ()
#2 if ()
#3 and ()
#4 expr ()
Set variable x
#0 test1 (x = <integer>1</integer>)
#1 eq ()
#2 if ()
#3 and ()
#4 expr ()
|
an Xexpr |
|
the symbol to trace |
gboolean xexpr_is_tracing (Xexpr *xexpr, const char *id);
Checks if a symbol is currently being traced, returning TRUE if it is.
|
an Xexpr |
|
the symbol to test for |
Returns : |
TRUE if id is being traced
|
void xexpr_free (Xexpr *xexpr);
Frees the memory allocated for the Xexpr.
|
an Xexpr |
XexprEnvironment * xexpr_get_environment (Xexpr *xexpr);
Gets the XexprEnvironment of the given Xexpr.
|
an Xexpr |
Returns : |
the innermost environment. transfer none. |
void xexpr_environment_foreach (XexprEnvironment *environment,
GTraverseFunc func,
gpointer user_data);
Calls a function for each active variable in an XexprEnvironment.
|
an XexprEnvironment |
|
the function to call with each active variable |
|
user data to pass to the function |