From 1010456b3544a7a03d5492e09dded8f981711b99 Mon Sep 17 00:00:00 2001 From: Sainan Date: Sun, 27 Oct 2024 05:52:21 +0100 Subject: [PATCH] Allow specifying of case comparison type --- src/lparser.cpp | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/lparser.cpp b/src/lparser.cpp index c1b801370..46edfdda0 100644 --- a/src/lparser.cpp +++ b/src/lparser.cpp @@ -3212,6 +3212,16 @@ static void lgoto (LexState *ls, TString *name, int line) { } +static BinOpr testcondtype (LexState *ls, BinOpr fallback) { + if (testnext(ls, TK_EQ)) return OPR_EQ; + if (testnext(ls, '<')) return OPR_LT; + if (testnext(ls, TK_LE)) return OPR_LE; + if (testnext(ls, TK_NE)) return OPR_NE; + if (testnext(ls, '>')) return OPR_GT; + if (testnext(ls, TK_GE)) return OPR_GE; + return fallback; +} + static std::vector casecond (LexState *ls, const expdesc& ctrl, int tk) { std::vector jumps{}; FuncState *fs = ls->fs; @@ -3222,17 +3232,19 @@ static std::vector casecond (LexState *ls, const expdesc& ctrl, int tk) { expr_flags |= E_NO_CONSUME_COLON; } + BinOpr op = testcondtype(ls, OPR_EQ); expdesc e, cmpval; e = ctrl; - luaK_infix(fs, OPR_EQ, &e); + luaK_infix(fs, op, &e); expr(ls, &cmpval, nullptr, expr_flags); - luaK_posfix(fs, OPR_EQ, &e, &cmpval, case_line); + luaK_posfix(fs, op, &e, &cmpval, case_line); jumps.emplace_back(e.u.pc); while (testnext(ls, ',')) { + op = testcondtype(ls, op); e = ctrl; - luaK_infix(fs, OPR_EQ, &e); + luaK_infix(fs, op, &e); expr(ls, &cmpval, nullptr, expr_flags); - luaK_posfix(fs, OPR_EQ, &e, &cmpval, case_line); + luaK_posfix(fs, op, &e, &cmpval, case_line); jumps.emplace_back(e.u.pc); } checknext(ls, tk);