You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: Add cross-module function calls with signature-based native calling
Add support for cross-language function calls in zyntax_embed runtime:
- Add extern fn declaration support to zig.zyn grammar
- Implement explicit export control for cross-module linking
- load_module_with_exports() for exporting during load
- export_function() for post-load exports
- check_export_conflict() for symbol conflict detection
- Add signature-based native calling API (NativeType, NativeSignature)
- call_native() method with explicit function signatures
- Supports I32, I64, F32, F64, Bool, Void, Ptr types
- NativeSignature::parse() for string-based signature parsing
- Add convenience methods to ZyntaxValue (as_i32, as_i64)
- Add cross_module_tests.rs with 6 comprehensive tests
- Update book and README documentation
Copy file name to clipboardExpand all lines: book/12-embedding-sdk.md
+83-4Lines changed: 83 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -202,14 +202,14 @@ println!("Language for .py: {:?}", runtime.language_for_extension("py")); //
202
202
203
203
### Cross-Language Function Calls
204
204
205
-
All modules loaded into the same runtime share a common execution environment. Functions can call each other across language boundaries:
205
+
All modules loaded into the same runtime share a common execution environment. Functions can call each other across language boundaries using **explicit exports**:
206
206
207
207
```rust
208
-
// Load core utilities in Zig
209
-
runtime.load_module("zig", r#"
208
+
// Load core utilities in Zig and EXPORT them for cross-module linking
209
+
runtime.load_module_with_exports("zig", r#"
210
210
pub fn square(x: i32) i32 { return x * x; }
211
211
pub fn cube(x: i32) i32 { return x * x * x; }
212
-
"#)?;
212
+
"#, &["square", "cube"])?;
213
213
214
214
// Load a DSL that uses the Zig functions via extern declarations
println!("Warning: my_func already exported at {:?}", existing_ptr);
242
+
}
243
+
244
+
// List all exported symbols
245
+
for (name, ptr) inruntime.exported_symbols() {
246
+
println!("Exported: {} at {:?}", name, ptr);
247
+
}
248
+
```
249
+
250
+
**Note:** Attempting to export a function with the same name as an existing export will log a warning and overwrite the existing symbol.
251
+
227
252
### TieredRuntime Multi-Language Support
228
253
229
254
The `TieredRuntime` also supports multi-language modules with the same API:
@@ -388,6 +413,60 @@ match result {
388
413
}
389
414
```
390
415
416
+
### Native Calling with Signatures
417
+
418
+
For JIT-compiled functions, use `call_native` with an explicit signature for optimal performance. This bypasses the `DynamicValue` ABI and calls functions with native types directly.
0 commit comments