Commit c392e49
docs: clarify codegen environment rules for top-level const and fn bindings (#91)
* docs: clarify codegen environment rules for top-level const and fn bindings (closes #89)
Add const_decl, extern_type_decl, extern_fn_decl to the top_level grammar in
SPEC.md 2.1. Add sections 2.9 and 2.10 covering their syntax. Add section 8
(Codegen Module Environment) documenting the func_indices dual-use encoding:
non-negative keys are Wasm function indices, negative keys are -(global_idx+1)
for constants. Update the func_indices field comment in lib/codegen.ml to match.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
* docs: tighten SPEC.md codegen-environment section, drop unmerged extern grammar
Review pass on the #89 spec changes against the current main:
- 1.2 / 2.1 / 2.10: remove `extern`, `extern_type_decl`, and `extern_fn_decl`.
`extern` is not yet a reserved keyword on main and is not parsed by the
current lib/parser.mly; the AST has no `TopExternFn` / `TopExternType`
variants. Documenting these forms here advertises features that arrive
with a separate, unmerged PR (#92, fix/issue-42-extern-parsing). Spec
re-introduces these sections when the implementation lands.
- 2.9: fix the cross-reference (was "see §5.1" which is Primitive Types;
correct target is §8). Rephrase to make clear that the initializer must
reduce to a Wasm constant expression in the linear-memory backend.
- 8.1: fix `gen_program` -> `generate_module` (the actual fold-over-decls
entry point in lib/codegen.ml). Rewrite the section to:
* separate the encoding (data layout) from the lookup (instruction
selection) so the reader understands what's currently implemented vs.
what issue #73 still needs;
* call out that `ExprApp (ExprVar _, _)` currently emits `call k`
unconditionally, so the sign-test decode path for the negative
sentinel is the remaining piece tracked under #73 rather than being
described as already implemented;
* spell out per-case `gen_decl` behaviour (TopFn registers before
generating its body; TopConst registers after appending the global).
- 8.2: removed alongside the extern grammar — same rationale as 2.10.
The lib/codegen.ml `func_indices` field doc-comment from the original PR
was accurate and stays.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
* docs: restore extern coverage after rebase onto main (#90 merged)
PR #90 landed `extern fn` / `extern type` parsing and codegen on main while
this branch was in review. Restore the SPEC.md coverage to match what
actually shipped:
- 1.2: re-add `extern` to the keyword list.
- 2.1: re-add `extern_fn_decl` and `extern_type_decl` to `top_level`.
Note the parser uses two separate productions that both feed back into
`TopFn` / `TopType` AST variants (with `FnExtern` / `TyExtern` as the
body kind); the spec describes the surface grammar, not the AST shape.
- 2.10: re-introduce, but with the actual parsed shape (the productions
accept `type_params`, the fn form accepts `effects`, and both accept
optional `visibility`) rather than the simplified form from the original
PR. Clarify the runtime contract: extern fn lowers to a Wasm import,
extern type generates no artifact.
- 8.1 / 8.2: split the `TopFn` population case into the
`FnExtern` / non-`FnExtern` variants so the description matches the
guard pattern in lib/codegen.ml. Hard-coded `"env"` Wasm module name is
called out explicitly.
Also update the lib/codegen.ml doc-comment on `func_indices` to mention
both `TopFn` paths (defined and extern) and clarify that insertion order
is source order.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
---------
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>1 parent d126286 commit c392e49
2 files changed
Lines changed: 125 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
28 | | - | |
| 28 | + | |
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
| |||
68 | 68 | | |
69 | 69 | | |
70 | 70 | | |
| 71 | + | |
71 | 72 | | |
72 | 73 | | |
73 | 74 | | |
| |||
194 | 195 | | |
195 | 196 | | |
196 | 197 | | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
197 | 236 | | |
198 | 237 | | |
199 | 238 | | |
| |||
524 | 563 | | |
525 | 564 | | |
526 | 565 | | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
527 | 643 | | |
528 | 644 | | |
529 | 645 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
31 | | - | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
32 | 39 | | |
33 | 40 | | |
34 | 41 | | |
| |||
0 commit comments