Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 50s
Guest Scheme call/cc is escape-only (re-entry hangs), so durable resume uses deterministic replay: suspend escapes to the driver; resume re-runs the flow and replays resolved suspends from a (tag value) log. No live continuation is ever serialized — persisted state is plain data, survives restart. Adds flow/start (now state-returning, backward compatible), flow/resume, flow/cancel, store.sx. Harness reuses one env with a per-test reset (full env rebuild 66x was too slow). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
60 lines
1.9 KiB
Plaintext
60 lines
1.9 KiB
Plaintext
;; lib/flow/api.sx — flow runtime entry points.
|
|
;;
|
|
;; Builds a Scheme env preloaded with the flow combinators (lib/flow/spec.sx) and
|
|
;; the durable store + lifecycle (lib/flow/store.sx), and provides SX helpers to
|
|
;; run flow programs.
|
|
;;
|
|
;; Scheme-level API (available inside flow programs):
|
|
;; (flow/start flow input) — run a flow; raw result if it completes, else
|
|
;; (flow-suspended id tag). Defined in store.sx.
|
|
;; (flow/resume id value) — resume a suspended flow (store.sx)
|
|
;; (flow/cancel id) — cancel a flow (store.sx)
|
|
;; (suspend tag) — suspension point (spec.sx)
|
|
;;
|
|
;; SX-level helpers (for hosts and tests):
|
|
;; (flow-make-env) — fresh standard env + combinators + store
|
|
;; (flow-run src) — eval a Scheme program string in a reset shared env
|
|
;; (flow-run-in env src) — eval a Scheme program string in a given env
|
|
;;
|
|
;; flow-run reuses ONE env (building the full standard env is expensive) and
|
|
;; resets the mutable flow globals before each program, so tests stay isolated
|
|
;; without paying for a fresh standard env each time.
|
|
|
|
(define
|
|
flow-make-env
|
|
(fn
|
|
()
|
|
(let
|
|
((env (scheme-standard-env)))
|
|
(flow-load-combinators! env)
|
|
(flow-load-store! env)
|
|
env)))
|
|
|
|
(define
|
|
flow-run-in
|
|
(fn (env src) (scheme-eval-program (scheme-parse-all src) env)))
|
|
|
|
(define
|
|
flow-reset-src
|
|
"(set! flow-store (list)) (set! flow-next-id 0) (set! flow-replay-log (list)) (set! flow-suspend-k #f) (set! flow-timeout-budget -1)")
|
|
|
|
(define flow-env-cache false)
|
|
|
|
(define
|
|
flow-shared-env
|
|
(fn
|
|
()
|
|
(begin
|
|
(if flow-env-cache nil (set! flow-env-cache (flow-make-env)))
|
|
flow-env-cache)))
|
|
|
|
(define
|
|
flow-run
|
|
(fn
|
|
(src)
|
|
(let
|
|
((env (flow-shared-env)))
|
|
(begin
|
|
(scheme-eval-program (scheme-parse-all flow-reset-src) env)
|
|
(scheme-eval-program (scheme-parse-all src) env)))))
|