25#define MRBC_DEFINE_SYMBOL_TABLE
26#include "_autogen_builtin_symbol.h"
27#undef MRBC_DEFINE_SYMBOL_TABLE
31#if !defined(MRBC_SYMBOL_SEARCH_LINEAR) && !defined(MRBC_SYMBOL_SEARCH_BTREE)
32#define MRBC_SYMBOL_SEARCH_BTREE
35#if MAX_SYMBOLS_COUNT <= UCHAR_MAX
36#define MRBC_SYMBOL_TABLE_INDEX_TYPE uint8_t
38#define MRBC_SYMBOL_TABLE_INDEX_TYPE uint16_t
41#define OFFSET_BUILTIN_SYMBOL 256
48#ifdef MRBC_SYMBOL_SEARCH_BTREE
76 while( *str !=
'\0' ) {
92 int right =
sizeof(builtin_symbols) /
sizeof(builtin_symbols[0]);
96 const unsigned char *p1 = (
const unsigned char *)builtin_symbols[mid];
97 const unsigned char *p2 = (
const unsigned char *)str;
130#ifdef MRBC_SYMBOL_SEARCH_LINEAR
139#ifdef MRBC_SYMBOL_SEARCH_BTREE
173#ifdef MRBC_SYMBOL_SEARCH_BTREE
220 if( sym_id >= 0 )
return sym_id;
224 if( sym_id < 0 ) sym_id =
add_index( h, str );
225 if( sym_id < 0 )
return sym_id;
241 return builtin_symbols[sym_id];
245 if( sym_id < 0 )
return NULL;
261 if( sym_id >= 0 )
return sym_id;
265 if( sym_id < 0 )
return sym_id;
280 static const int w =
sizeof(
mrbc_sym) * 2;
281 char *p = buf + w * 2;
285 for( i = w; i > 0; i-- ) {
286 *--p =
'0' + (id2 & 0x0f);
290 for( i = w; i > 0; i-- ) {
291 *--p =
'0' + (id1 & 0x0f);
307 static const int w =
sizeof(
mrbc_sym) * 2;
311 assert( strlen(s) == w*2 );
316 *id1 = (*id1 << 4) + (s[i++] -
'0');
319 if( id2 == NULL )
return;
322 *id2 = (*id2 << 4) + (s[i++] -
'0');
337 if( sym_id >= 0 )
goto DONE;
340 int size = strlen(str) + 1;
344 memcpy(buf, str, size);
348 "Overflow MAX_SYMBOLS_COUNT for '%s'", str );
364static void c_symbol_all_symbols(
struct VM *vm,
mrbc_value v[],
int argc)
368 for(
int i = 0; i <
sizeof(builtin_symbols) /
sizeof(builtin_symbols[0]); i++ ) {
383static void c_symbol_inspect(
struct VM *vm,
mrbc_value v[],
int argc)
394static void c_symbol_to_s(
struct VM *vm,
mrbc_value v[],
int argc)
419#include "_autogen_class_symbol.h"
423#if defined(MRBC_DEBUG)
430void mrbc_debug_dump_symbol(
void)
457void mrbc_symbol_statistics(
int *total_used )
void * mrbc_raw_alloc_no_free(unsigned int size)
int mrbc_array_push(mrbc_value *ary, mrbc_value *set_val)
mrbc_value mrbc_array_new(struct VM *vm, int size)
static mrbc_value mrbc_string_new_cstr(struct VM *vm, const char *src)
static int mrbc_string_append_cstr(mrbc_value *s1, const char *s2)
void mrbc_printf(const char *fstr,...)
void mrbc_print_symbol(mrbc_sym sym_id)
void mrbc_raisef(struct VM *vm, struct RClass *exc_cls, const char *fstr,...)
Include at once the necessary header files.
uint16_t hash
hash value, returned by calc_hash().
MRBC_SYMBOL_TABLE_INDEX_TYPE right
const char * cstr
point to the symbol string.
MRBC_SYMBOL_TABLE_INDEX_TYPE left
mrbc_sym mrbc_search_symid(const char *str)
mrbc_value mrbc_symbol_new(struct VM *vm, const char *str)
mrbc_sym mrbc_str_to_symid(const char *str)
static int search_index(uint16_t hash, const char *str)
static int add_index(uint16_t hash, const char *str)
void mrbc_separate_nested_symid(mrbc_sym sym_id, mrbc_sym *id1, mrbc_sym *id2)
#define MRBC_SYMBOL_TABLE_INDEX_TYPE
void mrbc_cleanup_symbol(void)
static uint16_t calc_hash(const char *str)
const char * mrbc_symid_to_str(mrbc_sym sym_id)
void make_nested_symbol_s(char *buf, mrbc_sym id1, mrbc_sym id2)
#define OFFSET_BUILTIN_SYMBOL
static struct SYM_INDEX sym_index[MAX_SYMBOLS_COUNT]
static int search_builtin_symbol(const char *str)
static int mrbc_is_nested_symid(mrbc_sym sym_id)
#define mrbc_symbol_value(n)
int16_t mrbc_sym
mruby/c symbol ID
struct RObject mrbc_value
Global configuration of mruby/c VM's.
#define MAX_SYMBOLS_COUNT