diff --git a/compiler/ccgstmts.nim b/compiler/ccgstmts.nim index bc05b79058..5512ed01c8 100644 --- a/compiler/ccgstmts.nim +++ b/compiler/ccgstmts.nim @@ -884,18 +884,23 @@ proc genRaiseStmt(p: BProc, t: PNode) = p.s(cpsStmts).addCallStmt(cgsymValue(p.module, "reraiseException")) raiseInstr(p, p.s(cpsStmts)) -template genCaseGenericBranch(p: BProc, b: PNode, e: TLoc, - rangeFormat, eqFormat: FormatStr, labl: TLabel) = +template genCaseGenericBranch(p: BProc, b: PNode, e: TLoc, labl: TLabel, + rangeFormat, eqFormat: untyped) = var x, y: TLoc for i in 0.. 0: genIfForCaseUntil(p, n, d, - rangeFormat = "if ($1 >= $2 && $1 <= $3) goto $4;$n", - eqFormat = "if ($1 == $2) goto $3;$n", - splitPoint, a) else: "" + var lend: TLabel = "" + if splitPoint > 0: + lend = genIfForCaseUntil(p, n, d, splitPoint, a): + p.s(cpsStmts).addSingleIfStmt(cOp(And, + cOp(GreaterEqual, ra, rb), + cOp(LessEqual, ra, rc))): + p.s(cpsStmts).addGoto(rlabel) + do: + p.s(cpsStmts).addSingleIfStmt( + removeSinglePar(cOp(Equal, ra, rb))): + p.s(cpsStmts).addGoto(rlabel) # generate switch part (might be empty): if splitPoint+1 < n.len: @@ -1098,8 +1113,15 @@ proc genCase(p: BProc, t: PNode, d: var TLoc) = of tyCstring: genStringCase(p, t, tyCstring, d) of tyFloat..tyFloat128: - genCaseGeneric(p, t, d, "if ($1 >= $2 && $1 <= $3) goto $4;$n", - "if ($1 == $2) goto $3;$n") + genCaseGeneric(p, t, d): + p.s(cpsStmts).addSingleIfStmt(cOp(And, + cOp(GreaterEqual, ra, rb), + cOp(LessEqual, ra, rc))): + p.s(cpsStmts).addGoto(rlabel) + do: + p.s(cpsStmts).addSingleIfStmt( + removeSinglePar(cOp(Equal, ra, rb))): + p.s(cpsStmts).addGoto(rlabel) else: if t[0].kind == nkSym and sfGoto in t[0].sym.flags: genGotoForCase(p, t)