diff --git a/rust-runner/src/alloc.rs b/rust-runner/src/alloc.rs index bd17625..ffb29cf 100644 --- a/rust-runner/src/alloc.rs +++ b/rust-runner/src/alloc.rs @@ -8,8 +8,7 @@ pub struct Error; impl Arena { pub fn new(stack_top: u32) -> Self { - MemoryArenaAllocator { - module: module, + Arena { dynamic_top: stack_top, } } diff --git a/rust-runner/src/main.rs b/rust-runner/src/main.rs index 9b845dc..22940fb 100644 --- a/rust-runner/src/main.rs +++ b/rust-runner/src/main.rs @@ -11,10 +11,10 @@ mod alloc; mod storage; use std::env; +use parity_wasm::interpreter::ModuleInstanceInterface; fn main() { - /// First, load wasm contract as a module - + // First, load wasm contract as a module wasm_utils::init_log(); let args = env::args().collect::>(); @@ -25,17 +25,17 @@ fn main() { let module = parity_wasm::deserialize_file(&args[1]).expect("Module deserialization to succeed"); - /// Second, create program instance + // Second, create program instance let program = parity_wasm::interpreter::ProgramInstance::new().expect("Program instance to be created"); - /// Add module to the programm - program.add_module("contract", module); + // Add module to the programm + let module_instance = program.add_module("contract", module).expect("Module to be added successfully"); - /// Create allocator + // Create allocator let mut allocator = alloc::Arena::new(5*1024*1024); + // Invoke _call method of the module + module_instance.execute_export("_call", vec![]).expect("_call to execute successfully"); - /// Invoke _call method of the module - - /// ??? + // ??? } \ No newline at end of file diff --git a/rust-runner/src/storage.rs b/rust-runner/src/storage.rs index 0ead7b4..70412f2 100644 --- a/rust-runner/src/storage.rs +++ b/rust-runner/src/storage.rs @@ -2,7 +2,7 @@ use parity_wasm::interpreter::ModuleInstanceInterface; use parity_wasm::interpreter::ItemIndex; use std::sync::Arc; -const DEFAULT_MEMORY_INDEX: ItemIndex = ItemIndex(0); +const DEFAULT_MEMORY_INDEX: ItemIndex = ItemIndex::Internal(0); pub struct Storage { data: Vec, @@ -21,7 +21,7 @@ impl Storage { match memory.set(dst, &self.data[offset as usize..offset as usize + len as usize]) { Err(_) => { return -1; } - Ok(_) => return len; + Ok(_) => { return len as i32; } } } @@ -33,16 +33,18 @@ impl Storage { let slice = match memory.get(src, len as usize) { Err(_) => { return -1; } - Ok(slice) => return slice; + Ok(slice) => slice, }; - if self.data.len() < offset as usize + slice.len { - self.data.reserve(offset as usize + slice.len); + if self.data.len() < offset as usize + slice.len() { + self.data.reserve(offset as usize + slice.len()); unsafe { - self.data.set_len(offset as usize + slice.len); + self.data.set_len(offset as usize + slice.len()); } } - self.data[offset as usize..offset as usize + slice.len].copy_from_slice(&slice[..]); + self.data[offset as usize..offset as usize + slice.len()].copy_from_slice(&slice[..]); + + slice.len() as i32 } pub fn size(&self) -> u32 { self.data.len() as u32 }