add some symbol primitive functions

This commit is contained in:
Yuichi Nishiwaki 2013-10-29 02:49:38 +09:00
parent 4402497a46
commit 15fdbc9c7d
2 changed files with 48 additions and 0 deletions

View File

@ -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;
}

View File

@ -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);
}