LispBM
Data Structures | Macros | Functions | Variables
symrepr.c File Reference
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <inttypes.h>
#include <lbm_memory.h>
#include <heap.h>
#include "symrepr.h"
#include "extensions.h"
#include "lbm_utils.h"
Include dependency graph for symrepr.c:

Data Structures

struct  special_sym
 

Macros

#define NUM_SPECIAL_SYMBOLS   (sizeof(special_symbols) / sizeof(special_sym))
 
#define NAME   0
 
#define ID   1
 
#define NEXT   2
 

Functions

int lbm_symrepr_init (void)
 
void lbm_symrepr_name_iterator (symrepr_name_iterator_fun f)
 
const char * lookup_symrepr_name_memory (lbm_uint id)
 
const char * lbm_get_name_by_symbol (lbm_uint id)
 
lbm_uintlbm_get_symbol_list_entry_by_name (char *name)
 
int lbm_get_symbol_by_name (char *name, lbm_uint *id)
 
lbm_flash_status lbm_write_const_array_padded (uint8_t *data, lbm_uint n, lbm_uint *res)
 
static bool store_symbol_name_flash (char *name, lbm_uint *res)
 
static bool add_symbol_to_symtab (char *name, lbm_uint id)
 
static bool add_symbol_to_symtab_flash (lbm_uint name, lbm_uint id)
 
int lbm_add_symbol_base (char *name, lbm_uint *id, bool flash)
 
int lbm_add_symbol (char *name, lbm_uint *id)
 
int lbm_add_symbol_flash (char *name, lbm_uint *id)
 
int lbm_add_symbol_const_base (char *name, lbm_uint *id)
 
int lbm_add_symbol_const (char *name, lbm_uint *id)
 
int lbm_str_to_symbol (char *name, lbm_uint *sym_id)
 
lbm_uint lbm_get_symbol_table_size (void)
 
lbm_uint lbm_get_symbol_table_size_flash (void)
 
lbm_uint lbm_get_symbol_table_size_names (void)
 
lbm_uint lbm_get_symbol_table_size_names_flash (void)
 
bool lbm_symbol_in_flash (char *str)
 
bool lbm_symbol_list_entry_in_flash (char *str)
 

Variables

const special_sym special_symbols []
 
static lbm_uintsymlist = NULL
 
static lbm_uint next_symbol_id = RUNTIME_SYMBOLS_START
 
static lbm_uint symbol_table_size_list = 0
 
static lbm_uint symbol_table_size_list_flash = 0
 
static lbm_uint symbol_table_size_strings = 0
 
static lbm_uint symbol_table_size_strings_flash = 0
 
lbm_value symbol_x = ENC_SYM_NIL
 
lbm_value symbol_y = ENC_SYM_NIL
 

Macro Definition Documentation

◆ ID

#define ID   1

◆ NAME

#define NAME   0

◆ NEXT

#define NEXT   2

◆ NUM_SPECIAL_SYMBOLS

#define NUM_SPECIAL_SYMBOLS   (sizeof(special_symbols) / sizeof(special_sym))

Function Documentation

◆ add_symbol_to_symtab()

static bool add_symbol_to_symtab ( char *  name,
lbm_uint  id 
)
static

◆ add_symbol_to_symtab_flash()

static bool add_symbol_to_symtab_flash ( lbm_uint  name,
lbm_uint  id 
)
static

◆ lbm_add_symbol()

int lbm_add_symbol ( char *  name,
lbm_uint id 
)

Add a symbol to the symbol table. The symbol name string is copied to arrays and symbols memory.

Parameters
nameString representation of the symbol.
idResulting id is returned through this argument.
Returns
1 for success and 0 for failure.

◆ lbm_add_symbol_base()

int lbm_add_symbol_base ( char *  name,
lbm_uint id,
bool  flash 
)

◆ lbm_add_symbol_const()

int lbm_add_symbol_const ( char *  name,
lbm_uint id 
)

Add a symbol to the symbol table. The name is assumed to be a statically allocated string.

Parameters
nameStatically allocated name string.
idResulting id is returned through this argument.
Returns
1 for success and 0 for failure.

◆ lbm_add_symbol_const_base()

int lbm_add_symbol_const_base ( char *  name,
lbm_uint id 
)

◆ lbm_add_symbol_flash()

int lbm_add_symbol_flash ( char *  name,
lbm_uint id 
)

Add a symbol to the symbol table. The symbol name string is copied to flash.

Parameters
nameString representation of the symbol.
idResulting id is returned through this argument.
Returns
1 for success and 0 for failure.

◆ lbm_get_name_by_symbol()

const char* lbm_get_name_by_symbol ( lbm_uint  id)

Look up a symbol name from the symbol table given an id.

Parameters
idThe id to look up in the symbol table.
Returns
pointer to the name string if success otherwise NULL.

◆ lbm_get_symbol_by_name()

int lbm_get_symbol_by_name ( char *  name,
lbm_uint id 
)

Look up an id from the symbol table given a name.

Parameters
nameName string to look up.
idResulting id is returned through this argument.
Returns
1 on success (name was found) and 0 for failure.

◆ lbm_get_symbol_list_entry_by_name()

lbm_uint* lbm_get_symbol_list_entry_by_name ( char *  name)

Get a pointer to the list entry holding a symbol name, id mapping.

Parameters
nameName string to look up.
Returns
Pointer to list entry or NULL.

◆ lbm_get_symbol_table_size()

lbm_uint lbm_get_symbol_table_size ( void  )
Returns
The total amount of lbm_memory space occupied by the symbol table in bytes.

◆ lbm_get_symbol_table_size_flash()

lbm_uint lbm_get_symbol_table_size_flash ( void  )
Returns
The total amount of flash space occupied by the symbol table in bytes.

◆ lbm_get_symbol_table_size_names()

lbm_uint lbm_get_symbol_table_size_names ( void  )
Returns
The size in bytes of all symbol strings stored in the symbol table.

◆ lbm_get_symbol_table_size_names_flash()

lbm_uint lbm_get_symbol_table_size_names_flash ( void  )
Returns
The size in bytes of all symbol strings stored in flash from the symbol table.

◆ lbm_str_to_symbol()

int lbm_str_to_symbol ( char *  name,
lbm_uint sym_id 
)

Name of symbol to symbol. If the symbol exists the ID of the symbol is returned. If the name does not match any existing symbol, one is created and that ID is returned.

Parameters
nameString name of symbol.
idResulting ID is returned through this argument.
Returns
1 for success and 0 for failure.

◆ lbm_symbol_in_flash()

bool lbm_symbol_in_flash ( char *  str)

Check if a symbol name is stored in flash.

Parameters
strSymbol name string.
Returns
True if symbol name is stored in flash, otherwise False.

◆ lbm_symbol_list_entry_in_flash()

bool lbm_symbol_list_entry_in_flash ( char *  str)

Check if a symbol name id mapping list entry is stored in flash.

Parameters
strSymbol name string.
Returns
True if symbol name/id mapping list entry is stored in flash, otherwise False.

◆ lbm_symrepr_init()

int lbm_symrepr_init ( void  )

Initialize the symbol table.

Returns
1

◆ lbm_symrepr_name_iterator()

void lbm_symrepr_name_iterator ( symrepr_name_iterator_fun  f)

Iterate over all symbol names as strings

Parameters
symrepr_name_iterator_funfunction taking a string

◆ lbm_write_const_array_padded()

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

◆ lookup_symrepr_name_memory()

const char* lookup_symrepr_name_memory ( lbm_uint  id)

◆ store_symbol_name_flash()

static bool store_symbol_name_flash ( char *  name,
lbm_uint res 
)
static

Variable Documentation

◆ next_symbol_id

lbm_uint next_symbol_id = RUNTIME_SYMBOLS_START
static

◆ special_symbols

const special_sym special_symbols[]

◆ symbol_table_size_list

lbm_uint symbol_table_size_list = 0
static

◆ symbol_table_size_list_flash

lbm_uint symbol_table_size_list_flash = 0
static

◆ symbol_table_size_strings

lbm_uint symbol_table_size_strings = 0
static

◆ symbol_table_size_strings_flash

lbm_uint symbol_table_size_strings_flash = 0
static

◆ symbol_x

lbm_value symbol_x = ENC_SYM_NIL

◆ symbol_y

lbm_value symbol_y = ENC_SYM_NIL

◆ symlist

lbm_uint* symlist = NULL
static