Expand description
Closure support for Seq
Provides runtime functions for creating and managing closures (quotations with captured environments).
A closure consists of:
- Function pointer (the compiled quotation code)
- Environment (Arc-shared array of captured values for TCO support)
Note: These extern “C” functions use Value and slice pointers, which aren’t technically FFI-safe, but they work correctly when called from LLVM-generated code (not actual C interop).
§Type Support Status
Currently supported capture types:
- Int (via
env_get_int) - Bool (via
env_get_bool) - returns i64 (0/1) - Float (via
env_get_float) - returns f64 - String (via
env_get_string) - Quotation (via
env_get_quotation) - returns function pointer as i64
Types to be added in future PR:
- Closure (nested closures with their own environments)
- Variant (tagged unions)
See https://github.com/navicore/patch-seq for roadmap.
Re-exports§
pub use patch_seq_create_env as create_env;pub use patch_seq_env_get as env_get;pub use patch_seq_env_get_bool as env_get_bool;pub use patch_seq_env_get_float as env_get_float;pub use patch_seq_env_get_int as env_get_int;pub use patch_seq_env_get_quotation as env_get_quotation;pub use patch_seq_env_get_string as env_get_string;pub use patch_seq_env_push_string as env_push_string;pub use patch_seq_env_set as env_set;pub use patch_seq_make_closure as make_closure;pub use patch_seq_push_closure as push_closure;
Constants§
- MAX_
CAPTURES - Maximum number of captured values allowed in a closure environment. This prevents unbounded memory allocation and potential resource exhaustion.
Functions§
- patch_
seq_ create_ env - Create a closure environment (array of captured values)
- patch_
seq_ ⚠env_ get - Get a value from the closure environment
- patch_
seq_ ⚠env_ get_ bool - Get a Bool value from the closure environment
- patch_
seq_ ⚠env_ get_ float - Get a Float value from the closure environment
- patch_
seq_ ⚠env_ get_ int - Get an Int value from the closure environment
- patch_
seq_ ⚠env_ get_ quotation - Get a Quotation impl_ function pointer from the closure environment
- patch_
seq_ ⚠env_ get_ string - Get a String value from the environment at the given index
- patch_
seq_ ⚠env_ push_ string - Push a String from the closure environment directly onto the stack
- patch_
seq_ ⚠env_ set - Set a value in the closure environment
- patch_
seq_ ⚠make_ closure - Create a closure value from a function pointer and environment
- patch_
seq_ ⚠push_ closure - Create closure from function pointer and stack values (all-in-one helper)