add OP_GT and OP_GE

This commit is contained in:
Yuichi Nishiwaki 2015-07-06 19:13:00 +09:00
parent 055691ebfc
commit 9e04a80636
7 changed files with 40 additions and 2 deletions

View File

@ -945,6 +945,8 @@ codegen_call_vm(pic_state *pic, codegen_context *cxt, pic_value proc, size_t len
VM(pic->uEQ, OP_EQ) VM(pic->uEQ, OP_EQ)
VM(pic->uLT, OP_LT) VM(pic->uLT, OP_LT)
VM(pic->uLE, OP_LE) VM(pic->uLE, OP_LE)
VM(pic->uGT, OP_GT)
VM(pic->uGE, OP_GE)
VM(pic->uADD, OP_ADD) VM(pic->uADD, OP_ADD)
VM(pic->uSUB, OP_SUB) VM(pic->uSUB, OP_SUB)
VM(pic->uMUL, OP_MUL) VM(pic->uMUL, OP_MUL)

View File

@ -552,6 +552,8 @@ gc_mark_system_procedures(pic_state *pic)
P(pEQ); P(pEQ);
P(pLT); P(pLT);
P(pLE); P(pLE);
P(pGT);
P(pGE);
} }
static void static void

View File

@ -107,7 +107,7 @@ struct pic_state {
pic_sym *uVALUES, *uCALL_WITH_VALUES; pic_sym *uVALUES, *uCALL_WITH_VALUES;
pic_value pCONS, pCAR, pCDR, pNILP, pPAIRP, pSYMBOLP, pNOT; pic_value pCONS, pCAR, pCDR, pNILP, pPAIRP, pSYMBOLP, pNOT;
pic_value pADD, pSUB, pMUL, pDIV, pEQ, pLT, pLE; pic_value pADD, pSUB, pMUL, pDIV, pEQ, pLT, pLE, pGT, pGE;
struct pic_lib *PICRIN_BASE; struct pic_lib *PICRIN_BASE;
struct pic_lib *PICRIN_USER; struct pic_lib *PICRIN_USER;

View File

@ -45,6 +45,8 @@ enum pic_opcode {
OP_EQ, OP_EQ,
OP_LT, OP_LT,
OP_LE, OP_LE,
OP_GT,
OP_GE,
OP_STOP OP_STOP
}; };
@ -193,6 +195,12 @@ pic_dump_code(pic_code c)
case OP_LE: case OP_LE:
puts("OP_LE"); puts("OP_LE");
break; break;
case OP_GT:
puts("OP_GT");
break;
case OP_GE:
puts("OP_GE");
break;
case OP_STOP: case OP_STOP:
puts("OP_STOP"); puts("OP_STOP");
break; break;

View File

@ -663,6 +663,8 @@ pic_define_aop(pic_div, /, f == round(f))
pic_define_cmp(pic_eq, ==) pic_define_cmp(pic_eq, ==)
pic_define_cmp(pic_lt, <) pic_define_cmp(pic_lt, <)
pic_define_cmp(pic_le, <=) pic_define_cmp(pic_le, <=)
pic_define_cmp(pic_gt, >)
pic_define_cmp(pic_ge, >=)
#if defined(__cplusplus) #if defined(__cplusplus)
} }

View File

@ -155,6 +155,8 @@ pic_init_core(pic_state *pic)
VM(pic->uEQ, "="); VM(pic->uEQ, "=");
VM(pic->uLT, "<"); VM(pic->uLT, "<");
VM(pic->uLE, "<="); VM(pic->uLE, "<=");
VM(pic->uGT, ">");
VM(pic->uGE, ">=");
pic_init_undef(pic); DONE; pic_init_undef(pic); DONE;
pic_init_bool(pic); DONE; pic_init_bool(pic); DONE;
@ -194,6 +196,8 @@ pic_init_core(pic_state *pic)
VM2(pic->pEQ, "="); VM2(pic->pEQ, "=");
VM2(pic->pLT, "<"); VM2(pic->pLT, "<");
VM2(pic->pLE, "<="); VM2(pic->pLE, "<=");
VM2(pic->pGT, ">");
VM2(pic->pGE, ">=");
pic_try { pic_try {
pic_load_cstr(pic, &pic_boot[0][0]); pic_load_cstr(pic, &pic_boot[0][0]);
@ -387,6 +391,8 @@ pic_open(pic_allocf allocf, void *userdata)
pic->pEQ = pic_invalid_value(); pic->pEQ = pic_invalid_value();
pic->pLT = pic_invalid_value(); pic->pLT = pic_invalid_value();
pic->pLE = pic_invalid_value(); pic->pLE = pic_invalid_value();
pic->pGT = pic_invalid_value();
pic->pGE = pic_invalid_value();
/* root tables */ /* root tables */
pic->globals = pic_make_dict(pic); pic->globals = pic_make_dict(pic);

View File

@ -536,7 +536,7 @@ pic_apply(pic_state *pic, struct pic_proc *proc, pic_value args)
&&L_OP_LAMBDA, &&L_OP_CONS, &&L_OP_CAR, &&L_OP_CDR, &&L_OP_NILP, &&L_OP_LAMBDA, &&L_OP_CONS, &&L_OP_CAR, &&L_OP_CDR, &&L_OP_NILP,
&&L_OP_SYMBOLP, &&L_OP_PAIRP, &&L_OP_SYMBOLP, &&L_OP_PAIRP,
&&L_OP_ADD, &&L_OP_SUB, &&L_OP_MUL, &&L_OP_DIV, &&L_OP_ADD, &&L_OP_SUB, &&L_OP_MUL, &&L_OP_DIV,
&&L_OP_EQ, &&L_OP_LT, &&L_OP_LE, &&L_OP_STOP &&L_OP_EQ, &&L_OP_LT, &&L_OP_LE, &&L_OP_GT, &&L_OP_GE, &&L_OP_STOP
}; };
#endif #endif
@ -968,6 +968,24 @@ pic_apply(pic_state *pic, struct pic_proc *proc, pic_value args)
PUSH(pic_bool_value(pic_lt(pic, a, b))); PUSH(pic_bool_value(pic_lt(pic, a, b)));
NEXT; NEXT;
} }
CASE(OP_GE) {
pic_value a, b;
check_condition(LT, 2);
b = POP();
a = POP();
(void)POP();
PUSH(pic_bool_value(pic_ge(pic, a, b)));
NEXT;
}
CASE(OP_GT) {
pic_value a, b;
check_condition(LE, 2);
b = POP();
a = POP();
(void)POP();
PUSH(pic_bool_value(pic_gt(pic, a, b)));
NEXT;
}
CASE(OP_STOP) { CASE(OP_STOP) {