rpg_source.zig, rpg_eval.zig: read SORTA of an array or of %SUBARR and %LOOKUP of a packed array #797

Manually merged
binjovi-bot merged 3 commits from lsrt into trunk 2026-11-13 23:47:29 +00:00
Owner

rpg_source.zig, rpg_eval.zig: read SORTA of an array or of %SUBARR and %LOOKUP of a packed array

SORTA a;, SORTA(D) a;, SORTA %SUBARR(a: 1: 5);, SORTA %SUBARR(a: 1: n);,
SORTA %SUBARR(a: s); and p = %LOOKUP(x: a), %LOOKUP(x: a: s), %LOOKUP(x: a: s: n)
were ? unresolved statement. Two rewrite units (rpg_sorta.zig, rpg_lookup.zig, in the chain of
rpg_value_units.zig) prove the whole operation family of the statement and become one operation each
(op_sort 0x7f000030, op_lookup 0x7f000031). rpg_sort_value.zig (the two step arms of rpg_eval.zig)
reads the names the unit cannot (the helper, the signalling procedure), writes the line, and gives the
emitter the array (array_element_v1: dimension and element width), so dcl-s a packed(5:0) dim(10);
comes with the statement. The families are written as text (rpg_unit_pattern.zig: 34 AR 0; 35 TP; ...,
a capital name is a slot that every later place must repeat), so the measurement is the pattern. A shape
that differs in any operation or operand reads nothing and the statement keeps its failure.

Emitter (the only edits of rpg_source*.zig, ten lines, no more were needed to print the statement):
rpg_source.zig has a head arm for SORTA and SORTA(D) (form emit_sorta_v1 in rpg_source_forms.zig;
noCalculationRule names SORTA) and %SUBARR, %LOOKUP in its list of built-in functions.

Measured (SC-ILE/EXPERIMENTS lsrt-sorta-, lsrt-lookup-; a packed(5) dim(10), c char(5) dim(10))

SORTA calls a helper procedure of the module, _QRNI_SORT_{A|D}_<name of the array of the source>
(_QRNI_SORT_A_A sorts a, _QRNI_SORT_A_C sorts c, _QRNI_SORT_D_A sorts a descending: the object
keeps the source name of the array in the name of the helper, a name the emitter does not use yet; one
helper for each SORTA statement, 89 operations): a shell sort of the array symbol AR with the element
type TE. SORTA and SORTA(D) are the same
statement operation for operation; only the one comparison in the helper differs (12 ascending, 10
descending), so the unit reads the helper (102 H; 106 x3; 103 x5; ... 32 AR 0 TE; CMP; 17 0; ... 101 H)
and the name must agree with the comparison. The call has five arguments: the address of the first
element, the count, three null pointers (99 H 5 0 0).

case statement 12 (frames left out) read as
sorta-all, sorta-desc 34 AR 0; 113 6 2; 35 TP; 27 TP; 27 CN; 27 NU x3; 99 H 5 0 0 (CN = dimension) sorta a; sorta(d) a;
sorta-subarr-lit 27 NU; 35 TP; 27 ST; 75 8; 27 ONE; 52; 75 4; 35 S0; 27 CT; 75 8; 75 4; 35 TC; 34 AR 0; 27 S0; 65 W; 35 TP; 27 TC; 35 S0; 27 TP; 27 TC; 77 4; 27 NU x3; 99 H 5 0 0 sorta %SUBARR(a: 1: 5);
sorta-subarr-n, sorta-char the same start, then 29 N 0 TN; 87 8; 75 8; 27 DIM; 27 S0; 52; 35 MX; 1; 35 CV; 27 CV; 27 MX; 75 8; 12; 16 L1; 27 CV; 27 ONE2; 10; 17 L2; 15 L1 2; 27 ER; 35 54; 99 SG 0 0 0; 15 L2 2; 75 4; 35 TC; and the address (ER = 121) sorta %SUBARR(a: 1: n); (c: char(5) dim(10))
sorta-subarr-s 27 NU; 35 TP; 29 S 0 TS; 87 8; 75 8; 1; 35 CV; 27 CV; 27 DIM; 12; 16 L1; 27 CV; 27 ONE2; 10; 17 L2; 15 L1 2; 27 ER; 35 54; 99 SG 0 0 0; 15 L2 2; 27 ONE; 52; 75 4; 35 S0; 27 DIM2; 27 S0; 52; 35 TC; then the address sorta %SUBARR(a: s);

%LOOKUP has no call. The compiler writes a loop: TS the first index, TE the last, TP the array address, TV the
search value (27 KV; 61 5 0 0; 35 TV), TI the result (0 when not found), the equality 7:

27 TS; 27 TE; 9; 17 LNF; 27 TS; 77 4; 35 TI; 15 LL 2; 27 TV; 27 TP; 27 TI; 27 ONE; 52; 65 W; 32 AR 0 ET; 7; 17 LF; 27 TI; 27 ONE; 47; 1; 35 TI; 78 4; 27 TE; 9; 16 LL; 15 LX 2; 15 LNF 2; 27 Z2; 35 TI; 18 LEND; 15 LF 2; 15 LEND 2; 27 TI (42 operations with the head), then the field store 76 8; 88 20; 61 5 0 0; 37 P 0 TP.

case head before the loop read as
lookup-2 27 K1; 35 TS; 27 DIM; 35 TE; 34 AR 0; 35 TP; 27 KV; 61 5 0 0; 35 TV (start 1, end = dimension) p = %LOOKUP(4: a);
lookup-3 29 S 0 TT; 35 TV; 27 TV; 27 K1; 86 5; 10; 16 LE; 27 TV; 27 DIM; 86 5; 12; 16 LE; 18 LOK; 15 LE 1; 27 ER; 35 54; 99 SG 0 0 0; 15 LOK 1; 27 TV; 87 8; 75 4; 35 TS; 27 DIM; 35 TE; 34 AR 0; 35 TP; and the search value (TV is the start, then the value) %LOOKUP(4: a: s)
lookup-4 the start check, then 27 DIM; 27 TS; 52; 27 ONE; 78 4; 47; 35 TE; 29 N 0 TN; 35 TC; 27 TC; 27 Z1; 86 63; 10; 16 LE2; 27 TC; 27 TE; 86 63; 12; 16 LE2; 18 LOK2; 15 LE2 1; 27 ER; 35 54; 99 SG 0 0 0; 15 LOK2 1; 27 TC; 87 8; 75 4; 27 TS; 27 ONE; 78 4; 52; 47; 35 TE; (the count is checked 0 to the elements left, TE = TS + N - 1) %LOOKUP(4: a: s: n)
lookup-elem 34 253 0; 27 OFF; 62 before the unit (the address of a(2), OFF = 3), and 32 SA 0 TS2; 61 5 0 0; 35 TV for the value %LOOKUP(a(2): a: s)

Proved before a unit reads: the helper body and its array, direction and element type (packed or character);
the dimension (the length of the array over the element width: the constant form of %SUBARR holds no
dimension constant, so for it that is the whole proof), the element width and the constants (1, 0, 121, the
dimension; the start of a %SUBARR is the constant 1, no other start is measured; the literal count is 1 to
the dimension); the element of a %LOOKUP is an element of the array it searches (the only measured case);
the null pointers; the packed fields and their types; the temporaries are
compiler temporaries that no other operation names; the labels are defined once, inside the unit, and
jumped to only from inside it; the digits of the rescale and of the checked temporaries; the names of the
helper (_QRNI_SORT_{A|D}_ and a name, the letter agrees with the comparison) and of the signalling
procedure (_QRNI_SOFT_ERR). A changed operation, a changed operand of any of them (all but the
signalling procedure, which the evaluator proves by its name), a stray reader of a temporary, a start other
than 1, an element of another array and another comparison refuse, in src/rpg_lsrt_test.zig.

Effect

The ten battery statements read (agree.sh: same 61 to 75, suspect 2 to 2, wrong parameters 0, emit-lint
0 findings); none of the ten emits is free of failure lines, because statements 9, 10 and 13 of the probes
(an array element assignment, %CHAR, %CHAR(a(1))) are other work. Development programs, reported as fit
(no rule or test holds their text): p3 5 failure lines to 3 (its two SORTA %SUBARR(array: 1: count) read),
p4 6 to 4 (its two SORTA read); the %LOOKUP of p4 (a search value that is an element of another array
at a variable index) matches the three-argument unit and is refused where the value is read, because the
battery has no such element: the request requests/lsrt/sorta2 holds it, and 23 more shapes (a variable,
literal or expression start, a literal count, a character, zoned and integer array, %LOOKUPGT, LT, GE and LE
of an ASCEND array, a variable start and count and a literal start of 2 in %SUBARR, SORTA(D) of a character
array; a shape that keeps the measured family, as SORTA(D) of a character array does, would already read).

Probes adopted (matrix rows, none host-matching yet): lsrt-sorta-all, lsrt-sorta-desc,
lsrt-sorta-subarr-lit, lsrt-sorta-subarr-n, lsrt-sorta-subarr-s, lsrt-sorta-char, lsrt-lookup-2,
lsrt-lookup-3, lsrt-lookup-4, lsrt-lookup-elem. docs/OPERATIONS.md is regenerated (ops-legend.sh --write).

Gates

{"checks":{"net_statements":0},"census":{"statuses":{"recovered":645,"partial":0,"unresolved":0},"regressions":0,"newly_recovered":0},"golden":"golden floor 173 ceiling 0 <= dump 173/5/0","legend":"regenerated","emit":{"worse":[],"better":0,"newly_clean":0,"clean_delta":0,"base":593,"new":593},"twins":{"groups":841,"recovered":819,"regressions":[],"newly":10},"allgroups":{"regressions":[],"newly":[],"worse":[]},"unit":{"exit":0,"last":"ship-unit: src/rpg_lsrt_test.zig ok"},"full_check":{"exit":0,"seconds":2127}}
# rpg_source.zig, rpg_eval.zig: read SORTA of an array or of %SUBARR and %LOOKUP of a packed array `SORTA a;`, `SORTA(D) a;`, `SORTA %SUBARR(a: 1: 5);`, `SORTA %SUBARR(a: 1: n);`, `SORTA %SUBARR(a: s);` and `p = %LOOKUP(x: a)`, `%LOOKUP(x: a: s)`, `%LOOKUP(x: a: s: n)` were `? unresolved statement`. Two rewrite units (`rpg_sorta.zig`, `rpg_lookup.zig`, in the chain of `rpg_value_units.zig`) prove the whole operation family of the statement and become one operation each (`op_sort` 0x7f000030, `op_lookup` 0x7f000031). `rpg_sort_value.zig` (the two `step` arms of `rpg_eval.zig`) reads the names the unit cannot (the helper, the signalling procedure), writes the line, and gives the emitter the array (`array_element_v1`: dimension and element width), so `dcl-s a packed(5:0) dim(10);` comes with the statement. The families are written as text (`rpg_unit_pattern.zig`: `34 AR 0; 35 TP; ...`, a capital name is a slot that every later place must repeat), so the measurement is the pattern. A shape that differs in any operation or operand reads nothing and the statement keeps its failure. Emitter (the only edits of `rpg_source*.zig`, ten lines, no more were needed to print the statement): `rpg_source.zig` has a head arm for `SORTA` and `SORTA(D)` (form `emit_sorta_v1` in `rpg_source_forms.zig`; `noCalculationRule` names SORTA) and `%SUBARR`, `%LOOKUP` in its list of built-in functions. ## Measured (SC-ILE/EXPERIMENTS lsrt-sorta-*, lsrt-lookup-*; a packed(5) dim(10), c char(5) dim(10)) SORTA calls a helper procedure of the module, `_QRNI_SORT_{A|D}_<name of the array of the source>` (`_QRNI_SORT_A_A` sorts `a`, `_QRNI_SORT_A_C` sorts `c`, `_QRNI_SORT_D_A` sorts `a` descending: the object keeps the source name of the array in the name of the helper, a name the emitter does not use yet; one helper for each SORTA statement, 89 operations): a shell sort of the array symbol AR with the element type TE. SORTA and SORTA(D) are the same statement operation for operation; only the one comparison in the helper differs (`12` ascending, `10` descending), so the unit reads the helper (`102 H; 106 x3; 103 x5; ... 32 AR 0 TE; CMP; 17 0; ... 101 H`) and the name must agree with the comparison. The call has five arguments: the address of the first element, the count, three null pointers (`99 H 5 0 0`). | case | statement 12 (frames left out) | read as | |---|---|---| | sorta-all, sorta-desc | `34 AR 0; 113 6 2; 35 TP; 27 TP; 27 CN; 27 NU x3; 99 H 5 0 0` (CN = dimension) | `sorta a;` `sorta(d) a;` | | sorta-subarr-lit | `27 NU; 35 TP; 27 ST; 75 8; 27 ONE; 52; 75 4; 35 S0; 27 CT; 75 8; 75 4; 35 TC; 34 AR 0; 27 S0; 65 W; 35 TP; 27 TC; 35 S0; 27 TP; 27 TC; 77 4; 27 NU x3; 99 H 5 0 0` | `sorta %SUBARR(a: 1: 5);` | | sorta-subarr-n, sorta-char | the same start, then `29 N 0 TN; 87 8; 75 8; 27 DIM; 27 S0; 52; 35 MX; 1; 35 CV; 27 CV; 27 MX; 75 8; 12; 16 L1; 27 CV; 27 ONE2; 10; 17 L2; 15 L1 2; 27 ER; 35 54; 99 SG 0 0 0; 15 L2 2; 75 4; 35 TC;` and the address (ER = 121) | `sorta %SUBARR(a: 1: n);` (c: `char(5) dim(10)`) | | sorta-subarr-s | `27 NU; 35 TP; 29 S 0 TS; 87 8; 75 8; 1; 35 CV; 27 CV; 27 DIM; 12; 16 L1; 27 CV; 27 ONE2; 10; 17 L2; 15 L1 2; 27 ER; 35 54; 99 SG 0 0 0; 15 L2 2; 27 ONE; 52; 75 4; 35 S0; 27 DIM2; 27 S0; 52; 35 TC;` then the address | `sorta %SUBARR(a: s);` | %LOOKUP has no call. The compiler writes a loop: TS the first index, TE the last, TP the array address, TV the search value (`27 KV; 61 5 0 0; 35 TV`), TI the result (0 when not found), the equality `7`: `27 TS; 27 TE; 9; 17 LNF; 27 TS; 77 4; 35 TI; 15 LL 2; 27 TV; 27 TP; 27 TI; 27 ONE; 52; 65 W; 32 AR 0 ET; 7; 17 LF; 27 TI; 27 ONE; 47; 1; 35 TI; 78 4; 27 TE; 9; 16 LL; 15 LX 2; 15 LNF 2; 27 Z2; 35 TI; 18 LEND; 15 LF 2; 15 LEND 2; 27 TI` (42 operations with the head), then the field store `76 8; 88 20; 61 5 0 0; 37 P 0 TP`. | case | head before the loop | read as | |---|---|---| | lookup-2 | `27 K1; 35 TS; 27 DIM; 35 TE; 34 AR 0; 35 TP; 27 KV; 61 5 0 0; 35 TV` (start 1, end = dimension) | `p = %LOOKUP(4: a);` | | lookup-3 | `29 S 0 TT; 35 TV; 27 TV; 27 K1; 86 5; 10; 16 LE; 27 TV; 27 DIM; 86 5; 12; 16 LE; 18 LOK; 15 LE 1; 27 ER; 35 54; 99 SG 0 0 0; 15 LOK 1; 27 TV; 87 8; 75 4; 35 TS; 27 DIM; 35 TE; 34 AR 0; 35 TP;` and the search value (TV is the start, then the value) | `%LOOKUP(4: a: s)` | | lookup-4 | the start check, then `27 DIM; 27 TS; 52; 27 ONE; 78 4; 47; 35 TE; 29 N 0 TN; 35 TC; 27 TC; 27 Z1; 86 63; 10; 16 LE2; 27 TC; 27 TE; 86 63; 12; 16 LE2; 18 LOK2; 15 LE2 1; 27 ER; 35 54; 99 SG 0 0 0; 15 LOK2 1; 27 TC; 87 8; 75 4; 27 TS; 27 ONE; 78 4; 52; 47; 35 TE;` (the count is checked 0 to the elements left, TE = TS + N - 1) | `%LOOKUP(4: a: s: n)` | | lookup-elem | `34 253 0; 27 OFF; 62` before the unit (the address of `a(2)`, OFF = 3), and `32 SA 0 TS2; 61 5 0 0; 35 TV` for the value | `%LOOKUP(a(2): a: s)` | Proved before a unit reads: the helper body and its array, direction and element type (packed or character); the dimension (the length of the array over the element width: the constant form of %SUBARR holds no dimension constant, so for it that is the whole proof), the element width and the constants (1, 0, 121, the dimension; the start of a %SUBARR is the constant 1, no other start is measured; the literal count is 1 to the dimension); the element of a %LOOKUP is an element of the array it searches (the only measured case); the null pointers; the packed fields and their types; the temporaries are compiler temporaries that no other operation names; the labels are defined once, inside the unit, and jumped to only from inside it; the digits of the rescale and of the checked temporaries; the names of the helper (`_QRNI_SORT_{A|D}_` and a name, the letter agrees with the comparison) and of the signalling procedure (`_QRNI_SOFT_ERR`). A changed operation, a changed operand of any of them (all but the signalling procedure, which the evaluator proves by its name), a stray reader of a temporary, a start other than 1, an element of another array and another comparison refuse, in `src/rpg_lsrt_test.zig`. ## Effect The ten battery statements read (`agree.sh`: same 61 to 75, suspect 2 to 2, wrong parameters 0, `emit-lint` 0 findings); none of the ten emits is free of failure lines, because statements 9, 10 and 13 of the probes (an array element assignment, `%CHAR`, `%CHAR(a(1))`) are other work. Development programs, reported as fit (no rule or test holds their text): p3 5 failure lines to 3 (its two `SORTA %SUBARR(array: 1: count)` read), p4 6 to 4 (its two SORTA read); the `%LOOKUP` of p4 (a search value that is an element of another array at a variable index) matches the three-argument unit and is refused where the value is read, because the battery has no such element: the request `requests/lsrt/sorta2` holds it, and 23 more shapes (a variable, literal or expression start, a literal count, a character, zoned and integer array, %LOOKUPGT, LT, GE and LE of an ASCEND array, a variable start and count and a literal start of 2 in %SUBARR, SORTA(D) of a character array; a shape that keeps the measured family, as SORTA(D) of a character array does, would already read). Probes adopted (matrix rows, none host-matching yet): lsrt-sorta-all, lsrt-sorta-desc, lsrt-sorta-subarr-lit, lsrt-sorta-subarr-n, lsrt-sorta-subarr-s, lsrt-sorta-char, lsrt-lookup-2, lsrt-lookup-3, lsrt-lookup-4, lsrt-lookup-elem. docs/OPERATIONS.md is regenerated (`ops-legend.sh --write`). ## Gates ``` {"checks":{"net_statements":0},"census":{"statuses":{"recovered":645,"partial":0,"unresolved":0},"regressions":0,"newly_recovered":0},"golden":"golden floor 173 ceiling 0 <= dump 173/5/0","legend":"regenerated","emit":{"worse":[],"better":0,"newly_clean":0,"clean_delta":0,"base":593,"new":593},"twins":{"groups":841,"recovered":819,"regressions":[],"newly":10},"allgroups":{"regressions":[],"newly":[],"worse":[]},"unit":{"exit":0,"last":"ship-unit: src/rpg_lsrt_test.zig ok"},"full_check":{"exit":0,"seconds":2127}} ```
Two rewrite units prove the whole operation family of the statement
(rpg_sorta.zig: the helper procedure _QRNI_SORT_{A|D}_<array>, its
comparison and the %SUBARR start and count with their status 121
checks; rpg_lookup.zig: the inline search loop with two, three or four
arguments and a constant or element search value). rpg_sort_value.zig
reads the names, writes the line and tells the emitter the array.
The families are written as text in rpg_unit_pattern.zig. The emitter
prints SORTA and knows %SUBARR and %LOOKUP.
Read only the measured starts and the array of the element in SORTA and %LOOKUP
Some checks reported errors
binjovi/ci A newer source or plan superseded this Build
6260f66082
A %SUBARR start other than the constant 1 is not measured, so it is not
read. The element that %LOOKUP searches for must be of the array it
searches. The temporaries of a %LOOKUP are proved before any symbol is
indexed. The tests name no array of a development program.
sean force-pushed lsrt from 6260f66082
Some checks reported errors
binjovi/ci A newer source or plan superseded this Build
to db5007bdbd
All checks were successful
binjovi/ci Binjovi completed the frozen plan
2026-11-13 20:51:00 +00:00
Compare
sean force-pushed lsrt from db5007bdbd
All checks were successful
binjovi/ci Binjovi completed the frozen plan
to 536c21a579
All checks were successful
binjovi/ci Binjovi completed the frozen plan
2026-11-13 23:36:13 +00:00
Compare
binjovi-bot manually merged commit 407d977809 into trunk 2026-11-13 23:47:29 +00:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
sean/sourcerer!797
No description provided.