Quellcode durchsuchen

compiler: zero AH for one-byte FOR control variables

A CHAR or BYTE FOR variable loads into AL only.  The loop test compared AX
against the word bound, so the body's leftover AH (wrchar leaves 02h) made the
next comparison read 0242h and the loop stopped after the first character.
CALC's Grid therefore printed only the 'A' column header.

Zero AH after both the test load and the step load.  Add t117_charfor, which
prints A..G, and re-baseline CALC to code 27,498 / image 36,894.
Eric Streit vor 1 Tag
Ursprung
Commit
df803160d0

+ 6 - 6
CALC-COMPILE.md

@@ -97,7 +97,7 @@ Current rung (measured today, normalised position):
 
 | position | blocker |
 |---|---|
-| **compiles** | `CALC.PAS` reaches its final `.` — code **27,458** B, data **19,694** B |
+| **compiles** | `CALC.PAS` reaches its final `.` — code **27,498** B, data **19,694** B |
 
 Rungs behind it (now passed):
 
@@ -164,7 +164,7 @@ Rungs ahead:
 | 51322 | CASE/ELSE closing `end;` - DONE |
 | 52316 | string vs CHAR comparison (`S <> Chr($FF)`) - DONE |
 | 56540 | code-image ceiling - DONE (DataStart moved to 0xA000) |
-| **OK** | **CALC.PAS compiles: code 27,458, data 19,694** |
+| **OK** | **CALC.PAS compiles: code 27,498, data 19,694** |
 
 Corrections the measurements force, worth stating plainly because the stage list
 below was written before them:
@@ -1263,14 +1263,14 @@ include directory, boots it under qemu and feeds the default welcome/quit keys.
 are available; input is a static boot-time key stream, not a live terminal.
 
 **CALC.PAS compiles and runs.**  The runtime is 9,393 bytes; the generated
-program is 27,458 bytes of code and 19,694 bytes of data, with
+program is 27,498 bytes of code and 19,694 bytes of data, with
 `DataStart=0xA000` and `CodeMax=0xA000`.  The boot harness now loads images at
 segment `0x1000` and puts its input descriptor at `0x9800`, so the larger image
 no longer collides with the boot sector/BIOS areas.  The loader reads 77
 sectors and accepts images up to 38,656 bytes.  `tests/calc_smoke.py`
 boots CALC.COM under qemu, enters `1+2` in cell A1, checks the resulting
 `3.00` and the welcome/grid/command menu, sends `/Q`, and requires exit code 0.  The original CALC.COM is 27,901 bytes; ours is
-36,854 bytes because the runtime, static links and code layout differ.
+36,894 bytes because the runtime, static links and code layout differ.
 
 **Stage 14 — the CRT identifiers.** `GotoXY` (25), `LowVideo`/`NormVideo`
 (16 + 16), `ClrEol` (10), `ClrScr` (6), `KeyPressed` (3), `Delay` (1),
@@ -1317,8 +1317,8 @@ remaining run-time capacity note.
 | limit | value | CALC needs | verdict |
 |---|---|---|---|
 | `TextLimit` (source buffer) | 62,903 | `CALC.PAS` + `CALC.INC`, normalised = **62,415** | **488 bytes of slack** |
-| `MaxCode` | 0A000h | 27,458 B program + 9,393 B runtime = **36,851 B** | **OK, 4,109 B spare** |
-| code window | `CodeMax = 0A000h`, capped by `MaxCode` | 27,458 B | **OK**; no data gap (§3.2) |
+| `MaxCode` | 0A000h | 27,498 B program + 9,393 B runtime = **36,891 B** | **OK, 4,069 B spare** |
+| code window | `CodeMax = 0A000h`, capped by `MaxCode` | 27,498 B | **OK**; no data gap (§3.2) |
 | data area | fixed image `0A000h`, zeroed by `initmem` | **19,694 B** (generated) | **OK**; CALC boots under qemu |
 | stack | 16,384 min / 655,360 max | 16,384 min | matches the original's `minstk`/`maxstk` |
 | `MaxSym` | 3,000 | 47 routines + locals + params | **inferred** OK, verify |

+ 1 - 1
README.md

@@ -18,7 +18,7 @@ second copy of a status table is a claim about the world that expires silently
 and is never noticed expiring, so there is one now, and this file says where it
 is.
 
-In short, current as of `v-TP3-CALC-DOSOUT`:
+In short, current as of `v-TP3-CALC-CHARFOR`:
 
 - The shell and the WordStar-style editor are done.
 - The compiler front end and 8086 code generator are done for the language

+ 2 - 2
SUMMARY.md

@@ -2044,7 +2044,7 @@ the compiler *emitting* a 16,560-byte program). The ratchet and front-end
 features through **file control-block operations and the original memory
 layout** are landed: the ladder (`tests/calc_ladder.sh` +
 `tests/fixtures/calc_ladder.tsv`, run by `run_all.sh`; CALC.PAS now stops at
-**CALC.PAS compiles and runs** (code 27,458, data 19,694), the `{$I}` include,
+**CALC.PAS compiles and runs** (code 27,498, data 19,694), the `{$I}` include,
 `^X`/`#nn`, scalar typed constants, sets, enums, records (CellRec = 80),
 subranges, arrays, element/field access, file types, string value parameters,
 `Length`, the CRT identifiers (`ClrScr`/`GotoXY`/`ClrEol`/`LowVideo`/
@@ -2070,7 +2070,7 @@ standard functions (`Abs`, `Sqr`, `Sqrt`, `Ln`, `Exp`, `Sin`, `Cos`,
 landed, along with `Delete` and local `set of Char` variables.  The math runtime
 was compacted to guest Horner/square loops, reducing it from 14,063 to 9,203
 bytes.  `Insert`, CASE/ELSE trailing semicolons and string-vs-CHAR comparisons
-are also landed.  **CALC.PAS now compiles to its final `.`** with code 27,458
+are also landed.  **CALC.PAS now compiles to its final `.`** with code 27,498
 and data 19,694.  Nested procedures now use a real static link, so a cell can
 be entered and its formula/text edited (the first cell-entry path no longer
 restarts or corrupts the screen).  The boot loader now uses segment 0x1000

+ 9 - 0
shell/Compiler.mod

@@ -6653,6 +6653,12 @@ BEGIN
          leaves the bound in place. *)
       EmMovCxSp () ;
       LoadSymVar (idx, symtab [idx].off, symtab [idx].size) ;
+      IF symtab [idx].size = 1 THEN
+         (* A CHAR/BYTE control variable loads into AL only.  Without zeroing
+            AH, the previous body's leftover AH (wrchar leaves 02h there) makes
+            the 16-bit CMP read 0242h and the loop stops after 'A'. *)
+         EmMovAh0 ()
+      END ;
       EmCmpAxCx () ;
       IF dow THEN
          zj := EmJcc (8CH, 0)          (* JL -> done *)
@@ -6676,6 +6682,9 @@ BEGIN
          leaves this one intact. *)
       (* step *)
       LoadSymVar (idx, symtab [idx].off, symtab [idx].size) ;
+      IF symtab [idx].size = 1 THEN
+         EmMovAh0 ()
+      END ;
       IF dow THEN
          EmDecAx ()
       ELSE

+ 1 - 1
shell/tests/fixtures/calc_ladder.tsv

@@ -32,4 +32,4 @@
 # data base.  UpCase, set membership, strings, pointers, files, REAL
 # expressions/functions, recursion, forward definitions, Copy/Val/Delete/
 # Insert, local sets and the compact math runtime are all landed.
-CALC.PAS	OK	27458	19694
+CALC.PAS	OK	27498	19694

+ 2 - 0
shell/tests/fixtures/expected.tsv

@@ -740,3 +740,5 @@ t114_nested2	OK	106	5
 t115_nestedlocal	OK	104	5
 
 t116_nestedstr	OK	301	263
+
+t117_charfor	OK	88	6

+ 1 - 0
shell/tests/fixtures/t117_charfor.out

@@ -0,0 +1 @@
+ABCDEFG

+ 6 - 0
shell/tests/fixtures/t117_charfor.pas

@@ -0,0 +1,6 @@
+program charfor;
+var c : char;
+begin
+  for c := 'A' to 'G' do write(c);
+  writeln
+end.