add pic_intern_cstr

This commit is contained in:
Yuichi Nishiwaki 2013-10-10 17:22:25 +09:00
parent 0fad63f22a
commit 0c382c2bdb
2 changed files with 24 additions and 3 deletions

View File

@ -13,8 +13,10 @@ void pic_free(pic_state *, void *);
pic_state *pic_open();
void pic_close(pic_state *);
pic_value pic_cons(pic_state *pic, pic_value, pic_value);
pic_value pic_car(pic_state *pic, pic_value);
pic_value pic_cdr(pic_state *pic, pic_value);
pic_value pic_cons(pic_state *, pic_value, pic_value);
pic_value pic_car(pic_state *, pic_value);
pic_value pic_cdr(pic_state *, pic_value);
pic_value pic_intern_cstr(pic_state *, const char *);
#endif

19
src/symbol.c Normal file
View File

@ -0,0 +1,19 @@
#include <string.h>
#include "picrin.h"
pic_value
pic_intern_cstr(pic_state *pic, char *name)
{
struct pic_symbol *sym;
size_t len;
sym = (struct pic_symbol*)pic_gc_alloc(pic, sizeof(struct pic_symbol), PIC_TT_SYMBOL);
/* clone name string */
len = strlen(name);
sym->name = (char *)pic_alloc(pic, len + 1);
strncpy(sym->name, name, len + 1);
return pic_obj_value(sym);
}