LispBM
Data Structures | Macros | Typedefs | Enumerations | Functions | Variables
eval_cps.c File Reference
#include <lbm_memory.h>
#include <lbm_types.h>
#include "symrepr.h"
#include "heap.h"
#include "env.h"
#include "eval_cps.h"
#include "stack.h"
#include "fundamental.h"
#include "extensions.h"
#include "tokpar.h"
#include "lbm_channel.h"
#include "print.h"
#include "platform_mutex.h"
#include "lbm_flat_value.h"
#include "lbm_flags.h"
#include <setjmp.h>
#include <stdarg.h>
Include dependency graph for eval_cps.c:

Data Structures

struct  eval_context_queue_t
 

Macros

#define S_TO_US(X)   (lbm_uint)((X) * 1000000)
 
#define DEC_CONTINUATION(x)   (((x) & ~LBM_CONTINUATION_INTERNAL) >> LBM_ADDRESS_SHIFT)
 
#define IS_CONTINUATION(x)   (((x) & LBM_CONTINUATION_INTERNAL) == LBM_CONTINUATION_INTERNAL)
 
#define CONTINUATION(x)   (((x) << LBM_ADDRESS_SHIFT) | LBM_CONTINUATION_INTERNAL)
 
#define DONE   CONTINUATION(0)
 
#define SET_GLOBAL_ENV   CONTINUATION(1)
 
#define BIND_TO_KEY_REST   CONTINUATION(2)
 
#define IF   CONTINUATION(3)
 
#define PROGN_REST   CONTINUATION(4)
 
#define APPLICATION_ARGS   CONTINUATION(5)
 
#define AND   CONTINUATION(6)
 
#define OR   CONTINUATION(7)
 
#define WAIT   CONTINUATION(8)
 
#define MATCH   CONTINUATION(9)
 
#define APPLICATION_START   CONTINUATION(10)
 
#define EVAL_R   CONTINUATION(11)
 
#define RESUME   CONTINUATION(12)
 
#define CLOSURE_ARGS   CONTINUATION(13)
 
#define EXIT_ATOMIC   CONTINUATION(14)
 
#define READ_NEXT_TOKEN   CONTINUATION(15)
 
#define READ_APPEND_CONTINUE   CONTINUATION(16)
 
#define READ_EVAL_CONTINUE   CONTINUATION(17)
 
#define READ_EXPECT_CLOSEPAR   CONTINUATION(18)
 
#define READ_DOT_TERMINATE   CONTINUATION(19)
 
#define READ_DONE   CONTINUATION(20)
 
#define READ_QUOTE_RESULT   CONTINUATION(21)
 
#define READ_COMMAAT_RESULT   CONTINUATION(22)
 
#define READ_COMMA_RESULT   CONTINUATION(23)
 
#define READ_START_ARRAY   CONTINUATION(24)
 
#define READ_APPEND_ARRAY   CONTINUATION(25)
 
#define MAP   CONTINUATION(26)
 
#define MATCH_GUARD   CONTINUATION(27)
 
#define TERMINATE   CONTINUATION(28)
 
#define PROGN_VAR   CONTINUATION(29)
 
#define SETQ   CONTINUATION(30)
 
#define MOVE_TO_FLASH   CONTINUATION(31)
 
#define MOVE_VAL_TO_FLASH_DISPATCH   CONTINUATION(32)
 
#define MOVE_LIST_TO_FLASH   CONTINUATION(33)
 
#define CLOSE_LIST_IN_FLASH   CONTINUATION(34)
 
#define QQ_EXPAND_START   CONTINUATION(35)
 
#define QQ_EXPAND   CONTINUATION(36)
 
#define QQ_APPEND   CONTINUATION(37)
 
#define QQ_EXPAND_LIST   CONTINUATION(38)
 
#define QQ_LIST   CONTINUATION(39)
 
#define KILL   CONTINUATION(40)
 
#define LOOP   CONTINUATION(41)
 
#define LOOP_CONDITION   CONTINUATION(42)
 
#define MERGE_REST   CONTINUATION(43)
 
#define MERGE_LAYER   CONTINUATION(44)
 
#define CLOSURE_ARGS_REST   CONTINUATION(45)
 
#define MOVE_ARRAY_ELTS_TO_FLASH   CONTINUATION(46)
 
#define POP_READER_FLAGS   CONTINUATION(47)
 
#define EXCEPTION_HANDLER   CONTINUATION(48)
 
#define RECV_TO   CONTINUATION(49)
 
#define NUM_CONTINUATIONS   50
 
#define FM_NEED_GC   -1
 
#define FM_NO_MATCH   -2
 
#define FM_PATTERN_ERROR   -3
 
#define FB_OK   0
 
#define FB_TYPE_ERROR   -1
 
#define WITH_GC(y, x)
 
#define WITH_GC_RMBR_1(y, x, r)
 
#define EVAL_CPS_DEFAULT_STACK_SIZE   256
 
#define EVAL_CPS_MIN_SLEEP   200
 
#define EVAL_STEPS_QUOTA   10
 
#define CLO_PARAMS   0
 
#define CLO_BODY   1
 
#define CLO_ENV   2
 
#define LOOP_BINDS   0
 
#define LOOP_COND   1
 
#define LOOP_BODY   2
 
#define ERROR_MESSAGE_BUFFER_SIZE_BYTES   256
 
#define KEY   1
 
#define VAL   2
 
#define READING_EXPRESSION   ((0 << LBM_VAL_SHIFT) | LBM_TYPE_U)
 
#define READING_PROGRAM   ((1 << LBM_VAL_SHIFT) | LBM_TYPE_U)
 
#define READING_PROGRAM_INCREMENTALLY   ((2 << LBM_VAL_SHIFT) | LBM_TYPE_U)
 

Typedefs

typedef void(* apply_fun) (lbm_value *, lbm_uint, eval_context_t *)
 
typedef void(* cont_fun) (eval_context_t *)
 
typedef void(* evaluator_fun) (eval_context_t *)
 

Enumerations

enum  binding_location_status { BL_OK = 0, BL_NO_MEMORY, BL_INCORRECT_KEY }
 

Functions

static int gc (void)
 
static void error_ctx (lbm_value)
 
static void error_at_ctx (lbm_value err_val, lbm_value at)
 
static void enqueue_ctx (eval_context_queue_t *q, eval_context_t *ctx)
 
static bool mailbox_add_mail (eval_context_t *ctx, lbm_value mail)
 
void lbm_request_gc (void)
 
void lbm_set_eval_step_quota (uint32_t quota)
 
static void usleep_nonsense (uint32_t us)
 
static bool dynamic_load_nonsense (const char *sym, const char **code)
 
static uint32_t timestamp_nonsense (void)
 
static int printf_nonsense (const char *fmt,...)
 
static void ctx_done_nonsense (eval_context_t *ctx)
 
static void critical_nonsense (void)
 
static void user_callback_nonsense (void *arg)
 
void lbm_set_user_callback (void(*fptr)(void *))
 
void lbm_set_critical_error_callback (void(*fptr)(void))
 
void lbm_set_usleep_callback (void(*fptr)(uint32_t))
 
void lbm_set_timestamp_us_callback (uint32_t(*fptr)(void))
 
void lbm_set_ctx_done_callback (void(*fptr)(eval_context_t *))
 
void lbm_set_printf_callback (int(*fptr)(const char *,...))
 
void lbm_set_dynamic_load_callback (bool(*fptr)(const char *, const char **))
 
lbm_cid lbm_get_event_handler_pid (void)
 
void lbm_set_event_handler_pid (lbm_cid pid)
 
bool lbm_event_handler_exists (void)
 
static bool event_internal (lbm_event_type_t event_type, lbm_uint parameter, lbm_uint buf_ptr, lbm_uint buf_len)
 
bool lbm_event_define (lbm_value key, lbm_flat_value_t *fv)
 
bool lbm_event_run_user_callback (void *arg)
 
bool lbm_event_unboxed (lbm_value unboxed)
 
bool lbm_event (lbm_flat_value_t *fv)
 
static bool lbm_event_pop (lbm_event_t *event)
 
bool lbm_event_queue_is_empty (void)
 
void lbm_toggle_verbose (void)
 
void lbm_set_verbose (bool verbose)
 
lbm_cid lbm_get_current_cid (void)
 
eval_context_tlbm_get_current_context (void)
 
static lbm_array_header_tassume_array (lbm_value a)
 
static lbm_value cons_with_gc (lbm_value head, lbm_value tail, lbm_value remember)
 
static lbm_uintget_stack_ptr (eval_context_t *ctx, unsigned int n)
 
static lbm_uintpop_stack_ptr (eval_context_t *ctx, unsigned int n)
 
static lbm_uintstack_reserve (eval_context_t *ctx, unsigned int n)
 
static void handle_flash_status (lbm_flash_status s)
 
static void lift_array_flash (lbm_value flash_cell, bool bytearray, char *data, lbm_uint num_elt)
 
static void get_car_and_cdr (lbm_value a, lbm_value *a_car, lbm_value *a_cdr)
 
static lbm_value get_car (lbm_value a)
 
static lbm_value get_cdr (lbm_value a)
 
static lbm_value get_cadr (lbm_value a)
 
static lbm_value allocate_closure (lbm_value params, lbm_value body, lbm_value env)
 
static lbm_value allocate_binding (lbm_value key, lbm_value val, lbm_value the_cdr)
 
static lbm_value extract_n (lbm_value curr, lbm_value *res, unsigned int n)
 
static void call_fundamental (lbm_uint fundamental, lbm_value *args, lbm_uint arg_count, eval_context_t *ctx)
 
static void atomic_error (void)
 
static void block_current_ctx (uint32_t state, lbm_uint sleep_us, bool do_cont)
 
lbm_flash_status lbm_write_const_array_padded (uint8_t *data, lbm_uint n, lbm_uint *res)
 
void print_environments (char *buf, unsigned int size)
 
void print_error_message (lbm_value error, bool has_at, lbm_value at, unsigned int row, unsigned int col, lbm_int row0, lbm_int row1, lbm_int cid, char *name)
 
bool create_string_channel (char *str, lbm_value *res)
 
bool lift_char_channel (lbm_char_channel_t *chan, lbm_value *res)
 
static void queue_iterator_nm (eval_context_queue_t *q, ctx_fun f, void *arg1, void *arg2)
 
void lbm_running_iterator (ctx_fun f, void *arg1, void *arg2)
 
void lbm_blocked_iterator (ctx_fun f, void *arg1, void *arg2)
 
static void enqueue_ctx_nm (eval_context_queue_t *q, eval_context_t *ctx)
 
static eval_context_tlookup_ctx_nm (eval_context_queue_t *q, lbm_cid cid)
 
static bool drop_ctx_nm (eval_context_queue_t *q, eval_context_t *ctx)
 
static void finish_ctx (void)
 
static void context_exists (eval_context_t *ctx, void *cid, void *b)
 
void lbm_set_error_suspect (lbm_value suspect)
 
void lbm_set_error_reason (char *error_str)
 
static void error_ctx_base (lbm_value err_val, bool has_at, lbm_value at, unsigned int row, unsigned int column)
 
static void read_error_ctx (unsigned int row, unsigned int column)
 
void lbm_critical_error (void)
 
static void ok_ctx (void)
 
static eval_context_tdequeue_ctx_nm (eval_context_queue_t *q)
 
static void wake_up_ctxs_nm (void)
 
static void yield_ctx (lbm_uint sleep_us)
 
static lbm_cid lbm_create_ctx_parent (lbm_value program, lbm_value env, lbm_uint stack_size, lbm_cid parent, uint32_t context_flags, char *name)
 
lbm_cid lbm_create_ctx (lbm_value program, lbm_value env, lbm_uint stack_size, char *name)
 
bool lbm_mailbox_change_size (eval_context_t *ctx, lbm_uint new_size)
 
static void mailbox_remove_mail (eval_context_t *ctx, lbm_uint ix)
 
static void advance_ctx (eval_context_t *ctx)
 
bool lbm_unblock_ctx (lbm_cid cid, lbm_flat_value_t *fv)
 
bool lbm_unblock_ctx_r (lbm_cid cid)
 
bool lbm_unblock_ctx_unboxed (lbm_cid cid, lbm_value unboxed)
 
static bool lbm_block_ctx_base (bool timeout, float t_s)
 
void lbm_block_ctx_from_extension_timeout (float s)
 
void lbm_block_ctx_from_extension (void)
 
void lbm_undo_block_ctx_from_extension (void)
 
lbm_value lbm_find_receiver_and_send (lbm_cid cid, lbm_value msg)
 
static lbm_value get_match_binder_variable (lbm_value exp)
 
static bool match (lbm_value p, lbm_value e, lbm_value *env, bool *gc)
 
static int find_match (lbm_value plist, lbm_value *earr, lbm_uint num, lbm_value *e, lbm_value *env)
 
static void mark_context (eval_context_t *ctx, void *arg1, void *arg2)
 
int lbm_perform_gc (void)
 
static void eval_symbol (eval_context_t *ctx)
 
static void eval_quote (eval_context_t *ctx)
 
static void eval_selfevaluating (eval_context_t *ctx)
 
static void eval_progn (eval_context_t *ctx)
 
static void eval_atomic (eval_context_t *ctx)
 
static void eval_callcc (eval_context_t *ctx)
 
static void eval_define (eval_context_t *ctx)
 
static void eval_lambda (eval_context_t *ctx)
 
static void eval_if (eval_context_t *ctx)
 
static void eval_cond (eval_context_t *ctx)
 
static void eval_app_cont (eval_context_t *ctx)
 
static binding_location_status create_binding_location_internal (lbm_value key, lbm_value *env)
 
static void create_binding_location (lbm_value key, lbm_value *env)
 
static void let_bind_values_eval (lbm_value binds, lbm_value exp, lbm_value env, eval_context_t *ctx)
 
static void eval_var (eval_context_t *ctx)
 
static void eval_setq (eval_context_t *ctx)
 
static void eval_move_to_flash (eval_context_t *ctx)
 
static void eval_loop (eval_context_t *ctx)
 
static void eval_trap (eval_context_t *ctx)
 
static void eval_let (eval_context_t *ctx)
 
static void eval_and (eval_context_t *ctx)
 
static void eval_or (eval_context_t *ctx)
 
static void eval_match (eval_context_t *ctx)
 
static void receive_base (eval_context_t *ctx, lbm_value pats, float timeout_time, bool timeout)
 
static void eval_receive_timeout (eval_context_t *ctx)
 
static void eval_receive (eval_context_t *ctx)
 
static void cont_set_global_env (eval_context_t *ctx)
 
static void cont_resume (eval_context_t *ctx)
 
static void cont_progn_rest (eval_context_t *ctx)
 
static void cont_wait (eval_context_t *ctx)
 
static lbm_value perform_setvar (lbm_value key, lbm_value val, lbm_value env)
 
static void apply_setvar (lbm_value *args, lbm_uint nargs, eval_context_t *ctx)
 
static void apply_read_base (lbm_value *args, lbm_uint nargs, eval_context_t *ctx, bool program, bool incremental)
 
static void apply_read_program (lbm_value *args, lbm_uint nargs, eval_context_t *ctx)
 
static void apply_read_eval_program (lbm_value *args, lbm_uint nargs, eval_context_t *ctx)
 
static void apply_read (lbm_value *args, lbm_uint nargs, eval_context_t *ctx)
 
static void apply_spawn_base (lbm_value *args, lbm_uint nargs, eval_context_t *ctx, uint32_t context_flags)
 
static void apply_spawn (lbm_value *args, lbm_uint nargs, eval_context_t *ctx)
 
static void apply_spawn_trap (lbm_value *args, lbm_uint nargs, eval_context_t *ctx)
 
static void apply_yield (lbm_value *args, lbm_uint nargs, eval_context_t *ctx)
 
static void apply_sleep (lbm_value *args, lbm_uint nargs, eval_context_t *ctx)
 
static void apply_wait (lbm_value *args, lbm_uint nargs, eval_context_t *ctx)
 
static void apply_eval (lbm_value *args, lbm_uint nargs, eval_context_t *ctx)
 
static void apply_eval_program (lbm_value *args, lbm_uint nargs, eval_context_t *ctx)
 
static void apply_send (lbm_value *args, lbm_uint nargs, eval_context_t *ctx)
 
static void apply_ok (lbm_value *args, lbm_uint nargs, eval_context_t *ctx)
 
static void apply_error (lbm_value *args, lbm_uint nargs, eval_context_t *ctx)
 
static void apply_map (lbm_value *args, lbm_uint nargs, eval_context_t *ctx)
 
static void apply_reverse (lbm_value *args, lbm_uint nargs, eval_context_t *ctx)
 
static void apply_flatten (lbm_value *args, lbm_uint nargs, eval_context_t *ctx)
 
static void apply_unflatten (lbm_value *args, lbm_uint nargs, eval_context_t *ctx)
 
static void apply_kill (lbm_value *args, lbm_uint nargs, eval_context_t *ctx)
 
static lbm_value cmp_to_clo (lbm_value cmp)
 
static void apply_merge (lbm_value *args, lbm_uint nargs, eval_context_t *ctx)
 
static void apply_sort (lbm_value *args, lbm_uint nargs, eval_context_t *ctx)
 
static void apply_rest_args (lbm_value *args, lbm_uint nargs, eval_context_t *ctx)
 
static void apply_rotate (lbm_value *args, lbm_uint nargs, eval_context_t *ctx)
 
static void application (eval_context_t *ctx, lbm_value *fun_args, lbm_uint arg_count)
 
static void cont_closure_application_args (eval_context_t *ctx)
 
static void cont_closure_args_rest (eval_context_t *ctx)
 
static void cont_application_args (eval_context_t *ctx)
 
static void cont_and (eval_context_t *ctx)
 
static void cont_or (eval_context_t *ctx)
 
static int fill_binding_location (lbm_value key, lbm_value value, lbm_value env)
 
static void cont_bind_to_key_rest (eval_context_t *ctx)
 
static void cont_if (eval_context_t *ctx)
 
static void cont_match (eval_context_t *ctx)
 
static void cont_exit_atomic (eval_context_t *ctx)
 
static void cont_map (eval_context_t *ctx)
 
static void cont_match_guard (eval_context_t *ctx)
 
static void cont_terminate (eval_context_t *ctx)
 
static void cont_loop (eval_context_t *ctx)
 
static void cont_loop_condition (eval_context_t *ctx)
 
static void cont_merge_rest (eval_context_t *ctx)
 
static void cont_merge_layer (eval_context_t *ctx)
 
static void read_finish (lbm_char_channel_t *str, eval_context_t *ctx)
 
static void cont_read_next_token (eval_context_t *ctx)
 
static void cont_read_start_array (eval_context_t *ctx)
 
static void cont_read_append_array (eval_context_t *ctx)
 
static void cont_read_append_continue (eval_context_t *ctx)
 
static void cont_read_eval_continue (eval_context_t *ctx)
 
static void cont_read_expect_closepar (eval_context_t *ctx)
 
static void cont_read_dot_terminate (eval_context_t *ctx)
 
static void cont_read_done (eval_context_t *ctx)
 
static void cont_read_quote_result (eval_context_t *ctx)
 
static void cont_read_commaat_result (eval_context_t *ctx)
 
static void cont_read_comma_result (eval_context_t *ctx)
 
static void cont_application_start (eval_context_t *ctx)
 
static void cont_eval_r (eval_context_t *ctx)
 
static void cont_progn_var (eval_context_t *ctx)
 
static void cont_setq (eval_context_t *ctx)
 
lbm_flash_status request_flash_storage_cell (lbm_value val, lbm_value *res)
 
static void cont_move_to_flash (eval_context_t *ctx)
 
static void cont_move_val_to_flash_dispatch (eval_context_t *ctx)
 
static void cont_move_list_to_flash (eval_context_t *ctx)
 
static void cont_close_list_in_flash (eval_context_t *ctx)
 
static void cont_move_array_elts_to_flash (eval_context_t *ctx)
 
static void cont_qq_expand_start (eval_context_t *ctx)
 
lbm_value quote_it (lbm_value qquoted)
 
bool is_append (lbm_value a)
 
lbm_value append (lbm_value front, lbm_value back)
 
static void cont_qq_expand (eval_context_t *ctx)
 
static void cont_qq_append (eval_context_t *ctx)
 
static void cont_qq_expand_list (eval_context_t *ctx)
 
static void cont_qq_list (eval_context_t *ctx)
 
static void cont_kill (eval_context_t *ctx)
 
static void cont_pop_reader_flags (eval_context_t *ctx)
 
static void cont_exception_handler (eval_context_t *ctx)
 
static void cont_recv_to (eval_context_t *ctx)
 
static void evaluation_step (void)
 
void lbm_reset_eval (void)
 
void lbm_pause_eval (void)
 
void lbm_pause_eval_with_gc (uint32_t num_free)
 
void lbm_continue_eval (void)
 
void lbm_kill_eval (void)
 
uint32_t lbm_get_eval_state (void)
 
static void handle_event_unblock_ctx (lbm_cid cid, lbm_value v)
 
static void handle_event_define (lbm_value key, lbm_value val)
 
static lbm_value get_event_value (lbm_event_t *e)
 
static void process_events (void)
 
void lbm_run_eval (void)
 
lbm_cid lbm_eval_program (lbm_value lisp)
 
lbm_cid lbm_eval_program_ext (lbm_value lisp, unsigned int stack_size)
 
int lbm_eval_init ()
 
bool lbm_eval_init_events (unsigned int num_events)
 

Variables

static jmp_buf error_jmp_buf
 
static jmp_buf critical_error_jmp_buf
 
const char * lbm_error_str_parse_eof = "End of parse stream."
 
const char * lbm_error_str_parse_dot = "Incorrect usage of '.'."
 
const char * lbm_error_str_parse_close = "Expected closing parenthesis."
 
const char * lbm_error_str_num_args = "Incorrect number of arguments."
 
const char * lbm_error_str_forbidden_in_atomic = "Operation is forbidden in an atomic block."
 
const char * lbm_error_str_no_number = "Argument(s) must be a number."
 
const char * lbm_error_str_not_a_boolean = "Argument must be t or nil (true or false)."
 
const char * lbm_error_str_incorrect_arg = "Incorrect argument."
 
const char * lbm_error_str_var_outside_progn = "Usage of var outside of progn."
 
const char * lbm_error_str_flash_not_possible = "Value cannot be written to flash."
 
const char * lbm_error_str_flash_error = "Error writing to flash."
 
const char * lbm_error_str_flash_full = "Flash memory is full."
 
const char * lbm_error_str_variable_not_bound = "Variable not bound."
 
const char * lbm_error_str_read_no_mem = "Out of memory while reading."
 
static lbm_value lbm_error_suspect
 
static bool lbm_error_has_suspect = false
 
eval_context_tctx_running = NULL
 
volatile bool lbm_system_sleeping = false
 
static volatile bool gc_requested = false
 
static volatile uint32_t eval_steps_refill = EVAL_STEPS_QUOTA
 
static uint32_t eval_steps_quota = EVAL_STEPS_QUOTA
 
static uint32_t eval_cps_run_state = EVAL_CPS_STATE_DEAD
 
static volatile uint32_t eval_cps_next_state = EVAL_CPS_STATE_NONE
 
static volatile uint32_t eval_cps_next_state_arg = 0
 
static volatile bool eval_cps_state_changed = false
 
static void(* critical_error_callback )(void) = critical_nonsense
 
static void(* usleep_callback )(uint32_t) = usleep_nonsense
 
static uint32_t(* timestamp_us_callback )(void) = timestamp_nonsense
 
static void(* ctx_done_callback )(eval_context_t *) = ctx_done_nonsense
 
static int(* printf_callback )(const char *,...) = printf_nonsense
 
static bool(* dynamic_load_callback )(const char *, const char **) = dynamic_load_nonsense
 
static void(* user_callback )(void *) = user_callback_nonsense
 
static volatile lbm_event_tlbm_events = NULL
 
static unsigned int lbm_events_head = 0
 
static unsigned int lbm_events_tail = 0
 
static unsigned int lbm_events_max = 0
 
static bool lbm_events_full = false
 
static mutex_t lbm_events_mutex
 
static bool lbm_events_mutex_initialized = false
 
static volatile lbm_cid lbm_event_handler_pid = -1
 
static bool eval_running = false
 
static volatile bool blocking_extension = false
 
static mutex_t blocking_extension_mutex
 
static bool blocking_extension_mutex_initialized = false
 
static lbm_uint blocking_extension_timeout_us = 0
 
static bool blocking_extension_timeout = false
 
static bool is_atomic = false
 
static eval_context_queue_t blocked = {NULL, NULL}
 
static eval_context_queue_t queue = {NULL, NULL}
 
mutex_t qmutex
 
bool qmutex_initialized = false
 
static volatile bool lbm_verbose = false
 
static const apply_fun fun_table []
 
static const cont_fun continuations [NUM_CONTINUATIONS]
 
static const evaluator_fun evaluators []
 

Macro Definition Documentation

◆ AND

#define AND   CONTINUATION(6)

◆ APPLICATION_ARGS

#define APPLICATION_ARGS   CONTINUATION(5)

◆ APPLICATION_START

#define APPLICATION_START   CONTINUATION(10)

◆ BIND_TO_KEY_REST

#define BIND_TO_KEY_REST   CONTINUATION(2)

◆ CLO_BODY

#define CLO_BODY   1

◆ CLO_ENV

#define CLO_ENV   2

◆ CLO_PARAMS

#define CLO_PARAMS   0

◆ CLOSE_LIST_IN_FLASH

#define CLOSE_LIST_IN_FLASH   CONTINUATION(34)

◆ CLOSURE_ARGS

#define CLOSURE_ARGS   CONTINUATION(13)

◆ CLOSURE_ARGS_REST

#define CLOSURE_ARGS_REST   CONTINUATION(45)

◆ CONTINUATION

#define CONTINUATION (   x)    (((x) << LBM_ADDRESS_SHIFT) | LBM_CONTINUATION_INTERNAL)

◆ DEC_CONTINUATION

#define DEC_CONTINUATION (   x)    (((x) & ~LBM_CONTINUATION_INTERNAL) >> LBM_ADDRESS_SHIFT)

◆ DONE

#define DONE   CONTINUATION(0)

◆ ERROR_MESSAGE_BUFFER_SIZE_BYTES

#define ERROR_MESSAGE_BUFFER_SIZE_BYTES   256

◆ EVAL_CPS_DEFAULT_STACK_SIZE

#define EVAL_CPS_DEFAULT_STACK_SIZE   256

◆ EVAL_CPS_MIN_SLEEP

#define EVAL_CPS_MIN_SLEEP   200

◆ EVAL_R

#define EVAL_R   CONTINUATION(11)

◆ EVAL_STEPS_QUOTA

#define EVAL_STEPS_QUOTA   10

◆ EXCEPTION_HANDLER

#define EXCEPTION_HANDLER   CONTINUATION(48)

◆ EXIT_ATOMIC

#define EXIT_ATOMIC   CONTINUATION(14)

◆ FB_OK

#define FB_OK   0

◆ FB_TYPE_ERROR

#define FB_TYPE_ERROR   -1

◆ FM_NEED_GC

#define FM_NEED_GC   -1

◆ FM_NO_MATCH

#define FM_NO_MATCH   -2

◆ FM_PATTERN_ERROR

#define FM_PATTERN_ERROR   -3

◆ IF

#define IF   CONTINUATION(3)

◆ IS_CONTINUATION

#define IS_CONTINUATION (   x)    (((x) & LBM_CONTINUATION_INTERNAL) == LBM_CONTINUATION_INTERNAL)

◆ KEY

#define KEY   1

◆ KILL

#define KILL   CONTINUATION(40)

◆ LOOP

#define LOOP   CONTINUATION(41)

◆ LOOP_BINDS

#define LOOP_BINDS   0

◆ LOOP_BODY

#define LOOP_BODY   2

◆ LOOP_COND

#define LOOP_COND   1

◆ LOOP_CONDITION

#define LOOP_CONDITION   CONTINUATION(42)

◆ MAP

#define MAP   CONTINUATION(26)

◆ MATCH

#define MATCH   CONTINUATION(9)

◆ MATCH_GUARD

#define MATCH_GUARD   CONTINUATION(27)

◆ MERGE_LAYER

#define MERGE_LAYER   CONTINUATION(44)

◆ MERGE_REST

#define MERGE_REST   CONTINUATION(43)

◆ MOVE_ARRAY_ELTS_TO_FLASH

#define MOVE_ARRAY_ELTS_TO_FLASH   CONTINUATION(46)

◆ MOVE_LIST_TO_FLASH

#define MOVE_LIST_TO_FLASH   CONTINUATION(33)

◆ MOVE_TO_FLASH

#define MOVE_TO_FLASH   CONTINUATION(31)

◆ MOVE_VAL_TO_FLASH_DISPATCH

#define MOVE_VAL_TO_FLASH_DISPATCH   CONTINUATION(32)

◆ NUM_CONTINUATIONS

#define NUM_CONTINUATIONS   50

◆ OR

#define OR   CONTINUATION(7)

◆ POP_READER_FLAGS

#define POP_READER_FLAGS   CONTINUATION(47)

◆ PROGN_REST

#define PROGN_REST   CONTINUATION(4)

◆ PROGN_VAR

#define PROGN_VAR   CONTINUATION(29)

◆ QQ_APPEND

#define QQ_APPEND   CONTINUATION(37)

◆ QQ_EXPAND

#define QQ_EXPAND   CONTINUATION(36)

◆ QQ_EXPAND_LIST

#define QQ_EXPAND_LIST   CONTINUATION(38)

◆ QQ_EXPAND_START

#define QQ_EXPAND_START   CONTINUATION(35)

◆ QQ_LIST

#define QQ_LIST   CONTINUATION(39)

◆ READ_APPEND_ARRAY

#define READ_APPEND_ARRAY   CONTINUATION(25)

◆ READ_APPEND_CONTINUE

#define READ_APPEND_CONTINUE   CONTINUATION(16)

◆ READ_COMMA_RESULT

#define READ_COMMA_RESULT   CONTINUATION(23)

◆ READ_COMMAAT_RESULT

#define READ_COMMAAT_RESULT   CONTINUATION(22)

◆ READ_DONE

#define READ_DONE   CONTINUATION(20)

◆ READ_DOT_TERMINATE

#define READ_DOT_TERMINATE   CONTINUATION(19)

◆ READ_EVAL_CONTINUE

#define READ_EVAL_CONTINUE   CONTINUATION(17)

◆ READ_EXPECT_CLOSEPAR

#define READ_EXPECT_CLOSEPAR   CONTINUATION(18)

◆ READ_NEXT_TOKEN

#define READ_NEXT_TOKEN   CONTINUATION(15)

◆ READ_QUOTE_RESULT

#define READ_QUOTE_RESULT   CONTINUATION(21)

◆ READ_START_ARRAY

#define READ_START_ARRAY   CONTINUATION(24)

◆ READING_EXPRESSION

#define READING_EXPRESSION   ((0 << LBM_VAL_SHIFT) | LBM_TYPE_U)

◆ READING_PROGRAM

#define READING_PROGRAM   ((1 << LBM_VAL_SHIFT) | LBM_TYPE_U)

◆ READING_PROGRAM_INCREMENTALLY

#define READING_PROGRAM_INCREMENTALLY   ((2 << LBM_VAL_SHIFT) | LBM_TYPE_U)

◆ RECV_TO

#define RECV_TO   CONTINUATION(49)

◆ RESUME

#define RESUME   CONTINUATION(12)

◆ S_TO_US

#define S_TO_US (   X)    (lbm_uint)((X) * 1000000)

◆ SET_GLOBAL_ENV

#define SET_GLOBAL_ENV   CONTINUATION(1)

◆ SETQ

#define SETQ   CONTINUATION(30)

◆ TERMINATE

#define TERMINATE   CONTINUATION(28)

◆ VAL

#define VAL   2

◆ WAIT

#define WAIT   CONTINUATION(8)

◆ WITH_GC

#define WITH_GC (   y,
 
)
Value:
(y) = (x); \
if (lbm_is_symbol_merror((y))) { \
gc(); \
(y) = (x); \
if (lbm_is_symbol_merror((y))) { \
error_ctx(ENC_SYM_MERROR); \
} \
/* continue executing statements below */ \
}

◆ WITH_GC_RMBR_1

#define WITH_GC_RMBR_1 (   y,
  x,
 
)
Value:
(y) = (x); \
if (lbm_is_symbol_merror((y))) { \
lbm_gc_mark_phase(r); \
gc(); \
(y) = (x); \
if (lbm_is_symbol_merror((y))) { \
error_ctx(ENC_SYM_MERROR); \
} \
/* continue executing statements below */ \
}

Typedef Documentation

◆ apply_fun

typedef void(* apply_fun) (lbm_value *, lbm_uint, eval_context_t *)

◆ cont_fun

typedef void(* cont_fun) (eval_context_t *)

◆ evaluator_fun

typedef void(* evaluator_fun) (eval_context_t *)

Enumeration Type Documentation

◆ binding_location_status

Enumerator
BL_OK 
BL_NO_MEMORY 
BL_INCORRECT_KEY 

Function Documentation

◆ advance_ctx()

static void advance_ctx ( eval_context_t ctx)
static

◆ allocate_binding()

static lbm_value allocate_binding ( lbm_value  key,
lbm_value  val,
lbm_value  the_cdr 
)
static

◆ allocate_closure()

static lbm_value allocate_closure ( lbm_value  params,
lbm_value  body,
lbm_value  env 
)
static

◆ append()

lbm_value append ( lbm_value  front,
lbm_value  back 
)

◆ application()

static void application ( eval_context_t ctx,
lbm_value fun_args,
lbm_uint  arg_count 
)
static

◆ apply_error()

static void apply_error ( lbm_value args,
lbm_uint  nargs,
eval_context_t ctx 
)
static

◆ apply_eval()

static void apply_eval ( lbm_value args,
lbm_uint  nargs,
eval_context_t ctx 
)
static

◆ apply_eval_program()

static void apply_eval_program ( lbm_value args,
lbm_uint  nargs,
eval_context_t ctx 
)
static

◆ apply_flatten()

static void apply_flatten ( lbm_value args,
lbm_uint  nargs,
eval_context_t ctx 
)
static

◆ apply_kill()

static void apply_kill ( lbm_value args,
lbm_uint  nargs,
eval_context_t ctx 
)
static

◆ apply_map()

static void apply_map ( lbm_value args,
lbm_uint  nargs,
eval_context_t ctx 
)
static

◆ apply_merge()

static void apply_merge ( lbm_value args,
lbm_uint  nargs,
eval_context_t ctx 
)
static

◆ apply_ok()

static void apply_ok ( lbm_value args,
lbm_uint  nargs,
eval_context_t ctx 
)
static

◆ apply_read()

static void apply_read ( lbm_value args,
lbm_uint  nargs,
eval_context_t ctx 
)
static

◆ apply_read_base()

static void apply_read_base ( lbm_value args,
lbm_uint  nargs,
eval_context_t ctx,
bool  program,
bool  incremental 
)
static

◆ apply_read_eval_program()

static void apply_read_eval_program ( lbm_value args,
lbm_uint  nargs,
eval_context_t ctx 
)
static

◆ apply_read_program()

static void apply_read_program ( lbm_value args,
lbm_uint  nargs,
eval_context_t ctx 
)
static

◆ apply_rest_args()

static void apply_rest_args ( lbm_value args,
lbm_uint  nargs,
eval_context_t ctx 
)
static

◆ apply_reverse()

static void apply_reverse ( lbm_value args,
lbm_uint  nargs,
eval_context_t ctx 
)
static

◆ apply_rotate()

static void apply_rotate ( lbm_value args,
lbm_uint  nargs,
eval_context_t ctx 
)
static

◆ apply_send()

static void apply_send ( lbm_value args,
lbm_uint  nargs,
eval_context_t ctx 
)
static

◆ apply_setvar()

static void apply_setvar ( lbm_value args,
lbm_uint  nargs,
eval_context_t ctx 
)
static

◆ apply_sleep()

static void apply_sleep ( lbm_value args,
lbm_uint  nargs,
eval_context_t ctx 
)
static

◆ apply_sort()

static void apply_sort ( lbm_value args,
lbm_uint  nargs,
eval_context_t ctx 
)
static

◆ apply_spawn()

static void apply_spawn ( lbm_value args,
lbm_uint  nargs,
eval_context_t ctx 
)
static

◆ apply_spawn_base()

static void apply_spawn_base ( lbm_value args,
lbm_uint  nargs,
eval_context_t ctx,
uint32_t  context_flags 
)
static

◆ apply_spawn_trap()

static void apply_spawn_trap ( lbm_value args,
lbm_uint  nargs,
eval_context_t ctx 
)
static

◆ apply_unflatten()

static void apply_unflatten ( lbm_value args,
lbm_uint  nargs,
eval_context_t ctx 
)
static

◆ apply_wait()

static void apply_wait ( lbm_value args,
lbm_uint  nargs,
eval_context_t ctx 
)
static

◆ apply_yield()

static void apply_yield ( lbm_value args,
lbm_uint  nargs,
eval_context_t ctx 
)
static

◆ assume_array()

static lbm_array_header_t* assume_array ( lbm_value  a)
inlinestatic

◆ atomic_error()

static void atomic_error ( void  )
static

◆ block_current_ctx()

static void block_current_ctx ( uint32_t  state,
lbm_uint  sleep_us,
bool  do_cont 
)
static

◆ call_fundamental()

static void call_fundamental ( lbm_uint  fundamental,
lbm_value args,
lbm_uint  arg_count,
eval_context_t ctx 
)
static

◆ cmp_to_clo()

static lbm_value cmp_to_clo ( lbm_value  cmp)
static

◆ cons_with_gc()

static lbm_value cons_with_gc ( lbm_value  head,
lbm_value  tail,
lbm_value  remember 
)
static

◆ cont_and()

static void cont_and ( eval_context_t ctx)
static

◆ cont_application_args()

static void cont_application_args ( eval_context_t ctx)
static

◆ cont_application_start()

static void cont_application_start ( eval_context_t ctx)
static

◆ cont_bind_to_key_rest()

static void cont_bind_to_key_rest ( eval_context_t ctx)
static

◆ cont_close_list_in_flash()

static void cont_close_list_in_flash ( eval_context_t ctx)
static

◆ cont_closure_application_args()

static void cont_closure_application_args ( eval_context_t ctx)
static

◆ cont_closure_args_rest()

static void cont_closure_args_rest ( eval_context_t ctx)
static

◆ cont_eval_r()

static void cont_eval_r ( eval_context_t ctx)
static

◆ cont_exception_handler()

static void cont_exception_handler ( eval_context_t ctx)
static

◆ cont_exit_atomic()

static void cont_exit_atomic ( eval_context_t ctx)
static

◆ cont_if()

static void cont_if ( eval_context_t ctx)
static

◆ cont_kill()

static void cont_kill ( eval_context_t ctx)
static

◆ cont_loop()

static void cont_loop ( eval_context_t ctx)
static

◆ cont_loop_condition()

static void cont_loop_condition ( eval_context_t ctx)
static

◆ cont_map()

static void cont_map ( eval_context_t ctx)
static

◆ cont_match()

static void cont_match ( eval_context_t ctx)
static

◆ cont_match_guard()

static void cont_match_guard ( eval_context_t ctx)
static

◆ cont_merge_layer()

static void cont_merge_layer ( eval_context_t ctx)
static

◆ cont_merge_rest()

static void cont_merge_rest ( eval_context_t ctx)
static

◆ cont_move_array_elts_to_flash()

static void cont_move_array_elts_to_flash ( eval_context_t ctx)
static

◆ cont_move_list_to_flash()

static void cont_move_list_to_flash ( eval_context_t ctx)
static

◆ cont_move_to_flash()

static void cont_move_to_flash ( eval_context_t ctx)
static

◆ cont_move_val_to_flash_dispatch()

static void cont_move_val_to_flash_dispatch ( eval_context_t ctx)
static

◆ cont_or()

static void cont_or ( eval_context_t ctx)
static

◆ cont_pop_reader_flags()

static void cont_pop_reader_flags ( eval_context_t ctx)
static

◆ cont_progn_rest()

static void cont_progn_rest ( eval_context_t ctx)
static

◆ cont_progn_var()

static void cont_progn_var ( eval_context_t ctx)
static

◆ cont_qq_append()

static void cont_qq_append ( eval_context_t ctx)
static

◆ cont_qq_expand()

static void cont_qq_expand ( eval_context_t ctx)
static

◆ cont_qq_expand_list()

static void cont_qq_expand_list ( eval_context_t ctx)
static

◆ cont_qq_expand_start()

static void cont_qq_expand_start ( eval_context_t ctx)
static

◆ cont_qq_list()

static void cont_qq_list ( eval_context_t ctx)
static

◆ cont_read_append_array()

static void cont_read_append_array ( eval_context_t ctx)
static

◆ cont_read_append_continue()

static void cont_read_append_continue ( eval_context_t ctx)
static

◆ cont_read_comma_result()

static void cont_read_comma_result ( eval_context_t ctx)
static

◆ cont_read_commaat_result()

static void cont_read_commaat_result ( eval_context_t ctx)
static

◆ cont_read_done()

static void cont_read_done ( eval_context_t ctx)
static

◆ cont_read_dot_terminate()

static void cont_read_dot_terminate ( eval_context_t ctx)
static

◆ cont_read_eval_continue()

static void cont_read_eval_continue ( eval_context_t ctx)
static

◆ cont_read_expect_closepar()

static void cont_read_expect_closepar ( eval_context_t ctx)
static

◆ cont_read_next_token()

static void cont_read_next_token ( eval_context_t ctx)
static

◆ cont_read_quote_result()

static void cont_read_quote_result ( eval_context_t ctx)
static

◆ cont_read_start_array()

static void cont_read_start_array ( eval_context_t ctx)
static

◆ cont_recv_to()

static void cont_recv_to ( eval_context_t ctx)
static

◆ cont_resume()

static void cont_resume ( eval_context_t ctx)
static

◆ cont_set_global_env()

static void cont_set_global_env ( eval_context_t ctx)
static

◆ cont_setq()

static void cont_setq ( eval_context_t ctx)
static

◆ cont_terminate()

static void cont_terminate ( eval_context_t ctx)
static

◆ cont_wait()

static void cont_wait ( eval_context_t ctx)
static

◆ context_exists()

static void context_exists ( eval_context_t ctx,
void *  cid,
void *  b 
)
static

◆ create_binding_location()

static void create_binding_location ( lbm_value  key,
lbm_value env 
)
static

◆ create_binding_location_internal()

static binding_location_status create_binding_location_internal ( lbm_value  key,
lbm_value env 
)
static

◆ create_string_channel()

bool create_string_channel ( char *  str,
lbm_value res 
)

◆ critical_nonsense()

static void critical_nonsense ( void  )
static

◆ ctx_done_nonsense()

static void ctx_done_nonsense ( eval_context_t ctx)
static

◆ dequeue_ctx_nm()

static eval_context_t* dequeue_ctx_nm ( eval_context_queue_t q)
static

◆ drop_ctx_nm()

static bool drop_ctx_nm ( eval_context_queue_t q,
eval_context_t ctx 
)
static

◆ dynamic_load_nonsense()

static bool dynamic_load_nonsense ( const char *  sym,
const char **  code 
)
static

◆ enqueue_ctx()

static void enqueue_ctx ( eval_context_queue_t q,
eval_context_t ctx 
)
static

◆ enqueue_ctx_nm()

static void enqueue_ctx_nm ( eval_context_queue_t q,
eval_context_t ctx 
)
static

◆ error_at_ctx()

static void error_at_ctx ( lbm_value  err_val,
lbm_value  at 
)
static

◆ error_ctx()

static void error_ctx ( lbm_value  err_val)
static

◆ error_ctx_base()

static void error_ctx_base ( lbm_value  err_val,
bool  has_at,
lbm_value  at,
unsigned int  row,
unsigned int  column 
)
static

◆ eval_and()

static void eval_and ( eval_context_t ctx)
static

◆ eval_app_cont()

static void eval_app_cont ( eval_context_t ctx)
static

◆ eval_atomic()

static void eval_atomic ( eval_context_t ctx)
static

◆ eval_callcc()

static void eval_callcc ( eval_context_t ctx)
static

◆ eval_cond()

static void eval_cond ( eval_context_t ctx)
static

◆ eval_define()

static void eval_define ( eval_context_t ctx)
static

◆ eval_if()

static void eval_if ( eval_context_t ctx)
static

◆ eval_lambda()

static void eval_lambda ( eval_context_t ctx)
static

◆ eval_let()

static void eval_let ( eval_context_t ctx)
static

◆ eval_loop()

static void eval_loop ( eval_context_t ctx)
static

◆ eval_match()

static void eval_match ( eval_context_t ctx)
static

◆ eval_move_to_flash()

static void eval_move_to_flash ( eval_context_t ctx)
static

◆ eval_or()

static void eval_or ( eval_context_t ctx)
static

◆ eval_progn()

static void eval_progn ( eval_context_t ctx)
static

◆ eval_quote()

static void eval_quote ( eval_context_t ctx)
static

◆ eval_receive()

static void eval_receive ( eval_context_t ctx)
static

◆ eval_receive_timeout()

static void eval_receive_timeout ( eval_context_t ctx)
static

◆ eval_selfevaluating()

static void eval_selfevaluating ( eval_context_t ctx)
static

◆ eval_setq()

static void eval_setq ( eval_context_t ctx)
static

◆ eval_symbol()

static void eval_symbol ( eval_context_t ctx)
static

◆ eval_trap()

static void eval_trap ( eval_context_t ctx)
static

◆ eval_var()

static void eval_var ( eval_context_t ctx)
static

◆ evaluation_step()

static void evaluation_step ( void  )
static

◆ event_internal()

static bool event_internal ( lbm_event_type_t  event_type,
lbm_uint  parameter,
lbm_uint  buf_ptr,
lbm_uint  buf_len 
)
static

◆ extract_n()

static lbm_value extract_n ( lbm_value  curr,
lbm_value res,
unsigned int  n 
)
static

◆ fill_binding_location()

static int fill_binding_location ( lbm_value  key,
lbm_value  value,
lbm_value  env 
)
static

◆ find_match()

static int find_match ( lbm_value  plist,
lbm_value earr,
lbm_uint  num,
lbm_value e,
lbm_value env 
)
static

◆ finish_ctx()

static void finish_ctx ( void  )
static

◆ gc()

static int gc ( void  )
static

◆ get_cadr()

static lbm_value get_cadr ( lbm_value  a)
static

◆ get_car()

static lbm_value get_car ( lbm_value  a)
static

◆ get_car_and_cdr()

static void get_car_and_cdr ( lbm_value  a,
lbm_value a_car,
lbm_value a_cdr 
)
static

◆ get_cdr()

static lbm_value get_cdr ( lbm_value  a)
static

◆ get_event_value()

static lbm_value get_event_value ( lbm_event_t e)
static

◆ get_match_binder_variable()

static lbm_value get_match_binder_variable ( lbm_value  exp)
inlinestatic

◆ get_stack_ptr()

static lbm_uint* get_stack_ptr ( eval_context_t ctx,
unsigned int  n 
)
static

◆ handle_event_define()

static void handle_event_define ( lbm_value  key,
lbm_value  val 
)
static

◆ handle_event_unblock_ctx()

static void handle_event_unblock_ctx ( lbm_cid  cid,
lbm_value  v 
)
static

◆ handle_flash_status()

static void handle_flash_status ( lbm_flash_status  s)
static

◆ is_append()

bool is_append ( lbm_value  a)

◆ lbm_block_ctx_base()

static bool lbm_block_ctx_base ( bool  timeout,
float  t_s 
)
static

◆ lbm_block_ctx_from_extension()

void lbm_block_ctx_from_extension ( void  )

Block a context from an extension

◆ lbm_block_ctx_from_extension_timeout()

void lbm_block_ctx_from_extension_timeout ( float  s)

Block a context from an extension with a timeout.

Parameters
sTimeout in seconds.

◆ lbm_blocked_iterator()

void lbm_blocked_iterator ( ctx_fun  f,
void *  ,
void *   
)

Iterate over all blocked contexts and apply function on each context.

Parameters
fFunction to apply to each context.
arg1Pointer argument that can be used to convey information back to user.
arg2Same as above

◆ lbm_continue_eval()

void lbm_continue_eval ( void  )

Resume from being in EVAL_CPS_STATE_PAUSED.

◆ lbm_create_ctx()

lbm_cid lbm_create_ctx ( lbm_value  program,
lbm_value  env,
lbm_uint  stack_size,
char *  name 
)

Create a context and enqueue it as runnable.

Parameters
programThe program to evaluate in the context.
envAn initial environment.
stack_sizeStack size for the context.
nameName of thread or NULL.
Returns

◆ lbm_create_ctx_parent()

static lbm_cid lbm_create_ctx_parent ( lbm_value  program,
lbm_value  env,
lbm_uint  stack_size,
lbm_cid  parent,
uint32_t  context_flags,
char *  name 
)
static

◆ lbm_critical_error()

void lbm_critical_error ( void  )

Terminate the runtime system in response to an error that it is not possible to recover from.

◆ lbm_eval_init()

int lbm_eval_init ( void  )

Initialize the evaluator.

Returns
1 on success and 0 on failure.

◆ lbm_eval_init_events()

bool lbm_eval_init_events ( unsigned int  num_events)

Initialize events

Parameters
num_eventsThe maximum number of unprocessed events.
Returns
true on success, false otherwise.

◆ lbm_eval_program()

lbm_cid lbm_eval_program ( lbm_value  lisp)

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.

Parameters
lispProgram to launch
Returns
a context id on success and 0 on failure to launch a context.

◆ lbm_eval_program_ext()

lbm_cid lbm_eval_program_ext ( lbm_value  lisp,
unsigned int  stack_size 
)

An extended version of lbm_eval_program that allows specification of stack size to use.

Parameters
lispProgram to launch.
stack_sizeSize of the continuation stack for this context.
Returns
a context id on success and 0 on failure to launch a context.

◆ lbm_event()

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.

Parameters
eventThe event to send to the registered handler.
opt_arrayAn optional array to pass to the event handler.
opt_array_lenLength of array mandatory if array is passed in.
Returns
true if the event was successfully enqueued to be sent, false otherwise.

◆ lbm_event_define()

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.

Parameters
keysymbol to bind.
fvFlat value representation of value.
Returns
true if event is successfully added to queue.

◆ lbm_event_handler_exists()

bool lbm_event_handler_exists ( void  )

Check if an event handler is registerd.

Returns
True if event handler exists, otherwise false.

◆ lbm_event_pop()

static bool lbm_event_pop ( lbm_event_t event)
static

◆ lbm_event_queue_is_empty()

bool lbm_event_queue_is_empty ( void  )

Check if the event queue is empty.

Returns
true if event queue is empty, otherwise false.

◆ lbm_event_run_user_callback()

bool lbm_event_run_user_callback ( void *  arg)

Send an event causing the user_callback to be run at the next convenience.

Returns
true if event is successfully added to queue.

◆ lbm_event_unboxed()

bool lbm_event_unboxed ( lbm_value  unboxed)

Send an unboxed value as an event to the event handler.

Parameters
unboxed.An lbm_value (encoded) such as a symbol. int, uint, character.
Returns
true on success.

◆ lbm_find_receiver_and_send()

lbm_value lbm_find_receiver_and_send ( lbm_cid  cid,
lbm_value  msg 
)

deliver a message

Parameters
cidProcess to deliver to.
msgMessage to deliver
Returns
lbm_enc_sym(SYM_NIL) on failure and lbm_enc_sym(SYM_TRUE) on success.

◆ lbm_get_current_cid()

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

◆ lbm_get_current_context()

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

◆ lbm_get_eval_state()

uint32_t lbm_get_eval_state ( void  )

Get the current state of the evaluator.

Returns
Current state of the evaluator.

◆ lbm_get_event_handler_pid()

lbm_cid lbm_get_event_handler_pid ( void  )

Get the process ID for the current event handler.

Returns
process ID on success and -1 if no event handler is registered.

◆ lbm_kill_eval()

void lbm_kill_eval ( void  )

This will kill the evaluator on the next iteration.

◆ lbm_mailbox_change_size()

bool lbm_mailbox_change_size ( eval_context_t ctx,
lbm_uint  new_size 
)

Change the mailbox size for a given context.

Parameters
ctxThe context to change mailbox size for.
new_sizeThe new size of the mailbox.
Returns
true on success and false otherwise.

◆ lbm_pause_eval()

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.

◆ lbm_pause_eval_with_gc()

void lbm_pause_eval_with_gc ( uint32_t  num_free)

Pause the evaluator and perform GC if needed.

Parameters
num_freePerform GC if there are less than this many elements free on the heap.

◆ lbm_perform_gc()

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!

Returns
1 on success

◆ lbm_request_gc()

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.

◆ lbm_reset_eval()

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.

◆ lbm_run_eval()

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.

◆ lbm_running_iterator()

void lbm_running_iterator ( ctx_fun  f,
void *  ,
void *   
)

Iterate over all ready contexts and apply function on each context.

Parameters
fFunction to apply to each context.
arg1Pointer argument that can be used to convey information back to user.
arg2Same as above.

◆ lbm_set_critical_error_callback()

void lbm_set_critical_error_callback ( void(*)(void)  fptr)

Set the critical error callback

◆ lbm_set_ctx_done_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.

Parameters
fptrPointer to a "done" function.

◆ lbm_set_dynamic_load_callback()

void lbm_set_dynamic_load_callback ( bool(*)(const char *, const char **)  fptr)

Set a callback for dynamically loading code associated with an undefined symbol

◆ lbm_set_error_reason()

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.

Parameters
error_str

◆ lbm_set_error_suspect()

void lbm_set_error_suspect ( lbm_value  suspect)

Provide the expression that is most suspicious in relation to the error at hand.

Parameters
lbm_value

◆ lbm_set_eval_step_quota()

void lbm_set_eval_step_quota ( uint32_t  quota)

Set a new value to use as step quota. This changes the scheduling interval.

Parameters
quotaThe new quota.

◆ lbm_set_event_handler_pid()

void lbm_set_event_handler_pid ( lbm_cid  pid)

Set the event handler process ID.

Parameters
pidThe ID of the process to which events should be sent

◆ lbm_set_printf_callback()

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.

Parameters
fptrPointer to a "printf" function.

◆ lbm_set_timestamp_us_callback()

void lbm_set_timestamp_us_callback ( uint32_t(*)(void)  fptr)

Set a timestamp callback for use by the evaluator thread.

Parameters
fptrPointer to a timestamp generating function.

◆ lbm_set_user_callback()

void lbm_set_user_callback ( void(*)(void *)  fptr)

Set the arbitrary user function callback

◆ lbm_set_usleep_callback()

void lbm_set_usleep_callback ( void(*)(uint32_t)  fptr)

Set a usleep callback for use by the evaluator thread.

Parameters
fptrPointer to a sleep function.

◆ lbm_set_verbose()

void lbm_set_verbose ( bool  verbose)

Set verbosity level of lispbm error messages.

Parameters
verboseBoolean to turn verbose errors on or off.

◆ lbm_toggle_verbose()

void lbm_toggle_verbose ( void  )

toggle verbosity level of error messages

◆ lbm_unblock_ctx()

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

Parameters
cidLisp process to wake up.
fvlbm_flat_value to give return as result from the unblocket process.

◆ lbm_unblock_ctx_r()

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.

Parameters
cidLisp process to unblock.
Returns
True on successfully unblocking. False otherwise.

◆ lbm_unblock_ctx_unboxed()

bool lbm_unblock_ctx_unboxed ( lbm_cid  cid,
lbm_value  unboxed 
)

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.

Parameters
cidLisp process to unblock.
unboxedAn unboxed lbm_value: char, i, u or symbol type.
Returns
True on successfully unblocking. False otherwise.

◆ lbm_undo_block_ctx_from_extension()

void lbm_undo_block_ctx_from_extension ( void  )

Undo a previous call to lbm_block_ctx_from_extension.

◆ lbm_write_const_array_padded()

lbm_flash_status lbm_write_const_array_padded ( uint8_t *  data,
lbm_uint  n,
lbm_uint res 
)

◆ let_bind_values_eval()

static void let_bind_values_eval ( lbm_value  binds,
lbm_value  exp,
lbm_value  env,
eval_context_t ctx 
)
static

◆ lift_array_flash()

static void lift_array_flash ( lbm_value  flash_cell,
bool  bytearray,
char *  data,
lbm_uint  num_elt 
)
static

◆ lift_char_channel()

bool lift_char_channel ( lbm_char_channel_t chan,
lbm_value res 
)

◆ lookup_ctx_nm()

static eval_context_t* lookup_ctx_nm ( eval_context_queue_t q,
lbm_cid  cid 
)
static

◆ mailbox_add_mail()

static bool mailbox_add_mail ( eval_context_t ctx,
lbm_value  mail 
)
static

◆ mailbox_remove_mail()

static void mailbox_remove_mail ( eval_context_t ctx,
lbm_uint  ix 
)
static

◆ mark_context()

static void mark_context ( eval_context_t ctx,
void *  arg1,
void *  arg2 
)
static

◆ match()

static bool match ( lbm_value  p,
lbm_value  e,
lbm_value env,
bool *  gc 
)
static

◆ ok_ctx()

static void ok_ctx ( void  )
static

◆ perform_setvar()

static lbm_value perform_setvar ( lbm_value  key,
lbm_value  val,
lbm_value  env 
)
static

◆ pop_stack_ptr()

static lbm_uint* pop_stack_ptr ( eval_context_t ctx,
unsigned int  n 
)
static

◆ print_environments()

void print_environments ( char *  buf,
unsigned int  size 
)

◆ print_error_message()

void print_error_message ( lbm_value  error,
bool  has_at,
lbm_value  at,
unsigned int  row,
unsigned int  col,
lbm_int  row0,
lbm_int  row1,
lbm_int  cid,
char *  name 
)

◆ printf_nonsense()

static int printf_nonsense ( const char *  fmt,
  ... 
)
static

◆ process_events()

static void process_events ( void  )
static

◆ queue_iterator_nm()

static void queue_iterator_nm ( eval_context_queue_t q,
ctx_fun  f,
void *  arg1,
void *  arg2 
)
static

◆ quote_it()

lbm_value quote_it ( lbm_value  qquoted)

◆ read_error_ctx()

static void read_error_ctx ( unsigned int  row,
unsigned int  column 
)
static

◆ read_finish()

static void read_finish ( lbm_char_channel_t str,
eval_context_t ctx 
)
static

◆ receive_base()

static void receive_base ( eval_context_t ctx,
lbm_value  pats,
float  timeout_time,
bool  timeout 
)
static

◆ request_flash_storage_cell()

lbm_flash_status request_flash_storage_cell ( lbm_value  val,
lbm_value res 
)

◆ stack_reserve()

static lbm_uint* stack_reserve ( eval_context_t ctx,
unsigned int  n 
)
inlinestatic

◆ timestamp_nonsense()

static uint32_t timestamp_nonsense ( void  )
static

◆ user_callback_nonsense()

static void user_callback_nonsense ( void *  arg)
static

◆ usleep_nonsense()

static void usleep_nonsense ( uint32_t  us)
static

◆ wake_up_ctxs_nm()

static void wake_up_ctxs_nm ( void  )
static

◆ yield_ctx()

static void yield_ctx ( lbm_uint  sleep_us)
static

Variable Documentation

◆ blocked

eval_context_queue_t blocked = {NULL, NULL}
static

◆ blocking_extension

volatile bool blocking_extension = false
static

◆ blocking_extension_mutex

mutex_t blocking_extension_mutex
static

◆ blocking_extension_mutex_initialized

bool blocking_extension_mutex_initialized = false
static

◆ blocking_extension_timeout

bool blocking_extension_timeout = false
static

◆ blocking_extension_timeout_us

lbm_uint blocking_extension_timeout_us = 0
static

◆ continuations

const cont_fun continuations[NUM_CONTINUATIONS]
static

◆ critical_error_callback

void(* critical_error_callback) (void) = critical_nonsense
static

◆ critical_error_jmp_buf

jmp_buf critical_error_jmp_buf
static

◆ ctx_done_callback

void(* ctx_done_callback) (eval_context_t *) = ctx_done_nonsense
static

◆ ctx_running

eval_context_t* ctx_running = NULL

◆ dynamic_load_callback

bool(* dynamic_load_callback) (const char *, const char **) = dynamic_load_nonsense
static

◆ error_jmp_buf

jmp_buf error_jmp_buf
static

◆ eval_cps_next_state

volatile uint32_t eval_cps_next_state = EVAL_CPS_STATE_NONE
static

◆ eval_cps_next_state_arg

volatile uint32_t eval_cps_next_state_arg = 0
static

◆ eval_cps_run_state

uint32_t eval_cps_run_state = EVAL_CPS_STATE_DEAD
static

◆ eval_cps_state_changed

volatile bool eval_cps_state_changed = false
static

◆ eval_running

bool eval_running = false
static

◆ eval_steps_quota

uint32_t eval_steps_quota = EVAL_STEPS_QUOTA
static

◆ eval_steps_refill

volatile uint32_t eval_steps_refill = EVAL_STEPS_QUOTA
static

◆ evaluators

const evaluator_fun evaluators[]
static

◆ fun_table

const apply_fun fun_table[]
static

◆ gc_requested

volatile bool gc_requested = false
static

◆ is_atomic

bool is_atomic = false
static

◆ lbm_error_has_suspect

bool lbm_error_has_suspect = false
static

◆ lbm_error_str_flash_error

const char* lbm_error_str_flash_error = "Error writing to flash."

◆ lbm_error_str_flash_full

const char* lbm_error_str_flash_full = "Flash memory is full."

◆ lbm_error_str_flash_not_possible

const char* lbm_error_str_flash_not_possible = "Value cannot be written to flash."

◆ lbm_error_str_forbidden_in_atomic

const char* lbm_error_str_forbidden_in_atomic = "Operation is forbidden in an atomic block."

◆ lbm_error_str_incorrect_arg

const char* lbm_error_str_incorrect_arg = "Incorrect argument."

◆ lbm_error_str_no_number

const char* lbm_error_str_no_number = "Argument(s) must be a number."

◆ lbm_error_str_not_a_boolean

const char* lbm_error_str_not_a_boolean = "Argument must be t or nil (true or false)."

◆ lbm_error_str_num_args

const char* lbm_error_str_num_args = "Incorrect number of arguments."

◆ lbm_error_str_parse_close

const char* lbm_error_str_parse_close = "Expected closing parenthesis."

◆ lbm_error_str_parse_dot

const char* lbm_error_str_parse_dot = "Incorrect usage of '.'."

◆ lbm_error_str_parse_eof

const char* lbm_error_str_parse_eof = "End of parse stream."

◆ lbm_error_str_read_no_mem

const char* lbm_error_str_read_no_mem = "Out of memory while reading."

◆ lbm_error_str_var_outside_progn

const char* lbm_error_str_var_outside_progn = "Usage of var outside of progn."

◆ lbm_error_str_variable_not_bound

const char* lbm_error_str_variable_not_bound = "Variable not bound."

◆ lbm_error_suspect

lbm_value lbm_error_suspect
static

◆ lbm_event_handler_pid

volatile lbm_cid lbm_event_handler_pid = -1
static

◆ lbm_events

volatile lbm_event_t* lbm_events = NULL
static

◆ lbm_events_full

bool lbm_events_full = false
static

◆ lbm_events_head

unsigned int lbm_events_head = 0
static

◆ lbm_events_max

unsigned int lbm_events_max = 0
static

◆ lbm_events_mutex

mutex_t lbm_events_mutex
static

◆ lbm_events_mutex_initialized

bool lbm_events_mutex_initialized = false
static

◆ lbm_events_tail

unsigned int lbm_events_tail = 0
static

◆ lbm_system_sleeping

volatile bool lbm_system_sleeping = false

◆ lbm_verbose

volatile bool lbm_verbose = false
static

◆ printf_callback

int(* printf_callback) (const char *,...) = printf_nonsense
static

◆ qmutex

mutex_t qmutex

◆ qmutex_initialized

bool qmutex_initialized = false

◆ queue

eval_context_queue_t queue = {NULL, NULL}
static

◆ timestamp_us_callback

uint32_t(* timestamp_us_callback) (void) = timestamp_nonsense
static

◆ user_callback

void(* user_callback) (void *) = user_callback_nonsense
static

◆ usleep_callback

void(* usleep_callback) (uint32_t) = usleep_nonsense
static
eval_lambda
static void eval_lambda(eval_context_t *ctx)
Definition: eval_cps.c:1746
eval_receive
static void eval_receive(eval_context_t *ctx)
Definition: eval_cps.c:2133
apply_map
static void apply_map(lbm_value *args, lbm_uint nargs, eval_context_t *ctx)
Definition: eval_cps.c:2550
apply_yield
static void apply_yield(lbm_value *args, lbm_uint nargs, eval_context_t *ctx)
Definition: eval_cps.c:2427
eval_loop
static void eval_loop(eval_context_t *ctx)
Definition: eval_cps.c:1969
eval_move_to_flash
static void eval_move_to_flash(eval_context_t *ctx)
Definition: eval_cps.c:1958
apply_sleep
static void apply_sleep(lbm_value *args, lbm_uint nargs, eval_context_t *ctx)
Definition: eval_cps.c:2438
eval_match
static void eval_match(eval_context_t *ctx)
Definition: eval_cps.c:2053
apply_merge
static void apply_merge(lbm_value *args, lbm_uint nargs, eval_context_t *ctx)
Definition: eval_cps.c:2712
eval_app_cont
static void eval_app_cont(eval_context_t *ctx)
Definition: eval_cps.c:1812
apply_ok
static void apply_ok(lbm_value *args, lbm_uint nargs, eval_context_t *ctx)
Definition: eval_cps.c:2531
lbm_is_symbol_merror
static bool lbm_is_symbol_merror(lbm_value exp)
Definition: heap.h:936
eval_quote
static void eval_quote(eval_context_t *ctx)
Definition: eval_cps.c:1641
eval_define
static void eval_define(eval_context_t *ctx)
Definition: eval_cps.c:1708
eval_atomic
static void eval_atomic(eval_context_t *ctx)
Definition: eval_cps.c:1673
apply_wait
static void apply_wait(lbm_value *args, lbm_uint nargs, eval_context_t *ctx)
Definition: eval_cps.c:2449
apply_rotate
static void apply_rotate(lbm_value *args, lbm_uint nargs, eval_context_t *ctx)
Definition: eval_cps.c:2884
eval_progn
static void eval_progn(eval_context_t *ctx)
Definition: eval_cps.c:1651
eval_callcc
static void eval_callcc(eval_context_t *ctx)
Definition: eval_cps.c:1681
apply_read
static void apply_read(lbm_value *args, lbm_uint nargs, eval_context_t *ctx)
Definition: eval_cps.c:2352
apply_spawn_trap
static void apply_spawn_trap(lbm_value *args, lbm_uint nargs, eval_context_t *ctx)
Definition: eval_cps.c:2423
eval_setq
static void eval_setq(eval_context_t *ctx)
Definition: eval_cps.c:1948
eval_var
static void eval_var(eval_context_t *ctx)
Definition: eval_cps.c:1908
eval_trap
static void eval_trap(eval_context_t *ctx)
Definition: eval_cps.c:1987
apply_read_program
static void apply_read_program(lbm_value *args, lbm_uint nargs, eval_context_t *ctx)
Definition: eval_cps.c:2344
eval_receive_timeout
static void eval_receive_timeout(eval_context_t *ctx)
Definition: eval_cps.c:2121
apply_reverse
static void apply_reverse(lbm_value *args, lbm_uint nargs, eval_context_t *ctx)
Definition: eval_cps.c:2593
eval_let
static void eval_let(eval_context_t *ctx)
Definition: eval_cps.c:2003
apply_setvar
static void apply_setvar(lbm_value *args, lbm_uint nargs, eval_context_t *ctx)
Definition: eval_cps.c:2255
apply_read_eval_program
static void apply_read_eval_program(lbm_value *args, lbm_uint nargs, eval_context_t *ctx)
Definition: eval_cps.c:2348
eval_and
static void eval_and(eval_context_t *ctx)
Definition: eval_cps.c:2011
apply_eval_program
static void apply_eval_program(lbm_value *args, lbm_uint nargs, eval_context_t *ctx)
Definition: eval_cps.c:2478
eval_cond
static void eval_cond(eval_context_t *ctx)
Definition: eval_cps.c:1782
apply_flatten
static void apply_flatten(lbm_value *args, lbm_uint nargs, eval_context_t *ctx)
Definition: eval_cps.c:2613
eval_or
static void eval_or(eval_context_t *ctx)
Definition: eval_cps.c:2026
apply_error
static void apply_error(lbm_value *args, lbm_uint nargs, eval_context_t *ctx)
Definition: eval_cps.c:2540
apply_kill
static void apply_kill(lbm_value *args, lbm_uint nargs, eval_context_t *ctx)
Definition: eval_cps.c:2657
ENC_SYM_MERROR
#define ENC_SYM_MERROR
Definition: lbm_defines.h:401
apply_spawn
static void apply_spawn(lbm_value *args, lbm_uint nargs, eval_context_t *ctx)
Definition: eval_cps.c:2419
apply_eval
static void apply_eval(lbm_value *args, lbm_uint nargs, eval_context_t *ctx)
Definition: eval_cps.c:2465
apply_sort
static void apply_sort(lbm_value *args, lbm_uint nargs, eval_context_t *ctx)
Definition: eval_cps.c:2790
apply_unflatten
static void apply_unflatten(lbm_value *args, lbm_uint nargs, eval_context_t *ctx)
Definition: eval_cps.c:2634
eval_if
static void eval_if(eval_context_t *ctx)
Definition: eval_cps.c:1770
apply_send
static void apply_send(lbm_value *args, lbm_uint nargs, eval_context_t *ctx)
Definition: eval_cps.c:2512
eval_selfevaluating
static void eval_selfevaluating(eval_context_t *ctx)
Definition: eval_cps.c:1646
apply_rest_args
static void apply_rest_args(lbm_value *args, lbm_uint nargs, eval_context_t *ctx)
Definition: eval_cps.c:2868