Seven-Streams opened a new pull request, #693:
URL: https://github.com/apache/tvm-ffi/pull/693
This PR adds native Rust structural traversal support to TVM FFI. It
introduces `structural_visit` and `structural_walk`, similar to the C++ side.
It also introduces a #[dispatch(visit)] macro for ordered, typed visitor
dispatch. For example:
```rust
use tvm_ffi::{dispatch, structural_visit, Function, VisitCtx, WalkResult};
#[derive(Default)]
struct Calculator {
value: f64,
}
#[dispatch(visit)]
impl Calculator {
fn visit_integer(&mut self, value: i64, _ctx: &mut VisitCtx<'_>) ->
WalkResult {
self.value += value as f64;
WalkResult::Advance
}
fn visit_float(&mut self, value: f64, _ctx: &mut VisitCtx<'_>) ->
WalkResult {
self.value -= value;
WalkResult::Advance
}
}
let values = Function::get_global("ffi.Array")
.unwrap()
.call_tuple((10_i64, 2.5_f64))
.unwrap();
let mut calculator = Calculator::default();
assert!(structural_visit(&values, &mut calculator)
.unwrap()
.is_continue());
assert_eq!(calculator.value, 7.5);
```
We can also visit the objects registered on the C++ side as well.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]