LispBM
Macros | Functions
env.h File Reference
#include "lbm_types.h"
Include dependency graph for env.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define GLOBAL_ENV_ROOTS   32
 
#define GLOBAL_ENV_MASK   0x1F
 

Functions

int lbm_init_env (void)
 
lbm_valuelbm_get_global_env (void)
 
lbm_value lbm_env_copy_spine (lbm_value env)
 
bool lbm_env_lookup_b (lbm_value *res, lbm_value sym, lbm_value env)
 
bool lbm_global_env_lookup (lbm_value *res, lbm_value sym)
 
lbm_value lbm_env_lookup (lbm_value sym, lbm_value env)
 
lbm_value lbm_env_set (lbm_value env, lbm_value key, lbm_value val)
 
lbm_value lbm_env_set_functional (lbm_value env, lbm_value key, lbm_value val)
 
lbm_value lbm_env_modify_binding (lbm_value env, lbm_value key, lbm_value val)
 
lbm_value lbm_env_drop_binding (lbm_value env, lbm_value key)
 

Macro Definition Documentation

◆ GLOBAL_ENV_MASK

#define GLOBAL_ENV_MASK   0x1F

◆ GLOBAL_ENV_ROOTS

#define GLOBAL_ENV_ROOTS   32

Function Documentation

◆ lbm_env_copy_spine()

lbm_value lbm_env_copy_spine ( lbm_value  env)

Copy the spine of an environment. The list structure is recreated but the values themselves are not copied but rather just referenced.

Parameters
envEnvironment to copy.
Returns
Copy of environment.

◆ lbm_env_drop_binding()

lbm_value lbm_env_drop_binding ( lbm_value  env,
lbm_value  key 
)

Removes a binding (destructively) from the input environment.

Parameters
envEnvironment to modify.
keyKey to remove from environment.
Returns
Updated environment or not_found symbol.

◆ lbm_env_lookup()

lbm_value lbm_env_lookup ( lbm_value  sym,
lbm_value  env 
)

Lookup a value in from the global environment.

Parameters
symThe key to look for in the environment
envThe environment to search for the key.
Returns
The value bound to key or lbm_enc_sym(SYM_NOT_FOUND).

◆ lbm_env_lookup_b()

bool lbm_env_lookup_b ( lbm_value res,
lbm_value  sym,
lbm_value  env 
)

Lookup a value in an environment.

Parameters
resResult stored here
symThe key to look for in the environment
envThe environment to search for the key.
Returns
True on success or false otherwise.

◆ lbm_env_modify_binding()

lbm_value lbm_env_modify_binding ( lbm_value  env,
lbm_value  key,
lbm_value  val 
)

Modifies an existing binding on the environment.

Parameters
envThe environment to modify.
keyThe key.
valThe new value to associate with the key.
Returns
The modified environment of Success and lbm_enc_sym(SYM_NOT_FOUND) if the key does not exist.

◆ lbm_env_set()

lbm_value lbm_env_set ( lbm_value  env,
lbm_value  key,
lbm_value  val 
)

Create a new binding on the environment or replace an old binding.

Parameters
envEnvironment to modify.
keyA symbol to associate with a value.
valThe value.
Returns
The modified environment or lbm_enc_sym(SYM_MERROR) if GC needs to be run.

◆ lbm_env_set_functional()

lbm_value lbm_env_set_functional ( lbm_value  env,
lbm_value  key,
lbm_value  val 
)

Create a new binding on the environment without destroying the old value. If the old value is unused (the key-value pair) it will be freed by GC at next convenience.

Parameters
envEnvironment to modify.
keyA symbol to associate with a value.
valThe value.
Returns
The modified environment or lbm_enc_sym(SYM_MERROR) if GC needs to be run.

◆ lbm_get_global_env()

lbm_value* lbm_get_global_env ( void  )
Returns
the global environment

◆ lbm_global_env_lookup()

bool lbm_global_env_lookup ( lbm_value res,
lbm_value  sym 
)

Lookup a value in the global environment.

Parameters
resResult stored here
symThe key to look for in the environment
envThe environment to search for the key.
Returns
True on success or false otherwise.

◆ lbm_init_env()

int lbm_init_env ( void  )

Initialize the global environment. This sets the global environment to NIL

Returns
1