raz / commit 2044831e

commit
2044831ee87754b55cdd5a0770217fd49da5bc61
author
Luis <42945842+ldiaz94@users.noreply.github.com>
date
parent
d3ddbe6b
Propose implementation limits and a compiler for a small stack

patch · log

1 file changed, +44 -0

PROPOSALS.md modified +44 -0

@@ -1193,3 +1193,47 @@
11931193
11941194 Met in rabble, which shows every time in UTC, in the screen and in its
11951195 logs, since the library has no zone (2026-10-21).
1196+
1197+## Implementation limits, and a compiler for a small stack
1198+
1199+**Status.** To investigate; nothing decided.
1200+
1201+The report names no implementation limits: how deep expressions,
1202+statements, imports and generic instances may nest, how long a name or
1203+a string may be. A compiler for a small machine that rejects a deep
1204+nesting is then arguably not a raz compiler at all. C settles it with
1205+its translation limits (C99 ยง5.2.4.1: 63 levels of nested parentheses,
1206+15 of nested includes, and so on): every compiler must take at least
1207+that much, and may take more. The proposal: a short section in the
1208+report giving the least each compiler must accept, and saying that a
1209+compiler that goes past its own limit stops with an error naming it,
1210+never a crash. It changes the report, not the language.
1211+
1212+Behind it, three things in this compiler that need no change to the
1213+report at all, so that it runs in a small stack:
1214+
1215+1. **Nesting.** Each level of a nested expression costs about 1 KiB
1216+ of stack. A constant expression with 64 nested parentheses fails a
1217+ 64 KiB stack and passes 256 KiB; 256 of them fail 256 KiB and pass
1218+ 1 MiB. A limit from the section above, checked in the parser, makes
1219+ the stack a program needs bounded and known.
1220+2. **Imports.** `importModule` compiles an imported module in the
1221+ middle of the one importing it, on the same stack, so the stack
1222+ grows with the depth of the chain of imports. Ordering the modules
1223+ first and compiling them from the leaves, in a loop, keeps whole
1224+ program compilation and a stack that doesn't grow; symbol files, as
1225+ Wirth's compilers have, would do it too, but must then carry a
1226+ generic module's body.
1227+3. **Instances.** `makeInstance` keeps the declaration under way aside
1228+ in arrays on the stack (`[MaxFwd]PType`, `[MaxFwd]Diag.Pos`,
1229+ `[MaxNames]INT`, several KiB) for every instance it nests. A list
1230+ of instances still to make, made between declarations, would keep
1231+ none.
1232+
1233+Not yet measured: which of these filled the stack when the stripped
1234+compiler, given one more `-I` directory, overflowed 64 KiB building
1235+itself, where the ordinary self-build fit.
1236+
1237+Met in moss (`docs/raz-port.md`): its stored programs get a guarded
1238+64 KiB stack, and a native compiler must fit, or the stack must grow
1239+(2026-10-22).