Off-chain Targets (Native & WASM)
Relevant source files
The following files were used as context for generating this wiki page:
Sploosh is designed as a dual-target programming language, capable of compiling a single source tree to both web2 off-chain environments (Native via LLVM and WASM) and web3 on-chain environments (EVM and Solana SBF). The off-chain targets focus on systems-grade application authoring, providing Rust-level memory safety and Elixir-style actor concurrency for high-performance services and tools.
The off-chain surface area allows for features restricted in on-chain modules, such as floating-point mathematics, actor-based concurrency, and filesystem/network I/O. These capabilities are managed through a single syntax where the compiler enforces target-specific restrictions at compile time.
Sources: README.md:15-18, VISION.md:5-10, VISION.md:55-58
Architecture and Target Matrix
Sploosh utilizes a unified frontend (lexer and parser) to generate a typed Abstract Syntax Tree (AST). This AST is then processed by different backends depending on the specified build target. The off-chain targets (Native and WASM) are part of a four-target commitment.
The diagram above illustrates the compilation flow from Sploosh source code to the various supported backends, highlighting the separation between off-chain and on-chain targets.
Sources: README.md:100-112, VISION.md:55-58, crates/sploosh-parser/src/lib.rs:35-75
Language Features for Off-chain Targets
Off-chain targets support the full extent of the Sploosh language core, including concurrency models and data types that are prohibited in onchain mod blocks.
Actor Concurrency
Actors are the primary mechanism for concurrent execution in off-chain Sploosh. They provide isolated units of execution with private state and a message mailbox, eliminating shared-state bugs.
- Actor State: Private mutable state held within the actor.
- Mailbox: Asynchronous message queue for incoming requests.
- Handle: A
Clone + Sendreference used to interact with a running actor.
Sources: VISION.md:85-88, README.md:43-55, crates/sploosh-parser/src/lib.rs:252-290
Native and WASM Specific Capabilities
Unlike on-chain modules, Native and WASM targets have access to non-deterministic operations and standard system resources.
| Feature | Off-chain (Native/WASM) | On-chain (EVM/SVM) |
|---|---|---|
| Floating Point | Supported (f32, f64) | Prohibited |
| Actors | Supported (spawn, send) | Prohibited |
| Host IO | Supported (fs, net, env) | Prohibited |
| Memory | System Managed | Blockchain Storage |
Sources: VISION.md:81-84, VISION.md:118-121, crates/sploosh-lexer/src/lib.rs:410-415
Implementation and Parsing logic
The sploosh-parser and sploosh-lexer crates handle the identification of off-chain specific modifiers. Key keywords and logic within the compiler frontend distinguish these components.
Off-chain Modifiers
The parser identifies offchain as a contextual keyword and applies it specifically to function items. This modifier explicitly marks behavior intended only for non-blockchain environments.
// crates/sploosh-parser/src/lib.rs:77-100
let offchain_token = self.eat_keyword(Keyword::Offchain);
let is_offchain = offchain_token.is_some();
if !matches!(next, TokenKind::Keyword(Keyword::Fn)) {
if let Some(token) = &offchain_token {
self.error_at(token.span, "`offchain` applies only to `fn` items");
}
}
Sources: crates/sploosh-parser/src/lib.rs:81-95, crates/sploosh-lexer/src/lib.rs:118
Primitive Types
The lexer and parser support primitive types required for systems programming on Native/WASM targets, such as various integer widths and floating-point types.
- Integers:
i8throughi128, and unsigned variants. - Floats:
f32,f64(Prohibited on-chain). - Others:
bool,char,str,String.
Sources: crates/sploosh-parser/src/lib.rs:955-975, crates/sploosh-lexer/src/lib.rs:410-415
Execution Flow for Off-chain Logic
The interaction between the main program and actors in an off-chain environment follows a request/reply or fire-and-forget pattern.
Conclusion
Off-chain targets in Sploosh provide the robust featureset required for building high-performance applications outside the constraints of a blockchain virtual machine. By leveraging actors and providing access to native system primitives while maintaining strict memory safety, Sploosh allows developers to share a familiar syntax across the entire stack, from the backend server (Native) to the web client (WASM) and the smart contract (EVM/SVM).
Sources: VISION.md:5-10, README.md:15-18