ongoing work on rust runner

This commit is contained in:
NikVolf
2017-05-12 14:22:58 +03:00
parent db28fe95b6
commit c93212f5f4
3 changed files with 19 additions and 18 deletions

View File

@@ -8,8 +8,7 @@ pub struct Error;
impl Arena {
pub fn new(stack_top: u32) -> Self {
MemoryArenaAllocator {
module: module,
Arena {
dynamic_top: stack_top,
}
}

View File

@@ -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::<Vec<_>>();
@@ -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
/// ???
// ???
}

View File

@@ -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<u8>,
@@ -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 }