|
|
@@ -0,0 +1,50 @@
|
|
|
+# Step: ProgramArgs + IOChan
|
|
|
+
|
|
|
+Tag `v3-programargs-iochan`. Suite **126/126**; fixpoint **OK**
|
|
|
+(`bootstrap/fixpoint.sh`, image **2,071,330 bytes**).
|
|
|
+
|
|
|
+## `ProgramArgs`
|
|
|
+
|
|
|
+- `ArgCount() : CARDINAL` — the number of arguments *after* the
|
|
|
+ program name.
|
|
|
+- `GetArg(n : CARDINAL; VAR s : ARRAY OF CHAR) : BOOLEAN` —
|
|
|
+ 1-based (`1` = first argument); `FALSE` when absent.
|
|
|
+- Over `SysShim.argc`/`SysShim.arg` → shim `m2argc`/`m2arg`, which
|
|
|
+ read `/proc/self/cmdline` (Linux).
|
|
|
+
|
|
|
+## `IOChan`
|
|
|
+
|
|
|
+- `TYPE ChanId;` — opaque; completed as `ADDRESS` (a C `FILE *`).
|
|
|
+- `StdInChan`/`StdOutChan`/`StdErrChan`.
|
|
|
+- `ReadChar`, `WriteChar`, `WriteString`, `WriteLn`, `WriteInt`.
|
|
|
+- All operations go through `SysShim` (`stdin`/`stdout`/`stderr`,
|
|
|
+ `fgetc`/`fputc`/`fputs`/`fwriteln`/`fwriteint`); a `NIL` handle
|
|
|
+ degrades to a safe no-op / `0C`, as in `Files`.
|
|
|
+
|
|
|
+## Bridge additions
|
|
|
+
|
|
|
+- `runtime/syslib/SysShim.def`/`.mod`: `argc`, `stdin`, `fgetc`,
|
|
|
+ `fwriteint`.
|
|
|
+- `runtime/syslib/shim.c`: `m2stdin`.
|
|
|
+
|
|
|
+## Tests
|
|
|
+
|
|
|
+- `progargs_prog.mod` (exit 7, run with no arguments): `ArgCount = 0`,
|
|
|
+ `GetArg(1)` and `GetArg(999)` return `FALSE`.
|
|
|
+- `iochan_prog.mod`: writes `hello 42` on `StdOutChan`, reads one
|
|
|
+ character from `StdInChan`, echoes `got Z`; first stdout line
|
|
|
+ `hello 42`, exit 0.
|
|
|
+
|
|
|
+## Scope notes
|
|
|
+
|
|
|
+- `ProgramArgs.ArgCount` excludes `argv[0]`; `GetArg` is 1-based.
|
|
|
+- `IOChan` is a pragmatic subset: `ReadString`, `ReadResult`,
|
|
|
+ seek/position and channels over files are not included; `ChanId`
|
|
|
+ wraps only the standard streams for now.
|
|
|
+
|
|
|
+## Files
|
|
|
+
|
|
|
+`stdlib/programargs.def`/`.mod`, `stdlib/iochan.def`/`.mod`,
|
|
|
+`runtime/syslib/SysShim.def`/`.mod`, `runtime/syslib/shim.c`,
|
|
|
+`compiler/tests/{progargs_prog,iochan_prog}.mod`,
|
|
|
+`compiler/run_tests.sh`, `docs/{features,plan}.md`.
|