Self-hosted z3.sx translator, prove.sx prover, parser unicode, auto reader macros
- z3.sx: SX-to-SMT-LIB translator written in SX (359 lines), replaces Python translation logic - prove.sx: SMT-LIB satisfiability checker in SX — proves all 91 primitives sat by construction - Parser: support unicode characters (em-dash, accented letters) in symbols - Auto-resolve reader macros: #name finds name-translate in component env, no Python registration - Platform primitives: type-of, symbol-name, keyword-name, sx-parse registered in primitives.py - Cond heuristic: predicates ending in ? recognized as Clojure-style tests - Library loading: z3.sx loaded at startup with reload callbacks for hot-reload ordering - reader_z3.py: rewritten as thin shell delegating to z3.sx - Split monolithic .sx files: essays (22), plans (13), reactive-islands (6) into separate files Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -10,7 +10,7 @@ from __future__ import annotations
|
||||
import math
|
||||
from typing import Any, Callable
|
||||
|
||||
from .types import Keyword, NIL
|
||||
from .types import Component, Island, Keyword, Lambda, Macro, NIL, Symbol
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
@@ -494,6 +494,56 @@ def prim_dict_set_mut(d: Any, key: Any, val: Any) -> Any:
|
||||
d[key] = val
|
||||
return val
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Type introspection — platform primitives declared in eval.sx
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
@register_primitive("type-of")
|
||||
def prim_type_of(x: Any) -> str:
|
||||
if isinstance(x, bool):
|
||||
return "boolean"
|
||||
if isinstance(x, (int, float)):
|
||||
return "number"
|
||||
if isinstance(x, str):
|
||||
return "string"
|
||||
if x is None or x is NIL:
|
||||
return "nil"
|
||||
if isinstance(x, Symbol):
|
||||
return "symbol"
|
||||
if isinstance(x, Keyword):
|
||||
return "keyword"
|
||||
if isinstance(x, list):
|
||||
return "list"
|
||||
if isinstance(x, dict):
|
||||
return "dict"
|
||||
if isinstance(x, Lambda):
|
||||
return "lambda"
|
||||
if isinstance(x, Component):
|
||||
return "component"
|
||||
if isinstance(x, Island):
|
||||
return "island"
|
||||
if isinstance(x, Macro):
|
||||
return "macro"
|
||||
return "unknown"
|
||||
|
||||
|
||||
@register_primitive("symbol-name")
|
||||
def prim_symbol_name(s: Any) -> str:
|
||||
return s.name if isinstance(s, Symbol) else str(s)
|
||||
|
||||
|
||||
@register_primitive("keyword-name")
|
||||
def prim_keyword_name(k: Any) -> str:
|
||||
return k.name if isinstance(k, Keyword) else str(k)
|
||||
|
||||
|
||||
@register_primitive("sx-parse")
|
||||
def prim_sx_parse(source: str) -> list:
|
||||
from .parser import parse_all
|
||||
return parse_all(source)
|
||||
|
||||
|
||||
@register_primitive("into")
|
||||
def prim_into(target: Any, coll: Any) -> Any:
|
||||
if isinstance(target, list):
|
||||
|
||||
Reference in New Issue
Block a user