Skip to main content

pepl_codegen/
lib.rs

1//! PEPL WASM code generator: compiles a verified AST to `.wasm` binary.
2//!
3//! # Architecture
4//!
5//! The code generator takes a validated [`pepl_types::ast::Program`] and
6//! produces a self-contained `.wasm` module.  The generated module follows
7//! the PEPL host-integration contract:
8//!
9//! ## Imports
10//! - `env.host_call(cap_id, fn_id, args_ptr) → result_ptr`
11//! - `env.log(ptr, len)`
12//! - `env.trap(ptr, len)`
13//!
14//! ## Exports
15//! - `init(gas_limit)` — initialise state to defaults
16//! - `dispatch_action(action_id, args_ptr) → result_ptr`
17//! - `render(view_id) → surface_ptr`
18//! - `get_state() → state_ptr`
19//! - `alloc(size) → ptr`
20//! - `memory` — linear memory
21//! - (conditional) `update(dt_ptr)`, `handle_event(event_ptr)`
22//!
23//! ## Value Representation
24//!
25//! Every PEPL value is a heap-allocated 12-byte cell:
26//! `[tag: i32, payload: 8 bytes]`.  See [`types`] for tag constants.
27
28pub mod compiler;
29pub mod error;
30pub mod expr;
31pub mod gas;
32pub mod runtime;
33pub mod source_map;
34pub mod space;
35pub mod stmt;
36pub mod test_codegen;
37pub mod types;
38
39pub use compiler::{compile, compile_with_source_map};
40pub use error::{CodegenError, CodegenResult};
41pub use source_map::SourceMap;