From 52396b000c9c62a8f2d50bf0407112babcd160f9 Mon Sep 17 00:00:00 2001 From: Luis <42945842+ldiaz94@users.noreply.github.com> Date: Tue, 13 Oct 2026 18:10:04 +0100 Subject: [PATCH] Self: Item uses the arm of several names foldInt's sDiv, sMod and setOp's sLeq, sGeq are one arm each again, as in the seed; foldDiv and setSubset are gone. Co-Authored-By: Claude Sonnet 5.5 --- diff --git a/self/Item.raz b/self/Item.raz index 4364631..c91817b 100644 --- a/self/Item.raz +++ b/self/Item.raz @@ -868,19 +868,6 @@ return t^.size * 8; end; -(* a div b and a mod b, of type t *) -proc foldDiv(op: Scan.Sym; a, b: I64; t: ^Sym.Type; p: Diag.Pos): (I64, ERROR); -begin - if b = 0 then return 0, Scan.markAt(p, "division by zero"); end; - if (t^.form = Sym.fInt) and not t^.signed then - if op = Scan.sDiv then return I64(U64(a) div U64(b)), nil; end; - return I64(U64(a) mod U64(b)), nil; - end; - if (b = -1) and (a = I64(-1) shl (bits(t) - 1)) then return 0, Scan.markAt(p, "division overflows"); end; - if op = Scan.sDiv then return a div b, nil; end; - return a mod b, nil; -end; - proc foldInt(op: Scan.Sym; a, b: I64; t: ^Sym.Type; p: Diag.Pos): (I64, ERROR); var u: BOOL; begin @@ -892,8 +879,15 @@ | sPlus: return a + b, nil; | sMinus: return a - b, nil; | sTimes: return a * b, nil; - | sDiv: return foldDiv(op, a, b, t, p); - | sMod: return foldDiv(op, a, b, t, p); + | sDiv, sMod: + if b = 0 then return 0, Scan.markAt(p, "division by zero"); end; + if u then + if op = Scan.sDiv then return I64(U64(a) div U64(b)), nil; end; + return I64(U64(a) mod U64(b)), nil; + end; + if (b = -1) and (a = I64(-1) shl (bits(t) - 1)) then return 0, Scan.markAt(p, "division overflows"); end; + if op = Scan.sDiv then return a div b, nil; end; + return a mod b, nil; | sAmp: return a & b, nil; | sBar: return a | b, nil; | sXor: return a xor b, nil; @@ -986,16 +980,6 @@ return nil; end; -(* x <= y has no bit of x outside y; x >= y is y <= x *) -proc setSubset(op: Scan.Sym); -begin - if op = Scan.sGeq then Gen.swap(); end; - Gen.complement(8, false); - Gen.op(Scan.sAmp, Gen.kWord, 8, false); - Gen.pushConst(Gen.kWord, 0); - Gen.compare(Scan.sEql, Gen.kWord, false); -end; - (* A set's operations, as operations on its bits: the two values on top *) proc setOp(op: Scan.Sym); begin @@ -1003,8 +987,13 @@ | sPlus: Gen.op(Scan.sBar, Gen.kWord, 8, false); | sTimes: Gen.op(Scan.sAmp, Gen.kWord, 8, false); | sMinus: Gen.complement(8, false); Gen.op(Scan.sAmp, Gen.kWord, 8, false); - | sLeq: setSubset(op); - | sGeq: setSubset(op); + | sLeq, sGeq: + (* x <= y has no bit of x outside y *) + if op = Scan.sGeq then Gen.swap(); end; + Gen.complement(8, false); + Gen.op(Scan.sAmp, Gen.kWord, 8, false); + Gen.pushConst(Gen.kWord, 0); + Gen.compare(Scan.sEql, Gen.kWord, false); | sIn: Gen.swap(); Gen.op(Scan.sShr, Gen.kWord, 8, false); diff --git a/self/README.md b/self/README.md index 4739d22..2474031 100644 --- a/self/README.md +++ b/self/README.md @@ -125,10 +125,10 @@ the speed test of step 4 to say. A `const` parameter (a hint that the callee won't change it, so that the caller may pass its address) would be a language change: it goes on the wish list. -- **Sets of `Scan.Sym`.** The operators a rule names are chains of `=` - or the helpers `oneOf` and `isRel`; the arms of a `match` on them - take one name each, so those with two names call a procedure of - their own (`foldDiv`, `setSubset`). +- **Sets of `Scan.Sym`.** It has 76 names and a set holds 64, so the + operators a rule names are chains of `=` or the helpers `oneOf` and + `isRel`. (A `match` arm with several names, which the seed's `case` + has, was added to the report for this: 2026-10.21.) - **Strings made by the compiler.** A joined string (`"a" + "b"`) and an error's text are built in memory from `Scan.grab`, which is never freed, in place of `GetMem` and `FreeMem`; the compiler runs once.