change pic_dict_for_each interface
This commit is contained in:
parent
e3833eb039
commit
499b68c835
|
@ -64,6 +64,7 @@ new_analyze_state(pic_state *pic)
|
|||
{
|
||||
analyze_state *state;
|
||||
pic_sym *sym;
|
||||
xh_entry *it;
|
||||
|
||||
state = pic_alloc(pic, sizeof(analyze_state));
|
||||
state->pic = pic;
|
||||
|
@ -92,7 +93,7 @@ new_analyze_state(pic_state *pic)
|
|||
/* push initial scope */
|
||||
push_scope(state, pic_nil_value());
|
||||
|
||||
pic_dict_for_each (sym, pic->globals) {
|
||||
pic_dict_for_each (sym, pic->globals, it) {
|
||||
xv_push(&state->scope->locals, &sym);
|
||||
}
|
||||
|
||||
|
|
|
@ -19,12 +19,9 @@ struct pic_dict {
|
|||
|
||||
struct pic_dict *pic_make_dict(pic_state *);
|
||||
|
||||
#define pic_dict_for_each(sym, dict) \
|
||||
pic_dict_for_each_helper_((sym), PIC_GENSYM(tmp), (dict))
|
||||
#define pic_dict_for_each_helper_(var, tmp, dict) \
|
||||
for (xh_entry *tmp = xh_begin(&dict->hash); \
|
||||
(tmp && ((var = xh_key(tmp, pic_sym *)), 1)); \
|
||||
tmp = xh_next(tmp))
|
||||
#define pic_dict_for_each(sym, dict, it) \
|
||||
for (it = xh_begin(&(dict)->hash); it != NULL; it = xh_next(it)) \
|
||||
if ((sym = xh_key(it, pic_sym *)), true)
|
||||
|
||||
pic_value pic_dict_ref(pic_state *, struct pic_dict *, pic_sym *);
|
||||
void pic_dict_set(pic_state *, struct pic_dict *, pic_sym *, pic_value);
|
||||
|
|
|
@ -75,6 +75,7 @@ import_table(pic_state *pic, pic_value spec, struct pic_dict *imports)
|
|||
struct pic_dict *table;
|
||||
pic_value val, tmp, prefix, it;
|
||||
pic_sym *sym, *id, *tag;
|
||||
xh_entry *iter;
|
||||
|
||||
table = pic_make_dict(pic);
|
||||
|
||||
|
@ -104,7 +105,7 @@ import_table(pic_state *pic, pic_value spec, struct pic_dict *imports)
|
|||
import_table(pic, pic_cadr(pic, spec), table);
|
||||
|
||||
prefix = pic_list_ref(pic, spec, 2);
|
||||
pic_dict_for_each (sym, table) {
|
||||
pic_dict_for_each (sym, table, iter) {
|
||||
id = pic_intern(pic, pic_format(pic, "~s~s", prefix, pic_obj_value(sym)));
|
||||
pic_dict_set(pic, imports, id, pic_dict_ref(pic, table, sym));
|
||||
}
|
||||
|
@ -122,7 +123,7 @@ import_table(pic_state *pic, pic_value spec, struct pic_dict *imports)
|
|||
if (! lib) {
|
||||
pic_errorf(pic, "library not found: ~a", spec);
|
||||
}
|
||||
pic_dict_for_each (sym, lib->exports) {
|
||||
pic_dict_for_each (sym, lib->exports, iter) {
|
||||
pic_dict_set(pic, imports, sym, pic_dict_ref(pic, lib->exports, sym));
|
||||
}
|
||||
}
|
||||
|
@ -132,12 +133,13 @@ import(pic_state *pic, pic_value spec)
|
|||
{
|
||||
struct pic_dict *imports;
|
||||
pic_sym *sym;
|
||||
xh_entry *it;
|
||||
|
||||
imports = pic_make_dict(pic);
|
||||
|
||||
import_table(pic, spec, imports);
|
||||
|
||||
pic_dict_for_each (sym, imports) {
|
||||
pic_dict_for_each (sym, imports, it) {
|
||||
pic_put_rename(pic, pic->lib->env, sym, pic_sym_ptr(pic_dict_ref(pic, imports, sym)));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue