Bosatsu Multi-Target Compilation

Same language, compiled to JavaScript and WebAssembly, working together

Data Flow: Bosatsu orchestration (JS) calls Bosatsu computation (WASM)
Source
orchestrator.bosatsu
validation, sequencing
Compiled to
JavaScript
runs in browser
→ calls →
Compiled to
WebAssembly
via C
Source
compute.bosatsu
fib, factorial
Bosatsu → JS
Bosatsu → WASM
JS↔WASM Bridge

Fibonacci Sequence

Factorial Table

Collatz Conjecture (Compute Intensive)

Computes Collatz sequence steps for ALL numbers from 1 to n, returns max steps found. This is O(n × avg_steps) — try 10,000+ to see WASM vs JS performance difference.

Bosatsu Source Code

orchestrator.bosatsu → JS

package Demo/Orchestrator from Demo/Compute import fib, factorial # Validation logic (runs in JS) def validate_fib_input(n: Int) -> Bool: match cmp_Int(n, 0): case LT: False case _: cmp_Int(n, 40) matches LT | EQ # Orchestration (runs in JS, calls WASM) def compute_fib_sequence(n: Int) -> List[(Int, Int)]: range(n.add(1)).map(i -> (i, fib(i)))

compute.bosatsu → WASM

package Demo/Compute export fib, factorial # Heavy computation (runs in WASM) def fib(n: Int) -> Int: int_loop(n, (0, 1), (i, acc) -> (a, b) = acc (i.sub(1), (b, a.add(b)))) .fst def factorial(n: Int) -> Int: int_loop(n, 1, (i, acc) -> (i.sub(1), acc.times(i))).snd