2013-10-10 04:22:25 -04:00
|
|
|
#include <string.h>
|
2013-10-13 03:01:40 -04:00
|
|
|
#include <stdlib.h>
|
2013-10-10 04:22:25 -04:00
|
|
|
|
|
|
|
#include "picrin.h"
|
2013-10-28 13:11:31 -04:00
|
|
|
#include "xhash/xhash.h"
|
2013-10-20 01:05:35 -04:00
|
|
|
|
2013-10-28 13:11:31 -04:00
|
|
|
pic_sym
|
|
|
|
pic_intern_cstr(pic_state *pic, const char *str)
|
2013-10-20 01:05:35 -04:00
|
|
|
{
|
2013-10-28 13:11:31 -04:00
|
|
|
struct xh_entry *e;
|
|
|
|
pic_sym id;
|
2013-10-20 01:05:35 -04:00
|
|
|
|
2013-10-28 13:11:31 -04:00
|
|
|
e = xh_get(pic->sym_tbl, str);
|
|
|
|
if (e) {
|
|
|
|
return e->val;
|
2013-10-20 01:05:35 -04:00
|
|
|
}
|
|
|
|
|
2013-10-28 13:16:26 -04:00
|
|
|
if (pic->slen >= pic->scapa) {
|
|
|
|
pic->scapa *= 2;
|
|
|
|
pic->sym_pool = pic_realloc(pic, pic->sym_pool, sizeof(const char *) * pic->scapa);
|
|
|
|
}
|
2013-10-28 13:11:31 -04:00
|
|
|
id = pic->slen++;
|
|
|
|
pic->sym_pool[id] = strdup(str);
|
|
|
|
xh_put(pic->sym_tbl, str, id);
|
|
|
|
return id;
|
2013-10-20 01:05:35 -04:00
|
|
|
}
|
|
|
|
|
2013-10-28 13:11:31 -04:00
|
|
|
const char *
|
|
|
|
pic_symbol_name(pic_state *pic, pic_sym sym)
|
2013-10-20 01:05:35 -04:00
|
|
|
{
|
2013-10-28 13:11:31 -04:00
|
|
|
return pic->sym_pool[sym];
|
2013-10-10 04:22:25 -04:00
|
|
|
}
|