Decouple core evaluator from web platform, extract libraries

The core evaluator (spec/evaluator.sx) is now the irreducible computational
core with zero web, rendering, or type-system knowledge. 2531 → 2313 lines.

- Add extensible special form registry (*custom-special-forms* + register-special-form!)
- Add render dispatch hooks (*render-check* / *render-fn*) replacing hardcoded render-active?/is-render-expr?/render-expr
- Extract freeze scopes → spec/freeze.sx (library, not core)
- Extract content addressing → spec/content.sx (library, not core)
- Move sf-deftype/sf-defeffect → spec/types.sx (self-registering)
- Move sf-defstyle → web/forms.sx (self-registering with all web forms)
- Move web tests (defpage, streaming) → web/tests/test-forms.sx
- Add is-else-clause? helper (replaces 5 inline patterns)
- Make escape-html/escape-attr library functions in render.sx (pure SX, not platform-provided)
- Add foundations plan: Step 3.5 (data representations), Step 3.7 (verified components), OCaml for Step 4d
- Update all three bootstrappers (JS 957/957, Python 744/744, OCaml 952/952)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-03-16 08:37:50 +00:00
parent 5ab3ecb7e0
commit 06666ac8c4
21 changed files with 886 additions and 603 deletions

View File

@@ -179,6 +179,11 @@ class PyEmitter:
"*batch-depth*": "_batch_depth",
"*batch-queue*": "_batch_queue",
"*store-registry*": "_store_registry",
"*custom-special-forms*": "_custom_special_forms",
"*render-check*": "_render_check",
"*render-fn*": "_render_fn",
"register-special-form!": "register_special_form_b",
"is-else-clause?": "is_else_clause_p",
"def-store": "def_store",
"use-store": "use_store",
"clear-stores": "clear_stores",

View File

@@ -612,13 +612,7 @@ def inspect(x):
return repr(x)
def escape_html(s):
s = str(s)
return s.replace("&", "&amp;").replace("<", "&lt;").replace(">", "&gt;").replace('"', "&quot;")
def escape_attr(s):
return escape_html(s)
# escape_html and escape_attr are now library functions defined in render.sx
def raw_html_content(x):
@@ -842,7 +836,7 @@ def _sx_parse_int(v, default=0):
"stdlib.text": '''
# stdlib.text
PRIMITIVES["pluralize"] = lambda n, s="", p="s": s if n == 1 else p
PRIMITIVES["escape"] = escape_html
PRIMITIVES["escape"] = lambda s: str(s).replace("&", "&amp;").replace("<", "&lt;").replace(">", "&gt;").replace('"', "&quot;")
PRIMITIVES["strip-tags"] = lambda s: _strip_tags(str(s))
import re as _re
@@ -1647,12 +1641,15 @@ SPEC_MODULES = {
"signals": ("signals.sx", "signals (reactive signal runtime)"),
"page-helpers": ("page-helpers.sx", "page-helpers (pure data transformation helpers)"),
"types": ("types.sx", "types (gradual type system)"),
"freeze": ("freeze.sx", "freeze (serializable state boundaries)"),
"content": ("content.sx", "content (content-addressed computation)"),
}
# Note: frames and cek are now part of evaluator.sx (always loaded as core)
# Explicit ordering for spec modules with dependencies.
# freeze depends on signals; content depends on freeze.
SPEC_MODULE_ORDER = [
"deps", "engine", "page-helpers", "router", "signals", "types",
"deps", "engine", "page-helpers", "router", "signals", "types", "freeze", "content",
]
EXTENSION_NAMES = {"continuations"}

View File

@@ -172,9 +172,6 @@ env["sf-lambda"] = sx_ref.sf_lambda
env["sf-defcomp"] = sx_ref.sf_defcomp
env["sf-defisland"] = sx_ref.sf_defisland
env["sf-defmacro"] = sx_ref.sf_defmacro
env["sf-defstyle"] = sx_ref.sf_defstyle
env["sf-deftype"] = sx_ref.sf_deftype
env["sf-defeffect"] = sx_ref.sf_defeffect
env["sf-letrec"] = sx_ref.sf_letrec
env["sf-named-let"] = sx_ref.sf_named_let
env["sf-dynamic-wind"] = sx_ref.sf_dynamic_wind
@@ -194,10 +191,25 @@ env["ho-every"] = sx_ref.ho_every
env["ho-for-each"] = sx_ref.ho_for_each
env["call-fn"] = sx_ref.call_fn
# Render-related (stub for testing — no active rendering)
env["render-active?"] = lambda: False
env["is-render-expr?"] = lambda expr: False
env["render-expr"] = lambda expr, env: NIL
# Render dispatch globals — evaluator checks *render-check* and *render-fn*
env["*render-check*"] = NIL
env["*render-fn*"] = NIL
# Custom special forms registry — modules register forms at load time
env["*custom-special-forms*"] = {}
def _register_special_form(name, handler):
env["*custom-special-forms*"][name] = handler
return NIL
env["register-special-form!"] = _register_special_form
# is-else-clause? — check if a cond/case test is an else marker
def _is_else_clause(test):
if isinstance(test, Keyword) and test.name == "else":
return True
if isinstance(test, Symbol) and test.name in ("else", ":else"):
return True
return False
env["is-else-clause?"] = _is_else_clause
# Scope primitives
env["scope-push!"] = sx_ref.PRIMITIVES.get("scope-push!", lambda *a: NIL)
@@ -214,15 +226,12 @@ env["call-thunk"] = lambda f, e: f() if callable(f) else trampoline(eval_expr([f
# Mutation helpers used by parse-keyword-args etc
env["dict-get"] = lambda d, k: d.get(k, NIL) if isinstance(d, dict) else NIL
# defhandler, defpage, defquery, defaction — these are registrations
# Use the bootstrapped versions if they exist, otherwise stub
for name in ["sf-defhandler", "sf-defpage", "sf-defquery", "sf-defaction"]:
pyname = name.replace("-", "_")
fn = getattr(sx_ref, pyname, None)
if fn:
env[name] = fn
else:
env[name] = lambda args, e, _n=name: NIL
# defstyle, defhandler, defpage, defquery, defaction — now registered via
# register-special-form! by forms.sx at load time. Stub them here in case
# forms.sx is not loaded (CEK tests don't load it).
for form_name in ["defstyle", "defhandler", "defpage", "defquery", "defaction"]:
if form_name not in env["*custom-special-forms*"]:
env["*custom-special-forms*"][form_name] = lambda args, e, _n=form_name: NIL
# Load test framework
with open(os.path.join(_SPEC_TESTS, "test-framework.sx")) as f:

View File

@@ -248,9 +248,26 @@ env["macro-closure"] = lambda m: m.closure
env["symbol-name"] = lambda s: s.name if isinstance(s, Symbol) else str(s)
env["keyword-name"] = lambda k: k.name if isinstance(k, Keyword) else str(k)
env["sx-serialize"] = sx_ref.sx_serialize if hasattr(sx_ref, "sx_serialize") else lambda x: str(x)
env["is-render-expr?"] = lambda expr: False
env["render-active?"] = lambda: False
env["render-expr"] = lambda expr, env: NIL
# Render dispatch globals — evaluator checks *render-check* and *render-fn*
env["*render-check*"] = NIL
env["*render-fn*"] = NIL
# Custom special forms registry — modules register forms at load time
env["*custom-special-forms*"] = {}
def _register_special_form(name, handler):
env["*custom-special-forms*"][name] = handler
return NIL
env["register-special-form!"] = _register_special_form
# is-else-clause? — check if a cond/case test is an else marker
def _is_else_clause(test):
if isinstance(test, Keyword) and test.name == "else":
return True
if isinstance(test, Symbol) and test.name in ("else", ":else"):
return True
return False
env["is-else-clause?"] = _is_else_clause
# Strict mode stubs (not yet bootstrapped to Python — no-ops for now)
env["set-strict!"] = lambda val: NIL

View File

@@ -93,6 +93,11 @@
"*batch-depth*" "_batch_depth"
"*batch-queue*" "_batch_queue"
"*store-registry*" "_store_registry"
"*custom-special-forms*" "_custom_special_forms"
"*render-check*" "_render_check"
"*render-fn*" "_render_fn"
"register-special-form!" "register_special_form_b"
"is-else-clause?" "is_else_clause_p"
"def-store" "def_store"
"use-store" "use_store"
"clear-stores" "clear_stores"