w32tex
About: TeX Live provides a comprehensive TeX system including all the major TeX-related programs, macro packages, and fonts that are free software. Windows sources.
  Fossies Dox: w32tex-src.tar.xz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

symbol.c File Reference
#include <limits.h>
#include <string.h>
#include <mruby.h>
#include <mruby/khash.h>
#include <mruby/dump.h>
#include <mruby/class.h>
#include <mruby/presym.h>
#include <mruby/presym/table.h>
Include dependency graph for symbol.c:

Go to the source code of this file.

Classes

struct  symbol_name
 

Macros

#define SYMBOL_INLINE_P(sym)   ((sym) >= (1<<24))
 
#define SIGN_EXTEND_CHAR(c)   ((((unsigned char)(c)) ^ 128) - 128)
 
#define is_identchar(c)   (SIGN_EXTEND_CHAR(c)!=-1&&(ISALNUM(c) || (c) == '_'))
 
#define lesser(a, b)   (((a)>(b))?(b):(a))
 

Typedefs

typedef struct symbol_name symbol_name
 

Functions

static mrb_sym presym_find (const char *name, size_t len)
 
static const char * presym_sym2name (mrb_sym sym, mrb_int *lenp)
 
static void sym_validate_len (mrb_state *mrb, size_t len)
 
static mrb_sym sym_inline_pack (const char *name, size_t len)
 
static const char * sym_inline_unpack (mrb_sym sym, char *buf, mrb_int *lenp)
 
static uint8_t symhash (const char *key, size_t len)
 
static mrb_sym find_symbol (mrb_state *mrb, const char *name, size_t len, uint8_t *hashp)
 
static mrb_sym sym_intern (mrb_state *mrb, const char *name, size_t len, mrb_bool lit)
 
mrb_sym mrb_intern (mrb_state *mrb, const char *name, size_t len)
 
mrb_sym mrb_intern_static (mrb_state *mrb, const char *name, size_t len)
 
mrb_sym mrb_intern_cstr (mrb_state *mrb, const char *name)
 
mrb_sym mrb_intern_str (mrb_state *mrb, mrb_value str)
 
mrb_sym mrb_intern_check (mrb_state *mrb, const char *name, size_t len)
 
mrb_value mrb_check_intern (mrb_state *mrb, const char *name, size_t len)
 
mrb_sym mrb_intern_check_cstr (mrb_state *mrb, const char *name)
 
mrb_value mrb_check_intern_cstr (mrb_state *mrb, const char *name)
 
mrb_sym mrb_intern_check_str (mrb_state *mrb, mrb_value str)
 
mrb_value mrb_check_intern_str (mrb_state *mrb, mrb_value str)
 
static const char * sym2name_len (mrb_state *mrb, mrb_sym sym, char *buf, mrb_int *lenp)
 
const char * mrb_sym_name_len (mrb_state *mrb, mrb_sym sym, mrb_int *lenp)
 
mrb_bool mrb_sym_static_p (mrb_state *mrb, mrb_sym sym)
 
void mrb_free_symtbl (mrb_state *mrb)
 
void mrb_init_symtbl (mrb_state *mrb)
 
static mrb_value sym_to_s (mrb_state *mrb, mrb_value sym)
 
static mrb_value sym_to_sym (mrb_state *mrb, mrb_value sym)
 
static mrb_bool is_special_global_name (const char *m)
 
static mrb_bool symname_p (const char *name)
 
static mrb_value sym_inspect (mrb_state *mrb, mrb_value sym)
 
mrb_value mrb_sym_str (mrb_state *mrb, mrb_sym sym)
 
static const char * sym_name (mrb_state *mrb, mrb_sym sym, mrb_bool dump)
 
const char * mrb_sym_name (mrb_state *mrb, mrb_sym sym)
 
const char * mrb_sym_dump (mrb_state *mrb, mrb_sym sym)
 
static mrb_value sym_cmp (mrb_state *mrb, mrb_value s1)
 
void mrb_init_symbol (mrb_state *mrb)
 

Variables

static const char pack_table [] = "_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
 

Macro Definition Documentation

◆ is_identchar

#define is_identchar (   c)    (SIGN_EXTEND_CHAR(c)!=-1&&(ISALNUM(c) || (c) == '_'))

Definition at line 446 of file symbol.c.

◆ lesser

#define lesser (   a,
  b 
)    (((a)>(b))?(b):(a))

Definition at line 627 of file symbol.c.

◆ SIGN_EXTEND_CHAR

#define SIGN_EXTEND_CHAR (   c)    ((((unsigned char)(c)) ^ 128) - 128)

Definition at line 444 of file symbol.c.

◆ SYMBOL_INLINE_P

#define SYMBOL_INLINE_P (   sym)    ((sym) >= (1<<24))

Definition at line 77 of file symbol.c.

Typedef Documentation

◆ symbol_name

typedef struct symbol_name symbol_name

Function Documentation

◆ find_symbol()

static mrb_sym find_symbol ( mrb_state mrb,
const char *  name,
size_t  len,
uint8_t hashp 
)
static

◆ is_special_global_name()

static mrb_bool is_special_global_name ( const char *  m)
static

Definition at line 449 of file symbol.c.

References FALSE, is_identchar, ISDIGIT, and m.

Referenced by symname_p().

◆ mrb_check_intern()

mrb_value mrb_check_intern ( mrb_state mrb,
const char *  name,
size_t  len 
)

Definition at line 268 of file symbol.c.

References len, mrb_intern_check(), mrb_nil_value(), mrb_symbol_value(), name, and sym.

◆ mrb_check_intern_cstr()

mrb_value mrb_check_intern_cstr ( mrb_state mrb,
const char *  name 
)

Definition at line 282 of file symbol.c.

References mrb_intern_check_cstr(), mrb_nil_value(), mrb_symbol_value(), name, and sym.

◆ mrb_check_intern_str()

mrb_value mrb_check_intern_str ( mrb_state mrb,
mrb_value  str 
)

Definition at line 296 of file symbol.c.

References mrb_intern_check_str(), mrb_nil_value(), mrb_symbol_value(), str, and sym.

◆ mrb_free_symtbl()

void mrb_free_symtbl ( mrb_state mrb)

Definition at line 346 of file symbol.c.

References i, symbol_name::lit, mrb_free(), symbol_name::name, mrb_state::symidx, and mrb_state::symtbl.

Referenced by mrb_close().

◆ mrb_init_symbol()

◆ mrb_init_symtbl()

void mrb_init_symtbl ( mrb_state mrb)

Definition at line 359 of file symbol.c.

Referenced by mrb_init_core().

◆ mrb_intern()

◆ mrb_intern_check()

mrb_sym mrb_intern_check ( mrb_state mrb,
const char *  name,
size_t  len 
)

◆ mrb_intern_check_cstr()

mrb_sym mrb_intern_check_cstr ( mrb_state mrb,
const char *  name 
)

◆ mrb_intern_check_str()

mrb_sym mrb_intern_check_str ( mrb_state mrb,
mrb_value  str 
)

Definition at line 290 of file symbol.c.

References mrb_intern_check(), RSTRING_LEN, RSTRING_PTR, and str.

Referenced by mrb_check_intern_str().

◆ mrb_intern_cstr()

mrb_sym mrb_intern_cstr ( mrb_state mrb,
const char *  str 
)

Create a symbol from C string. But usually it's better to use MRB_SYM, MRB_OPSYM, MRB_CVSYM, MRB_IVSYM, MRB_SYM_B, MRB_SYM_Q, MRB_SYM_E macros.

Example:

# Ruby style:
:pizza # => :pizza

// C style:
mrb_sym sym1 = mrb_intern_lit(mrb, "pizza"); //  => :pizza
mrb_sym sym2 = MRB_SYM(pizza);               //  => :pizza
mrb_sym sym3 = MRB_SYM_Q(pizza);             //  => :pizza?
Parameters
mrbThe current mruby state.
strThe string to be symbolized
Returns
[mrb_sym] mrb_sym A symbol.

Definition at line 245 of file symbol.c.

References mrb_intern(), name, and strlen().

◆ mrb_intern_static()

mrb_sym mrb_intern_static ( mrb_state mrb,
const char *  name,
size_t  len 
)

Definition at line 239 of file symbol.c.

References len, name, sym_intern(), and TRUE.

Referenced by read_irep_record_1(), read_section_debug(), and read_section_lv().

◆ mrb_intern_str()

mrb_sym mrb_intern_str ( mrb_state mrb,
mrb_value  str 
)

◆ mrb_sym_dump()

const char* mrb_sym_dump ( mrb_state mrb,
mrb_sym  sym 
)

Definition at line 622 of file symbol.c.

References sym, sym_name(), and TRUE.

Referenced by codedump(), mrb_parser_dump(), and print_r().

◆ mrb_sym_name()

const char* mrb_sym_name ( mrb_state mrb,
mrb_sym  sym 
)

◆ mrb_sym_name_len()

◆ mrb_sym_static_p()

mrb_bool mrb_sym_static_p ( mrb_state mrb,
mrb_sym  sym 
)

Definition at line 338 of file symbol.c.

References FALSE, MRB_PRESYM_MAX, sym, SYMBOL_INLINE_P, and TRUE.

◆ mrb_sym_str()

◆ presym_find()

static mrb_sym presym_find ( const char *  name,
size_t  len 
)
static

Definition at line 25 of file symbol.c.

References cmp(), idx, int(), len, memcmp, MRB_PRESYM_MAX, name, and start.

Referenced by find_symbol().

◆ presym_sym2name()

static const char* presym_sym2name ( mrb_sym  sym,
mrb_int lenp 
)
static

Definition at line 47 of file symbol.c.

References MRB_PRESYM_MAX, NULL, and sym.

Referenced by sym2name_len().

◆ sym2name_len()

static const char* sym2name_len ( mrb_state mrb,
mrb_sym  sym,
char *  buf,
mrb_int lenp 
)
static

◆ sym_cmp()

static mrb_value sym_cmp ( mrb_state mrb,
mrb_value  s1 
)
static

◆ sym_inline_pack()

static mrb_sym sym_inline_pack ( const char *  name,
size_t  len 
)
static

Definition at line 82 of file symbol.c.

References bits, c, i, len, mrb_assert, name, p, pack_table, strchr, sym, SYMBOL_INLINE_P, and uint32_t.

Referenced by find_symbol().

◆ sym_inline_unpack()

static const char* sym_inline_unpack ( mrb_sym  sym,
char *  buf,
mrb_int lenp 
)
static

Definition at line 108 of file symbol.c.

References buf, i, mrb_assert, pack_table, sym, and SYMBOL_INLINE_P.

Referenced by sym2name_len().

◆ sym_inspect()

◆ sym_intern()

◆ sym_name()

static const char* sym_name ( mrb_state mrb,
mrb_sym  sym,
mrb_bool  dump 
)
static

◆ sym_to_s()

static mrb_value sym_to_s ( mrb_state mrb,
mrb_value  sym 
)
static

Document-class: Symbol

Symbol objects represent names and some strings inside the Ruby interpreter. They are generated using the :name and :"string" literals syntax, and by the various to_sym methods. The same Symbol object will be created for a given name or string for the duration of a program's execution, regardless of the context or meaning of that name. Thus if Fred is a constant in one context, a method in another, and a class in a third, the Symbol :Fred will be the same object in all three contexts.

module One class Fred end $f1 = :Fred end module Two Fred = 1 $f2 = :Fred end def Fred() end $f3 = :Fred $f1.object_id #=> 2514190 $f2.object_id #=> 2514190 $f3.object_id #=> 2514190

Definition at line 408 of file symbol.c.

References mrb_sym_str(), mrb_symbol, and sym.

Referenced by mrb_init_symbol().

◆ sym_to_sym()

static mrb_value sym_to_sym ( mrb_state mrb,
mrb_value  sym 
)
static

Definition at line 425 of file symbol.c.

References sym.

Referenced by mrb_init_symbol().

◆ sym_validate_len()

static void sym_validate_len ( mrb_state mrb,
size_t  len 
)
static

Definition at line 65 of file symbol.c.

References E_ARGUMENT_ERROR, len, mrb_raise(), and UINT16_MAX.

Referenced by mrb_intern_check(), and sym_intern().

◆ symhash()

static uint8_t symhash ( const char *  key,
size_t  len 
)
static

Definition at line 126 of file symbol.c.

References hash, i, key, and len.

Referenced by find_symbol().

◆ symname_p()

static mrb_bool symname_p ( const char *  name)
static

Definition at line 472 of file symbol.c.

References FALSE, id, is_identchar, is_special_global_name(), ISALPHA, ISUPPER, m, name, and TRUE.

Referenced by sym_inspect(), and sym_name().

Variable Documentation

◆ pack_table

const char pack_table[] = "_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
static

Definition at line 79 of file symbol.c.

Referenced by sym_inline_pack(), and sym_inline_unpack().