Polyglot & interop architecture
Supported directions
| Ecosystem | Direction | Exact mechanism |
|---|---|---|
| Python | PeaLang → Python module functions; Python host → embedded PeaLang | interop.call_python(module, function, *args, kwargs=...), interop.import_python, generate_python_stub, PeaRuntime |
| Java | HTTP service → Java client; Java host → runtime sidecar | interop.generate_java(base_url) produces PeaLangGeneratedClient; java-sdk/ |
| Rust | Exported PeaLang functions → Rust SDK; native symbols → PeaLang | generate_sdk_from_source(src, "rust") (reqwest/serde/tokio), interop.call_native |
| TypeScript / Node / browser | Exported functions → typed TS client; browser host → WASM runtime | interop.generate_typescript(base_url), generate_sdk_from_source(..., "node"|"browser"), browser-sdk/, react-sdk/ |
| Go | HTTP service → Go client; Go programs → PeaLang | interop.generate_go(base_url, package_name), interop.go_run(source, args) |
| C#, Ruby, PHP | Exported functions → host SDKs / clients | generate_sdk_from_source(src, language, target_dir=None) branches; no COBOL target |
| WASM | .peac → PEAWASM artifact | compile_peac_to_wasm(), pea wasm-build |
WASM policy and artifact API
PEAWASM builds are policy-bounded. The Python-level surface is WasmPolicy, ABI_VERSION, compile_peac_to_wasm(module, policy=None, exports=None, imports=None) and inspect_wasm(value); the CLI equivalents are pea wasm-build and pea wasm-inspect. A WASM differential namespace is also present for parity checks. This is bytecode-to-artifact compilation, not source translation.
Calling Python from PeaLang
let version = interop.run("python", ["--version"])
print version
let root = interop.call_python("math", "sqrt", 81)
print root
let stub = interop.generate_python_stub("risk", ["evaluate", "explain"])
print stub
call_python imports the target module in the host process and invokes the named function with PeaLang values converted at the boundary. Treat this as an in-process dependency: pin the interpreter, avoid untrusted module names and pass plain data rather than live objects.
HTTP and JSON-RPC service boundary
let health = interop.http_get("http://127.0.0.1:8787/health", 5)
print health
let reply = interop.json_rpc("http://127.0.0.1:8787/rpc", "sum", [1, 2, 3], 7)
print reply
let ts = interop.generate_typescript("http://127.0.0.1:8787")
print ts
Generated clients call /health and POST {module, function, args} to /v1/invoke. This is an RPC contract, not semantic translation: function bodies are not ported into the host language.
Host SDK generation from exported functions
# math_utils.pea
function add(a, b) { return a + b }
function multiply(a, b) { return a * b }
export add
export multiply
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
Exact supported SDK names: node, browser, go, python, java, csharp, rust, ruby, php, library. extract_functions() parses only function declarations and parameter names; generated methods are thin RPC wrappers. Use the library target when you need a PeaLang stub to implement locally.
Native FFI and command execution
let lib = interop.load_library("./target/release/libmetrics.so")
let value = interop.call_native("./target/release/libmetrics.so", "score", 21)
print value
let result = interop.run("git", ["status", "--short"], ".", 30)
print result
Native calls use ctypes under the hood; errors from missing symbols or libraries surface as host exceptions. PeaLang call arguments are positional: call_native(path, symbol, ...args) uses the host-side defaults restype="int" and argtypes=None; interop.run(command, args, cwd, timeout) maps to run_command. Validate values crossing the boundary, or wrap specialized FFI signatures in host code.
Architecture guidance
- Keep PeaLang as the decision layer; keep I/O-heavy systems in their native ecosystem.
- Pass plain maps, lists and scalars across boundaries; avoid host object graphs.
- Put secrets in host configuration and inject only the minimum capability set.
- Version the RPC contract with generated clients and gate it in CI.
Applied versions live in the polyglot SDK example and the code library.