add new_uniq_sym function
This commit is contained in:
+17
@@ -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 *));
|
||||
|
||||
Reference in New Issue
Block a user