module level validation

This commit is contained in:
Svyatoslav Nikolsky
2017-06-08 10:49:32 +03:00
parent 6c31fd61c2
commit 0cb48d7730
6 changed files with 145 additions and 24 deletions

View File

@ -32,6 +32,7 @@ pub struct VariableInstance {
impl VariableInstance {
/// New variable instance
pub fn new(is_mutable: bool, variable_type: VariableType, value: RuntimeValue) -> Result<Self, Error> {
// TODO: there is nothing about null value in specification + there is nothing about initializing missing table elements? => runtime check for nulls
if !value.is_null() && value.variable_type() != Some(variable_type) {
return Err(Error::Variable(format!("trying to initialize variable of type {:?} with value of type {:?}", variable_type, value.variable_type())));
}
@ -48,6 +49,11 @@ impl VariableInstance {
Self::new(global_type.is_mutable(), global_type.content_type().into(), value)
}
/// Is mutable
pub fn is_mutable(&self) -> bool {
self.is_mutable
}
/// Get the value of the variable instance
pub fn get(&self) -> RuntimeValue {
self.value.read().clone()