From 0c382c2bdbc330bcac6868c40015d537bb17467c Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Thu, 10 Oct 2013 17:22:25 +0900 Subject: [PATCH] add pic_intern_cstr --- include/picrin.h | 8 +++++--- src/symbol.c | 19 +++++++++++++++++++ 2 files changed, 24 insertions(+), 3 deletions(-) create mode 100644 src/symbol.c diff --git a/include/picrin.h b/include/picrin.h index 6dcc8afe..bfb72de7 100644 --- a/include/picrin.h +++ b/include/picrin.h @@ -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 diff --git a/src/symbol.c b/src/symbol.c new file mode 100644 index 00000000..a3bde2b8 --- /dev/null +++ b/src/symbol.c @@ -0,0 +1,19 @@ +#include + +#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); +}