PeaLang / Code Library / Blueprint
Production Blueprint ยท v3.1.36
Polyglot SDK generation
Domain: Developer Tooling / InteropSDKRustNode.jsPythonJavaGo
Verified example. The code below was checked against the local PeaLang v3.1.36 parser, interpreter or async VM. It uses only syntax and built-ins present in that source tree.
Problem statement
A shared calculation module is needed by services written in several languages. Rewriting it in each repository invites semantic drift; the team wants generated host SDKs whose method names and parameters come from the PeaLang functions themselves.
Complete code
function add(a, b) { return a + b }
function multiply(a, b) { return a * b }
print add(2, 3)
print multiply(4, 5)
Save as
polyglot-sdk-generation.peaRun & verify
pea fmt --check math_utils.pea
pea check math_utils.pea
pea run math_utils.pea
pea sdk list
pea sdk-codegen math_utils.pea rust ./sdk-rust
pea sdk-codegen math_utils.pea node ./sdk-node
pea sdk-codegen math_utils.pea python ./sdk-python
pea sdk-codegen math_utils.pea java ./sdk-java
pea sdk-codegen math_utils.pea go ./sdk-go
# Or scaffold an empty host SDK without a source file:
pea sdk generate rust ./sdk-rust-empty
Always run the formatter and static checker before execution:
pea fmt --check polyglot-sdk-generation.pea && pea check polyglot-sdk-generation.pea, then pea run polyglot-sdk-generation.pea (or the host command shown above for async modules).Why & How
- Source of truth. The two plain functions are valid standalone PeaLang and also readable by
extract_functions().exportstatements are reserved for imported modules, so they are intentionally omitted here to keeppea runworking. - Two CLI surfaces.
pea sdk listreports the ten supported targets;pea sdk generate <lang> <dir>scaffolds an empty SDK;pea sdk-codegen <source.pea> <lang> <dir>derives methods from source functions. - Exact targets. The generator names are
node,browser,go,python,java,csharp,rust,ruby,phpandlibrary. Do not invent a target name; checkpea sdk listfirst. - What is generated. These are thin RPC wrappers and host-side scaffolding, not a compiler that rewrites PeaLang function bodies into Rust or Java. Generated code still talks to a PeaLang runtime or service boundary.
- Local verification.
pea runprints5and20, proving the source functions themselves are valid before any SDK is generated. - Operational guardrail. Commit generated SDKs alongside a lockfile and add a CI step that regenerates them and fails on a diff; that turns contract drift into a visible build failure.