ocaml: phase 4 open / include (+5 tests, 220 total)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 57s

Parser: open Path and include Path top-level decls; Path is Ctor (.Ctor)*.
Eval resolves via ocaml-resolve-module-path (same :con-as-module-lookup
escape hatch used by :field). open extends the env with the module's
bindings; include also merges into the surrounding module's exports
(when inside a struct...end).

Path resolver lets M.Sub.x work for nested modules. Phase 4 LOC ~165.
This commit is contained in:
2026-05-08 08:39:13 +00:00
parent 317f93b2af
commit d45e653a87
4 changed files with 125 additions and 2 deletions

View File

@@ -186,8 +186,11 @@ SX CEK evaluator (both JS and OCaml hosts)
- [ ] `module M : S = struct ... end` — coercive sealing (runtime: pass-through).
- [ ] `functor (M : S) -> struct ... end` → SX `(fn (M) ...)`.
- [ ] `module F = Functor(Base)` — functor application.
- [ ] `open M` — merge M's dict into current env (`env-merge`).
- [ ] `include M` — same as open at structure level.
- [x] `open M` — merge M's dict into current env (via
`ocaml-env-merge-dict`). Module path `M.Sub` resolves via
`ocaml-resolve-module-path`.
- [x] `include M` — at top level same as `open`; inside a module also
copies M's bindings into the surrounding module's exports.
- [x] `M.name` — dict get via field access.
- [ ] First-class modules (pack/unpack) — deferred to Phase 5.
- [ ] Standard module hierarchy: `List`, `Option`, `Result`, `String`, `Char`,
@@ -322,6 +325,15 @@ the "mother tongue" closure: OCaml → SX → OCaml. This means:
_Newest first._
- 2026-05-08 Phase 4 — `open M` / `include M` (+5 tests, 220 total).
Parser: top-level `open Path` / `include Path` decls; path is `Ctor (.
Ctor)*`. Eval resolves the path via `ocaml-resolve-module-path` (the
same `:con`-as-module-lookup escape hatch used for `:field`); merges
the dict bindings into the current env via `ocaml-env-merge-dict`.
`include` inside a module also adds the bindings to the module's
resulting dict, so `module Sphere = struct include Math let area r =
... end` exposes both Math's `pi` and Sphere's `area`. Phase 4 LOC
cumulative: ~165.
- 2026-05-08 Phase 4 — modules + field access (+11 tests, 215 total). Parser:
`module M = struct DECLS end` decl in `ocaml-parse-program`. Body parsed
by sub-tokenising the source between `struct` and the matching `end`,