|
infix
A JIT-Powered FFI Library for C
|
Cookbook Chapter 12: High-Performance Language Bindings. More...
Classes | |
| struct | Point |
| A simple struct with two doubles, often used to test pass-by-value on registers. More... | |
| struct | MockObject |
Enumerations | |
| enum | MockType { MOCK_INT , MOCK_POINT } |
Functions | |
| void | move_point_ref (Point *p, int dx, int dy) |
| MockObject * | NewMockInt (int v) |
| MockObject * | NewMockPoint (double x, double y) |
| infix_direct_value_t | marshal_mock_int (void *source_obj) |
| Scalar Marshaller for Integer arguments. Extracts the integer value from a MockObject. | |
| void | marshal_mock_point (void *source_obj, void *dest_buffer, const infix_type *type) |
| Aggregate Marshaller for Point struct arguments. Copies data from the MockObject into the temporary C buffer provided by the JIT. | |
| void | writeback_mock_point (void *source_obj, void *c_data_ptr, const infix_type *type) |
| Write-back Handler for Point struct arguments. Called after the C function returns. Copies data from the C buffer back to the MockObject. | |
| int | main () |
Cookbook Chapter 12: High-Performance Language Bindings.
This example demonstrates the "Direct Marshalling" (or "Bundle") API. This is an advanced feature for writing language bindings (like for Python, Lua, or Perl) where performance is critical.
Instead of unboxing your language's objects into temporary C variables and creating a void* args[] array for every call, you provide "Marshaller" functions. The infix JIT compiler calls these functions directly to fetch data from your objects just-in-time.
Scenario: We simulate a simple scripting language ("MockLang") and bind a C function move_point that takes a struct pointer and modifies it. This demonstrates:
| enum MockType |
| int main | ( | void | ) |
| infix_direct_value_t marshal_mock_int | ( | void * | source_obj | ) |
Scalar Marshaller for Integer arguments. Extracts the integer value from a MockObject.
| void marshal_mock_point | ( | void * | source_obj, |
| void * | dest_buffer, | ||
| const infix_type * | type | ||
| ) |
Aggregate Marshaller for Point struct arguments. Copies data from the MockObject into the temporary C buffer provided by the JIT.
| void move_point_ref | ( | Point * | p, |
| int | dx, | ||
| int | dy | ||
| ) |
| MockObject * NewMockInt | ( | int | v | ) |
| MockObject * NewMockPoint | ( | double | x, |
| double | y | ||
| ) |
| void writeback_mock_point | ( | void * | source_obj, |
| void * | c_data_ptr, | ||
| const infix_type * | type | ||
| ) |
Write-back Handler for Point struct arguments. Called after the C function returns. Copies data from the C buffer back to the MockObject.