@@ -685,24 +685,47 @@ void CaseStatement::generate(Emitter &emitter) const
685685
686686void CaseStatement::ComparisonWhenCondition::generate (Emitter &emitter) const
687687{
688- static const unsigned char op[] = {EQN, NEN, LTN, GTN, LEN, GEN};
688+ static const unsigned char opn[] = {EQN, NEN, LTN, GTN, LEN, GEN};
689+ static const unsigned char ops[] = {EQS, NES, LTS, GTS, LES, GES};
690+ const unsigned char *op;
691+ if (expr->type == TYPE_NUMBER) {
692+ op = opn;
693+ } else if (expr->type == TYPE_STRING) {
694+ op = ops;
695+ } else {
696+ fprintf (stderr, " compiler internal error: when condition not number or string" );
697+ abort ();
698+ }
699+
689700 emitter.emit (DUP);
690701 expr->generate (emitter);
691702 emitter.emit (op[comp]);
692703}
693704
694705void CaseStatement::RangeWhenCondition::generate (Emitter &emitter) const
695706{
707+ static const unsigned char opn[] = {EQN, NEN, LTN, GTN, LEN, GEN};
708+ static const unsigned char ops[] = {EQS, NES, LTS, GTS, LES, GES};
709+ const unsigned char *op;
710+ if (low_expr->type == TYPE_NUMBER) {
711+ op = opn;
712+ } else if (low_expr->type == TYPE_STRING) {
713+ op = ops;
714+ } else {
715+ fprintf (stderr, " compiler internal error: when condition not number or string" );
716+ abort ();
717+ }
718+
696719 emitter.emit (DUP);
697720 auto result_label = emitter.create_label ();
698721 low_expr->generate (emitter);
699- emitter.emit (GEN );
722+ emitter.emit (op[ComparisonExpression::GE] );
700723 emitter.emit (DUP);
701724 emitter.emit_jump (JF, result_label);
702725 emitter.emit (DROP);
703726 emitter.emit (DUP);
704727 high_expr->generate (emitter);
705- emitter.emit (LEN );
728+ emitter.emit (op[ComparisonExpression::LE] );
706729 emitter.jump_target (result_label);
707730}
708731
0 commit comments