|
Hyperon C
|
Top-level API to execute MeTTa code. More...
Classes | |
| struct | step_result_t |
| Contains the state for an in-flight interpreter operation. More... | |
| struct | metta_t |
| A top-level MeTTa runner. More... | |
| struct | run_context_t |
| An interface object providing access to the MeTTa run interface. More... | |
| struct | runner_state_t |
| Represents the state of an in-flight MeTTa execution run. More... | |
Functions | |
| struct step_result_t | interpret_init (struct space_t *space, const atom_ref_t *expr) |
| Initializes an interpreter operation and take the initial step. | |
| struct step_result_t | interpret_step (struct step_result_t step) |
| Takes a subsequent step in an in-flight interpreter operation. | |
| uintptr_t | step_to_str (const struct step_result_t *step, char *buf, uintptr_t buf_len) |
| Renders a text description of a step_result_t into a buffer. | |
| bool | step_has_next (const struct step_result_t *step) |
| Examines a step_result_t to determine if more work is needed. | |
| void | step_get_result (struct step_result_t step, c_atom_vec_callback_t callback, void *context) |
| Consumes a step_result_t and provides the ultimate outcome of a MeTTa interpreter session. | |
| struct metta_t | metta_new (void) |
| Creates a new top-level MeTTa Runner, with only the Rust stdlib loaded. | |
| struct metta_t | metta_new_with_stdlib_loader (struct module_loader_t *stdlib_loader_mov, struct space_t *space_ref, struct env_builder_t env_builder_mov) |
| Creates a new top-level MeTTa Runner, with the specified stdlib module loaded. | |
| struct metta_t | metta_new_core (struct space_t *space, struct env_builder_t env_builder) |
| Creates a new core MeTTa runner, with no loaded stdlib nor initialization. | |
| struct metta_t | metta_clone_handle (const struct metta_t *metta) |
| Clones a metta_t handle. | |
| void | metta_free (struct metta_t metta) |
| Frees a metta_t handle. | |
| const char * | metta_err_str (const struct metta_t *metta) |
| Returns the error string associated with the last metta_run, metta_evaluate_atom, or metta_load_module call. | |
| bool | metta_eq (const struct metta_t *a, const struct metta_t *b) |
| Compares two metta_t handles to test whether the referenced MeTTa runner is the same. | |
| struct space_t | metta_space (struct metta_t *metta) |
| Provides access to the Space of the runner's top-level module. | |
| struct tokenizer_t | metta_tokenizer (struct metta_t *metta) |
| Provides access to the Tokenizer of the runner's top-level module. | |
| uintptr_t | metta_working_dir (const struct metta_t *metta, char *buf, uintptr_t buf_len) |
| Renders the working directory of the runner's environment into a buffer. | |
| void | metta_run (struct metta_t *metta, struct sexpr_parser_t parser, c_atom_vec_callback_t callback, void *context) |
| Runs the MeTTa runner until the input text has been fully parsed and evaluated. | |
| void | metta_evaluate_atom (struct metta_t *metta, atom_t atom, c_atom_vec_callback_t callback, void *context) |
| Runs the MeTTa runner to evaluate an input Atom. | |
| struct module_id_t | metta_load_module_direct (struct metta_t *metta_ref, const char *name_ref, struct module_loader_t *loader_mov) |
| Loads a module directly into the runner, from a module_loader_t. | |
| struct module_id_t | metta_load_module_at_path (struct metta_t *metta, const char *path, const char *name) |
| Loads a module into the runner from a module resource at a file system path. | |
| struct space_t | metta_get_module_space (const struct metta_t *metta, struct module_id_t mod_id) |
| Returns the Space for a loaded module. | |
| void | run_context_push_parser (struct run_context_t *run_context, struct sexpr_parser_t parser) |
| Appends the parser to the Run Context's queue of input to run. | |
| struct metta_t | run_context_get_metta (const struct run_context_t *run_context) |
| Returns a pointer to the metta_t runner that a run context is executing within. | |
| struct space_t | run_context_get_space (const struct run_context_t *run_context) |
| Provides access to the Space of the currently running module. | |
| struct tokenizer_t | run_context_get_tokenizer (const struct run_context_t *run_context) |
| Provides access to the Tokenizer of the currently running module. | |
| void | run_context_raise_error (struct run_context_t *run_context, const char *message) |
| Sets a runtime error. | |
| struct runner_state_t | runner_state_new_with_parser (const struct metta_t *metta, struct sexpr_parser_t parser) |
| Creates a runner_state_t, to use for step-wise execution of MeTTa text. | |
| struct runner_state_t | runner_state_new_with_atoms (const struct metta_t *metta, const struct atom_vec_t *atoms) |
| Creates a runner_state_t, to use for step-wise execution of a list of atoms. | |
| void | runner_state_free (struct runner_state_t state) |
| Frees a runner_state_t. | |
| const char * | runner_state_err_str (const struct runner_state_t *state) |
| Returns the error string associated with the last runner_state_step | |
| void | runner_state_step (struct runner_state_t *state) |
| Runs one step of the runner. | |
| bool | runner_state_is_complete (const struct runner_state_t *state) |
| Returns whether or not the runner_state_t has completed all outstanding work. | |
| uintptr_t | runner_state_to_str (const struct runner_state_t *state, char *buf, uintptr_t buf_len) |
| Renders a text description of a runner_state_t into a buffer. | |
| void | runner_state_current_results (const struct runner_state_t *state, c_atom_vec_callback_t callback, void *context) |
| Accesses the current in-flight results in the runner_state_t. | |
Top-level API to execute MeTTa code.
This Interface includes the types and functions to instantiate a MeTTa interpreter and step through MeTTa code.
| struct step_result_t interpret_init | ( | struct space_t * | space, |
| const atom_ref_t * | expr ) |
Initializes an interpreter operation and take the initial step.
| [in] | space | A pointer to the Space in which to perform the operation |
| [in] | expr | A pointer to an atom_t or atom_ref_t Expression atom to interpret |
| struct step_result_t interpret_step | ( | struct step_result_t | step | ) |
Takes a subsequent step in an in-flight interpreter operation.
| [in] | step | The existing state for the in-flight interpreter operation |
Clones a metta_t handle.
| [in] | metta | The handle to clone |
Compares two metta_t handles to test whether the referenced MeTTa runner is the same.
| [in] | a | A pointer to the first runner handle |
| [in] | b | A pointer to the first runner handle |
| const char * metta_err_str | ( | const struct metta_t * | metta | ) |
Returns the error string associated with the last metta_run, metta_evaluate_atom, or metta_load_module call.
| [in] | metta | A pointer to the MeTTa handle |
| void metta_evaluate_atom | ( | struct metta_t * | metta, |
| atom_t | atom, | ||
| c_atom_vec_callback_t | callback, | ||
| void * | context ) |
Runs the MeTTa runner to evaluate an input Atom.
| [in] | metta | A pointer to the runner handle |
| [in] | atom | The atom_t representing the atom to evaluate |
| [in] | callback | A function that will be called to provide a vector of atoms produced by the evaluation |
| [in] | context | A pointer to a caller-defined structure to facilitate communication with the callback function |
| void metta_free | ( | struct metta_t | metta | ) |
Frees a metta_t handle.
| [in] | metta | The handle to free |
| struct space_t metta_get_module_space | ( | const struct metta_t * | metta, |
| struct module_id_t | mod_id ) |
Returns the Space for a loaded module.
| [in] | metta | A pointer to the handle specifying the runner into which to load the module |
| [in] | mod_id | The module_id_t of the loaded module to access |
| struct module_id_t metta_load_module_at_path | ( | struct metta_t * | metta, |
| const char * | path, | ||
| const char * | name ) |
Loads a module into the runner from a module resource at a file system path.
| [in] | metta | A pointer to the handle specifying the runner into which to load the module |
| [in] | path | A C-string specifying the path from which to load the module |
| [in] | name | A C-string specifying a name for the module, or NULL if you want the module to be private and unable to be loaded by name |
| struct module_id_t metta_load_module_direct | ( | struct metta_t * | metta_ref, |
| const char * | name_ref, | ||
| struct module_loader_t * | loader_mov ) |
Loads a module directly into the runner, from a module_loader_t.
| [in] | metta_ref | A pointer to the handle specifying the runner into which to load the module |
| [in] | name_ref | A C-string specifying a name for the module |
| [in] | loader_mov | The module_loader_t instance to load the module |
| struct metta_t metta_new | ( | void | ) |
Creates a new top-level MeTTa Runner, with only the Rust stdlib loaded.
| struct metta_t metta_new_core | ( | struct space_t * | space, |
| struct env_builder_t | env_builder ) |
Creates a new core MeTTa runner, with no loaded stdlib nor initialization.
| [in] | space | A pointer to a handle for the Space for use as the space of the top-level module |
| [in] | environment | An env_builder_t handle to configure the environment to use |
| struct metta_t metta_new_with_stdlib_loader | ( | struct module_loader_t * | stdlib_loader_mov, |
| struct space_t * | space_ref, | ||
| struct env_builder_t | env_builder_mov ) |
Creates a new top-level MeTTa Runner, with the specified stdlib module loaded.
| [in] | space_ref | A pointer to a handle for the Space for use in the Runner's top-level module |
| [in] | env_builder_mov | An env_builder_t handle to configure the environment to use |
| [in] | stdlib_loader_mov | Stdlib loader implemented in C code. Pass NULL to use the default stdlib |
| void metta_run | ( | struct metta_t * | metta, |
| struct sexpr_parser_t | parser, | ||
| c_atom_vec_callback_t | callback, | ||
| void * | context ) |
Runs the MeTTa runner until the input text has been fully parsed and evaluated.
| [in] | metta | A pointer to the runner handle |
| [in] | parser | An S-Expression Parser containing the MeTTa text |
| [in] | callback | A function that will be called to provide a vector of atoms produced by the evaluation |
| [in] | context | A pointer to a caller-defined structure to facilitate communication with the callback function |
Provides access to the Space of the runner's top-level module.
| [in] | metta | A pointer to the runner handle |
| struct tokenizer_t metta_tokenizer | ( | struct metta_t * | metta | ) |
Provides access to the Tokenizer of the runner's top-level module.
| [in] | metta | A pointer to the runner handle |
| uintptr_t metta_working_dir | ( | const struct metta_t * | metta, |
| char * | buf, | ||
| uintptr_t | buf_len ) |
Renders the working directory of the runner's environment into a buffer.
| [in] | metta | A pointer to the runner handle |
| [out] | buf | A buffer into which the path will be rendered |
| [in] | buf_len | The maximum allocated size of buf |
| struct metta_t run_context_get_metta | ( | const struct run_context_t * | run_context | ) |
Returns a pointer to the metta_t runner that a run context is executing within.
| [in] | run_context | A pointer to the run_context_t to access the runner API |
| struct space_t run_context_get_space | ( | const struct run_context_t * | run_context | ) |
Provides access to the Space of the currently running module.
| [in] | run_context | A pointer to the run_context_t to access the runner API |
| struct tokenizer_t run_context_get_tokenizer | ( | const struct run_context_t * | run_context | ) |
Provides access to the Tokenizer of the currently running module.
| [in] | run_context | A pointer to the run_context_t to access the runner API |
| void run_context_push_parser | ( | struct run_context_t * | run_context, |
| struct sexpr_parser_t | parser ) |
Appends the parser to the Run Context's queue of input to run.
| [in] | run_context | A pointer to the run_context_t to access the runner API |
| [in] | parser | An S-Expression Parser containing the MeTTa source code to execute |
| void run_context_raise_error | ( | struct run_context_t * | run_context, |
| const char * | message ) |
Sets a runtime error.
| [in] | run_context | A pointer to the run_context_t to access the runner API |
| [in] | message | A C-string specifying an error message |
| void runner_state_current_results | ( | const struct runner_state_t * | state, |
| c_atom_vec_callback_t | callback, | ||
| void * | context ) |
Accesses the current in-flight results in the runner_state_t.
| [in] | state | The runner_state_t within which to preview results |
| [in] | callback | A function that will be called to provide a vector of atoms produced by the evaluation |
| [in] | context | A pointer to a caller-defined structure to facilitate communication with the callback function |
| const char * runner_state_err_str | ( | const struct runner_state_t * | state | ) |
Returns the error string associated with the last runner_state_step
| [in] | state | A pointer to the runner state |
| void runner_state_free | ( | struct runner_state_t | state | ) |
Frees a runner_state_t.
| [in] | node | The runner_state_t to free |
| bool runner_state_is_complete | ( | const struct runner_state_t * | state | ) |
Returns whether or not the runner_state_t has completed all outstanding work.
| [in] | state | The runner_state_t to inspect |
| struct runner_state_t runner_state_new_with_atoms | ( | const struct metta_t * | metta, |
| const struct atom_vec_t * | atoms ) |
Creates a runner_state_t, to use for step-wise execution of a list of atoms.
| [in] | metta | A pointer to the runner handle in which to perform the run |
| [in] | atoms | A pointer to an atom_vec_t containing the atoms to run |
| struct runner_state_t runner_state_new_with_parser | ( | const struct metta_t * | metta, |
| struct sexpr_parser_t | parser ) |
Creates a runner_state_t, to use for step-wise execution of MeTTa text.
| [in] | metta | A pointer to the runner handle in which to perform the run |
| [in] | parser | An S-Expression Parser containing the MeTTa text |
| void runner_state_step | ( | struct runner_state_t * | state | ) |
Runs one step of the runner.
| [in] | state | A pointer to the in-flight runner state |
| uintptr_t runner_state_to_str | ( | const struct runner_state_t * | state, |
| char * | buf, | ||
| uintptr_t | buf_len ) |
Renders a text description of a runner_state_t into a buffer.
| [in] | state | A pointer to a runner_state_t to render |
| [out] | buf | A buffer into which the text will be rendered |
| [in] | buf_len | The maximum allocated size of buf |
| void step_get_result | ( | struct step_result_t | step, |
| c_atom_vec_callback_t | callback, | ||
| void * | context ) |
Consumes a step_result_t and provides the ultimate outcome of a MeTTa interpreter session.
| [in] | step | A pointer to a step_result_t to render |
| [in] | callback | A function that will be called to provide a vector of all atoms resulting from the interpreter session |
| [in] | context | A pointer to a caller-defined structure to facilitate communication with the callback function |
| bool step_has_next | ( | const struct step_result_t * | step | ) |
Examines a step_result_t to determine if more work is needed.
| [in] | step | A pointer to the step_result_t representing the in-flight interpreter operation |
| uintptr_t step_to_str | ( | const struct step_result_t * | step, |
| char * | buf, | ||
| uintptr_t | buf_len ) |
Renders a text description of a step_result_t into a buffer.
| [in] | step | A pointer to a step_result_t to render |
| [out] | buf | A buffer into which the text will be rendered |
| [in] | buf_len | The maximum allocated size of buf |