change pic_for_each interface
This commit is contained in:
parent
1b637d1763
commit
e3833eb039
|
@ -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)
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
|
|
@ -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))
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue