From 72cf45d4eabd2716143b8399dc9082359a35d7f2 Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Mon, 25 Nov 2013 23:38:39 -0800 Subject: [PATCH] add `new_uniq_sym` function --- include/picrin.h | 1 + src/macro.c | 17 +++++++++++++++++ src/state.c | 1 + 3 files changed, 19 insertions(+) diff --git a/include/picrin.h b/include/picrin.h index 7588ec61..b9a2190a 100644 --- a/include/picrin.h +++ b/include/picrin.h @@ -50,6 +50,7 @@ typedef struct { struct xhash *sym_tbl; const char **sym_pool; size_t slen, scapa; + int uniq_sym_count; /* positive for variables, negative for macros (bitwise-not) */ struct xhash *global_tbl; diff --git a/src/macro.c b/src/macro.c index ff716c42..f3d0262b 100644 --- a/src/macro.c +++ b/src/macro.c @@ -1,5 +1,7 @@ #include #include +#include +#include #include "picrin.h" #include "picrin/pair.h" @@ -190,3 +192,18 @@ pic_macroexpand(pic_state *pic, pic_value obj) return v; } + +static pic_sym +new_uniq_sym(pic_state *pic, pic_sym base) +{ + int s = pic->uniq_sym_count++; + char *str; + pic_sym uniq; + + str = (char *)pic_alloc(pic, strlen(pic_symbol_name(pic, base)), + (int)log10(s) + 2); + sprintf(str, "%s@%d", pic_symbol_name(pic, base), s); + uniq = pic_intern_cstr(pic, str); + + pic_free(pic, str); + return uniq; +} diff --git a/src/state.c b/src/state.c index d8db2f75..ea212174 100644 --- a/src/state.c +++ b/src/state.c @@ -51,6 +51,7 @@ pic_open(int argc, char *argv[], char **envp) pic->sym_pool = (const char **)calloc(PIC_SYM_POOL_SIZE, sizeof(const char *)); pic->slen = 0; pic->scapa = pic->slen + PIC_SYM_POOL_SIZE; + pic->uniq_sym_count = 0; /* irep */ pic->irep = (struct pic_irep **)calloc(PIC_IREP_SIZE, sizeof(struct pic_irep *));