LispBM
|
Go to the source code of this file.
Data Structures | |
struct | eval_context_s |
struct | lbm_event_t |
Typedefs | |
typedef struct eval_context_s | eval_context_t |
typedef lbm_value(* | fundamental_fun) (lbm_value *, lbm_uint, eval_context_t *) |
typedef void(* | ctx_fun) (eval_context_t *, void *, void *) |
Enumerations | |
enum | lbm_event_type_t { LBM_EVENT_FOR_HANDLER = 0, LBM_EVENT_UNBLOCK_CTX, LBM_EVENT_DEFINE, LBM_EVENT_RUN_USER_CALLBACK } |
Variables | |
const fundamental_fun | fundamental_table [] |
#define EVAL_CPS_CONTEXT_FLAG_CONST (uint32_t)0x02 |
#define EVAL_CPS_CONTEXT_FLAG_CONST_SYMBOL_STRINGS (uint32_t)0x04 |
#define EVAL_CPS_CONTEXT_FLAG_INCREMENTAL_READ (uint32_t)0x08 |
#define EVAL_CPS_CONTEXT_FLAG_NOTHING (uint32_t)0x00 |
#define EVAL_CPS_CONTEXT_FLAG_TRAP (uint32_t)0x01 |
#define EVAL_CPS_CONTEXT_FLAG_TRAP_UNROLL_RETURN (uint32_t)0x10 |
#define EVAL_CPS_CONTEXT_READER_FLAGS_MASK (EVAL_CPS_CONTEXT_FLAG_CONST | EVAL_CPS_CONTEXT_FLAG_CONST_SYMBOL_STRINGS | EVAL_CPS_CONTEXT_FLAG_INCREMENTAL_READ) |
#define EVAL_CPS_DEFAULT_MAILBOX_SIZE 10 |
#define EVAL_CPS_STATE_DEAD 8 |
#define EVAL_CPS_STATE_KILL 4 |
#define EVAL_CPS_STATE_NONE 0 |
#define EVAL_CPS_STATE_PAUSED 1 |
#define EVAL_CPS_STATE_RESET 16 |
#define EVAL_CPS_STATE_RUNNING 2 |
#define LBM_IS_STATE_RECV | ( | X | ) | (X & (LBM_THREAD_STATE_RECV_BL | LBM_THREAD_STATE_RECV_TO)) |
#define LBM_IS_STATE_TIMEOUT | ( | X | ) | (X & (LBM_THREAD_STATE_TIMEOUT | LBM_THREAD_STATE_RECV_TO)) |
#define LBM_IS_STATE_UNBLOCKABLE | ( | X | ) | (X & (LBM_THREAD_STATE_BLOCKED | LBM_THREAD_STATE_TIMEOUT)) |
#define LBM_IS_STATE_WAKE_UP_WAKABLE | ( | X | ) | (X & (LBM_THREAD_STATE_SLEEPING | LBM_IS_STATE_TIMEOUT(X))) |
#define LBM_THREAD_STATE_BLOCKED (uint32_t)1u |
#define LBM_THREAD_STATE_GC_BIT (uint32_t)(1u << 31) |
#define LBM_THREAD_STATE_READY (uint32_t)0u |
The eval_context_t struct represents a lispbm process.
#define LBM_THREAD_STATE_RECV_BL (uint32_t)8u |
#define LBM_THREAD_STATE_RECV_TO (uint32_t)16u |
#define LBM_THREAD_STATE_SLEEPING (uint32_t)4u |
#define LBM_THREAD_STATE_TIMEOUT (uint32_t)2u |
typedef void(* ctx_fun) (eval_context_t *, void *, void *) |
A function pointer type to use together with the queue iterators.
typedef struct eval_context_s eval_context_t |
typedef lbm_value(* fundamental_fun) (lbm_value *, lbm_uint, eval_context_t *) |
Fundamental operation type
enum lbm_event_type_t |
Create a string channel from a C string.
str | Zero terminated C string. |
res | Resulting string channel. |
dep | Dependency that must be kept alive for as long as string channel is alive. \ return true on success and false otherwise. |
lbm_value eval_cps_get_env | ( | void | ) |
Get the global environment
void lbm_all_ctxs_iterator | ( | ctx_fun | f, |
void * | arg1, | ||
void * | arg2 | ||
) |
Iterate over ALL contexts and apply function on each context. This includes the currently running context, if there is one.
f | Function to apply to each context. |
arg1 | Pointer argument that can be used to convey information back to user. |
arg2 | Same as above. |
void lbm_block_ctx_from_extension | ( | void | ) |
Block a context from an extension
void lbm_block_ctx_from_extension_timeout | ( | float | s | ) |
Block a context from an extension with a timeout.
s | Timeout in seconds. |
void lbm_blocked_iterator | ( | ctx_fun | f, |
void * | , | ||
void * | |||
) |
Iterate over all blocked contexts and apply function on each context.
f | Function to apply to each context. |
arg1 | Pointer argument that can be used to convey information back to user. |
arg2 | Same as above |
void lbm_continue_eval | ( | void | ) |
Resume from being in EVAL_CPS_STATE_PAUSED.
Create a context and enqueue it as runnable.
program | The program to evaluate in the context. |
env | An initial environment. |
stack_size | Stack size for the context. |
name | Name of thread or NULL. |
void lbm_critical_error | ( | void | ) |
Terminate the runtime system in response to an error that it is not possible to recover from.
int lbm_eval_init | ( | void | ) |
Initialize the evaluator.
bool lbm_eval_init_events | ( | unsigned int | num_events | ) |
Initialize events
num_events | The maximum number of unprocessed events. |
Creates a context and initializes it with the provided program. The context is added to the ready queue and will start executing when the evaluator is free.
lisp | Program to launch |
An extended version of lbm_eval_program that allows specification of stack size to use.
lisp | Program to launch. |
stack_size | Size of the continuation stack for this context. |
bool lbm_event | ( | lbm_flat_value_t * | fv | ) |
Send an event to the registered event handler process. If lbm_event returns false the C code will still be responsible for the flat_value passed into lbm_event. If lbm_event returns true, the LBM runtime system will take responsibility for the freeing of the memory allocated in the flat_value.
event | The event to send to the registered handler. |
opt_array | An optional array to pass to the event handler. |
opt_array_len | Length of array mandatory if array is passed in. |
bool lbm_event_define | ( | lbm_value | key, |
lbm_flat_value_t * | fv | ||
) |
Sen an event that causes a definition to be performed at the nect convenience.
key | symbol to bind. |
fv | Flat value representation of value. |
bool lbm_event_handler_exists | ( | void | ) |
Check if an event handler is registerd.
bool lbm_event_queue_is_empty | ( | void | ) |
Check if the event queue is empty.
bool lbm_event_run_user_callback | ( | void * | arg | ) |
Send an event causing the user_callback to be run at the next convenience.
bool lbm_event_unboxed | ( | lbm_value | unboxed | ) |
Send an unboxed value as an event to the event handler.
unboxed. | An lbm_value (encoded) such as a symbol. int, uint, character. |
deliver a message
cid | Process to deliver to. |
msg | Message to deliver |
lbm_cid lbm_get_current_cid | ( | void | ) |
Get the CID of the currently executing context. Should be called from an extension where there is a guarantee that a context is running
eval_context_t* lbm_get_current_context | ( | void | ) |
Get the currently executing context. Should be called from an extension where there is a guarantee that a context is running
uint32_t lbm_get_eval_state | ( | void | ) |
Get the current state of the evaluator.
lbm_cid lbm_get_event_handler_pid | ( | void | ) |
Get the process ID for the current event handler.
void lbm_kill_eval | ( | void | ) |
This will kill the evaluator on the next iteration.
bool lbm_mailbox_change_size | ( | eval_context_t * | ctx, |
lbm_uint | new_size | ||
) |
Change the mailbox size for a given context.
ctx | The context to change mailbox size for. |
new_size | The new size of the mailbox. |
void lbm_pause_eval | ( | void | ) |
Indicate that the evaluator should pause at the next iteration. You cannot assume that the evaluator has paused unless you call lbm_get_eval_state and get the return value EVAL_CPS_STATE_PAUSED.
void lbm_pause_eval_with_gc | ( | uint32_t | num_free | ) |
Pause the evaluator and perform GC if needed.
num_free | Perform GC if there are less than this many elements free on the heap. |
int lbm_perform_gc | ( | void | ) |
Perform garbage collection, If this is called from another thread than the eval thread, evaluation must be paused! Or there will be lots of trouble!
Remove a context that has finished executing and free up its associated memory.
cid | Context id of context to free. |
v | Pointer to an lbm_value to store the result computed by the program into. Note that for comples values, GC will free these up the next time it runs. |
void lbm_request_gc | ( | void | ) |
Request that the runtime system performs a garbage collection on its earliers convenience. Can be called from any thread and does NOT require that the evaluator is paused.
void lbm_reset_eval | ( | void | ) |
Indicate that the evaluator should reset at the next opportunity. You cannot assume that the evaluator has entered reset state unless you call lbm_get_eval_state and get the return value EVAL_CPS_STATE_RESET. While in reset state, all LBM memories should be reinitialized and cleared. Use lbm_continue_eval(), to resume operation after reset.
void lbm_run_eval | ( | void | ) |
This function executes the evaluation loop and does not return. lbm_run_eval should be started in a new thread provided by the underlying HAL or OS.
void lbm_running_iterator | ( | ctx_fun | f, |
void * | , | ||
void * | |||
) |
Iterate over all ready contexts and apply function on each context.
f | Function to apply to each context. |
arg1 | Pointer argument that can be used to convey information back to user. |
arg2 | Same as above. |
void lbm_set_critical_error_callback | ( | void(*)(void) | fptr | ) |
Set the critical error callback
void lbm_set_ctx_done_callback | ( | void(*)(eval_context_t *) | fptr | ) |
Set a "done" callback function. This function will be called by the evaluator when a context finishes execution.
fptr | Pointer to a "done" function. |
void lbm_set_dynamic_load_callback | ( | bool(*)(const char *, const char **) | fptr | ) |
Set a callback for dynamically loading code associated with an undefined symbol
void lbm_set_error_reason | ( | char * | error_str | ) |
Provide a description of an error as a string. Use when implementing for example extensions to report an error message to the programmer in case the extension is used incorrectly.
The error string can be allocated in lbm_memory and will in that case be freed when the context that errored is removed.
error_str |
void lbm_set_error_suspect | ( | lbm_value | suspect | ) |
Provide the expression that is most suspicious in relation to the error at hand.
lbm_value |
void lbm_set_eval_step_quota | ( | uint32_t | quota | ) |
Set a new value to use as step quota. This changes the scheduling interval.
quota | The new quota. |
void lbm_set_event_handler_pid | ( | lbm_cid | pid | ) |
Set the event handler process ID.
pid | The ID of the process to which events should be sent |
void lbm_set_hide_trapped_error | ( | bool | hide | ) |
Hide error messages for trapped errors
hide | true to hide error messages when trapped. |
void lbm_set_printf_callback | ( | int(*)(const char *,...) | prnt | ) |
Set a "printf" callback function. This function will be called by the evaluator to report error strings back to the user.
fptr | Pointer to a "printf" function. |
void lbm_set_timestamp_us_callback | ( | uint32_t(*)(void) | fptr | ) |
Set a timestamp callback for use by the evaluator thread.
fptr | Pointer to a timestamp generating function. |
void lbm_set_user_callback | ( | void(*)(void *) | fptr | ) |
Set the arbitrary user function callback
void lbm_set_usleep_callback | ( | void(*)(uint32_t) | fptr | ) |
Set a usleep callback for use by the evaluator thread.
fptr | Pointer to a sleep function. |
void lbm_set_verbose | ( | bool | verbose | ) |
Set verbosity level of lispbm error messages.
verbose | Boolean to turn verbose errors on or off. |
void lbm_surrender_quota | ( | void | ) |
Surrenders remaining eval quota. Call this from extensions that takes non-trivial amounts of time.
void lbm_toggle_verbose | ( | void | ) |
toggle verbosity level of error messages
bool lbm_unblock_ctx | ( | lbm_cid | cid, |
lbm_flat_value_t * | fv | ||
) |
Unblock a context that has been blocked by a C extension Trying to unblock a context that is waiting on a message in a mailbox is not encouraged
cid | Lisp process to wake up. |
fv | lbm_flat_value to give return as result from the unblocket process. |
bool lbm_unblock_ctx_r | ( | lbm_cid | cid | ) |
Unblock a context bypassing the event-queue. The return value is unchanged from when the context was blocked.
cid | Lisp process to unblock. |
Unblock a context bypassing the event-queue. Since the context will be unblocked in a separate tread it cannot take a composite return value. Only unboxed lbm_values are allowed.
cid | Lisp process to unblock. |
unboxed | An unboxed lbm_value: char, i, u or symbol type. |
void lbm_undo_block_ctx_from_extension | ( | void | ) |
Undo a previous call to lbm_block_ctx_from_extension.
bool lift_char_channel | ( | lbm_char_channel_t * | ch, |
lbm_value * | res | ||
) |
lbm_flash_status request_flash_storage_cell | ( | lbm_value | val, |
lbm_value * | res | ||
) |
const fundamental_fun fundamental_table[] |