diff --git a/shared/static/scripts/sx-browser.js b/shared/static/scripts/sx-browser.js index 67ce7af..3e9632d 100644 --- a/shared/static/scripts/sx-browser.js +++ b/shared/static/scripts/sx-browser.js @@ -14,7 +14,7 @@ // ========================================================================= var NIL = Object.freeze({ _nil: true, toString: function() { return "nil"; } }); - var SX_VERSION = "2026-03-15T14:39:41Z"; + var SX_VERSION = "2026-03-15T15:05:23Z"; function isNil(x) { return x === NIL || x === null || x === undefined; } function isSxTruthy(x) { return x !== false && !isNil(x); } @@ -1064,7 +1064,7 @@ PRIMITIVES["value-matches-type?"] = valueMatchesType_p; PRIMITIVES["strict-check-args"] = strictCheckArgs; // eval-expr - var evalExpr = function(expr, env) { return error("eval-expr: CEK fixup not loaded"); }; + var evalExpr = function(expr, env) { return NIL; }; PRIMITIVES["eval-expr"] = evalExpr; // call-lambda @@ -2053,6 +2053,14 @@ PRIMITIVES["freeze-to-cid"] = freezeToCid; })(); }; PRIMITIVES["thaw-from-cid"] = thawFromCid; + // eval-expr + var evalExpr = function(expr, env) { return cekRun(makeCekState(expr, env, [])); }; +PRIMITIVES["eval-expr"] = evalExpr; + + // trampoline + var trampoline = function(val) { return (isSxTruthy(isThunk(val)) ? evalExpr(thunkExpr(val), thunkEnv(val)) : val); }; +PRIMITIVES["trampoline"] = trampoline; + // === Transpiled from render (core) === diff --git a/spec/evaluator.sx b/spec/evaluator.sx index 3127c12..72658fd 100644 --- a/spec/evaluator.sx +++ b/spec/evaluator.sx @@ -453,11 +453,10 @@ ;; trampoline = (val) → if thunk? then eval-expr(thunk-expr, thunk-env) else val ;; All evaluation goes through the CEK machine. +;; eval-expr: forward declaration — redefined at end of file after cek-run exists. +;; This stub is needed so functions between here and Part 3 can reference eval-expr. (define eval-expr - (fn (expr (env :as dict)) - ;; Stub — overridden by CEK fixup before any code runs. - ;; If this executes, CEK fixup failed to load. - (error "eval-expr: CEK fixup not loaded"))) + (fn (expr (env :as dict)) nil)) @@ -2470,3 +2469,22 @@ (when sx-text (thaw-from-sx sx-text) true)))) + + +;; ************************************************************************** +;; eval-expr / trampoline — canonical definitions (after cek-run is defined) +;; ************************************************************************** +;; +;; These override the forward declarations from Part 2. All evaluation +;; goes through the CEK machine. The CEK fixups in the host platform +;; may further override these (e.g., to make cek-run iterative). + +(define eval-expr + (fn (expr (env :as dict)) + (cek-run (make-cek-state expr env (list))))) + +(define trampoline + (fn (val) + (if (thunk? val) + (eval-expr (thunk-expr val) (thunk-env val)) + val)))