Hyperon C
Loading...
Searching...
No Matches
gnd_api_t Struct Reference

A table of callback functions to implement a Grounded Atom with behavior defined in C. More...

#include <hyperon.h>

Public Attributes

struct exec_error_t(* execute )(const struct gnd_t *gnd, const struct atom_vec_t *args, struct atom_vec_t *out)
 An optional function to implement executable atom behavior.
struct bindings_set_t(* match_ )(const struct gnd_t *gnd, const atom_ref_t *other)
 An optional function to match the atom with another atom.
enum serial_result_t(* serialize )(const struct gnd_t *gnd, const struct serializer_api_t *api, void *context)
 An optional function to encode the atom in terms of primitive types.
bool(* eq )(const struct gnd_t *gnd, const struct gnd_t *other)
 Tests whether two atoms instantiated from the same interface are equal.
struct gnd_t *(* clone )(const struct gnd_t *gnd)
 Makes a deep copy of a Grounded Atom.
uintptr_t(* display )(const struct gnd_t *gnd, char *buf, uintptr_t buf_len)
 Renders a human-readable text description of the Grounded Atom into a buffer.
void(* free )(struct gnd_t *gnd)
 Frees the backing object belonging to a Grounded Atom, and all associated resources.

Detailed Description

A table of callback functions to implement a Grounded Atom with behavior defined in C.

See also
atom_gnd
atom_get_object

Member Data Documentation

◆ clone

struct gnd_t *(* gnd_api_t::clone) (const struct gnd_t *gnd)

Makes a deep copy of a Grounded Atom.

Parameters
[in]gndA pointer to the Grounded Atom object
Returns
A pointer to a newly allocated buffer to back a new Grounded Atom, which has been initialized as a clone of the atom backed by the incoming gnd argument.
See also
atom_gnd

◆ display

uintptr_t(* gnd_api_t::display) (const struct gnd_t *gnd, char *buf, uintptr_t buf_len)

Renders a human-readable text description of the Grounded Atom into a buffer.

Parameters
[in]gndA pointer to the Grounded Atom object
[out]bufA buffer into which the text should be rendered
[in]buf_lenThe maximum allocated size of buf
Returns
The length of the fully rendered text description, minus the string terminator character. Regardless of whether the text was able to be completely rendered into the buffer.
See also
atom_to_str
Warning
This function implementation must write a null terminator character at the end of the text, and must never overwrite the buf_len parameter.

◆ eq

bool(* gnd_api_t::eq) (const struct gnd_t *gnd, const struct gnd_t *other)

Tests whether two atoms instantiated from the same interface are equal.

Parameters
[in]gndA pointer to the Grounded Atom object
[in]otherA pointer to the other grounded atom's object
Returns
true if the two atoms are equal, and false if they are not

◆ execute

struct exec_error_t(* gnd_api_t::execute) (const struct gnd_t *gnd, const struct atom_vec_t *args, struct atom_vec_t *out)

An optional function to implement executable atom behavior.

Parameters
[in]gndA pointer to the Grounded Atom object
[in]argsA pointer to an atom_vec_t containing the argument atoms for this execution
[out]outA pointer to a mutable atom_vec_t, into which result atoms may be added by the execution
Returns
An exec_error_t status that informs the MeTTa interpreter if execution may continue or whether to handle a fault
Note
Assigning NULL to this field means the atom is not executable

◆ free

void(* gnd_api_t::free) (struct gnd_t *gnd)

Frees the backing object belonging to a Grounded Atom, and all associated resources.

Parameters
[in]gndA pointer to the Grounded Atom object
Note
This function must free the typ field in the gnd_t header

◆ match_

struct bindings_set_t(* gnd_api_t::match_) (const struct gnd_t *gnd, const atom_ref_t *other)

An optional function to match the atom with another atom.

Parameters
[in]gndA pointer to the Grounded Atom object
[in]otherThe other atom to match with
Returns
A bindings_set_t that contains all matches between the Grounded Atom and the other atom. Returning an empty Bindings Set means the atom do not match
Note
Assigning NULL to this field means the atom will match only other atoms which are considered equal by the eq function below

◆ serialize

enum serial_result_t(* gnd_api_t::serialize) (const struct gnd_t *gnd, const struct serializer_api_t *api, void *context)

An optional function to encode the atom in terms of primitive types.

Parameters
[in]gndA pointer to the Grounded Atom object
[in]apiA table of functions the serialize implementation may call to encode the atom value
[in]contextA caller-defined object to pass to functions in the api, to receive the encoded value(s)
Returns
A serial_result_t indicating whether the serialize operation was successful

The documentation for this struct was generated from the following file: