diff --git a/src/interpreter/table.rs b/src/interpreter/table.rs index b154de3..6a86e4e 100644 --- a/src/interpreter/table.rs +++ b/src/interpreter/table.rs @@ -15,6 +15,7 @@ pub struct TableInstance { } impl TableInstance { + /// New instance of the table pub fn new(variable_type: VariableType, table_type: &TableType) -> Result, Error> { Ok(Arc::new(TableInstance { variable_type: variable_type, @@ -24,6 +25,7 @@ impl TableInstance { })) } + /// Get the specific value in the table pub fn get(&self, offset: u32) -> Result { let buffer = self.buffer.read(); let buffer_len = buffer.len(); @@ -32,6 +34,7 @@ impl TableInstance { .ok_or(Error::Table(format!("trying to read table item with index {} when there are only {} items", offset, buffer_len))) } + /// Set the table value from raw slice pub fn set_raw(&self, mut offset: u32, value: &[u32]) -> Result<(), Error> { for val in value { match self.variable_type { @@ -43,6 +46,7 @@ impl TableInstance { Ok(()) } + /// Set the table from runtime variable value pub fn set(&self, offset: u32, value: RuntimeValue) -> Result<(), Error> { let mut buffer = self.buffer.write(); let buffer_len = buffer.len(); diff --git a/src/interpreter/variable.rs b/src/interpreter/variable.rs index 327d619..79a2ff2 100644 --- a/src/interpreter/variable.rs +++ b/src/interpreter/variable.rs @@ -30,6 +30,7 @@ pub struct VariableInstance { } impl VariableInstance { + /// New variable instance pub fn new(is_mutable: bool, variable_type: VariableType, value: RuntimeValue) -> Result { 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()))); @@ -42,14 +43,17 @@ impl VariableInstance { }) } + /// New global variable pub fn new_global(global_type: &GlobalType, value: RuntimeValue) -> Result { Self::new(global_type.is_mutable(), global_type.content_type().into(), value) } + /// Get the value of the variable instance pub fn get(&self) -> RuntimeValue { self.value.read().clone() } + /// Set the value of the variable instance pub fn set(&self, value: RuntimeValue) -> Result<(), Error> { if !self.is_mutable { return Err(Error::Variable("trying to update immutable variable".into()));