Implement explicit CEK machine, continuations, effect signatures, fix dynamic-wind and inspect shadowing

Three-phase foundations implementation:

Phase A — Activate dormant shift/reset continuations with 24 SX-native tests
covering basic semantics, predicates, stored continuations, nested reset,
scope interaction, and TCO.

Phase B — Bridge compile-time effect system to runtime: boundary_parser extracts
46 effect annotations, platform provides populate_effect_annotations() and
check_component_effects() for static analysis. 6 new type tests.

Phase C — Explicit CEK machine (frames.sx + cek.sx): evaluation state as data
({control, env, kont, phase, value}), 21 frame types, two-phase step function
(step-eval/step-continue), native shift/reset via frame capture. Bootstrapper
integration: --spec-modules cek transpiles to Python with iterative cek_run.
43 interpreted + 49 transpiled tests passing.

Bug fixes:
- inspect() shadowed by `import inspect` in PLATFORM_ASYNC_PY — renamed to
  `import inspect as _inspect`
- dynamic-wind missing platform functions (call_thunk, push_wind!, pop_wind!) —
  added with try/finally error safety via dynamic_wind_call

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-13 22:14:55 +00:00
parent 11fdd1a840
commit 1765216335
16 changed files with 2174 additions and 26 deletions

View File

@@ -1129,17 +1129,21 @@ try:
from .platform_py import (
PREAMBLE, PLATFORM_PY, PRIMITIVES_PY_PRE, PRIMITIVES_PY_POST,
PRIMITIVES_PY_MODULES, _ALL_PY_MODULES,
PLATFORM_DEPS_PY, PLATFORM_ASYNC_PY, FIXUPS_PY, CONTINUATIONS_PY,
PLATFORM_DEPS_PY, PLATFORM_CEK_PY, CEK_FIXUPS_PY, PLATFORM_ASYNC_PY,
FIXUPS_PY, CONTINUATIONS_PY,
_assemble_primitives_py, public_api_py,
ADAPTER_FILES, SPEC_MODULES, EXTENSION_NAMES, EXTENSION_FORMS,
ADAPTER_FILES, SPEC_MODULES, SPEC_MODULE_ORDER,
EXTENSION_NAMES, EXTENSION_FORMS,
)
except ImportError:
from shared.sx.ref.platform_py import (
PREAMBLE, PLATFORM_PY, PRIMITIVES_PY_PRE, PRIMITIVES_PY_POST,
PRIMITIVES_PY_MODULES, _ALL_PY_MODULES,
PLATFORM_DEPS_PY, PLATFORM_ASYNC_PY, FIXUPS_PY, CONTINUATIONS_PY,
PLATFORM_DEPS_PY, PLATFORM_CEK_PY, CEK_FIXUPS_PY, PLATFORM_ASYNC_PY,
FIXUPS_PY, CONTINUATIONS_PY,
_assemble_primitives_py, public_api_py,
ADAPTER_FILES, SPEC_MODULES, EXTENSION_NAMES, EXTENSION_FORMS,
ADAPTER_FILES, SPEC_MODULES, SPEC_MODULE_ORDER,
EXTENSION_NAMES, EXTENSION_FORMS,
)
@@ -1280,7 +1284,11 @@ def compile_ref_to_py(
spec_mod_set.add("page-helpers")
if "router" in SPEC_MODULES:
spec_mod_set.add("router")
# cek module requires frames
if "cek" in spec_mod_set:
spec_mod_set.add("frames")
has_deps = "deps" in spec_mod_set
has_cek = "cek" in spec_mod_set
# Core files always included, then selected adapters, then spec modules
sx_files = [
@@ -1291,8 +1299,14 @@ def compile_ref_to_py(
for name in ("html", "sx"):
if name in adapter_set:
sx_files.append(ADAPTER_FILES[name])
# Use explicit ordering for spec modules (respects dependencies)
for name in SPEC_MODULE_ORDER:
if name in spec_mod_set:
sx_files.append(SPEC_MODULES[name])
# Any spec modules not in the order list (future-proofing)
for name in sorted(spec_mod_set):
sx_files.append(SPEC_MODULES[name])
if name not in SPEC_MODULE_ORDER:
sx_files.append(SPEC_MODULES[name])
# Pre-scan define-async names (needed before transpilation so emitter
# knows which calls require 'await')
@@ -1352,6 +1366,9 @@ def compile_ref_to_py(
if has_deps:
parts.append(PLATFORM_DEPS_PY)
if has_cek:
parts.append(PLATFORM_CEK_PY)
if has_async:
parts.append(PLATFORM_ASYNC_PY)
@@ -1363,6 +1380,8 @@ def compile_ref_to_py(
parts.append("")
parts.append(FIXUPS_PY)
if has_cek:
parts.append(CEK_FIXUPS_PY)
if has_continuations:
parts.append(CONTINUATIONS_PY)
parts.append(public_api_py(has_html, has_sx, has_deps, has_async))