Explorar el Código

calc: allow local set variables (ladder code ceiling 48574)

DefVar now admits TSet alongside STRING/REAL/records/arrays/file types for
both local and global storage.  The identifier-statement assignment path in
Statmnt does not go through ParseVar, so it now carries setoff/setbase/setsize
too; without that, Assignment saw setsize 0 and refused the literal.

t109_localset covers a local `set of Char`, `S := [' '..'}']' and a run-time
`in` test, and runs under qemu and Exec86.

CALC now compiles through GotoX's local set and assignment.  The ladder stops
at ERR 98 48574: runtime plus generated code reaches the 0x8000 data base.
That is the next task: shrink the runtime or make a deliberate data-base/code
ceiling layout change.

Verified: compile matrix 110/110, ladder 1/1 at ERR 98 48574, 96 .COM
executions under both oracles, rt_exec 276/276, nonvacuity 121/121, run_all
ALL PASS.
Eric Streit hace 4 días
padre
commit
9af6d20600

+ 13 - 6
CALC-COMPILE.md

@@ -97,7 +97,7 @@ Current rung (measured today, normalised position):
 
 | position | blocker |
 |---|---|
-| **48461** | `OkChars : set of Char` inside `GotoX` — local set variable (`ERR 102`) |
+| **48574** | code-image ceiling — runtime + generated code reaches the `0x8000` data base (`ERR 98`) |
 
 Rungs behind it (now passed):
 
@@ -158,7 +158,8 @@ Rungs ahead:
 | 43902 | forward definition repeating only the name - DONE |
 | 44567 | `Delete` string builtin - DONE |
 | 47788 | code ceiling reached; raised to 0x8000 - DONE |
-| 48461 | local `set of Char` variable (`ERR 102`) |
+| 48461 | local `set of Char` variable - DONE |
+| 48574 | code-image ceiling (`ERR 98`) |
 
 Corrections the measurements force, worth stating plainly because the stage list
 below was written before them:
@@ -597,6 +598,10 @@ Exec86):
 - **`Abs`, `Sqr` and `Sqrt` are landed (`t104_mathbasic`).**  `Abs` clears the
   MBF sign, `Sqr` lowers to the real multiply entry, and `Sqrt` is Newton over
   the existing real division/addition entries.
+- **Local `set of Char` variables are landed (`t109_localset`).**  The local
+  variable declaration path now admits sets, and the identifier-statement
+  assignment path carries the set size/base metadata; literal assignment and
+  `in` both work.
 - **`Delete(S,pos,len)` is landed (`t108_delete`).**  A counted-string
   runtime entry rewrites the length and moves the tail; positions outside the
   string and non-positive lengths are no-ops.
@@ -1236,10 +1241,12 @@ and TEXT file output is done (`t91_textout`), both compile-only because the
 harness has no filesystem.  `Str` real formatting is done (`t92_strreal`),
 pointer types with `New`/`Dispose`/dereference are done (`t93_pointer`), and
 text `Eof`/`Readln` plus integer `Str` are done (`t94_textread`/`t95_strint`).
-The next ladder blocker is a local `set of Char` variable in `GotoX`.  All the
-REAL builtins CALC uses, forward definitions and `Delete` are implemented.  The
-runtime is 14,063 bytes; `rt_exec` is at HDR=0x4000 / data 0x5000, and the
-compiler's code ceiling is 0x8000.
+The next blocker is image capacity, not a language construct: the runtime plus
+generated CALC code reaches the `0x8000` data base.  The runtime is 14,063
+bytes; `rt_exec` is at HDR=0x4000 / data 0x5000, and the compiler's code
+ceiling is 0x8000.  The next change must either shrink the runtime (the
+unrolled math entries are the largest part) or move the data base/code
+ceiling as a deliberate layout change.
 
 **Stage 14 — the CRT identifiers.** `GotoXY` (25), `LowVideo`/`NormVideo`
 (16 + 16), `ClrEol` (10), `ClrScr` (6), `KeyPressed` (3), `Delay` (1),

+ 5 - 5
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
-`ERR 102` at pos 48461, a local `set of Char`), the `{$I}` include,
+`ERR 98` at pos 48574, the code-image ceiling), 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`/
@@ -2067,10 +2067,10 @@ pointer types with `New`/`Dispose`/dereference (`t93`), text `Eof`/`Readln`
 literals/comparisons/arithmetic, self-recursion, `Copy`, real `Val`, the REAL
 standard functions (`Abs`, `Sqr`, `Sqrt`, `Ln`, `Exp`, `Sin`, `Cos`,
 `Arctan`), `Int(REAL)` and forward definitions that repeat only the name are
-landed, along with `Delete`.  The ladder now stops at a local `set of Char`
-(`ERR 102 48461`).  The runtime is 14,063 bytes / 55 entries; the rt_exec
-scaffold is at HDR=0x4000 / data 0x5000.  Items 1-4 below are independent of
-both tracks.
+landed, along with `Delete` and local `set of Char` variables.  The ladder now
+stops at the code-image ceiling (`ERR 98 48574`), not a source construct.  The
+runtime is 14,063 bytes / 55 entries; the rt_exec scaffold is at HDR=0x4000 /
+data 0x5000.  Items 1-4 below are independent of both tracks.
 
 1. The rest of the string language. `v-TP3-STRVAR`/`v-TP3-STRREAD-ASSIGN` cover
    string variables, `s := 'literal'`, `writeln (s)`, `readln (s)`/`read (s)`

+ 10 - 2
shell/Compiler.mod

@@ -6785,6 +6785,14 @@ BEGIN
             t.cls := symtab [t.idx].cls
          END ;
          t.sz := symtab [t.idx].size ;      (* ParseSub may narrow it further *)
+         IF t.cls = TSet THEN
+            (* The identifier-statement path does not go through ParseVar, so
+               it must carry the same set metadata: Assignment's set branch
+               uses setsize/setbase to build the constructor. *)
+            t.setoff := symtab [t.idx].off ;
+            t.setbase := symtab [t.idx].elem ;
+            t.setsize := symtab [t.idx].size
+         END ;
          ParseSub (t) ;
          IF MatchAssign () THEN
             Assignment (t) ;
@@ -7178,7 +7186,7 @@ BEGIN
          IF lexnest = 0 THEN
             IF (size > 2) AND (cls # TString) AND (cls # TRecord)
                AND (cls # TArray) AND (cls # TFile) AND (cls # TText)
-               AND (cls # TUntyp) AND (cls # TReal) THEN
+               AND (cls # TUntyp) AND (cls # TReal) AND (cls # TSet) THEN
                (* Still the catch-all for a type whose storage this compiler does
                   not lay out yet (an ARRAY at its point of use, a RECORD, ...).
                   A STRING is the exception now: its layout is length byte +
@@ -7224,7 +7232,7 @@ BEGIN
          ELSE
             IF (size > 2) AND (cls # TString) AND (cls # TRecord)
                AND (cls # TArray) AND (cls # TFile) AND (cls # TText)
-               AND (cls # TUntyp) AND (cls # TReal) THEN
+               AND (cls # TUntyp) AND (cls # TReal) AND (cls # TSet) THEN
                Err (ENoLib) ;
                RETURN
             END ;

+ 7 - 5
shell/tests/fixtures/calc_ladder.tsv

@@ -25,7 +25,7 @@
 # positions shift — which is exactly why this must be a measured number, not a
 # remembered one.
 #
-# Current rung (2026-10-23): `OkChars : set of Char' in GotoX's scope.
+# Current rung (2026-10-23): the code image reaches the 0x8000 data boundary.
 # UpCase, run-time set membership, string fields through DI, the original memory
 # layout, untyped-file declarations, file control-block operations, VAR string
 # parameters, Chr, typed-file block I/O, text-file output, Str,
@@ -33,7 +33,9 @@
 # value REAL and REAL function results, REAL literals/comparisons/arithmetic,
 # self-recursion, enum-indexed arrays, string-array typed constants, local REAL
 # variables, Copy, real Val, Abs/Sqr/Sqrt, Ln/Exp/Sin/Cos/Arctan, Int(REAL),
-# forward definitions that repeat only the name and Delete moved the ladder
-# 15911 -> ... -> 43902 -> 44567 -> 47788 -> 48461.  The next blocker is a
-# local `set of Char' declaration (TP3 error 102).
-CALC.PAS	ERR	102	48461
+# forward definitions that repeat only the name, Delete and local set of Char
+# variables moved the ladder 15911 -> ... -> 44567 -> 47788 -> 48461 -> 48574.
+# The next blocker is the image layout/code ceiling (TP3 error 98), not a
+# source construct: the runtime and generated code no longer fit below the
+# 0x8000 data base.
+CALC.PAS	ERR	98	48574

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

@@ -722,3 +722,6 @@ t107_forward	OK	99	6
 
 #   t108_delete           Delete(S,pos,len): middle/front/truncation/no-ops.
 t108_delete	OK	417	26
+
+#   t109_localset       local `set of Char` declaration, literal assignment and IN.
+t109_localset	OK	322	5

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

@@ -0,0 +1 @@
+yes

+ 8 - 0
shell/tests/fixtures/t109_localset.pas

@@ -0,0 +1,8 @@
+program ls;
+procedure P;
+var S:set of char;
+begin
+ S := [' '..'}'];
+ if 'a' in S then writeln('yes') else writeln('no')
+end;
+begin P end.