Преглед изворни кода

docs: record absolute variables and compiler progress

Eric Streit пре 1 дан
родитељ
комит
50c3dabe36
1 измењених фајлова са 89 додато и 10 уклоњено
  1. 89 10
      docs/future-work-2026-10-25.md

+ 89 - 10
docs/future-work-2026-10-25.md

@@ -14,6 +14,22 @@ implement everything.
 (3,845,439 bytes), per-object fixpoint OK (11 objects), corpus
 521/612 compile-OK, 0 crashes, 64 `LANG` and 27 `LIB`.
 
+**Progress update 2026-10-27:** suite 327/327.  The SQLite binding
+is under `bindings/sqlite3` and has its own tests/showcases.  Compiler
+work completed since this note:
+
+- long string literals are no longer truncated by lowering (the previous
+  64-byte `SymTab.Name` path);
+- `EXPORT` after declarations now produces the explicit diagnostic
+  `EXPORT must precede declarations`;
+- `SYSTEM.CSIZE_T` / `SYSTEM.CSSIZE_T` are 64-bit on amd64;
+- `VAL(ADDRESS, integer)` supports pointer sentinels such as
+  `VAL(ADDRESS, -1)`;
+- `ADR(array)` remains descriptor-based for compatibility; C bindings
+  use `ADR(a[0])` for the data address;
+- absolute variables (`VAR x [addr] : T`) remain unimplemented; see
+  section 2.1 below.
+
 ---
 
 ## 1. `TBITSIZE`
@@ -88,6 +104,66 @@ escape hatch.
 
 ---
 
+### 2.1 Absolute variables (`VAR x [address] : T`) — not implemented
+
+GNU Modula-2 supports fixed-address variables:
+
+```modula2
+VAR
+  port [0x1000] : CARDINAL;
+```
+
+The address is a constant expression; `ADR(port)` is `0x1000`, and
+reads/writes access that address directly.  This is useful for
+memory-mapped I/O, firmware tables and embedded targets.
+
+Current V3 status:
+
+- the syntax is rejected by `VarIdents` (`':' expected` / `'..' expected`);
+- gm2 corpus cases `varaddress`, `varaddress2`, `varaddress3` remain
+  unsupported;
+- `docs/comparison-PIM4-gm2-V3.md` lists absolute variables as a V3
+  missing feature.
+
+Implementation requirements:
+
+1. Parser: accept an optional `[constant-expression]` after each name in
+   `VarIdents`; do not confuse it with the `[lo..hi]` type subrange.
+2. Constant folding: require a constant address, using the V3 `0x...`
+   form (the gm2 `1000H` suffix is not currently accepted).
+3. Symbol table: add absolute-variable metadata (flag + address); expose
+   it to `Lower`.
+4. AST/Lower: record the address; a designator of an absolute variable
+   must produce the fixed address instead of `AddrOf`.
+5. QBE: do not emit a normal global data object or initializer for an
+   absolute variable; emit direct loads/stores.
+6. `ADR(var)` must return the fixed address; passes to `VAR` formals and
+   pointer-based access should remain addressable.
+7. Decide whether absolute variables are module-level only or also
+   allowed locally.
+8. Document alignment/volatile limits: V3 has no `VOLATILE` annotation
+   yet, so memory-mapped I/O still needs careful review.
+9. Tests: compile-only checks such as `ADR(var) = 0x1000`; avoid
+   dereferencing arbitrary unmapped addresses in the normal suite.
+   A runtime test needs a deliberately mapped address or an allocated
+   buffer.
+
+Current workaround:
+
+```modula2
+TYPE PCard = POINTER TO CARDINAL;
+VAR p : PCard;
+BEGIN
+  p := VAL(PCard, 0x1000);
+  (* p^ accesses the word at address 0x1000 *)
+END
+```
+
+This is not a named absolute variable, but it is usable today now that
+`VAL` supports integer-to-pointer conversion.
+
+---
+
 ## 3. Set ordering
 
 PIM/ISO set operations are:
@@ -1904,7 +1980,8 @@ truncate; link names need an independent, larger mechanism.
 
 ### 14.3 C ABI/type gaps
 
-The binding layer needs a C ABI profile:
+The binding layer needs a C ABI profile.  The status marks below reflect
+the 2026-10-27 work:
 
 ```modula2
 TYPE
@@ -1922,14 +1999,15 @@ TYPE
 
 Required changes:
 
-- true `SHORTREAL`/`REAL32` 4-byte float;
-- correct `CSIZE_T`/`CSSIZE_T` widths on amd64;
-- C `bool` (1 byte) separate from `BOOLEAN` (4 bytes);
-- C enums represented as integer aliases, not Modula-2 enums;
-- C `long`/`unsigned long` target-dependent aliases;
-- C string and buffer ownership helpers;
-- C `void *` as `ADDRESS`;
-- C function pointers as compatible procedure values.
+- ✅ true `SHORTREAL`/`REAL32` 4-byte float;
+- ✅ correct `CSIZE_T`/`CSSIZE_T` widths on amd64;
+- ✅ C `bool` (1 byte) separate from `BOOLEAN` (4 bytes);
+- ⚠ C enums represented as integer aliases, not Modula-2 enums;
+- ⚠ C `long`/`unsigned long` target-dependent aliases;
+- ✅ partial C string/buffer ownership helpers (`CStr`, `SQLiteUtils`);
+- ✅ C `void *` as `ADDRESS`;
+- ✅ top-level C function pointers/callbacks; nested callbacks still need
+  trampolines.
 
 ### 14.4 Structs, unions and arrays
 
@@ -2654,7 +2732,8 @@ classes are GObject classes.
 ## 17. Suggested order of future work
 
 1. `TBITSIZE` (small, standard-facing).
-2. `ADDADR`/`SUBADR`/`DIFADR` (small, ISO SYSTEM).
+2. `ADDADR`/`SUBADR`/`DIFADR` (small, ISO SYSTEM), then absolute
+   variables (`VAR x [const] : T`) as the next address-related gap.
 3. Set ordering (bounded gm2 compatibility; fixes `largeset5`).
 4. Complex types: choose ISO built-ins versus a nonstandard value-record
    library; remove the misleading `COMPLEX*` aliases.