support more than 2 argument-comparators

This commit is contained in:
Yuichi Nishiwaki 2014-06-28 20:29:49 +09:00
parent 0716ff8a03
commit c5400b4b2d
1 changed files with 13 additions and 5 deletions

View File

@ -690,6 +690,12 @@ analyze_call_with_values(analyze_state *state, pic_value obj, bool tailpos)
} \ } \
} while (0) } while (0)
#define ARGC_ASSERT_WITH_FALLBACK(n) do { \
if (pic_length(pic, obj) != (n) + 1) { \
goto fallback; \
} \
} while (0)
#define CONSTRUCT_OP1(op) \ #define CONSTRUCT_OP1(op) \
pic_list2(pic, \ pic_list2(pic, \
pic_symbol_value(op), \ pic_symbol_value(op), \
@ -768,23 +774,23 @@ analyze_node(analyze_state *state, pic_value obj, bool tailpos)
return analyze_div(state, obj); return analyze_div(state, obj);
} }
else if (sym == state->rEQ) { else if (sym == state->rEQ) {
ARGC_ASSERT(2); ARGC_ASSERT_WITH_FALLBACK(2);
return CONSTRUCT_OP2(pic->sEQ); return CONSTRUCT_OP2(pic->sEQ);
} }
else if (sym == state->rLT) { else if (sym == state->rLT) {
ARGC_ASSERT(2); ARGC_ASSERT_WITH_FALLBACK(2);
return CONSTRUCT_OP2(pic->sLT); return CONSTRUCT_OP2(pic->sLT);
} }
else if (sym == state->rLE) { else if (sym == state->rLE) {
ARGC_ASSERT(2); ARGC_ASSERT_WITH_FALLBACK(2);
return CONSTRUCT_OP2(pic->sLE); return CONSTRUCT_OP2(pic->sLE);
} }
else if (sym == state->rGT) { else if (sym == state->rGT) {
ARGC_ASSERT(2); ARGC_ASSERT_WITH_FALLBACK(2);
return CONSTRUCT_OP2(pic->sGT); return CONSTRUCT_OP2(pic->sGT);
} }
else if (sym == state->rGE) { else if (sym == state->rGE) {
ARGC_ASSERT(2); ARGC_ASSERT_WITH_FALLBACK(2);
return CONSTRUCT_OP2(pic->sGE); return CONSTRUCT_OP2(pic->sGE);
} }
else if (sym == state->rNOT) { else if (sym == state->rNOT) {
@ -798,6 +804,8 @@ analyze_node(analyze_state *state, pic_value obj, bool tailpos)
return analyze_call_with_values(state, obj, tailpos); return analyze_call_with_values(state, obj, tailpos);
} }
} }
fallback:
return analyze_call(state, obj, tailpos); return analyze_call(state, obj, tailpos);
} }
case PIC_TT_BOOL: case PIC_TT_BOOL: