raz / commit 52396b00

commit
52396b000c9c62a8f2d50bf0407112babcd160f9
author
Luis <42945842+ldiaz94@users.noreply.github.com>
date
parent
57a5dff9
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 <noreply@anthropic.com>

patch · log

2 files changed, +20 -31

self/Item.raz modified +16 -27

@@ -868,19 +868,6 @@
868868 return t^.size * 8;
869869 end;
870870
871-(* a div b and a mod b, of type t *)
872-proc foldDiv(op: Scan.Sym; a, b: I64; t: ^Sym.Type; p: Diag.Pos): (I64, ERROR);
873-begin
874- if b = 0 then return 0, Scan.markAt(p, "division by zero"); end;
875- if (t^.form = Sym.fInt) and not t^.signed then
876- if op = Scan.sDiv then return I64(U64(a) div U64(b)), nil; end;
877- return I64(U64(a) mod U64(b)), nil;
878- end;
879- if (b = -1) and (a = I64(-1) shl (bits(t) - 1)) then return 0, Scan.markAt(p, "division overflows"); end;
880- if op = Scan.sDiv then return a div b, nil; end;
881- return a mod b, nil;
882-end;
883-
884871 proc foldInt(op: Scan.Sym; a, b: I64; t: ^Sym.Type; p: Diag.Pos): (I64, ERROR);
885872 var u: BOOL;
886873 begin
@@ -892,8 +879,15 @@
892879 | sPlus: return a + b, nil;
893880 | sMinus: return a - b, nil;
894881 | sTimes: return a * b, nil;
895- | sDiv: return foldDiv(op, a, b, t, p);
896- | sMod: return foldDiv(op, a, b, t, p);
882+ | sDiv, sMod:
883+ if b = 0 then return 0, Scan.markAt(p, "division by zero"); end;
884+ if u then
885+ if op = Scan.sDiv then return I64(U64(a) div U64(b)), nil; end;
886+ return I64(U64(a) mod U64(b)), nil;
887+ end;
888+ if (b = -1) and (a = I64(-1) shl (bits(t) - 1)) then return 0, Scan.markAt(p, "division overflows"); end;
889+ if op = Scan.sDiv then return a div b, nil; end;
890+ return a mod b, nil;
897891 | sAmp: return a & b, nil;
898892 | sBar: return a | b, nil;
899893 | sXor: return a xor b, nil;
@@ -986,16 +980,6 @@
986980 return nil;
987981 end;
988982
989-(* x <= y has no bit of x outside y; x >= y is y <= x *)
990-proc setSubset(op: Scan.Sym);
991-begin
992- if op = Scan.sGeq then Gen.swap(); end;
993- Gen.complement(8, false);
994- Gen.op(Scan.sAmp, Gen.kWord, 8, false);
995- Gen.pushConst(Gen.kWord, 0);
996- Gen.compare(Scan.sEql, Gen.kWord, false);
997-end;
998-
999983 (* A set's operations, as operations on its bits: the two values on top *)
1000984 proc setOp(op: Scan.Sym);
1001985 begin
@@ -1003,8 +987,13 @@
1003987 | sPlus: Gen.op(Scan.sBar, Gen.kWord, 8, false);
1004988 | sTimes: Gen.op(Scan.sAmp, Gen.kWord, 8, false);
1005989 | sMinus: Gen.complement(8, false); Gen.op(Scan.sAmp, Gen.kWord, 8, false);
1006- | sLeq: setSubset(op);
1007- | sGeq: setSubset(op);
990+ | sLeq, sGeq:
991+ (* x <= y has no bit of x outside y *)
992+ if op = Scan.sGeq then Gen.swap(); end;
993+ Gen.complement(8, false);
994+ Gen.op(Scan.sAmp, Gen.kWord, 8, false);
995+ Gen.pushConst(Gen.kWord, 0);
996+ Gen.compare(Scan.sEql, Gen.kWord, false);
1008997 | sIn:
1009998 Gen.swap();
1010999 Gen.op(Scan.sShr, Gen.kWord, 8, false);

self/README.md modified +4 -4

@@ -125,10 +125,10 @@
125125 the speed test of step 4 to say. A `const` parameter (a hint that
126126 the callee won't change it, so that the caller may pass its address)
127127 would be a language change: it goes on the wish list.
128-- **Sets of `Scan.Sym`.** The operators a rule names are chains of `=`
129- or the helpers `oneOf` and `isRel`; the arms of a `match` on them
130- take one name each, so those with two names call a procedure of
131- their own (`foldDiv`, `setSubset`).
128+- **Sets of `Scan.Sym`.** It has 76 names and a set holds 64, so the
129+ operators a rule names are chains of `=` or the helpers `oneOf` and
130+ `isRel`. (A `match` arm with several names, which the seed's `case`
131+ has, was added to the report for this: 2026-10.21.)
132132 - **Strings made by the compiler.** A joined string (`"a" + "b"`) and
133133 an error's text are built in memory from `Scan.grab`, which is never
134134 freed, in place of `GetMem` and `FreeMem`; the compiler runs once.