diff --git a/extlib/benz/blob.c b/extlib/benz/blob.c index cd5be767..4ca4006d 100644 --- a/extlib/benz/blob.c +++ b/extlib/benz/blob.c @@ -203,7 +203,7 @@ pic_blob_list_to_bytevector(pic_state *pic) { pic_blob *blob; unsigned char *data; - pic_value list, e; + pic_value list, e, it; pic_get_args(pic, "o", &list); @@ -211,7 +211,7 @@ pic_blob_list_to_bytevector(pic_state *pic) data = blob->data; - pic_for_each (e, list) { + pic_for_each (e, list, it) { pic_assert_type(pic, e, int); if (pic_int(e) < 0 || pic_int(e) > 255) diff --git a/extlib/benz/codegen.c b/extlib/benz/codegen.c index 51d94e6a..91e0a4f0 100644 --- a/extlib/benz/codegen.c +++ b/extlib/benz/codegen.c @@ -344,9 +344,9 @@ static void analyze_deferred(analyze_state *state) { pic_state *pic = state->pic; - pic_value defer, val, name, formal, body, dst; + pic_value defer, val, name, formal, body, dst, it; - pic_for_each (defer, pic_reverse(pic, state->scope->defer)) { + pic_for_each (defer, pic_reverse(pic, state->scope->defer), it) { name = pic_list_ref(pic, defer, 0); formal = pic_list_ref(pic, defer, 1); body = pic_list_ref(pic, defer, 2); @@ -566,7 +566,7 @@ analyze_quote(analyze_state *state, pic_value obj) #define FOLD_ARGS(sym) do { \ obj = analyze(state, pic_car(pic, args), false); \ - pic_for_each (arg, pic_cdr(pic, args)) { \ + pic_for_each (arg, pic_cdr(pic, args), it) { \ obj = pic_list3(pic, pic_obj_value(sym), obj, \ analyze(state, arg, false)); \ } \ @@ -576,7 +576,7 @@ static pic_value analyze_add(analyze_state *state, pic_value obj, bool tailpos) { pic_state *pic = state->pic; - pic_value args, arg; + pic_value args, arg, it; ARGC_ASSERT_GE(0); switch (pic_length(pic, obj)) { @@ -595,7 +595,7 @@ static pic_value analyze_sub(analyze_state *state, pic_value obj) { pic_state *pic = state->pic; - pic_value args, arg; + pic_value args, arg, it; ARGC_ASSERT_GE(1); switch (pic_length(pic, obj)) { @@ -613,7 +613,7 @@ static pic_value analyze_mul(analyze_state *state, pic_value obj, bool tailpos) { pic_state *pic = state->pic; - pic_value args, arg; + pic_value args, arg, it; ARGC_ASSERT_GE(0); switch (pic_length(pic, obj)) { @@ -632,7 +632,7 @@ static pic_value analyze_div(analyze_state *state, pic_value obj) { pic_state *pic = state->pic; - pic_value args, arg; + pic_value args, arg, it; ARGC_ASSERT_GE(1); switch (pic_length(pic, obj)) { @@ -651,7 +651,7 @@ static pic_value analyze_call(analyze_state *state, pic_value obj, bool tailpos) { pic_state *pic = state->pic; - pic_value seq, elt; + pic_value seq, elt, it; pic_sym *call; if (! tailpos) { @@ -660,7 +660,7 @@ analyze_call(analyze_state *state, pic_value obj, bool tailpos) call = pic->sTAILCALL; } seq = pic_list1(pic, pic_obj_value(call)); - pic_for_each (elt, obj) { + pic_for_each (elt, obj, it) { seq = pic_cons(pic, analyze(state, elt, false), seq); } return pic_reverse(pic, seq); @@ -670,14 +670,14 @@ static pic_value analyze_values(analyze_state *state, pic_value obj, bool tailpos) { pic_state *pic = state->pic; - pic_value v, seq; + pic_value v, seq, it; if (! tailpos) { return analyze_call(state, obj, false); } seq = pic_list1(pic, pic_obj_value(pic->sRETURN)); - pic_for_each (v, pic_cdr(pic, obj)) { + pic_for_each (v, pic_cdr(pic, obj), it) { seq = pic_cons(pic, analyze(state, v, false), seq); } return pic_reverse(pic, seq); @@ -964,7 +964,7 @@ push_codegen_context(codegen_state *state, pic_value name, pic_value args, pic_v { pic_state *pic = state->pic; codegen_context *cxt; - pic_value var; + pic_value var, it; pic_sym *sym; assert(pic_sym_p(name) || pic_false_p(name)); @@ -980,15 +980,15 @@ push_codegen_context(codegen_state *state, pic_value name, pic_value args, pic_v xv_init(&cxt->locals, sizeof(pic_sym *)); xv_init(&cxt->captures, sizeof(pic_sym *)); - pic_for_each (var, args) { + pic_for_each (var, args, it) { sym = pic_sym_ptr(var); xv_push(&cxt->args, &sym); } - pic_for_each (var, locals) { + pic_for_each (var, locals, it) { sym = pic_sym_ptr(var); xv_push(&cxt->locals, &sym); } - pic_for_each (var, captures) { + pic_for_each (var, captures, it) { sym = pic_sym_ptr(var); xv_push(&cxt->captures, &sym); } @@ -1240,10 +1240,10 @@ codegen(codegen_state *state, pic_value obj) return; } else if (sym == pic->sBEGIN) { - pic_value elt; + pic_value elt, it; int i = 0; - pic_for_each (elt, pic_cdr(pic, obj)) { + pic_for_each (elt, pic_cdr(pic, obj), it) { if (i++ != 0) { cxt->code[cxt->clen].insn = OP_POP; cxt->clen++; @@ -1406,9 +1406,9 @@ codegen(codegen_state *state, pic_value obj) } else if (sym == pic->sCALL || sym == pic->sTAILCALL) { int len = (int)pic_length(pic, obj); - pic_value elt; + pic_value elt, it; - pic_for_each (elt, pic_cdr(pic, obj)) { + pic_for_each (elt, pic_cdr(pic, obj), it) { codegen(state, elt); } cxt->code[cxt->clen].insn = (sym == pic->sCALL) ? OP_CALL : OP_TAILCALL; @@ -1432,9 +1432,9 @@ codegen(codegen_state *state, pic_value obj) } else if (sym == pic->sRETURN) { int len = (int)pic_length(pic, obj); - pic_value elt; + pic_value elt, it; - pic_for_each (elt, pic_cdr(pic, obj)) { + pic_for_each (elt, pic_cdr(pic, obj), it) { codegen(state, elt); } cxt->code[cxt->clen].insn = OP_RET; diff --git a/extlib/benz/cont.c b/extlib/benz/cont.c index 2678fb0b..17587e95 100644 --- a/extlib/benz/cont.c +++ b/extlib/benz/cont.c @@ -195,11 +195,11 @@ pic_values_by_array(pic_state *pic, size_t argc, pic_value *argv) pic_value pic_values_by_list(pic_state *pic, pic_value list) { - pic_value v; + pic_value v, it; int i; i = 0; - pic_for_each (v, list) { + pic_for_each (v, list, it) { pic->sp[i++] = v; } pic->ci->retc = i; diff --git a/extlib/benz/dict.c b/extlib/benz/dict.c index d677e935..4312c40f 100644 --- a/extlib/benz/dict.c +++ b/extlib/benz/dict.c @@ -273,13 +273,13 @@ static pic_value pic_dict_alist_to_dictionary(pic_state *pic) { struct pic_dict *dict; - pic_value alist, e; + pic_value alist, e, it; pic_get_args(pic, "o", &alist); dict = pic_make_dict(pic); - pic_for_each (e, pic_reverse(pic, alist)) { + pic_for_each (e, pic_reverse(pic, alist), it) { pic_assert_type(pic, pic_car(pic, e), sym); pic_dict_set(pic, dict, pic_sym_ptr(pic_car(pic, e)), pic_cdr(pic, e)); } diff --git a/extlib/benz/include/picrin/pair.h b/extlib/benz/include/picrin/pair.h index 11859482..3b3e29b0 100644 --- a/extlib/benz/include/picrin/pair.h +++ b/extlib/benz/include/picrin/pair.h @@ -59,12 +59,9 @@ pic_value pic_list7(pic_state *, pic_value, pic_value, pic_value, pic_value, pic pic_value pic_list_by_array(pic_state *, size_t, pic_value *); pic_value pic_make_list(pic_state *, size_t, pic_value); -#define pic_for_each(var, list) \ - pic_for_each_helper_(var, PIC_GENSYM(tmp), list) -#define pic_for_each_helper_(var, tmp, list) \ - for (pic_value tmp = (list); \ - pic_nil_p(tmp) ? false : ((var = pic_car(pic, tmp)), true); \ - tmp = pic_cdr(pic, tmp)) +#define pic_for_each(var, list, it) \ + for (it = (list); ! pic_nil_p(it); it = pic_cdr(pic, it)) \ + if ((var = pic_car(pic, it)), true) #define pic_push(pic, item, place) (place = pic_cons(pic, item, place)) #define pic_pop(pic, place) (place = pic_cdr(pic, place)) diff --git a/extlib/benz/lib.c b/extlib/benz/lib.c index 234f3833..0c4ad001 100644 --- a/extlib/benz/lib.c +++ b/extlib/benz/lib.c @@ -73,7 +73,7 @@ import_table(pic_state *pic, pic_value spec, struct pic_dict *imports) { struct pic_lib *lib; struct pic_dict *table; - pic_value val, tmp, prefix; + pic_value val, tmp, prefix, it; pic_sym *sym, *id, *tag; table = pic_make_dict(pic); @@ -85,7 +85,7 @@ import_table(pic_state *pic, pic_value spec, struct pic_dict *imports) if (tag == pic->sONLY) { import_table(pic, pic_cadr(pic, spec), table); - pic_for_each (val, pic_cddr(pic, spec)) { + pic_for_each (val, pic_cddr(pic, spec), it) { pic_dict_set(pic, imports, pic_sym_ptr(val), pic_dict_ref(pic, table, pic_sym_ptr(val))); } return; @@ -93,7 +93,7 @@ import_table(pic_state *pic, pic_value spec, struct pic_dict *imports) if (tag == pic->sRENAME) { import_table(pic, pic_cadr(pic, spec), imports); - pic_for_each (val, pic_cddr(pic, spec)) { + pic_for_each (val, pic_cddr(pic, spec), it) { tmp = pic_dict_ref(pic, imports, pic_sym_ptr(pic_car(pic, val))); pic_dict_del(pic, imports, pic_sym_ptr(pic_car(pic, val))); pic_dict_set(pic, imports, pic_sym_ptr(pic_cadr(pic, val)), tmp); @@ -112,7 +112,7 @@ import_table(pic_state *pic, pic_value spec, struct pic_dict *imports) } if (tag == pic->sEXCEPT) { import_table(pic, pic_cadr(pic, spec), imports); - pic_for_each (val, pic_cddr(pic, spec)) { + pic_for_each (val, pic_cddr(pic, spec), it) { pic_dict_del(pic, imports, pic_sym_ptr(val)); } return; @@ -202,13 +202,13 @@ static bool condexpand(pic_state *pic, pic_value clause) { pic_sym *tag; - pic_value c, feature; + pic_value c, feature, it; if (pic_eq_p(clause, pic_obj_value(pic->sELSE))) { return true; } if (pic_sym_p(clause)) { - pic_for_each (feature, pic->features) { + pic_for_each (feature, pic->features, it) { if(pic_eq_p(feature, clause)) return true; } @@ -228,14 +228,14 @@ condexpand(pic_state *pic, pic_value clause) return ! condexpand(pic, pic_list_ref(pic, clause, 1)); } if (tag == pic->sAND) { - pic_for_each (c, pic_cdr(pic, clause)) { + pic_for_each (c, pic_cdr(pic, clause), it) { if (! condexpand(pic, c)) return false; } return true; } if (tag == pic->sOR) { - pic_for_each (c, pic_cdr(pic, clause)) { + pic_for_each (c, pic_cdr(pic, clause), it) { if (condexpand(pic, c)) return true; } diff --git a/extlib/benz/macro.c b/extlib/benz/macro.c index 622a28d3..f934cdd3 100644 --- a/extlib/benz/macro.c +++ b/extlib/benz/macro.c @@ -124,9 +124,9 @@ macroexpand_defer(pic_state *pic, pic_value expr, struct pic_senv *senv) static void macroexpand_deferred(pic_state *pic, struct pic_senv *senv) { - pic_value defer, val, src, dst; + pic_value defer, val, src, dst, it; - pic_for_each (defer, pic_reverse(pic, senv->defer)) { + pic_for_each (defer, pic_reverse(pic, senv->defer), it) { src = pic_car(pic, defer); dst = pic_cdr(pic, defer); diff --git a/extlib/benz/pair.c b/extlib/benz/pair.c index 03621ec1..fc865921 100644 --- a/extlib/benz/pair.c +++ b/extlib/benz/pair.c @@ -204,10 +204,10 @@ pic_value pic_reverse(pic_state *pic, pic_value list) { size_t ai = pic_gc_arena_preserve(pic); - pic_value v, acc; + pic_value v, acc, it; acc = pic_nil_value(); - pic_for_each(v, list) { + pic_for_each(v, list, it) { acc = pic_cons(pic, v, acc); pic_gc_arena_restore(pic, ai); @@ -220,10 +220,10 @@ pic_value pic_append(pic_state *pic, pic_value xs, pic_value ys) { size_t ai = pic_gc_arena_preserve(pic); - pic_value x; + pic_value x, it; xs = pic_reverse(pic, xs); - pic_for_each (x, xs) { + pic_for_each (x, xs, it) { ys = pic_cons(pic, x, ys); pic_gc_arena_restore(pic, ai); diff --git a/extlib/benz/string.c b/extlib/benz/string.c index 43514b2d..abdefad0 100644 --- a/extlib/benz/string.c +++ b/extlib/benz/string.c @@ -425,7 +425,7 @@ static pic_value pic_str_list_to_string(pic_state *pic) { pic_str *str; - pic_value list, e; + pic_value list, e, it; size_t i = 0; pic_get_args(pic, "o", &list); @@ -435,7 +435,7 @@ pic_str_list_to_string(pic_state *pic) } else { char buf[pic_length(pic, list)]; - pic_for_each (e, list) { + pic_for_each (e, list, it) { pic_assert_type(pic, e, char); buf[i++] = pic_char(e); diff --git a/extlib/benz/vector.c b/extlib/benz/vector.c index 33070d24..60004cc8 100644 --- a/extlib/benz/vector.c +++ b/extlib/benz/vector.c @@ -302,7 +302,7 @@ static pic_value pic_vec_list_to_vector(pic_state *pic) { struct pic_vector *vec; - pic_value list, e, *data; + pic_value list, e, it, *data; pic_get_args(pic, "o", &list); @@ -310,7 +310,7 @@ pic_vec_list_to_vector(pic_state *pic) data = vec->data; - pic_for_each (e, list) { + pic_for_each (e, list, it) { *data++ = e; } return pic_obj_value(vec); diff --git a/extlib/benz/vm.c b/extlib/benz/vm.c index 0c82bdff..12862f9f 100644 --- a/extlib/benz/vm.c +++ b/extlib/benz/vm.c @@ -1153,13 +1153,13 @@ pic_apply_trampoline(pic_state *pic, struct pic_proc *proc, pic_value args) { OP_TAILCALL, { .i = -1 } } }; - pic_value v, *sp; + pic_value v, it, *sp; pic_callinfo *ci; *pic->sp++ = pic_obj_value(proc); sp = pic->sp; - pic_for_each (v, args) { + pic_for_each (v, args, it) { *sp++ = v; } diff --git a/src/main.c b/src/main.c index 03431ac4..f43419f1 100644 --- a/src/main.c +++ b/src/main.c @@ -20,11 +20,11 @@ pic_features(pic_state *pic) static pic_value pic_libraries(pic_state *pic) { - pic_value libs = pic_nil_value(), lib; + pic_value libs = pic_nil_value(), lib, it; pic_get_args(pic, ""); - pic_for_each (lib, pic->libs) { + pic_for_each (lib, pic->libs, it) { libs = pic_cons(pic, pic_car(pic, lib), libs); }