diff --git a/extlib/benz/codegen.c b/extlib/benz/codegen.c index 46972122..77f3a97b 100644 --- a/extlib/benz/codegen.c +++ b/extlib/benz/codegen.c @@ -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->uLT, OP_LT) VM(pic->uLE, OP_LE) + VM(pic->uGT, OP_GT) + VM(pic->uGE, OP_GE) VM(pic->uADD, OP_ADD) VM(pic->uSUB, OP_SUB) VM(pic->uMUL, OP_MUL) diff --git a/extlib/benz/gc.c b/extlib/benz/gc.c index bf677583..f890ca30 100644 --- a/extlib/benz/gc.c +++ b/extlib/benz/gc.c @@ -552,6 +552,8 @@ gc_mark_system_procedures(pic_state *pic) P(pEQ); P(pLT); P(pLE); + P(pGT); + P(pGE); } static void diff --git a/extlib/benz/include/picrin.h b/extlib/benz/include/picrin.h index d5507f5d..5d1c36be 100644 --- a/extlib/benz/include/picrin.h +++ b/extlib/benz/include/picrin.h @@ -107,7 +107,7 @@ struct pic_state { pic_sym *uVALUES, *uCALL_WITH_VALUES; 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_USER; diff --git a/extlib/benz/include/picrin/irep.h b/extlib/benz/include/picrin/irep.h index f78bf0da..327fb32c 100644 --- a/extlib/benz/include/picrin/irep.h +++ b/extlib/benz/include/picrin/irep.h @@ -45,6 +45,8 @@ enum pic_opcode { OP_EQ, OP_LT, OP_LE, + OP_GT, + OP_GE, OP_STOP }; @@ -193,6 +195,12 @@ pic_dump_code(pic_code c) case OP_LE: puts("OP_LE"); break; + case OP_GT: + puts("OP_GT"); + break; + case OP_GE: + puts("OP_GE"); + break; case OP_STOP: puts("OP_STOP"); break; diff --git a/extlib/benz/include/picrin/value.h b/extlib/benz/include/picrin/value.h index b190bce8..09e63151 100644 --- a/extlib/benz/include/picrin/value.h +++ b/extlib/benz/include/picrin/value.h @@ -663,6 +663,8 @@ pic_define_aop(pic_div, /, f == round(f)) pic_define_cmp(pic_eq, ==) pic_define_cmp(pic_lt, <) pic_define_cmp(pic_le, <=) +pic_define_cmp(pic_gt, >) +pic_define_cmp(pic_ge, >=) #if defined(__cplusplus) } diff --git a/extlib/benz/state.c b/extlib/benz/state.c index 3c74a25a..c7f65526 100644 --- a/extlib/benz/state.c +++ b/extlib/benz/state.c @@ -155,6 +155,8 @@ pic_init_core(pic_state *pic) VM(pic->uEQ, "="); VM(pic->uLT, "<"); VM(pic->uLE, "<="); + VM(pic->uGT, ">"); + VM(pic->uGE, ">="); pic_init_undef(pic); DONE; pic_init_bool(pic); DONE; @@ -194,6 +196,8 @@ pic_init_core(pic_state *pic) VM2(pic->pEQ, "="); VM2(pic->pLT, "<"); VM2(pic->pLE, "<="); + VM2(pic->pGT, ">"); + VM2(pic->pGE, ">="); pic_try { 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->pLT = pic_invalid_value(); pic->pLE = pic_invalid_value(); + pic->pGT = pic_invalid_value(); + pic->pGE = pic_invalid_value(); /* root tables */ pic->globals = pic_make_dict(pic); diff --git a/extlib/benz/vm.c b/extlib/benz/vm.c index 07ee2099..5e2217c6 100644 --- a/extlib/benz/vm.c +++ b/extlib/benz/vm.c @@ -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_SYMBOLP, &&L_OP_PAIRP, &&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 @@ -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))); 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) {