30 lines
787 B
Rust
Raw Normal View History

2017-12-11 18:52:07 +01:00
use elements::ResizableLimits;
2017-11-25 22:55:45 +03:00
use interpreter::Error;
2017-06-07 14:48:02 +03:00
2017-05-18 15:08:55 +03:00
/// Execution context.
2017-12-11 18:38:09 +01:00
pub struct ExecutionParams<'a, St: 'static> {
2017-12-11 16:38:52 +01:00
/// State that can be used by host functions,
2017-12-11 18:38:09 +01:00
pub state: &'a mut St,
2017-05-18 15:08:55 +03:00
}
2017-04-21 14:35:12 +03:00
/// Item index in items index space.
#[derive(Debug, Clone, Copy)]
pub enum ItemIndex {
/// Index in index space.
IndexSpace(u32),
/// Internal item index (i.e. index of item in items section).
Internal(u32),
2017-05-18 15:08:55 +03:00
/// External module item index (i.e. index of item in the import section).
2017-04-21 14:35:12 +03:00
External(u32),
}
2017-11-25 22:55:45 +03:00
pub fn check_limits(limits: &ResizableLimits) -> Result<(), Error> {
2017-06-08 10:49:32 +03:00
if let Some(maximum) = limits.maximum() {
if maximum < limits.initial() {
2017-12-01 15:36:43 +03:00
return Err(Error::Validation(format!("maximum limit {} is lesser than minimum {}", maximum, limits.initial())));
2017-06-08 10:49:32 +03:00
}
}
Ok(())
}