mirror of
https://github.com/fluencelabs/parity-wasm
synced 2025-06-21 18:51:52 +00:00
continue env
This commit is contained in:
@ -18,6 +18,7 @@ impl Func {
|
||||
}
|
||||
|
||||
/// Local definition inside the function body.
|
||||
#[derive(Debug)]
|
||||
pub struct Local {
|
||||
count: u32,
|
||||
value_type: ValueType,
|
||||
@ -57,6 +58,7 @@ impl Serialize for Local {
|
||||
}
|
||||
|
||||
/// Function body definition.
|
||||
#[derive(Debug)]
|
||||
pub struct FuncBody {
|
||||
locals: Vec<Local>,
|
||||
opcodes: Opcodes,
|
||||
|
@ -20,6 +20,8 @@ const TABLE_BASE_DEFAULT: i32 = 0;
|
||||
const INVOKE_VI_INDEX: u32 = 0; // (i32, i32) -> ()
|
||||
const INVOKE_INDEX: u32 = 1; // (i32) -> ()
|
||||
const GAS_INDEX: u32 = 2;
|
||||
const STORAGE_SIZE_INDEX: u32 = 3;
|
||||
const STORAGE_WRITE_INDEX: u32 = 4;
|
||||
|
||||
const TABLE_SIZE: u32 = 1024;
|
||||
const TABLE_INDEX: u32 = 0;
|
||||
@ -88,9 +90,21 @@ impl ModuleInstanceInterface for EnvModuleInstance {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
fn call_internal_function(&self, _outer: CallerContext, index: u32, _function_type: Option<&FunctionType>) -> Result<Option<RuntimeValue>, Error> {
|
||||
fn call_internal_function(&self, outer: CallerContext, index: u32, _function_type: Option<&FunctionType>) -> Result<Option<RuntimeValue>, Error> {
|
||||
match index {
|
||||
GAS_INDEX => Ok(None),
|
||||
GAS_INDEX => {
|
||||
outer.value_stack.pop()?;
|
||||
Ok(None)
|
||||
},
|
||||
STORAGE_SIZE_INDEX => {
|
||||
Ok(Some(RuntimeValue::I32(0)))
|
||||
},
|
||||
STORAGE_WRITE_INDEX => {
|
||||
outer.value_stack.pop()?;
|
||||
outer.value_stack.pop()?;
|
||||
outer.value_stack.pop()?;
|
||||
Ok(Some(RuntimeValue::I32(0)))
|
||||
},
|
||||
_ => unimplemented!(),
|
||||
}
|
||||
}
|
||||
@ -113,6 +127,8 @@ pub fn env_module() -> Result<EnvModuleInstance, Error> {
|
||||
.with_export(ExportEntry::new("invoke_vi".into(), Internal::Function(INVOKE_VI_INDEX)))
|
||||
.with_export(ExportEntry::new("invoke".into(), Internal::Function(INVOKE_INDEX)))
|
||||
.with_export(ExportEntry::new("gas".into(), Internal::Function(GAS_INDEX)))
|
||||
.with_export(ExportEntry::new("_storage_size".into(), Internal::Function(STORAGE_SIZE_INDEX)))
|
||||
.with_export(ExportEntry::new("_storage_write".into(), Internal::Function(STORAGE_WRITE_INDEX)))
|
||||
.build();
|
||||
|
||||
EnvModuleInstance::new(module)
|
||||
|
@ -1,3 +1,4 @@
|
||||
use std::iter::repeat;
|
||||
use std::sync::{Arc, Weak};
|
||||
use elements::{Module, InitExpr, Opcode, Type, FunctionType, FuncBody, Internal};
|
||||
use interpreter::Error;
|
||||
@ -345,7 +346,10 @@ fn prepare_function_locals(function_type: &FunctionType, function_body: &FuncBod
|
||||
VariableInstance::new(true, expected_type, param_value)
|
||||
})
|
||||
.collect::<Vec<_>>().into_iter().rev()
|
||||
.chain(function_body.locals().iter().map(|l| VariableInstance::new(true, l.value_type().into(), RuntimeValue::default(l.value_type().into()))))
|
||||
.chain(function_body.locals()
|
||||
.iter()
|
||||
.flat_map(|l| repeat(l.value_type().into()).take(l.count() as usize))
|
||||
.map(|vt| VariableInstance::new(true, vt, RuntimeValue::default(vt))))
|
||||
.collect::<Result<Vec<_>, _>>()
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user