mirror of
https://github.com/fluencelabs/parity-wasm
synced 2025-06-19 09:51:49 +00:00
Fix warnings
This commit is contained in:
@ -24,7 +24,7 @@ fn main() {
|
|||||||
// - a module declaration
|
// - a module declaration
|
||||||
// - "main" module doesn't import native module(s) this is why we don't need to provide external native modules here
|
// - "main" module doesn't import native module(s) this is why we don't need to provide external native modules here
|
||||||
// This test shows how to implement native module https://github.com/NikVolf/parity-wasm/blob/master/src/interpreter/tests/basics.rs#L197
|
// This test shows how to implement native module https://github.com/NikVolf/parity-wasm/blob/master/src/interpreter/tests/basics.rs#L197
|
||||||
let module = program.add_module("main", module, &mut ()).expect("Failed to initialize module");
|
program.add_module("main", module, &mut ()).expect("Failed to initialize module");
|
||||||
|
|
||||||
// The argument should be parsable as a valid integer
|
// The argument should be parsable as a valid integer
|
||||||
let argument: i32 = args[2].parse().expect("Integer argument required");
|
let argument: i32 = args[2].parse().expect("Integer argument required");
|
||||||
|
@ -2,7 +2,7 @@ extern crate parity_wasm;
|
|||||||
|
|
||||||
use std::env::args;
|
use std::env::args;
|
||||||
|
|
||||||
use parity_wasm::{interpreter, RuntimeValue};
|
use parity_wasm::RuntimeValue;
|
||||||
use parity_wasm::elements::{Internal, External, Type, FunctionType, ValueType};
|
use parity_wasm::elements::{Internal, External, Type, FunctionType, ValueType};
|
||||||
|
|
||||||
|
|
||||||
@ -76,7 +76,7 @@ fn main() {
|
|||||||
// - a module declaration
|
// - a module declaration
|
||||||
// - "main" module doesn't import native module(s) this is why we don't need to provide external native modules here
|
// - "main" module doesn't import native module(s) this is why we don't need to provide external native modules here
|
||||||
// This test shows how to implement native module https://github.com/NikVolf/parity-wasm/blob/master/src/interpreter/tests/basics.rs#L197
|
// This test shows how to implement native module https://github.com/NikVolf/parity-wasm/blob/master/src/interpreter/tests/basics.rs#L197
|
||||||
let module = program.add_module("main", module, &mut ()).expect("Failed to initialize module");
|
program.add_module("main", module, &mut ()).expect("Failed to initialize module");
|
||||||
|
|
||||||
println!("Result: {:?}", program.invoke_export("main", func_name, args, &mut ()).expect(""));
|
println!("Result: {:?}", program.invoke_export("main", func_name, args, &mut ()).expect(""));
|
||||||
}
|
}
|
||||||
|
@ -95,7 +95,7 @@ impl From<ModuleScaffold> for elements::Module {
|
|||||||
let import = module.import;
|
let import = module.import;
|
||||||
if import.entries().len() > 0 {
|
if import.entries().len() > 0 {
|
||||||
sections.push(elements::Section::Import(import));
|
sections.push(elements::Section::Import(import));
|
||||||
}
|
}
|
||||||
let functions = module.functions;
|
let functions = module.functions;
|
||||||
if functions.entries().len() > 0 {
|
if functions.entries().len() > 0 {
|
||||||
sections.push(elements::Section::Function(functions));
|
sections.push(elements::Section::Function(functions));
|
||||||
@ -159,7 +159,7 @@ impl<F> ModuleBuilder<F> where F: Invoke<elements::Module> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Fill module with sections from iterator
|
/// Fill module with sections from iterator
|
||||||
pub fn with_sections<I>(mut self, sections: I) -> Self
|
pub fn with_sections<I>(mut self, sections: I) -> Self
|
||||||
where I: IntoIterator<Item=elements::Section>
|
where I: IntoIterator<Item=elements::Section>
|
||||||
{
|
{
|
||||||
self.module.other.extend(sections);
|
self.module.other.extend(sections);
|
||||||
@ -262,7 +262,7 @@ impl<F> ModuleBuilder<F> where F: Invoke<elements::Module> {
|
|||||||
self.module.import.entries_mut().len() as u32 - 1
|
self.module.import.entries_mut().len() as u32 - 1
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Push export entry to module.
|
/// Push export entry to module.
|
||||||
pub fn push_export(&mut self, export: elements::ExportEntry) -> u32 {
|
pub fn push_export(&mut self, export: elements::ExportEntry) -> u32 {
|
||||||
self.module.export.entries_mut().push(export);
|
self.module.export.entries_mut().push(export);
|
||||||
self.module.export.entries_mut().len() as u32 - 1
|
self.module.export.entries_mut().len() as u32 - 1
|
||||||
@ -349,7 +349,7 @@ impl<F> ModuleBuilder<F> where F: Invoke<elements::Module> {
|
|||||||
/// .build();
|
/// .build();
|
||||||
///
|
///
|
||||||
/// assert_eq!(module.export_section().expect("export section to exist").entries().len(), 1);
|
/// assert_eq!(module.export_section().expect("export section to exist").entries().len(), 1);
|
||||||
/// ```
|
/// ```
|
||||||
pub fn export(self) -> export::ExportBuilder<Self> {
|
pub fn export(self) -> export::ExportBuilder<Self> {
|
||||||
export::ExportBuilder::with_callback(self)
|
export::ExportBuilder::with_callback(self)
|
||||||
}
|
}
|
||||||
@ -368,7 +368,7 @@ impl<F> ModuleBuilder<F> where F: Invoke<elements::Module> {
|
|||||||
/// .build();
|
/// .build();
|
||||||
///
|
///
|
||||||
/// assert_eq!(module.global_section().expect("global section to exist").entries().len(), 1);
|
/// assert_eq!(module.global_section().expect("global section to exist").entries().len(), 1);
|
||||||
/// ```
|
/// ```
|
||||||
pub fn global(self) -> global::GlobalBuilder<Self> {
|
pub fn global(self) -> global::GlobalBuilder<Self> {
|
||||||
global::GlobalBuilder::with_callback(self)
|
global::GlobalBuilder::with_callback(self)
|
||||||
}
|
}
|
||||||
@ -390,18 +390,18 @@ impl<F> ModuleBuilder<F> where F: Invoke<elements::Module> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<F> Invoke<elements::FunctionSection> for ModuleBuilder<F>
|
impl<F> Invoke<elements::FunctionSection> for ModuleBuilder<F>
|
||||||
where F: Invoke<elements::Module>
|
where F: Invoke<elements::Module>
|
||||||
{
|
{
|
||||||
type Result = Self;
|
type Result = Self;
|
||||||
|
|
||||||
fn invoke(self, section: elements::FunctionSection) -> Self {
|
fn invoke(self, section: elements::FunctionSection) -> Self {
|
||||||
self.with_section(elements::Section::Function(section))
|
self.with_section(elements::Section::Function(section))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<F> Invoke<code::SignatureBindings> for ModuleBuilder<F>
|
impl<F> Invoke<code::SignatureBindings> for ModuleBuilder<F>
|
||||||
where F: Invoke<elements::Module>
|
where F: Invoke<elements::Module>
|
||||||
{
|
{
|
||||||
type Result = Self;
|
type Result = Self;
|
||||||
|
|
||||||
@ -412,7 +412,7 @@ impl<F> Invoke<code::SignatureBindings> for ModuleBuilder<F>
|
|||||||
|
|
||||||
|
|
||||||
impl<F> Invoke<code::FunctionDefinition> for ModuleBuilder<F>
|
impl<F> Invoke<code::FunctionDefinition> for ModuleBuilder<F>
|
||||||
where F: Invoke<elements::Module>
|
where F: Invoke<elements::Module>
|
||||||
{
|
{
|
||||||
type Result = Self;
|
type Result = Self;
|
||||||
|
|
||||||
@ -424,7 +424,7 @@ impl<F> Invoke<code::FunctionDefinition> for ModuleBuilder<F>
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<F> Invoke<memory::MemoryDefinition> for ModuleBuilder<F>
|
impl<F> Invoke<memory::MemoryDefinition> for ModuleBuilder<F>
|
||||||
where F: Invoke<elements::Module>
|
where F: Invoke<elements::Module>
|
||||||
{
|
{
|
||||||
type Result = Self;
|
type Result = Self;
|
||||||
|
|
||||||
@ -436,7 +436,7 @@ impl<F> Invoke<memory::MemoryDefinition> for ModuleBuilder<F>
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<F> Invoke<table::TableDefinition> for ModuleBuilder<F>
|
impl<F> Invoke<table::TableDefinition> for ModuleBuilder<F>
|
||||||
where F: Invoke<elements::Module>
|
where F: Invoke<elements::Module>
|
||||||
{
|
{
|
||||||
type Result = Self;
|
type Result = Self;
|
||||||
|
|
||||||
@ -448,7 +448,7 @@ impl<F> Invoke<table::TableDefinition> for ModuleBuilder<F>
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<F> Invoke<elements::ImportEntry> for ModuleBuilder<F>
|
impl<F> Invoke<elements::ImportEntry> for ModuleBuilder<F>
|
||||||
where F: Invoke<elements::Module>
|
where F: Invoke<elements::Module>
|
||||||
{
|
{
|
||||||
type Result = Self;
|
type Result = Self;
|
||||||
|
|
||||||
@ -458,7 +458,7 @@ impl<F> Invoke<elements::ImportEntry> for ModuleBuilder<F>
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<F> Invoke<elements::ExportEntry> for ModuleBuilder<F>
|
impl<F> Invoke<elements::ExportEntry> for ModuleBuilder<F>
|
||||||
where F: Invoke<elements::Module>
|
where F: Invoke<elements::Module>
|
||||||
{
|
{
|
||||||
type Result = Self;
|
type Result = Self;
|
||||||
|
|
||||||
@ -468,7 +468,7 @@ impl<F> Invoke<elements::ExportEntry> for ModuleBuilder<F>
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<F> Invoke<elements::GlobalEntry> for ModuleBuilder<F>
|
impl<F> Invoke<elements::GlobalEntry> for ModuleBuilder<F>
|
||||||
where F: Invoke<elements::Module>
|
where F: Invoke<elements::Module>
|
||||||
{
|
{
|
||||||
type Result = Self;
|
type Result = Self;
|
||||||
|
|
||||||
@ -477,22 +477,23 @@ impl<F> Invoke<elements::GlobalEntry> for ModuleBuilder<F>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<F> Invoke<elements::DataSegment> for ModuleBuilder<F>
|
impl<F> Invoke<elements::DataSegment> for ModuleBuilder<F>
|
||||||
where F: Invoke<elements::Module>
|
where F: Invoke<elements::Module>
|
||||||
{
|
{
|
||||||
type Result = Self;
|
type Result = Self;
|
||||||
|
|
||||||
fn invoke(self, segment: elements::DataSegment) -> Self {
|
fn invoke(self, segment: elements::DataSegment) -> Self {
|
||||||
self.with_data_segment(segment)
|
self.with_data_segment(segment)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Start new module builder
|
/// Start new module builder
|
||||||
|
///
|
||||||
/// # Examples
|
/// # Examples
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// use parity_wasm::builder;
|
/// use parity_wasm::builder;
|
||||||
///
|
///
|
||||||
/// let module = builder::module()
|
/// let module = builder::module()
|
||||||
/// .function()
|
/// .function()
|
||||||
/// .signature().param().i32().build()
|
/// .signature().param().i32().build()
|
||||||
@ -553,7 +554,7 @@ mod tests {
|
|||||||
.global().value_type().i64().mutable().init_expr(::elements::Opcode::I64Const(5)).build()
|
.global().value_type().i64().mutable().init_expr(::elements::Opcode::I64Const(5)).build()
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
assert_eq!(module.global_section().expect("global section to exist").entries().len(), 1);
|
assert_eq!(module.global_section().expect("global section to exist").entries().len(), 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -47,22 +47,12 @@ impl<T> StackWithLimit<T> where T: Clone {
|
|||||||
self.limit
|
self.limit
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn values(&self) -> &VecDeque<T> {
|
|
||||||
&self.values
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn top(&self) -> Result<&T, Error> {
|
pub fn top(&self) -> Result<&T, Error> {
|
||||||
self.values
|
self.values
|
||||||
.back()
|
.back()
|
||||||
.ok_or(Error("non-empty stack expected".into()))
|
.ok_or(Error("non-empty stack expected".into()))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn top_mut(&mut self) -> Result<&mut T, Error> {
|
|
||||||
self.values
|
|
||||||
.back_mut()
|
|
||||||
.ok_or(Error("non-empty stack expected".into()))
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn get(&self, index: usize) -> Result<&T, Error> {
|
pub fn get(&self, index: usize) -> Result<&T, Error> {
|
||||||
if index >= self.values.len() {
|
if index >= self.values.len() {
|
||||||
return Err(Error(format!("trying to get value at position {} on stack of size {}", index, self.values.len())));
|
return Err(Error(format!("trying to get value at position {} on stack of size {}", index, self.values.len())));
|
||||||
@ -80,19 +70,6 @@ impl<T> StackWithLimit<T> where T: Clone {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn push_penultimate(&mut self, value: T) -> Result<(), Error> {
|
|
||||||
if self.values.is_empty() {
|
|
||||||
return Err(Error("trying to insert penultimate element into empty stack".into()));
|
|
||||||
}
|
|
||||||
self.push(value)?;
|
|
||||||
|
|
||||||
let last_index = self.values.len() - 1;
|
|
||||||
let penultimate_index = last_index - 1;
|
|
||||||
self.values.swap(last_index, penultimate_index);
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn pop(&mut self) -> Result<T, Error> {
|
pub fn pop(&mut self) -> Result<T, Error> {
|
||||||
self.values
|
self.values
|
||||||
.pop_back()
|
.pop_back()
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
use std::any::{Any, TypeId};
|
use std::any::Any;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::marker::PhantomData;
|
use std::marker::PhantomData;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
@ -370,59 +370,3 @@ impl<
|
|||||||
FunctionType::new(vec![P1::value_type(), P2::value_type()], Ret::value_type())
|
FunctionType::new(vec![P1::value_type(), P2::value_type()], Ret::value_type())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
use interpreter::UserError;
|
|
||||||
use interpreter::store::MemoryId;
|
|
||||||
|
|
||||||
// custom user error
|
|
||||||
#[derive(Debug, Clone, PartialEq)]
|
|
||||||
struct UserErrorWithCode {
|
|
||||||
error_code: i32,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ::std::fmt::Display for UserErrorWithCode {
|
|
||||||
fn fmt(&self, f: &mut ::std::fmt::Formatter) -> Result<(), ::std::fmt::Error> {
|
|
||||||
write!(f, "{}", self.error_code)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl UserError for UserErrorWithCode {}
|
|
||||||
|
|
||||||
// TODO: Rename to state
|
|
||||||
// user function executor
|
|
||||||
struct FunctionExecutor {
|
|
||||||
pub memory: MemoryId,
|
|
||||||
pub values: Vec<i32>,
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: Remove this stuff
|
|
||||||
fn build_env_module() -> HostModule {
|
|
||||||
let mut builder = HostModuleBuilder::<FunctionExecutor>::new();
|
|
||||||
builder.with_func2("add", |store: &mut Store, state: &mut FunctionExecutor, arg: i32, unused: i32| {
|
|
||||||
let memory_value = state.memory.resolve(store).get(0, 1).unwrap()[0];
|
|
||||||
let fn_argument_unused = unused as u8;
|
|
||||||
let fn_argument = arg as u8;
|
|
||||||
assert_eq!(fn_argument_unused, 0);
|
|
||||||
|
|
||||||
let sum = memory_value + fn_argument;
|
|
||||||
state.memory.resolve(store).set(0, &vec![sum]).unwrap();
|
|
||||||
state.values.push(sum as i32);
|
|
||||||
Ok(Some(sum as i32))
|
|
||||||
});
|
|
||||||
builder.with_func2("sub", |store: &mut Store, state: &mut FunctionExecutor, arg: i32, unused: i32| {
|
|
||||||
let memory_value = state.memory.resolve(store).get(0, 1).unwrap()[0];
|
|
||||||
let fn_argument_unused = unused as u8;
|
|
||||||
let fn_argument = arg as u8;
|
|
||||||
assert_eq!(fn_argument_unused, 0);
|
|
||||||
|
|
||||||
let diff = memory_value - fn_argument;
|
|
||||||
state.memory.resolve(store).set(0, &vec![diff]).unwrap();
|
|
||||||
state.values.push(diff as i32);
|
|
||||||
Ok(Some(diff as i32))
|
|
||||||
});
|
|
||||||
builder.with_func0("err", |store: &mut Store, state: &mut FunctionExecutor| -> Result<Option<i32>, Error> {
|
|
||||||
Err(Error::User(Box::new(UserErrorWithCode { error_code: 777 })))
|
|
||||||
});
|
|
||||||
builder.with_memory("memory", MemoryType::new(256, None));
|
|
||||||
builder.build()
|
|
||||||
}
|
|
||||||
|
@ -205,7 +205,6 @@ mod tests {
|
|||||||
use super::MemoryInstance;
|
use super::MemoryInstance;
|
||||||
use interpreter::Error;
|
use interpreter::Error;
|
||||||
use elements::MemoryType;
|
use elements::MemoryType;
|
||||||
use std::sync::Arc;
|
|
||||||
|
|
||||||
fn create_memory(initial_content: &[u8]) -> MemoryInstance {
|
fn create_memory(initial_content: &[u8]) -> MemoryInstance {
|
||||||
let mem = MemoryInstance::new(&MemoryType::new(1, Some(1)))
|
let mem = MemoryInstance::new(&MemoryType::new(1, Some(1)))
|
||||||
|
@ -1107,10 +1107,6 @@ impl FunctionContext {
|
|||||||
&self.frame_stack
|
&self.frame_stack
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn frame_stack_mut(&mut self) -> &mut StackWithLimit<BlockFrame> {
|
|
||||||
&mut self.frame_stack
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn push_frame(&mut self, labels: &HashMap<usize, usize>, frame_type: BlockFrameType, block_type: BlockType) -> Result<(), Error> {
|
pub fn push_frame(&mut self, labels: &HashMap<usize, usize>, frame_type: BlockFrameType, block_type: BlockType) -> Result<(), Error> {
|
||||||
let begin_position = self.position;
|
let begin_position = self.position;
|
||||||
let branch_position = match frame_type {
|
let branch_position = match frame_type {
|
||||||
|
@ -11,12 +11,6 @@ impl StackWithLimit<RuntimeValue> {
|
|||||||
TryInto::try_into(value)
|
TryInto::try_into(value)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn pop_pair(&mut self) -> Result<(RuntimeValue, RuntimeValue), InterpreterError> {
|
|
||||||
let right = self.pop()?;
|
|
||||||
let left = self.pop()?;
|
|
||||||
Ok((left, right))
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn pop_pair_as<T>(&mut self) -> Result<(T, T), InterpreterError>
|
pub fn pop_pair_as<T>(&mut self) -> Result<(T, T), InterpreterError>
|
||||||
where
|
where
|
||||||
RuntimeValue: TryInto<T, InterpreterError>,
|
RuntimeValue: TryInto<T, InterpreterError>,
|
||||||
|
@ -1,15 +1,10 @@
|
|||||||
///! Basic tests for instructions/constructions, missing in wabt tests
|
///! Basic tests for instructions/constructions, missing in wabt tests
|
||||||
|
|
||||||
use std::sync::Arc;
|
|
||||||
use std::cell::RefCell;
|
|
||||||
use std::collections::HashMap;
|
|
||||||
use builder::module;
|
use builder::module;
|
||||||
use elements::{ExportEntry, Internal, ImportEntry, External, GlobalEntry, GlobalType,
|
use elements::{ExportEntry, Internal, ImportEntry, External, GlobalEntry, GlobalType,
|
||||||
InitExpr, ValueType, Opcodes, Opcode, FunctionType, TableType, MemoryType};
|
InitExpr, ValueType, Opcodes, Opcode, TableType, MemoryType};
|
||||||
use interpreter::{Error, UserError, ProgramInstance};
|
use interpreter::{Error, UserError, ProgramInstance};
|
||||||
use interpreter::memory::MemoryInstance;
|
use interpreter::value::RuntimeValue;
|
||||||
use interpreter::value::{RuntimeValue, TryInto};
|
|
||||||
use interpreter::variable::{VariableInstance, ExternalVariableValue, VariableType};
|
|
||||||
use interpreter::host::{HostModuleBuilder, HostModule};
|
use interpreter::host::{HostModuleBuilder, HostModule};
|
||||||
use interpreter::store::{Store, MemoryId};
|
use interpreter::store::{Store, MemoryId};
|
||||||
use super::utils::program_with_default_env;
|
use super::utils::program_with_default_env;
|
||||||
@ -241,7 +236,7 @@ fn native_env_global() {
|
|||||||
|
|
||||||
// try to add module, exporting non-existant env' variable => error
|
// try to add module, exporting non-existant env' variable => error
|
||||||
{
|
{
|
||||||
let mut host_module_builder = HostModuleBuilder::<State>::new();
|
let host_module_builder = HostModuleBuilder::<State>::new();
|
||||||
assert!(module_constructor(host_module_builder.build()).is_err());
|
assert!(module_constructor(host_module_builder.build()).is_err());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -278,7 +273,7 @@ fn native_custom_error() {
|
|||||||
.build()
|
.build()
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
let module_instance = program.add_module("main", module, &mut state).unwrap();
|
program.add_module("main", module, &mut state).unwrap();
|
||||||
let user_error = match program.invoke_index(
|
let user_error = match program.invoke_index(
|
||||||
"main",
|
"main",
|
||||||
0,
|
0,
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
use builder::module;
|
use builder::module;
|
||||||
use elements::{ValueType, Opcodes, Opcode, BlockType, Local};
|
use elements::{ValueType, Opcodes, Opcode, BlockType, Local};
|
||||||
use interpreter::{Error, ProgramInstance, ItemIndex};
|
use interpreter::{Error, ProgramInstance};
|
||||||
use interpreter::value::{RuntimeValue, TryInto};
|
use interpreter::value::{RuntimeValue, TryInto};
|
||||||
|
|
||||||
fn make_function_i32(body: Opcodes) -> ProgramInstance {
|
fn make_function_i32(body: Opcodes) -> ProgramInstance {
|
||||||
@ -520,7 +520,7 @@ fn call_1() {
|
|||||||
.build();
|
.build();
|
||||||
|
|
||||||
let mut program = ProgramInstance::new();
|
let mut program = ProgramInstance::new();
|
||||||
let module = program.add_module("main", module, &mut ()).unwrap();
|
program.add_module("main", module, &mut ()).unwrap();
|
||||||
assert_eq!(program.invoke_index("main", 0, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::I32(10));
|
assert_eq!(program.invoke_index("main", 0, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::I32(10));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -567,7 +567,7 @@ fn call_2() {
|
|||||||
.build();
|
.build();
|
||||||
|
|
||||||
let mut program = ProgramInstance::new();
|
let mut program = ProgramInstance::new();
|
||||||
let module = program.add_module("main", module, &mut ()).unwrap();
|
program.add_module("main", module, &mut ()).unwrap();
|
||||||
assert_eq!(program.invoke_index("main", 0, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::I32(3628800));
|
assert_eq!(program.invoke_index("main", 0, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::I32(3628800));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -612,7 +612,7 @@ fn call_zero_args() {
|
|||||||
.build();
|
.build();
|
||||||
|
|
||||||
let mut program = ProgramInstance::new();
|
let mut program = ProgramInstance::new();
|
||||||
let module = program.add_module("main", module, &mut ()).unwrap();
|
program.add_module("main", module, &mut ()).unwrap();
|
||||||
assert_eq!(program.invoke_index("main", 2, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::I32(43));
|
assert_eq!(program.invoke_index("main", 2, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::I32(43));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -658,7 +658,7 @@ fn callindirect_1() {
|
|||||||
.build();
|
.build();
|
||||||
|
|
||||||
let mut program = ProgramInstance::new();
|
let mut program = ProgramInstance::new();
|
||||||
let module = program.add_module("main", module, &mut ()).unwrap();
|
program.add_module("main", module, &mut ()).unwrap();
|
||||||
assert_eq!(program.invoke_index("main", 2, vec![RuntimeValue::I32(0)], &mut ()).unwrap().unwrap(), RuntimeValue::I32(0));
|
assert_eq!(program.invoke_index("main", 2, vec![RuntimeValue::I32(0)], &mut ()).unwrap().unwrap(), RuntimeValue::I32(0));
|
||||||
assert_eq!(program.invoke_index("main", 2, vec![RuntimeValue::I32(1)], &mut ()).unwrap().unwrap(), RuntimeValue::I32(1));
|
assert_eq!(program.invoke_index("main", 2, vec![RuntimeValue::I32(1)], &mut ()).unwrap().unwrap(), RuntimeValue::I32(1));
|
||||||
}
|
}
|
||||||
@ -731,7 +731,7 @@ fn callindirect_2() {
|
|||||||
.build();
|
.build();
|
||||||
|
|
||||||
let mut program = ProgramInstance::new();
|
let mut program = ProgramInstance::new();
|
||||||
let module = program.add_module("main", module, &mut ()).unwrap();
|
program.add_module("main", module, &mut ()).unwrap();
|
||||||
assert_eq!(program.invoke_index("main", 3, vec![RuntimeValue::I32(10), RuntimeValue::I32(4), RuntimeValue::I32(0)], &mut ()).unwrap().unwrap(), RuntimeValue::I32(14));
|
assert_eq!(program.invoke_index("main", 3, vec![RuntimeValue::I32(10), RuntimeValue::I32(4), RuntimeValue::I32(0)], &mut ()).unwrap().unwrap(), RuntimeValue::I32(14));
|
||||||
assert_eq!(program.invoke_index("main", 3, vec![RuntimeValue::I32(10), RuntimeValue::I32(4), RuntimeValue::I32(1)], &mut ()).unwrap().unwrap(), RuntimeValue::I32(6));
|
assert_eq!(program.invoke_index("main", 3, vec![RuntimeValue::I32(10), RuntimeValue::I32(4), RuntimeValue::I32(1)], &mut ()).unwrap().unwrap(), RuntimeValue::I32(6));
|
||||||
match program.invoke_index("main", 3, vec![RuntimeValue::I32(10), RuntimeValue::I32(4), RuntimeValue::I32(2)], &mut ()) {
|
match program.invoke_index("main", 3, vec![RuntimeValue::I32(10), RuntimeValue::I32(4), RuntimeValue::I32(2)], &mut ()) {
|
||||||
@ -813,7 +813,7 @@ fn select() {
|
|||||||
.build();
|
.build();
|
||||||
|
|
||||||
let mut program = ProgramInstance::new();
|
let mut program = ProgramInstance::new();
|
||||||
let module = program.add_module("main", module, &mut ()).unwrap();
|
program.add_module("main", module, &mut ()).unwrap();
|
||||||
assert_eq!(program.invoke_index("main", 0, vec![RuntimeValue::I32(0)], &mut ()).unwrap().unwrap(), RuntimeValue::I32(2));
|
assert_eq!(program.invoke_index("main", 0, vec![RuntimeValue::I32(0)], &mut ()).unwrap().unwrap(), RuntimeValue::I32(2));
|
||||||
assert_eq!(program.invoke_index("main", 0, vec![RuntimeValue::I32(1)], &mut ()).unwrap().unwrap(), RuntimeValue::I32(1));
|
assert_eq!(program.invoke_index("main", 0, vec![RuntimeValue::I32(1)], &mut ()).unwrap().unwrap(), RuntimeValue::I32(1));
|
||||||
assert_eq!(program.invoke_index("main", 1, vec![RuntimeValue::I32(0)], &mut ()).unwrap().unwrap(), RuntimeValue::I64(2));
|
assert_eq!(program.invoke_index("main", 1, vec![RuntimeValue::I32(0)], &mut ()).unwrap().unwrap(), RuntimeValue::I64(2));
|
||||||
@ -966,7 +966,7 @@ fn binary_i32() {
|
|||||||
.build();
|
.build();
|
||||||
|
|
||||||
let mut program = ProgramInstance::new();
|
let mut program = ProgramInstance::new();
|
||||||
let module = program.add_module("main", module, &mut ()).unwrap();
|
program.add_module("main", module, &mut ()).unwrap();
|
||||||
assert_eq!(program.invoke_index("main", 0, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::I32(3));
|
assert_eq!(program.invoke_index("main", 0, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::I32(3));
|
||||||
assert_eq!(program.invoke_index("main", 1, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::I32(16));
|
assert_eq!(program.invoke_index("main", 1, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::I32(16));
|
||||||
assert_eq!(program.invoke_index("main", 2, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::I32(21));
|
assert_eq!(program.invoke_index("main", 2, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::I32(21));
|
||||||
@ -1126,7 +1126,7 @@ fn binary_i64() {
|
|||||||
.build();
|
.build();
|
||||||
|
|
||||||
let mut program = ProgramInstance::new();
|
let mut program = ProgramInstance::new();
|
||||||
let module = program.add_module("main", module, &mut ()).unwrap();
|
program.add_module("main", module, &mut ()).unwrap();
|
||||||
assert_eq!(program.invoke_index("main", 0, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::I64(3));
|
assert_eq!(program.invoke_index("main", 0, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::I64(3));
|
||||||
assert_eq!(program.invoke_index("main", 1, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::I64(16));
|
assert_eq!(program.invoke_index("main", 1, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::I64(16));
|
||||||
assert_eq!(program.invoke_index("main", 2, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::I64(21));
|
assert_eq!(program.invoke_index("main", 2, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::I64(21));
|
||||||
@ -1216,7 +1216,7 @@ fn binary_f32() {
|
|||||||
.build();
|
.build();
|
||||||
|
|
||||||
let mut program = ProgramInstance::new();
|
let mut program = ProgramInstance::new();
|
||||||
let module = program.add_module("main", module, &mut ()).unwrap();
|
program.add_module("main", module, &mut ()).unwrap();
|
||||||
assert_eq!(program.invoke_index("main", 0, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::F32(5.000000));
|
assert_eq!(program.invoke_index("main", 0, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::F32(5.000000));
|
||||||
assert_eq!(program.invoke_index("main", 1, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::F32(-9995.500000));
|
assert_eq!(program.invoke_index("main", 1, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::F32(-9995.500000));
|
||||||
assert_eq!(program.invoke_index("main", 2, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::F32(-8487.187500));
|
assert_eq!(program.invoke_index("main", 2, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::F32(-8487.187500));
|
||||||
@ -1298,7 +1298,7 @@ fn binary_f64() {
|
|||||||
.build();
|
.build();
|
||||||
|
|
||||||
let mut program = ProgramInstance::new();
|
let mut program = ProgramInstance::new();
|
||||||
let module = program.add_module("main", module, &mut ()).unwrap();
|
program.add_module("main", module, &mut ()).unwrap();
|
||||||
assert_eq!(program.invoke_index("main", 0, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::F64(1111111110.000000));
|
assert_eq!(program.invoke_index("main", 0, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::F64(1111111110.000000));
|
||||||
assert_eq!(program.invoke_index("main", 1, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::F64(123400000000000007812762268812638756607430593436581896388608.000000));
|
assert_eq!(program.invoke_index("main", 1, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::F64(123400000000000007812762268812638756607430593436581896388608.000000));
|
||||||
assert_eq!(program.invoke_index("main", 2, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::F64(-15179717820000.000000));
|
assert_eq!(program.invoke_index("main", 2, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::F64(-15179717820000.000000));
|
||||||
@ -1351,7 +1351,7 @@ fn cast() {
|
|||||||
.build();
|
.build();
|
||||||
|
|
||||||
let mut program = ProgramInstance::new();
|
let mut program = ProgramInstance::new();
|
||||||
let module = program.add_module("main", module, &mut ()).unwrap();
|
program.add_module("main", module, &mut ()).unwrap();
|
||||||
assert_eq!(program.invoke_index("main", 0, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::F32(4.5));
|
assert_eq!(program.invoke_index("main", 0, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::F32(4.5));
|
||||||
assert_eq!(program.invoke_index("main", 1, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::I32(-1067450368)); // 3227516928
|
assert_eq!(program.invoke_index("main", 1, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::I32(-1067450368)); // 3227516928
|
||||||
assert_eq!(program.invoke_index("main", 2, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::F64(125.125000));
|
assert_eq!(program.invoke_index("main", 2, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::F64(125.125000));
|
||||||
@ -1617,7 +1617,7 @@ fn compare_i32() {
|
|||||||
.build();
|
.build();
|
||||||
|
|
||||||
let mut program = ProgramInstance::new();
|
let mut program = ProgramInstance::new();
|
||||||
let module = program.add_module("main", module, &mut ()).unwrap();
|
program.add_module("main", module, &mut ()).unwrap();
|
||||||
assert_eq!(program.invoke_index("main", 0, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::I32(1));
|
assert_eq!(program.invoke_index("main", 0, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::I32(1));
|
||||||
assert_eq!(program.invoke_index("main", 1, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::I32(0));
|
assert_eq!(program.invoke_index("main", 1, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::I32(0));
|
||||||
assert_eq!(program.invoke_index("main", 2, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::I32(1));
|
assert_eq!(program.invoke_index("main", 2, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::I32(1));
|
||||||
@ -1907,7 +1907,7 @@ fn compare_i64() {
|
|||||||
.build();
|
.build();
|
||||||
|
|
||||||
let mut program = ProgramInstance::new();
|
let mut program = ProgramInstance::new();
|
||||||
let module = program.add_module("main", module, &mut ()).unwrap();
|
program.add_module("main", module, &mut ()).unwrap();
|
||||||
assert_eq!(program.invoke_index("main", 0, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::I32(1));
|
assert_eq!(program.invoke_index("main", 0, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::I32(1));
|
||||||
assert_eq!(program.invoke_index("main", 1, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::I32(0));
|
assert_eq!(program.invoke_index("main", 1, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::I32(0));
|
||||||
assert_eq!(program.invoke_index("main", 2, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::I32(1));
|
assert_eq!(program.invoke_index("main", 2, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::I32(1));
|
||||||
@ -2091,7 +2091,7 @@ fn compare_f32() {
|
|||||||
.build();
|
.build();
|
||||||
|
|
||||||
let mut program = ProgramInstance::new();
|
let mut program = ProgramInstance::new();
|
||||||
let module = program.add_module("main", module, &mut ()).unwrap();
|
program.add_module("main", module, &mut ()).unwrap();
|
||||||
assert_eq!(program.invoke_index("main", 0, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::I32(1));
|
assert_eq!(program.invoke_index("main", 0, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::I32(1));
|
||||||
assert_eq!(program.invoke_index("main", 1, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::I32(0));
|
assert_eq!(program.invoke_index("main", 1, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::I32(0));
|
||||||
assert_eq!(program.invoke_index("main", 2, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::I32(1));
|
assert_eq!(program.invoke_index("main", 2, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::I32(1));
|
||||||
@ -2263,7 +2263,7 @@ fn compare_f64() {
|
|||||||
.build();
|
.build();
|
||||||
|
|
||||||
let mut program = ProgramInstance::new();
|
let mut program = ProgramInstance::new();
|
||||||
let module = program.add_module("main", module, &mut ()).unwrap();
|
program.add_module("main", module, &mut ()).unwrap();
|
||||||
assert_eq!(program.invoke_index("main", 0, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::I32(1));
|
assert_eq!(program.invoke_index("main", 0, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::I32(1));
|
||||||
assert_eq!(program.invoke_index("main", 1, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::I32(0));
|
assert_eq!(program.invoke_index("main", 1, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::I32(0));
|
||||||
assert_eq!(program.invoke_index("main", 2, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::I32(1));
|
assert_eq!(program.invoke_index("main", 2, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::I32(1));
|
||||||
@ -2331,7 +2331,7 @@ fn convert_i32() {
|
|||||||
.build();
|
.build();
|
||||||
|
|
||||||
let mut program = ProgramInstance::new();
|
let mut program = ProgramInstance::new();
|
||||||
let module = program.add_module("main", module, &mut ()).unwrap();
|
program.add_module("main", module, &mut ()).unwrap();
|
||||||
assert_eq!(program.invoke_index("main", 0, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::I32(-1)); // 4294967295
|
assert_eq!(program.invoke_index("main", 0, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::I32(-1)); // 4294967295
|
||||||
assert_eq!(program.invoke_index("main", 1, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::I32(-100)); // 4294967196
|
assert_eq!(program.invoke_index("main", 1, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::I32(-100)); // 4294967196
|
||||||
assert_eq!(program.invoke_index("main", 2, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::I32(-1294967296)); // 3000000000
|
assert_eq!(program.invoke_index("main", 2, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::I32(-1294967296)); // 3000000000
|
||||||
@ -2404,7 +2404,7 @@ fn convert_i64() {
|
|||||||
.build();
|
.build();
|
||||||
|
|
||||||
let mut program = ProgramInstance::new();
|
let mut program = ProgramInstance::new();
|
||||||
let module = program.add_module("main", module, &mut ()).unwrap();
|
program.add_module("main", module, &mut ()).unwrap();
|
||||||
assert_eq!(program.invoke_index("main", 0, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::I64(4294967295));
|
assert_eq!(program.invoke_index("main", 0, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::I64(4294967295));
|
||||||
assert_eq!(program.invoke_index("main", 1, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::I64(-1)); // 18446744073709551615
|
assert_eq!(program.invoke_index("main", 1, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::I64(-1)); // 18446744073709551615
|
||||||
assert_eq!(program.invoke_index("main", 2, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::I32(1));
|
assert_eq!(program.invoke_index("main", 2, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::I32(1));
|
||||||
@ -2462,7 +2462,7 @@ fn convert_f32() {
|
|||||||
.build();
|
.build();
|
||||||
|
|
||||||
let mut program = ProgramInstance::new();
|
let mut program = ProgramInstance::new();
|
||||||
let module = program.add_module("main", module, &mut ()).unwrap();
|
program.add_module("main", module, &mut ()).unwrap();
|
||||||
assert_eq!(program.invoke_index("main", 0, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::F32(-1.000000));
|
assert_eq!(program.invoke_index("main", 0, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::F32(-1.000000));
|
||||||
assert_eq!(program.invoke_index("main", 1, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::F32(4294967296.000000));
|
assert_eq!(program.invoke_index("main", 1, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::F32(4294967296.000000));
|
||||||
assert_eq!(program.invoke_index("main", 2, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::F32(12345679.000000));
|
assert_eq!(program.invoke_index("main", 2, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::F32(12345679.000000));
|
||||||
@ -2519,7 +2519,7 @@ fn convert_f64() {
|
|||||||
.build();
|
.build();
|
||||||
|
|
||||||
let mut program = ProgramInstance::new();
|
let mut program = ProgramInstance::new();
|
||||||
let module = program.add_module("main", module, &mut ()).unwrap();
|
program.add_module("main", module, &mut ()).unwrap();
|
||||||
assert_eq!(program.invoke_index("main", 0, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::F64(-1.000000));
|
assert_eq!(program.invoke_index("main", 0, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::F64(-1.000000));
|
||||||
assert_eq!(program.invoke_index("main", 1, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::F64(4294967295.000000));
|
assert_eq!(program.invoke_index("main", 1, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::F64(4294967295.000000));
|
||||||
assert_eq!(program.invoke_index("main", 2, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::F64(12345679.000000));
|
assert_eq!(program.invoke_index("main", 2, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::F64(12345679.000000));
|
||||||
@ -2579,7 +2579,7 @@ fn load_i32() {
|
|||||||
.build();
|
.build();
|
||||||
|
|
||||||
let mut program = ProgramInstance::new();
|
let mut program = ProgramInstance::new();
|
||||||
let module = program.add_module("main", module, &mut ()).unwrap();
|
program.add_module("main", module, &mut ()).unwrap();
|
||||||
assert_eq!(program.invoke_index("main", 0, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::I32(-1));
|
assert_eq!(program.invoke_index("main", 0, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::I32(-1));
|
||||||
assert_eq!(program.invoke_index("main", 1, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::I32(-1));
|
assert_eq!(program.invoke_index("main", 1, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::I32(-1));
|
||||||
assert_eq!(program.invoke_index("main", 2, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::I32(-1));
|
assert_eq!(program.invoke_index("main", 2, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::I32(-1));
|
||||||
@ -2655,7 +2655,7 @@ fn load_i64() {
|
|||||||
.build();
|
.build();
|
||||||
|
|
||||||
let mut program = ProgramInstance::new();
|
let mut program = ProgramInstance::new();
|
||||||
let module = program.add_module("main", module, &mut ()).unwrap();
|
program.add_module("main", module, &mut ()).unwrap();
|
||||||
assert_eq!(program.invoke_index("main", 0, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::I64(-1));
|
assert_eq!(program.invoke_index("main", 0, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::I64(-1));
|
||||||
assert_eq!(program.invoke_index("main", 1, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::I64(-1));
|
assert_eq!(program.invoke_index("main", 1, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::I64(-1));
|
||||||
assert_eq!(program.invoke_index("main", 2, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::I64(-1));
|
assert_eq!(program.invoke_index("main", 2, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::I64(-1));
|
||||||
@ -2685,7 +2685,7 @@ fn load_f32() {
|
|||||||
.build();
|
.build();
|
||||||
|
|
||||||
let mut program = ProgramInstance::new();
|
let mut program = ProgramInstance::new();
|
||||||
let module = program.add_module("main", module, &mut ()).unwrap();
|
program.add_module("main", module, &mut ()).unwrap();
|
||||||
assert_eq!(program.invoke_index("main", 0, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::F32(25.750000));
|
assert_eq!(program.invoke_index("main", 0, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::F32(25.750000));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2709,7 +2709,7 @@ fn load_f64() {
|
|||||||
.build();
|
.build();
|
||||||
|
|
||||||
let mut program = ProgramInstance::new();
|
let mut program = ProgramInstance::new();
|
||||||
let module = program.add_module("main", module, &mut ()).unwrap();
|
program.add_module("main", module, &mut ()).unwrap();
|
||||||
assert_eq!(program.invoke_index("main", 0, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::F64(1023.875000));
|
assert_eq!(program.invoke_index("main", 0, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::F64(1023.875000));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2766,7 +2766,7 @@ fn store_i32() {
|
|||||||
.build();
|
.build();
|
||||||
|
|
||||||
let mut program = ProgramInstance::new();
|
let mut program = ProgramInstance::new();
|
||||||
let module = program.add_module("main", module, &mut ()).unwrap();
|
program.add_module("main", module, &mut ()).unwrap();
|
||||||
assert_eq!(program.invoke_index("main", 0, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::I32(-16909061));
|
assert_eq!(program.invoke_index("main", 0, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::I32(-16909061));
|
||||||
assert_eq!(program.invoke_index("main", 1, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::I32(-859059511));
|
assert_eq!(program.invoke_index("main", 1, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::I32(-859059511));
|
||||||
assert_eq!(program.invoke_index("main", 2, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::I32(-123456));
|
assert_eq!(program.invoke_index("main", 2, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::I32(-123456));
|
||||||
@ -2836,7 +2836,7 @@ fn store_i64() {
|
|||||||
.build();
|
.build();
|
||||||
|
|
||||||
let mut program = ProgramInstance::new();
|
let mut program = ProgramInstance::new();
|
||||||
let module = program.add_module("main", module, &mut ()).unwrap();
|
program.add_module("main", module, &mut ()).unwrap();
|
||||||
assert_eq!(program.invoke_index("main", 0, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::I64(4278058235));
|
assert_eq!(program.invoke_index("main", 0, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::I64(4278058235));
|
||||||
assert_eq!(program.invoke_index("main", 1, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::I64(3435907785));
|
assert_eq!(program.invoke_index("main", 1, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::I64(3435907785));
|
||||||
assert_eq!(program.invoke_index("main", 2, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::I64(4294843840));
|
assert_eq!(program.invoke_index("main", 2, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::I64(4294843840));
|
||||||
@ -2864,7 +2864,7 @@ fn store_f32() {
|
|||||||
.build();
|
.build();
|
||||||
|
|
||||||
let mut program = ProgramInstance::new();
|
let mut program = ProgramInstance::new();
|
||||||
let module = program.add_module("main", module, &mut ()).unwrap();
|
program.add_module("main", module, &mut ()).unwrap();
|
||||||
assert_eq!(program.invoke_index("main", 0, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::I32(1069547520));
|
assert_eq!(program.invoke_index("main", 0, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::I32(1069547520));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2889,7 +2889,7 @@ fn store_f64() {
|
|||||||
.build();
|
.build();
|
||||||
|
|
||||||
let mut program = ProgramInstance::new();
|
let mut program = ProgramInstance::new();
|
||||||
let module = program.add_module("main", module, &mut ()).unwrap();
|
program.add_module("main", module, &mut ()).unwrap();
|
||||||
assert_eq!(program.invoke_index("main", 0, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::I32(-1064352256));
|
assert_eq!(program.invoke_index("main", 0, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::I32(-1064352256));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2940,7 +2940,7 @@ fn unary_i32() {
|
|||||||
.build();
|
.build();
|
||||||
|
|
||||||
let mut program = ProgramInstance::new();
|
let mut program = ProgramInstance::new();
|
||||||
let module = program.add_module("main", module, &mut ()).unwrap();
|
program.add_module("main", module, &mut ()).unwrap();
|
||||||
assert_eq!(program.invoke_index("main", 0, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::I32(0));
|
assert_eq!(program.invoke_index("main", 0, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::I32(0));
|
||||||
assert_eq!(program.invoke_index("main", 1, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::I32(1));
|
assert_eq!(program.invoke_index("main", 1, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::I32(1));
|
||||||
assert_eq!(program.invoke_index("main", 2, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::I32(24));
|
assert_eq!(program.invoke_index("main", 2, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::I32(24));
|
||||||
@ -2995,7 +2995,7 @@ fn unary_i64() {
|
|||||||
.build();
|
.build();
|
||||||
|
|
||||||
let mut program = ProgramInstance::new();
|
let mut program = ProgramInstance::new();
|
||||||
let module = program.add_module("main", module, &mut ()).unwrap();
|
program.add_module("main", module, &mut ()).unwrap();
|
||||||
assert_eq!(program.invoke_index("main", 0, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::I32(0));
|
assert_eq!(program.invoke_index("main", 0, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::I32(0));
|
||||||
assert_eq!(program.invoke_index("main", 1, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::I32(1));
|
assert_eq!(program.invoke_index("main", 1, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::I32(1));
|
||||||
assert_eq!(program.invoke_index("main", 2, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::I64(56));
|
assert_eq!(program.invoke_index("main", 2, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::I64(56));
|
||||||
@ -3094,7 +3094,7 @@ fn unary_f32() {
|
|||||||
.build();
|
.build();
|
||||||
|
|
||||||
let mut program = ProgramInstance::new();
|
let mut program = ProgramInstance::new();
|
||||||
let module = program.add_module("main", module, &mut ()).unwrap();
|
program.add_module("main", module, &mut ()).unwrap();
|
||||||
assert_eq!(program.invoke_index("main", 1, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::F32(-100.000000));
|
assert_eq!(program.invoke_index("main", 1, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::F32(-100.000000));
|
||||||
assert_eq!(program.invoke_index("main", 2, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::F32(100.000000));
|
assert_eq!(program.invoke_index("main", 2, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::F32(100.000000));
|
||||||
assert_eq!(program.invoke_index("main", 3, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::I32(1));
|
assert_eq!(program.invoke_index("main", 3, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::I32(1));
|
||||||
@ -3197,7 +3197,7 @@ fn unary_f64() {
|
|||||||
.build();
|
.build();
|
||||||
|
|
||||||
let mut program = ProgramInstance::new();
|
let mut program = ProgramInstance::new();
|
||||||
let module = program.add_module("main", module, &mut ()).unwrap();
|
program.add_module("main", module, &mut ()).unwrap();
|
||||||
assert_eq!(program.invoke_index("main", 1, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::F64(-100.000000));
|
assert_eq!(program.invoke_index("main", 1, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::F64(-100.000000));
|
||||||
assert_eq!(program.invoke_index("main", 2, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::F64(100.000000));
|
assert_eq!(program.invoke_index("main", 2, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::F64(100.000000));
|
||||||
assert_eq!(program.invoke_index("main", 3, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::I32(1));
|
assert_eq!(program.invoke_index("main", 3, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::I32(1));
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
use elements::deserialize_file;
|
use elements::deserialize_file;
|
||||||
use elements::Module;
|
use elements::Module;
|
||||||
use interpreter::ExecutionParams;
|
|
||||||
use interpreter::value::RuntimeValue;
|
use interpreter::value::RuntimeValue;
|
||||||
use interpreter::module::{ItemIndex};
|
|
||||||
use super::utils::program_with_default_env;
|
use super::utils::program_with_default_env;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -23,7 +21,7 @@ fn interpreter_inc_i32() {
|
|||||||
|
|
||||||
let module_result = program.add_module("main", module, &mut ());
|
let module_result = program.add_module("main", module, &mut ());
|
||||||
|
|
||||||
let module = module_result
|
module_result
|
||||||
.expect("Failed to initialize module");
|
.expect("Failed to initialize module");
|
||||||
|
|
||||||
let retval = program.invoke_export("main", FUNCTION_NAME, args, &mut ()).expect("");
|
let retval = program.invoke_export("main", FUNCTION_NAME, args, &mut ()).expect("");
|
||||||
@ -44,7 +42,7 @@ fn interpreter_accumulate_u8() {
|
|||||||
// Load the module-structure from wasm-file and add to program
|
// Load the module-structure from wasm-file and add to program
|
||||||
let module: Module =
|
let module: Module =
|
||||||
deserialize_file(WASM_FILE).expect("Failed to deserialize module from buffer");
|
deserialize_file(WASM_FILE).expect("Failed to deserialize module from buffer");
|
||||||
let module = program
|
program
|
||||||
.add_module("main", module, &mut ())
|
.add_module("main", module, &mut ())
|
||||||
.expect("Failed to initialize module");
|
.expect("Failed to initialize module");
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user