refactor global_ref
This commit is contained in:
parent
e7d38ea165
commit
ae5acd005c
|
@ -1458,11 +1458,11 @@ global_ref(pic_state *pic, const char *name)
|
||||||
|
|
||||||
sym = pic_intern_cstr(pic, name);
|
sym = pic_intern_cstr(pic, name);
|
||||||
if (! (e = xh_get_int(pic->lib->senv->tbl, sym))) {
|
if (! (e = xh_get_int(pic->lib->senv->tbl, sym))) {
|
||||||
pic_error(pic, "symbol not defined");
|
return -1;
|
||||||
}
|
}
|
||||||
assert(e->val >= 0);
|
assert(e->val >= 0);
|
||||||
if (! (e = xh_get_int(pic->global_tbl, e->val))) {
|
if (! (e = xh_get_int(pic->global_tbl, e->val))) {
|
||||||
pic_abort(pic, "logic flaw");
|
return -1;
|
||||||
}
|
}
|
||||||
return e->val;
|
return e->val;
|
||||||
}
|
}
|
||||||
|
@ -1493,6 +1493,9 @@ pic_ref(pic_state *pic, const char *name)
|
||||||
int gid;
|
int gid;
|
||||||
|
|
||||||
gid = global_ref(pic, name);
|
gid = global_ref(pic, name);
|
||||||
|
if (gid == -1) {
|
||||||
|
pic_error(pic, "symbol not defined");
|
||||||
|
}
|
||||||
return pic->globals[gid];
|
return pic->globals[gid];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1502,6 +1505,9 @@ pic_set(pic_state *pic, const char *name, pic_value value)
|
||||||
int gid;
|
int gid;
|
||||||
|
|
||||||
gid = global_ref(pic, name);
|
gid = global_ref(pic, name);
|
||||||
|
if (gid == -1) {
|
||||||
|
pic_error(pic, "symbol not defined");
|
||||||
|
}
|
||||||
pic->globals[gid] = value;
|
pic->globals[gid] = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue