Files
rose-ash/shared/sx/__init__.py
giles d8cddbd971 Replace hand-written evaluator with bootstrapped spec, emit flat Python
- evaluator.py: replace 1200 lines of hand-written eval with thin shim
  that re-exports from bootstrapped sx_ref.py
- bootstrap_py.py: emit all fn-bodied defines as `def` (not `lambda`),
  flatten tail-position if/cond/case/when to if/elif with returns,
  fix &rest handling in _emit_define_as_def
- platform_py.py: EvalError imports from evaluator.py so catches work
- __init__.py: remove SX_USE_REF conditional, always use bootstrapped
- tests/run.py: reset render_active after render tests for isolation
- Removes setrecursionlimit(5000) hack — no longer needed with flat code

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-11 09:18:17 +00:00

73 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 .evaluator import (
EvalError,
evaluate,
make_env,
)
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",
]