aboutsummaryrefslogtreecommitdiff
path: root/docs/history/44-check-mode/notes.md
diff options
context:
space:
mode:
Diffstat (limited to 'docs/history/44-check-mode/notes.md')
-rw-r--r--docs/history/44-check-mode/notes.md33
1 files changed, 33 insertions, 0 deletions
diff --git a/docs/history/44-check-mode/notes.md b/docs/history/44-check-mode/notes.md
new file mode 100644
index 0000000..2cb0493
--- /dev/null
+++ b/docs/history/44-check-mode/notes.md
@@ -0,0 +1,33 @@
+# 44 — check mode, methods, closures, postfix pointers, wasm
+
+the language server stopped being its own program. `src/compiler.zc` grew a check mode, `lsp/server.zc` wraps it, and everything the editor shows comes from the compiler's own run over the document.
+
+## check mode
+
+`cmode` turns errors into records (`[severity, line, offset, length, text]`) instead of printing, and the compiler keeps going. `chkabort` makes `next` return end of file so the loops unwind after a fatal error, and a fuel counter halts a run that never unwinds. `expect` puts "expected x" at the end of the previous token. tokens carry their place (`toff`, `toklen`), packed with the line into one word that the quote lists and the lookahead queue carry along, so a hint can point at a token that was read earlier. check mode re-initialises the heap, symbols and tables for every document, so one check can't leak into the next.
+
+four sets of names (locals, parameters, type parameters, fields) are recorded as the compiler sees them declared, which is how the highlighter tells a field from a variable without a second parser.
+
+## hints
+
+a variable never read, a `let` that could be a `const`, multiplying by a power of two, a number with no name, `new` inside a loop, a small `new` that never leaves its function, an object given away once right after it was made, an owned object that outlives its last use by four lines. they are reported only in check mode and don't change the code that comes out.
+
+## methods and closures
+
+`fn name(params) { body }` inside a struct is a function called `Struct.name` with a hidden `Struct* this` first. `p.name(args)` calls it. `fn(a, b) { ... }` in an expression captures the variables it uses by value into a block whose first three words are a trampoline, so the block's address is a callable value.
+
+## postfix pointers
+
+`ptype0` reads a type and then any stars after it, so `int*`, `vec<T>*` and `point**` work, and the prefix star still does. `tprint` writes the new form.
+
+## same-line braces
+
+every `.zc` under src, lib, lsp, tools, bench, examples and tests (apart from the tests whose expected output names a line) moved to `fn name() {`. the history folders are untouched.
+
+## web
+
+`web/build.sh` builds the microcore to webassembly with clang's wasm32 target. `web/zc.js` and `web/index.html` run a program in the browser. the port is one small file, plus a 64 by 64 to 128 bit multiply the core uses.
+
+## numbers
+
+the fixpoint is 123810 words (the slot is 131072). the stage-0 image is 119013, so the small map's genome reservation went from 110592 to 126976 words. the suite is 426 passed, 0 failed on this machine: interpreter, microcore, soft-float, small and run-only maps, arm64 jit under qemu, llvm, the javascript vm, webassembly and the language server. the baremetal boards were skipped (no cross compilers here). the windows scripts were edited but not run.