You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Documentation: Clarify codegen environment rules for top-level const and function bindings #89
Describe the bug
Documentation needs to clarify that both top-level consts and fns must be present in the codegen environment. Current docs may only discuss top-level fns.
To Reproduce
Look for existing documentation on module environment in codegen.
Expected behavior
Section covering environment population rules for codegen makes explicit how top-level const and function bindings are represented and threaded.
Section 2.1 (Program Structure): top_level production now lists const_decl, extern_fn_decl, and extern_type_decl alongside fn_decl so the grammar matches what the parser actually accepts after PR feat: typed-wasm xmod + Node backend + extern + VS Code (#35, #42) #90 landed extern support.
Section 2.9 (Constant Declarations): new EBNF and prose noting that const initializers must reduce to Wasm constant expressions, with a forward-reference to section 8 for the codegen environment encoding.
Section 2.10 (Extern Declarations): new EBNF for extern fn / extern type, with the runtime contract (extern fn → (import "env" "<name>" ...), extern type → no Wasm artifact).
Section 8 (Codegen Module Environment): new section documenting the func_indices : (string * int) list table. Positive k ≥ 0 is a Wasm function index (defined functions or extern-imported functions); negative k < 0 encodes -(global_idx + 1) for top-level constants. Includes per-case gen_decl behaviour for TopFn (defined), TopFn with FnExtern body, and TopConst. Explicitly notes the call-site ExprApp lookup currently emits call k unconditionally — decoding the negative sentinel back to global.get is the implementation half tracked under Codegen.UnboundVariable for top-level const bindings (typecheck OK, compile fails) #73.
The companion lib/codegen.ml doc-comment on the func_indices field was updated to mention both TopFn paths (defined and extern) and that insertion is in source declaration order.
Note: PR #94 introduces a more detailed docs/specs/codegen-environment.adoc that goes deeper on cross-module threading and non-WASM target behaviour. That landing will subsume the SPEC.md §8 content here; this issue is resolved at the level it asked for (clarify that both consts and fns must be present in the codegen environment, document the population rules).
Activity
docs: tighten SPEC.md codegen-environment section, drop unmerged exte…
docs(spec): thin SPEC.md §8 to forward-reference codegen-environment.…
docs: clarify codegen environment rules for top-level const and fn bi…
docs: tighten SPEC.md codegen-environment section, drop unmerged exte…
docs: clarify codegen environment rules for top-level const and fn bi…
hyperpolymath commentedon May 11, 2026
Resolved by PR #91 (merged as c392e49).
The SPEC.md changes:
top_levelproduction now listsconst_decl,extern_fn_decl, andextern_type_declalongsidefn_declso the grammar matches what the parser actually accepts after PR feat: typed-wasm xmod + Node backend + extern + VS Code (#35, #42) #90 landed extern support.extern fn/extern type, with the runtime contract (extern fn →(import "env" "<name>" ...), extern type → no Wasm artifact).func_indices : (string * int) listtable. Positivek ≥ 0is a Wasm function index (defined functions or extern-imported functions); negativek < 0encodes-(global_idx + 1)for top-level constants. Includes per-casegen_declbehaviour forTopFn(defined),TopFnwithFnExternbody, andTopConst. Explicitly notes the call-siteExprApplookup currently emitscall kunconditionally — decoding the negative sentinel back toglobal.getis the implementation half tracked under Codegen.UnboundVariable for top-levelconstbindings (typecheck OK, compile fails) #73.The companion
lib/codegen.mldoc-comment on thefunc_indicesfield was updated to mention bothTopFnpaths (defined and extern) and that insertion is in source declaration order.Note: PR #94 introduces a more detailed
docs/specs/codegen-environment.adocthat goes deeper on cross-module threading and non-WASM target behaviour. That landing will subsume the SPEC.md §8 content here; this issue is resolved at the level it asked for (clarify that both consts and fns must be present in the codegen environment, document the population rules).Merge pull request #94 from hyperpolymath/docs/raw-decision-tree-exam…
docs(governance): add Hypatia and gitbot-fleet standing rules to .cla…