Xmlb.Machine¶
- Subclasses:
None
Methods¶
- Inherited:
- Structs:
class |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Virtual Methods¶
- Inherited:
Properties¶
None
Signals¶
- Inherited:
Fields¶
- Inherited:
Name |
Type |
Access |
Description |
---|---|---|---|
parent_instance |
r |
Class Details¶
- class Xmlb.Machine(**kwargs)¶
- Bases:
- Abstract:
No
- Structure:
- classmethod new()¶
- Returns:
a new
Xmlb.Machine
- Return type:
Creates a new virtual machine.
New in version 0.1.1.
- add_method(name, n_opcodes, method_cb, *user_data)¶
- Parameters:
Adds a new function to the virtual machine. Registered functions can then be used as methods.
The method_cb must not modify the stack it’s passed unless it’s going to succeed. In particular, if a method call is not optimisable, it must not modify the stack it’s passed.
You need to add a custom function using
Xmlb.Machine.add_method
() before using methods that may reference it, for exampleXmlb.Machine.add_opcode_fixup
().New in version 0.1.1.
- add_opcode_fixup(opcodes_sig, fixup_cb, *user_data)¶
- Parameters:
opcodes_sig (
str
) – signature, e.g.INTE,TEXT
fixup_cb (
Xmlb.MachineOpcodeFixupFunc
) – callbackuser_data (
object
orNone
) – user pointer to pass to fixup_cb
Adds an opcode fixup. Fixups can be used to optimize the stack of opcodes or to add support for a nonstandard feature, for instance supporting missing attributes to functions.
New in version 0.1.1.
- add_operator(str, name)¶
-
Adds a new operator to the virtual machine. Operators can then be used instead of explicit methods like
eq()
.You need to add a custom operator using
Xmlb.Machine.add_operator
() before usingXmlb.Machine.parse
(). Common operators like<=
and=
are built-in and do not have to be added manually.New in version 0.1.1.
- add_text_handler(handler_cb, *user_data)¶
- Parameters:
handler_cb (
Xmlb.MachineTextHandlerFunc
) – callbackuser_data (
object
orNone
) – user pointer to pass to handler_cb
Adds a text handler. This allows the virtual machine to support nonstandard encoding or shorthand mnemonics for standard functions.
New in version 0.1.1.
- get_stack_size()¶
- Returns:
integer
- Return type:
Gets the maximum stack size used for the machine.
New in version 0.1.3.
- opcode_func_init(func_name)¶
- Parameters:
func_name (
str
) – function name, e.g.eq
- Returns:
True
if the function was found and the opcode initialised,False
otherwise- opcode:
a stack allocated
Xmlb.Opcode
to initialise
- Return type:
(
bool
, opcode:Xmlb.Opcode
)
Initialises a stack allocated
Xmlb.Opcode
for a registered function. Some standard functions are registered by default, for instanceeq
orge
. Other functions have to be added usingXmlb.Machine.add_method
().New in version 0.2.0.
- parse(text, text_len)¶
- Parameters:
- Raises:
- Returns:
opcodes, or
None
on error- Return type:
Parses an XPath predicate. Not all of XPath 1.0 or XPath 1.0 is supported, and new functions and mnemonics can be added using
Xmlb.Machine.add_method
() andXmlb.Machine.add_text_handler
().New in version 0.1.1.
- parse_full(text, text_len, flags)¶
- Parameters:
text (
str
) – predicate to parse, e.g.contains(text(),'xyx')
text_len (
int
) – length of text, or -1 if text isNUL
terminatedflags (
Xmlb.MachineParseFlags
) –Xmlb.MachineParseFlags
, e.g.Xmlb.MachineParseFlags.OPTIMIZE
- Raises:
- Returns:
opcodes, or
None
on error- Return type:
Parses an XPath predicate. Not all of XPath 1.0 or XPath 1.0 is supported, and new functions and mnemonics can be added using
Xmlb.Machine.add_method
() andXmlb.Machine.add_text_handler
().New in version 0.1.4.
- run(opcodes, exec_data)¶
- Parameters:
opcodes (
Xmlb.Stack
) – aXmlb.Stack
of opcodesexec_data (
object
orNone
) – per-run user data that is passed to all theXmlb.MachineMethodFunc
functions
- Raises:
- Returns:
a new
Xmlb.Opcode
, orNone
- result:
return status after running opcodes
- Return type:
Runs a set of opcodes on the virtual machine.
It is safe to call this function from a different thread to the one that created the
Xmlb.Machine
.New in version 0.1.1.
Deprecated since version 0.3.0: Use
Xmlb.Machine.run_with_bindings
() instead.
- run_with_bindings(opcodes, bindings, exec_data)¶
- Parameters:
opcodes (
Xmlb.Stack
) – aXmlb.Stack
of opcodesbindings (
Xmlb.ValueBindings
orNone
) – values bound to opcodes of typeXmlb.OpcodeKind.BOUND_INTEGER
orXmlb.OpcodeKind.BOUND_TEXT
, orNone
if the query doesn’t need any bound valuesexec_data (
object
orNone
) – per-run user data that is passed to all theXmlb.MachineMethodFunc
functions
- Raises:
- Returns:
a new
Xmlb.Opcode
, orNone
- result:
return status after running opcodes
- Return type:
Runs a set of opcodes on the virtual machine, using the bound values given in bindings to substitute for bound opcodes.
It is safe to call this function from a different thread to the one that created the
Xmlb.Machine
.New in version 0.3.0.
- set_debug_flags(flags)¶
- Parameters:
flags (
Xmlb.MachineDebugFlags
) –Xmlb.MachineDebugFlags
, e.g.Xmlb.MachineDebugFlags.SHOW_STACK
Sets the debug level of the virtual machine.
New in version 0.1.1.
- set_stack_size(stack_size)¶
- Parameters:
stack_size (
int
) – integer
Sets the maximum stack size used for the machine.
The stack size will be affective for new jobs started with
Xmlb.Machine.run
() andXmlb.Machine.parse
().New in version 0.1.3.
- stack_pop(stack)¶
- Parameters:
stack (
Xmlb.Stack
) – aXmlb.Stack
- Raises:
- Returns:
True
if popping succeeded,False
if the stack was empty already- opcode_out:
return location for the popped
Xmlb.Opcode
- Return type:
(
bool
, opcode_out:Xmlb.Opcode
)
Pops an opcode from the stack.
New in version 0.2.0.
- stack_push(stack)¶
- Parameters:
stack (
Xmlb.Stack
) – aXmlb.Stack
- Raises:
- Returns:
True
if a new empty opcode was returned, orFalse
if the stack has reached its maximum size- opcode_out:
return location for the new
Xmlb.Opcode
- Return type:
(
bool
, opcode_out:Xmlb.Opcode
orNone
)
Pushes a new empty opcode onto the end of the stack. A pointer to the opcode is returned in opcode_out so that the caller can initialise it.
If the stack reaches its maximum size,
Gio.IOErrorEnum.NO_SPACE
will be returned.New in version 0.2.0.
- stack_push_integer(stack, val)¶
- Parameters:
stack (
Xmlb.Stack
) – aXmlb.Stack
val (
int
) – integer literal
- Raises:
- Returns:
- Return type:
Adds an integer literal to the stack.
Errors are as for
Xmlb.Machine.stack_push
().New in version 0.2.0.
- stack_push_text(stack, str)¶
- Parameters:
stack (
Xmlb.Stack
) – aXmlb.Stack
str (
str
) – text literal
- Raises:
- Returns:
- Return type:
Adds a text literal to the stack, copying str.
Errors are as for
Xmlb.Machine.stack_push
().New in version 0.2.0.
- stack_push_text_static(stack, str)¶
- Parameters:
stack (
Xmlb.Stack
) – aXmlb.Stack
str (
str
) – text literal
- Raises:
- Returns:
- Return type:
Adds static text literal to the stack.
Errors are as for
Xmlb.Machine.stack_push
().New in version 0.2.0.
- stack_push_text_steal(stack, str)¶
- Parameters:
stack (
Xmlb.Stack
) – aXmlb.Stack
str (
str
) – text literal
- Raises:
- Returns:
- Return type:
Adds a stolen text literal to the stack.
Errors are as for
Xmlb.Machine.stack_push
().New in version 0.2.0.