Hyperon C
Loading...
Searching...
No Matches
Platform Environment Interface

Configuration and settings shared by MeTTa runners. More...

Classes

struct  env_builder_t
 Represents an environment initialization, in progress. More...

Functions

uintptr_t environment_config_dir (char *buf, uintptr_t buf_len)
 Renders the config_dir path from the common environment into a text buffer.
struct env_builder_t env_builder_start (void)
 Begins initialization of an environment.
struct env_builder_t env_builder_use_default (void)
 Creates an env_builder_t to specify that the default common environment should be used.
struct env_builder_t env_builder_use_test_env (void)
 A convenience to create an env_builder_t, to specify that a unit-test environment should be used.
bool env_builder_init_common_env (struct env_builder_t builder)
 Finishes initialization of the common environment.
void env_builder_set_working_dir (struct env_builder_t *builder, const char *path)
 Sets the working directory for the environment.
void env_builder_set_config_dir (struct env_builder_t *builder, const char *path)
 Sets the config directory for the environment.
void env_builder_create_config_dir (struct env_builder_t *builder, bool should_create)
 Sets whether the config dir should be created if it doesn't already exist.
void env_builder_set_default_config_dir (struct env_builder_t *builder)
 Sets the default config directory for the environment.
void env_builder_set_is_test (struct env_builder_t *builder, bool is_test)
 Configures the environment for use in unit testing.
void env_builder_push_include_path (struct env_builder_t *builder, const char *path)
 Adds a directory to search for module imports.
void env_builder_push_fs_module_format (struct env_builder_t *builder, const struct fs_module_format_t *format)
 Adds logic to interpret a foreign format for MeTTa modules loaded from the file system.

Detailed Description

Configuration and settings shared by MeTTa runners.

This interface allows configuration of shared properties for MeTTa interpreters

Function Documentation

◆ env_builder_create_config_dir()

void env_builder_create_config_dir ( struct env_builder_t * builder,
bool should_create )

Sets whether the config dir should be created if it doesn't already exist.

Parameters
[in]builderA pointer to the in-process environment builder state
[in]should_createWhether the directory will be created. Defaults to true

◆ env_builder_init_common_env()

bool env_builder_init_common_env ( struct env_builder_t builder)

Finishes initialization of the common environment.

Parameters
[in]builderThe in-process environment builder state to install as the common environment
Returns
True if the environment was sucessfully initialized with the provided builder state. False if the environment had already been initialized by a prior call

◆ env_builder_push_fs_module_format()

void env_builder_push_fs_module_format ( struct env_builder_t * builder,
const struct fs_module_format_t * format )

Adds logic to interpret a foreign format for MeTTa modules loaded from the file system.

Parameters
[in]builderA pointer to the in-process environment builder state
[in]formatA pointer to a user-defined structure to store information related to this format

◆ env_builder_push_include_path()

void env_builder_push_include_path ( struct env_builder_t * builder,
const char * path )

Adds a directory to search for module imports.

Parameters
[in]builderA pointer to the in-process environment builder state
[in]pathA C-style string specifying a path to a directory, to search for modules to load
Note
The paths will be searched in the order they are added to the env_builder_t`

◆ env_builder_set_config_dir()

void env_builder_set_config_dir ( struct env_builder_t * builder,
const char * path )

Sets the config directory for the environment.

Parameters
[in]builderA pointer to the in-process environment builder state
[in]pathA C-style string specifying a path to the config directory

◆ env_builder_set_default_config_dir()

void env_builder_set_default_config_dir ( struct env_builder_t * builder)

Sets the default config directory for the environment.

Parameters
[in]builderA pointer to the in-process environment builder state

◆ env_builder_set_is_test()

void env_builder_set_is_test ( struct env_builder_t * builder,
bool is_test )

Configures the environment for use in unit testing.

Parameters
[in]builderA pointer to the in-process environment builder state
[in]is_testTrue if the environment is a unit-test environment, False otherwise

◆ env_builder_set_working_dir()

void env_builder_set_working_dir ( struct env_builder_t * builder,
const char * path )

Sets the working directory for the environment.

Parameters
[in]builderA pointer to the in-process environment builder state
[in]pathA C-string specifying a path to a working directory, to search for modules to load. Passing NULL will unset the working directory
Note
This working directory is not required to be the same as the process working directory, and it will not change as the process' working directory is changed

◆ env_builder_start()

struct env_builder_t env_builder_start ( void )

Begins initialization of an environment.

Returns
The env_builder_t object representing the in-process environment initialization
Note
The env_builder_t must be passed to either env_builder_init_common_env or metta_new_with_space in order to properly deallocate it

◆ env_builder_use_default()

struct env_builder_t env_builder_use_default ( void )

Creates an env_builder_t to specify that the default common environment should be used.

Returns
The env_builder_t object specifying the common environment
Note
This function exists to supply an argument to metta_new_with_space when no special behavior is desired
The env_builder_t must be passed to metta_new_with_space

◆ env_builder_use_test_env()

struct env_builder_t env_builder_use_test_env ( void )

A convenience to create an env_builder_t, to specify that a unit-test environment should be used.

Returns
The env_builder_t object specifying the unit test environment
Note
This function exists to supply an argument to metta_new_with_space when performing unit testing
The env_builder_t must be passed to metta_new_with_space

◆ environment_config_dir()

uintptr_t environment_config_dir ( char * buf,
uintptr_t buf_len )

Renders the config_dir path from the common environment into a text buffer.

Parameters
[out]bufA buffer into which the text will be written
[in]buf_lenThe maximum allocated size of buf
Returns
The length of the path string, minus the string terminator character. If return_value > buf_len + 1, then the text was not fully written and this function should be called again with a larger buffer. This function will return 0 if there is no config_dir.