From 7dbb2c6de4f7cc59b365b329df38123aa0be0195 Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Mon, 21 Oct 2013 11:44:23 +0900 Subject: [PATCH] cleanup --- include/picrin/string.h | 2 +- include/picrin/symbol.h | 1 - src/state.c | 26 ++++++++++++++++++++++---- src/symbol.c | 15 --------------- 4 files changed, 23 insertions(+), 21 deletions(-) diff --git a/include/picrin/string.h b/include/picrin/string.h index f4a1d39f..fa64b6de 100644 --- a/include/picrin/string.h +++ b/include/picrin/string.h @@ -3,7 +3,7 @@ struct pic_string { PIC_OBJECT_HEADER - const char *str; + char *str; size_t len; }; diff --git a/include/picrin/symbol.h b/include/picrin/symbol.h index 24908c37..a84a6e21 100644 --- a/include/picrin/symbol.h +++ b/include/picrin/symbol.h @@ -6,7 +6,6 @@ struct sym_tbl { size_t size; }; -struct sym_tbl * sym_tbl_new(); pic_value sym_tbl_get(struct sym_tbl *, const char *); #endif diff --git a/src/state.c b/src/state.c index 82b0327a..09bc261f 100644 --- a/src/state.c +++ b/src/state.c @@ -17,12 +17,28 @@ new_empty_env() return env; } +struct sym_tbl * +sym_tbl_new() +{ + struct sym_tbl *s_tbl; + int i; + + s_tbl = (struct sym_tbl *)malloc(sizeof(struct sym_tbl)); + s_tbl->size = PIC_SYM_TBL_SIZE; + + for (i = 0; i < PIC_SYM_TBL_SIZE; ++i) { + s_tbl->tbl[i] = pic_nil_value(); + } + return s_tbl; +} + void pic_init_core(pic_state *); pic_state * pic_open() { pic_state *pic; + int ai; pic = (pic_state *)malloc(sizeof(pic_state)); @@ -63,6 +79,11 @@ pic_open() /* GC arena */ pic->arena_idx = 0; + /* global environment */ + pic->global_env = new_empty_env(); + pic_init_core(pic); + + ai = pic_gc_arena_preserve(pic); pic->sDEFINE = pic_intern_cstr(pic, "define"); pic->sLAMBDA = pic_intern_cstr(pic, "lambda"); pic->sIF = pic_intern_cstr(pic, "if"); @@ -76,10 +97,7 @@ pic_open() pic->sSUB = pic_intern_cstr(pic, "-"); pic->sMUL = pic_intern_cstr(pic, "*"); pic->sDIV = pic_intern_cstr(pic, "/"); - - /* global environment */ - pic->global_env = new_empty_env(); - pic_init_core(pic); + pic_gc_arena_restore(pic, ai); return pic; } diff --git a/src/symbol.c b/src/symbol.c index b9d5fc2b..f9d67a54 100644 --- a/src/symbol.c +++ b/src/symbol.c @@ -17,21 +17,6 @@ str_hash(const char *str) return hash; } -struct sym_tbl * -sym_tbl_new() -{ - struct sym_tbl *s_tbl; - int i; - - s_tbl = (struct sym_tbl *)malloc(sizeof(struct sym_tbl)); - s_tbl->size = PIC_SYM_TBL_SIZE; - - for (i = 0; i < PIC_SYM_TBL_SIZE; ++i) { - s_tbl->tbl[i] = pic_nil_value(); - } - return s_tbl; -} - pic_value sym_tbl_get(struct sym_tbl *s_tbl, const char *key) {