refactor global_def
This commit is contained in:
parent
ae5acd005c
commit
c75d6e5789
|
@ -1437,17 +1437,22 @@ pic_compile(pic_state *pic, pic_value obj)
|
||||||
static int
|
static int
|
||||||
global_def(pic_state *pic, pic_sym sym)
|
global_def(pic_state *pic, pic_sym sym)
|
||||||
{
|
{
|
||||||
xh_entry *e;
|
pic_sym gsym;
|
||||||
|
size_t gidx;
|
||||||
|
|
||||||
if ((e = xh_get_int(pic->global_tbl, sym))) {
|
gsym = pic_gensym(pic, sym);
|
||||||
pic_warn(pic, "redefining global");
|
|
||||||
return e->val;
|
/* register to the senv */
|
||||||
}
|
xh_put_int(pic->lib->senv->tbl, sym, gsym);
|
||||||
e = xh_put_int(pic->global_tbl, sym, pic->glen++);
|
|
||||||
|
/* register to the global table */
|
||||||
|
gidx = pic->glen++;
|
||||||
if (pic->glen >= pic->gcapa) {
|
if (pic->glen >= pic->gcapa) {
|
||||||
pic_error(pic, "global table overflow");
|
pic_error(pic, "global table overflow");
|
||||||
}
|
}
|
||||||
return e->val;
|
xh_put_int(pic->global_tbl, gsym, gidx);
|
||||||
|
|
||||||
|
return gidx;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
@ -1471,18 +1476,14 @@ void
|
||||||
pic_define(pic_state *pic, const char *name, pic_value val)
|
pic_define(pic_state *pic, const char *name, pic_value val)
|
||||||
{
|
{
|
||||||
int idx;
|
int idx;
|
||||||
pic_sym sym, gsym;
|
pic_sym sym;
|
||||||
|
|
||||||
sym = pic_intern_cstr(pic, name);
|
sym = pic_intern_cstr(pic, name);
|
||||||
gsym = pic_gensym(pic, sym);
|
|
||||||
|
|
||||||
/* push to the global arena */
|
/* push to the global arena */
|
||||||
idx = global_def(pic, gsym);
|
idx = global_def(pic, sym);
|
||||||
pic->globals[idx] = val;
|
pic->globals[idx] = val;
|
||||||
|
|
||||||
/* register to the senv */
|
|
||||||
xh_put_int(pic->lib->senv->tbl, sym, gsym);
|
|
||||||
|
|
||||||
/* export! */
|
/* export! */
|
||||||
pic_export(pic, pic_intern_cstr(pic, name));
|
pic_export(pic, pic_intern_cstr(pic, name));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue