Skip to content

Add shen-swift as a Ratatoskr stage-2 target (Swift) - #7

Merged
pyrex41 merged 1 commit into
mainfrom
swift-stage2
Jun 20, 2026
Merged

Add shen-swift as a Ratatoskr stage-2 target (Swift)#7
pyrex41 merged 1 commit into
mainfrom
swift-stage2

Conversation

@pyrex41

@pyrex41 pyrex41 commented Jun 20, 2026

Copy link
Copy Markdown
Owner

shen-swift is a tree-walking KLambda interpreter (iOS-capable), not a compiler — so its stage-2 builder has nothing to code-generate. The artifact is the shaken slice, executed by the shen-swift binary, the same runtime-reference relationship the lua/julia targets have to their toolchains. The win is boot speed: a ~200-line shaken kernel vs the full ~2500-line kernel.

What's here

  • builders/swift/build.sh — reads the user .kl from the manifest, copies kernel.kl + user.kl next to a run launcher that drives shen-swift in --shaken mode (a new flag on the shen-swift side). Resolves/builds the shen-swift binary (SHEN_SWIFT/SHEN_SWIFT_BIN overridable).
  • builders.jsonswift entry (run_impl: shen-swift, needs: ["swift"]).
  • main.go + ratatoskr_cli.py{shen_swift} substitution and swift → shen-swift sibling map in both the Go CLI and the Python oracle.

Load order

Mirrors the Scheme/Lua builders: load all defuns → install native overrides → (shen.initialise) → run the collected top-level forms (kernel, then user) so the program runs against a fully initialised environment.

Verification

  • ratatoskr run --target swift tests/fib.shen out/fib 20 = 6765.
  • bifrost --shake --only recursion-fib-file --impls shen-swift,shen-lua → both PASS, byte-identical.
  • go vet / go test (4 passed) / pytest test_portable.py (7 passed) green.

With this, all eight bifrost ports have a Ratatoskr builder.

Cross-repo note: the --shaken flag lives in shen-swift (Boot.swift + main.swift). That repo is not currently under version control in this workspace, so those changes ship locally; build.sh will swift build shen-swift as-is.

🤖 Generated with Claude Code

shen-swift is a tree-walking KLambda interpreter (iOS-capable), not a
compiler, so its stage-2 builder has nothing to code-generate: the
artifact IS the shaken slice, executed by the shen-swift binary — the
same runtime-reference relationship the lua/julia targets have. The win
is boot speed: a ~200-line shaken kernel vs the full ~2500-line kernel.

builders/swift/build.sh copies the shaken kernel.kl + user .kl next to a
`run` launcher that drives shen-swift in `--shaken` mode (a new flag on
the shen-swift side: boot the slice — defuns, native overrides,
(shen.initialise), then top-level forms — and run the program to
completion, no full kernel, no launcher). Load order mirrors the
Scheme/Lua builders.

Wired: builders.json `swift` entry; `{shen_swift}` subst + swift→shen-swift
sibling map in both the Go CLI (main.go) and the Python oracle
(ratatoskr_cli.py). Verified `fib 20 = 6765` via `ratatoskr run --target
swift` and byte-identical with shen-lua under `bifrost --shake`. With
this, all eight bifrost ports have a builder.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@pyrex41
pyrex41 merged commit 4c21cc7 into main Jun 20, 2026
18 checks passed
@pyrex41
pyrex41 deleted the swift-stage2 branch June 20, 2026 00:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant