add some symbol primitive functions
This commit is contained in:
parent
4402497a46
commit
15fdbc9c7d
|
@ -10,6 +10,7 @@ void pic_init_time(pic_state *);
|
|||
void pic_init_system(pic_state *);
|
||||
void pic_init_file(pic_state *);
|
||||
void pic_init_proc(pic_state *);
|
||||
void pic_init_symbol(pic_state *);
|
||||
|
||||
void
|
||||
pic_load_stdlib(pic_state *pic)
|
||||
|
@ -66,6 +67,7 @@ pic_init_core(pic_state *pic)
|
|||
pic_init_system(pic); DONE;
|
||||
pic_init_file(pic); DONE;
|
||||
pic_init_proc(pic); DONE;
|
||||
pic_init_symbol(pic); DONE;
|
||||
|
||||
pic_load_stdlib(pic); DONE;
|
||||
}
|
||||
|
|
46
src/symbol.c
46
src/symbol.c
|
@ -30,3 +30,49 @@ pic_symbol_name(pic_state *pic, pic_sym sym)
|
|||
{
|
||||
return pic->sym_pool[sym];
|
||||
}
|
||||
|
||||
static pic_value
|
||||
pic_symbol_symbol_p(pic_state *pic)
|
||||
{
|
||||
pic_value v;
|
||||
|
||||
pic_get_args(pic, "o", &v);
|
||||
|
||||
return pic_bool_value(pic_symbol_p(v));
|
||||
}
|
||||
|
||||
static pic_value
|
||||
pic_symbol_symbol_to_string(pic_state *pic)
|
||||
{
|
||||
pic_value v;
|
||||
|
||||
pic_get_args(pic, "o", &v);
|
||||
|
||||
if (! pic_symbol_p(v)) {
|
||||
pic_error(pic, "symbol->string: expected symbol");
|
||||
}
|
||||
|
||||
return pic_str_new_cstr(pic, pic_symbol_name(pic, pic_sym(v)));
|
||||
}
|
||||
|
||||
static pic_value
|
||||
pic_symbol_string_to_symbol(pic_state *pic)
|
||||
{
|
||||
pic_value v;
|
||||
|
||||
pic_get_args(pic, "o", &v);
|
||||
|
||||
if (! pic_str_p(v)) {
|
||||
pic_error(pic, "string->symbol: expected string");
|
||||
}
|
||||
|
||||
return pic_symbol_value(pic_intern_cstr(pic, pic_str_ptr(v)->str));
|
||||
}
|
||||
|
||||
void
|
||||
pic_init_symbol(pic_state *pic)
|
||||
{
|
||||
pic_defun(pic, "symbol?", pic_symbol_symbol_p);
|
||||
pic_defun(pic, "symbol->string", pic_symbol_symbol_to_string);
|
||||
pic_defun(pic, "string->symbol", pic_symbol_string_to_symbol);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue