use pic_for_each

This commit is contained in:
Yuichi Nishiwaki 2014-02-01 16:05:29 +09:00
parent a4a63314a9
commit 2f50f92ddc
3 changed files with 27 additions and 29 deletions

View File

@ -435,14 +435,14 @@ analyze_node(analyze_state *state, pic_value obj, bool tailpos)
#define FOLD_ARGS(sym) do { \
obj = analyze(state, pic_car(pic, args), false); \
for (args = pic_cdr(pic, args); ! pic_nil_p(args); args = pic_cdr(pic, args)) { \
pic_for_each (arg, pic_cdr(pic, args)) { \
obj = pic_list(pic, 3, pic_symbol_value(sym), obj, \
analyze(state, pic_car(pic, args), false)); \
analyze(state, arg, false)); \
} \
} while (0)
else if (sym == state->rADD) {
pic_value args;
pic_value args, arg;
ARGC_ASSERT_GE(0);
switch (pic_length(pic, obj)) {
@ -457,7 +457,7 @@ analyze_node(analyze_state *state, pic_value obj, bool tailpos)
}
}
else if (sym == state->rSUB) {
pic_value args;
pic_value args, arg;
ARGC_ASSERT_GE(1);
switch (pic_length(pic, obj)) {
@ -471,7 +471,7 @@ analyze_node(analyze_state *state, pic_value obj, bool tailpos)
}
}
else if (sym == state->rMUL) {
pic_value args;
pic_value args, arg;
ARGC_ASSERT_GE(0);
switch (pic_length(pic, obj)) {
@ -486,7 +486,7 @@ analyze_node(analyze_state *state, pic_value obj, bool tailpos)
}
}
else if (sym == state->rDIV) {
pic_value args;
pic_value args, arg;
ARGC_ASSERT_GE(1);
switch (pic_length(pic, obj)) {
@ -556,7 +556,7 @@ analyze_call(analyze_state *state, pic_value obj, bool tailpos)
{
pic_state *pic = state->pic;
int ai = pic_gc_arena_preserve(pic);
pic_value seq;
pic_value seq, elt;
pic_sym call;
if (! tailpos) {
@ -565,8 +565,8 @@ analyze_call(analyze_state *state, pic_value obj, bool tailpos)
call = state->sTAILCALL;
}
seq = pic_list(pic, 1, pic_symbol_value(call));
for (; ! pic_nil_p(obj); obj = pic_cdr(pic, obj)) {
seq = pic_cons(pic, analyze(state, pic_car(pic, obj), false), seq);
pic_for_each (elt, obj) {
seq = pic_cons(pic, analyze(state, elt, false), seq);
}
seq = pic_reverse(pic, seq);
@ -863,12 +863,12 @@ resolve_reference_node(resolver_state *state, pic_value obj)
}
else {
int ai = pic_gc_arena_preserve(pic);
pic_value seq = pic_list(pic, 1, pic_symbol_value(tag));
for (obj = pic_cdr(pic, obj); ! pic_nil_p(obj); obj = pic_cdr(pic, obj)) {
seq = pic_cons(pic, resolve_reference(state, pic_car(pic, obj)), seq);
pic_value seq = pic_list(pic, 1, pic_symbol_value(tag)), elt;
pic_for_each (elt, pic_cdr(pic, obj)) {
seq = pic_cons(pic, resolve_reference(state, elt), seq);
pic_gc_arena_restore(pic, ai);
pic_gc_protect(pic, obj);
pic_gc_protect(pic, seq);
}
return pic_reverse(pic, seq);
@ -1133,8 +1133,9 @@ codegen(codegen_state *state, pic_value obj)
return;
}
else if (sym == pic->sBEGIN) {
for (obj = pic_cdr(pic, obj); ! pic_nil_p(obj); obj = pic_cdr(pic, obj)) {
codegen(state, pic_car(pic, obj));
pic_value elt;
pic_for_each (elt, pic_cdr(pic, obj)) {
codegen(state, elt);
}
return;
}
@ -1274,8 +1275,10 @@ codegen(codegen_state *state, pic_value obj)
}
else if (sym == state->sCALL || sym == state->sTAILCALL) {
int len = pic_length(pic, obj);
for (obj = pic_cdr(pic, obj); ! pic_nil_p(obj); obj = pic_cdr(pic, obj)) {
codegen(state, pic_car(pic, obj));
pic_value elt;
pic_for_each (elt, pic_cdr(pic, obj)) {
codegen(state, elt);
}
cxt->code[cxt->clen].insn = (sym == state->sCALL) ? OP_CALL : OP_TAILCALL;
cxt->code[cxt->clen].u.i = len - 1;

View File

@ -299,7 +299,6 @@ macroexpand(pic_state *pic, pic_value expr, struct pic_senv *senv)
if (pic_syntax_p(car)) {
switch (pic_syntax(car)->kind) {
case PIC_STX_DEFLIBRARY: {
pic_value exprs;
struct pic_lib *prev = pic->lib;
if (pic_length(pic, expr) < 2) {
@ -312,9 +311,7 @@ macroexpand(pic_state *pic, pic_value expr, struct pic_senv *senv)
{
struct pic_proc *proc;
for (exprs = pic_cddr(pic, expr); ! pic_nil_p(exprs); exprs = pic_cdr(pic, exprs)) {
v = pic_car(pic, exprs);
pic_for_each (v, pic_cddr(pic, expr)) {
proc = pic_compile(pic, v);
if (proc == NULL) {
abort();
@ -330,16 +327,15 @@ macroexpand(pic_state *pic, pic_value expr, struct pic_senv *senv)
return pic_none_value();
}
case PIC_STX_IMPORT: {
for (v = pic_cdr(pic, expr); ! pic_nil_p(v); v = pic_cdr(pic, v)) {
pic_value spec = pic_car(pic, v);
pic_value spec;
pic_for_each (spec, pic_cdr(pic, expr)) {
pic_import(pic, spec);
}
return pic_none_value();
}
case PIC_STX_EXPORT: {
for (v = pic_cdr(pic, expr); ! pic_nil_p(v); v = pic_cdr(pic, v)) {
pic_value spec = pic_car(pic, v);
pic_value spec;
pic_for_each (spec, pic_cdr(pic, expr)) {
if (! pic_sym_p(spec)) {
pic_error(pic, "syntax error");
}

View File

@ -126,12 +126,11 @@ pic_reverse(pic_state *pic, pic_value list)
pic_value v, acc;
acc = pic_nil_value();
for (v = list; ! pic_nil_p(v); v = pic_cdr(pic ,v)) {
acc = pic_cons(pic, pic_car(pic, v), acc);
pic_for_each(v, list) {
acc = pic_cons(pic, v, acc);
pic_gc_arena_restore(pic, ai);
pic_gc_protect(pic, acc);
pic_gc_protect(pic, v);
}
return acc;
}