add `new_uniq_sym` function
This commit is contained in:
parent
4701f86ff0
commit
72cf45d4ea
|
@ -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;
|
||||
|
|
17
src/macro.c
17
src/macro.c
|
@ -1,5 +1,7 @@
|
|||
#include <stdio.h>
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
|
||||
#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;
|
||||
}
|
||||
|
|
|
@ -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 *));
|
||||
|
|
Loading…
Reference in New Issue