Docs / Modularity

7. Module System & FFI

Dryad offers the ability to use file directives to invoke modules written purely in C or Rust through its optimized FFI, instantly without needing boilerplate wrappers. When passing heap-allocated Dryad objects across the FFI boundary, the gc.pin() and gc.unpin() intrinsics prevent the garbage collector from moving or collecting objects during native calls, ensuring pointer validity for the duration of the operation. Every FFI crossing should follow the mandatory pin-call-unpin pattern to guarantee memory safety.

Dryad TypeCorresponding C TypeBehavior
numberdouble (f64)Normalized 64-bit binary floating point.
stringconst char*UTF-8 buffer terminated with null character (\0).
boolbool / uint8_tContains 0 for false and 1 for true.
nullNULL / nullptrPassed directly as a null address pointer (0x0).
arrayvoid*Opaque buffer managed by reference counting.
objectvoid*Internal persisted object pointer.
FFI Loading and Calling
 1 #io       // Loads native I/O module into global scope
 2 #crypto   // Global native cryptography module
 3 
 4 function main() {
 5   // Access without quotes
 6   let content = io_read_file("chave.pem");
 7   let validacao = crypto_decrypt(content);
 8 
 9   return validacao;
10 }
11 
12 main();

Native modules map basic C types directly to Dryad's runtime representation contiguously in memory.

Found an error in the spec? Open a PR.
Official Version: 1.0 · May 2026