xb-opcode

## xb-opcode xb-opcode — |

## Functions

gboolean | xb_opcode_cmp_val ()
gboolean | xb_opcode_cmp_str ()
gchar * | xb_opcode_to_string ()
const gchar * | xb_opcode_kind_to_string ()
XbOpcodeKind | xb_opcode_kind_from_string ()
XbOpcodeKind | xb_opcode_get_kind ()
const gchar * | xb_opcode_get_str ()
guint32 | xb_opcode_get_val ()
void | xb_opcode_func_init ()
void | xb_opcode_integer_init ()
void | xb_opcode_text_init ()
void | xb_opcode_text_init_static ()
void | xb_opcode_text_init_steal ()

## Types and Values

enum | XbOpcodeFlags
enum | XbOpcodeKind
| XbOpcode

## Description

## Functions

### xb_opcode_cmp_val ()

    gboolean
    xb_opcode_cmp_val (XbOpcode *self);

Checks if the opcode can be compared using the integer value.

#### Parameters

self | a XbOpcode |

#### Returns

#`TRUE` if this opcode can be compared as an integer

Since: 0.1.1

### xb_opcode_cmp_str ()

    gboolean
    xb_opcode_cmp_str (XbOpcode *self);

Checks if the opcode can be compared using the string value.

#### Parameters

self | a XbOpcode |

#### Returns

#`TRUE` if this opcode can be compared as an string

Since: 0.1.1

### xb_opcode_to_string ()

    gchar *
    xb_opcode_to_string (XbOpcode *self);

Returns a string representing the specific opcode.

#### Parameters

self | a XbOpcode |

#### Returns

text

Since: 0.1.4

### xb_opcode_kind_to_string ()

    const gchar *
    xb_opcode_kind_to_string (XbOpcodeKind kind);

Converts the opcode kind to a string.

#### Parameters

kind | a XbOpcodeKind, e.g. `XB_OPCODE_KIND_FUNCTION` |

#### Returns

opcode kind, e.g. `FUNC`

Since: 0.1.1

### xb_opcode_kind_from_string ()

    XbOpcodeKind
    xb_opcode_kind_from_string (const gchar *str);

Converts a string to an opcode kind.

#### Parameters

str | a string, e.g. `FUNC` |

#### Returns

a XbOpcodeKind, e.g. `XB_OPCODE_KIND_TEXT`

Since: 0.1.1

### xb_opcode_get_kind ()

    XbOpcodeKind
    xb_opcode_get_kind (XbOpcode *self);

Gets the opcode kind.

#### Parameters

self | a XbOpcode |

#### Returns

a XbOpcodeKind, e.g. `XB_OPCODE_KIND_INTEGER`

Since: 0.1.1

### xb_opcode_get_str ()

    const gchar *
    xb_opcode_get_str (XbOpcode *self);

Gets the string value stored on the opcode.

#### Parameters

self | a XbOpcode |

#### Returns

a string, or `NULL` if unset

Since: 0.1.1

### xb_opcode_get_val ()

    guint32
    xb_opcode_get_val (XbOpcode *self);

Gets the integer value stored in the opcode. This may be a function ID, a index into the string table or a literal integer.

#### Parameters

self | a XbOpcode |

#### Returns

value, or 0 for unset.

Since: 0.1.1

### xb_opcode_func_init ()

    void
    xb_opcode_func_init (XbOpcode *self,
                         guint32 func);

Initialises a stack allocated XbOpcode to contain a specific function. Custom functions can be registered using `xb_machine_add_func()` and retrieved using `xb_machine_opcode_func_new()`.

#### Parameters

self | a stack allocated XbOpcode to initialise |
func | a function index |

Since: 0.2.0

### xb_opcode_integer_init ()

    void
    xb_opcode_integer_init (XbOpcode *self,
                            guint32 val);

Initialises a stack allocated XbOpcode to contain an integer literal.

#### Parameters

self | a stack allocated XbOpcode to initialise |
val | a integer value |

Since: 0.2.0

### xb_opcode_text_init ()

    void
    xb_opcode_text_init (XbOpcode *self,
                         const gchar *str);

Initialises a stack allocated XbOpcode to contain a text literal. The `str` argument is copied internally and is not tied to the lifecycle of the XbOpcode.

#### Parameters

self | a stack allocated XbOpcode to initialise |
str | a string |

Since: 0.2.0

### xb_opcode_text_init_static ()

    void
    xb_opcode_text_init_static (XbOpcode *self,
                                const gchar *str);

Initialises a stack allocated XbOpcode to contain a text literal, where `str` is either static text or will outlive the XbOpcode lifecycle.

#### Parameters

self | a stack allocated XbOpcode to initialise |
str | a string |

Since: 0.2.0

### xb_opcode_text_init_steal ()

    void
    xb_opcode_text_init_steal (XbOpcode *self,
                               gchar *str);

Initialises a stack allocated XbOpcode to contain a text literal, stealing the `str` . Once the opcode is finalized `g_free()` will be called on `str` .

#### Parameters

self | a stack allocated XbOpcode to initialise |
str | a string |

Since: 0.2.0

## Types and Values

### enum XbOpcodeFlags

The opcode flags. The values have been carefully chosen so that a simple bitmask can be done to know how to compare for equality.

function─┐ ┌─string bound──┐ │ │ ┌──integer token┐ │ │ │ │ X X X X X X X 8 4 2 1

#### Members

XB_OPCODE_FLAG_UNKNOWN |  |
XB_OPCODE_FLAG_INTEGER |  |
XB_OPCODE_FLAG_TEXT |  |
XB_OPCODE_FLAG_FUNCTION |  |
XB_OPCODE_FLAG_BOUND |  |
XB_OPCODE_FLAG_BOOLEAN |  |
XB_OPCODE_FLAG_TOKENIZED |  |

### enum XbOpcodeKind

#### Members

XB_OPCODE_KIND_UNKNOWN |  |
XB_OPCODE_KIND_INTEGER |  |
XB_OPCODE_KIND_TEXT |  |
XB_OPCODE_KIND_FUNCTION |  |
XB_OPCODE_KIND_BOUND_UNSET |  |
XB_OPCODE_KIND_BOUND_INTEGER |  |
XB_OPCODE_KIND_BOUND_TEXT |  |
XB_OPCODE_KIND_INDEXED_TEXT |  |
XB_OPCODE_KIND_BOOLEAN |  |
XB_OPCODE_KIND_BOUND_INDEXED_TEXT |  |

### XbOpcode

    typedef struct {
    	XbOpcodeKind kind;
    	guint32 val;
    	gpointer ptr;
    	guint8 tokens_len;
    	const gchar *tokens[XB_OPCODE_TOKEN_MAX + 1];
    	GDestroyNotify destroy_func;
    	guint8 level;
    } XbOpcode;