Created
December 31, 2017 19:16
-
-
Save gavofyork/6e67f6cd3499aa5685a9f6ff3a5e2c97 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| use std::result; | |
| use parity_wasm::elements::Module; | |
| use parity_wasm::interpreter::UserFunctionDescriptor; | |
| #[derive(Clone)] | |
| struct DummyUserFunctionExecutor; | |
| impl<E: interpreter::UserError> interpreter::UserFunctionExecutor<E> for DummyUserFunctionExecutor { | |
| fn execute(&mut self, name: &str, context: interpreter::CallerContext<E>) -> | |
| result::Result<Option<interpreter::RuntimeValue>, interpreter::Error<E>> | |
| { | |
| unimplemented!() | |
| } | |
| } | |
| trait AddModuleWithoutFullDependentInstance<E: interpreter::UserError> { | |
| fn add_module_by_sigs( | |
| &mut self, | |
| name: &str, | |
| module: Module, | |
| sigs: HashMap<String, &[UserFunctionDescriptor]> | |
| ) -> result::Result<Arc<interpreter::ModuleInstance<E>>, interpreter::Error<E>>; | |
| } | |
| impl<E: interpreter::UserError> AddModuleWithoutFullDependentInstance<E> for ProgramInstance<E> { | |
| fn add_module_by_sigs( | |
| &mut self, | |
| name: &str, | |
| module: Module, | |
| sigs: HashMap<String, &[UserFunctionDescriptor]> | |
| ) -> result::Result<Arc<interpreter::ModuleInstance<E>>, interpreter::Error<E>> { | |
| let dufe = vec![DummyUserFunctionExecutor; sigs.len()]; | |
| let fake_module_map = sigs.into_iter() | |
| .zip(dufe.iter_mut()) | |
| .map(|((dep_mod_name, sigs), dufe)| { | |
| let fake_module = Arc::new( | |
| interpreter::env_native_module( | |
| self.module(&dep_mod_name).unwrap(), UserDefinedElements { | |
| executor: Some(dufe), | |
| globals: HashMap::new(), | |
| functions: ::std::borrow::Cow::from(sigs), | |
| } | |
| ).unwrap() | |
| ); | |
| (dep_mod_name.into(), fake_module) | |
| }) | |
| .collect::<HashMap<_, Arc<interpreter::ModuleInstanceInterface<_>>>>(); | |
| self.add_module(name, module, Some(&fake_module_map)) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment