Removes the 5993-line bootstrapped Python evaluator (sx_ref.py) and all
code that depended on it exclusively. Both bootstrappers (JS + OCaml)
now use a new synchronous OCaml bridge (ocaml_sync.py) to run the
transpiler. JS build produces identical output; OCaml bootstrap produces
byte-identical sx_ref.ml.
Key changes:
- New shared/sx/ocaml_sync.py: sync subprocess bridge to sx_server.exe
- hosts/javascript/bootstrap.py: serialize defines → temp file → OCaml eval
- hosts/ocaml/bootstrap.py: same pattern for OCaml transpiler
- shared/sx/{html,async_eval,resolver,jinja_bridge,handlers,pages,deps,helpers}:
stub or remove sx_ref imports; runtime uses OCaml bridge (SX_USE_OCAML=1)
- sx/sxc/pages: parse defpage/defhandler from AST instead of Python eval
- hosts/ocaml/lib/sx_primitives.ml: append handles non-list 2nd arg per spec
- Deleted: sx_ref.py, async_eval_ref.py, 6 Python test runners, misc ref/ files
Test results: JS 1078/1078, OCaml 1114/1114.
sx_docs SSR has pre-existing rendering issues to investigate separately.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
69 lines
1.3 KiB
Python
69 lines
1.3 KiB
Python
"""
|
|
S-expression language core.
|
|
|
|
Parse, evaluate, and serialize s-expressions. This package provides the
|
|
foundation for the composable fragment architecture described in
|
|
``docs/sx-architecture-plan.md``.
|
|
|
|
Quick start::
|
|
|
|
from shared.sx import parse, evaluate, serialize, Symbol, Keyword
|
|
|
|
expr = parse('(let ((x 10)) (+ x 1))')
|
|
result = evaluate(expr) # → 11
|
|
|
|
expr2 = parse('(map (fn (n) (* n n)) (list 1 2 3))')
|
|
result2 = evaluate(expr2) # → [1, 4, 9]
|
|
"""
|
|
|
|
from .types import (
|
|
NIL,
|
|
Component,
|
|
HandlerDef,
|
|
Keyword,
|
|
Lambda,
|
|
Macro,
|
|
Symbol,
|
|
)
|
|
from .parser import (
|
|
ParseError,
|
|
parse,
|
|
parse_all,
|
|
serialize,
|
|
)
|
|
from .types import EvalError
|
|
|
|
from .primitives import (
|
|
all_primitives,
|
|
get_primitive,
|
|
register_primitive,
|
|
)
|
|
from . import primitives_stdlib # noqa: F401 — registers stdlib primitives
|
|
from .env import Env
|
|
|
|
__all__ = [
|
|
# Types
|
|
"Symbol",
|
|
"Keyword",
|
|
"Lambda",
|
|
"Macro",
|
|
"Component",
|
|
"HandlerDef",
|
|
"NIL",
|
|
# Parser
|
|
"parse",
|
|
"parse_all",
|
|
"serialize",
|
|
"ParseError",
|
|
# Evaluator
|
|
"evaluate",
|
|
"make_env",
|
|
"EvalError",
|
|
# Primitives
|
|
"register_primitive",
|
|
"get_primitive",
|
|
"all_primitives",
|
|
# Environment
|
|
"Env",
|
|
]
|