mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-09 20:11:09 +00:00
First step for generating host externals out of the function definition in sr-io (#3567)
* Adds new wrapper traits for wasm executor * Add new crate `substrate-wasm-interface` Thew new crate holds types and traits for the communicating between the wasm runtime and the host. * Rewrite externals with new macro etc * Fix vec initialization * Make executor tests working * Remove unused code + warnings * Introduce `Pointer` and `WordSize` for working with wasm * Fix tests and compilation * Fix compilation * Apply suggestions from code review Co-Authored-By: Sergei Pepyakin <sergei@parity.io> * Review feedback * Remove unused conversions * Make each host function its own struct `HostFunctions` now just returns these function structs. Each function can be executed by using one of the function structs. The inherent host functions are now moved to the "normal" host functions. * Remove byteorder * Add floating point types * Make pointer interface more safe * Add type alias for wasm-interface Result * More review comments
This commit is contained in:
@@ -0,0 +1,79 @@
|
||||
// Copyright 2019 Parity Technologies (UK) Ltd.
|
||||
// This file is part of Substrate.
|
||||
|
||||
// Substrate is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
// Substrate is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
//! Implementation of conversions between Substrate and wasmi types.
|
||||
|
||||
use crate::{Value, ValueType, Signature};
|
||||
|
||||
impl From<Value> for wasmi::RuntimeValue {
|
||||
fn from(value: Value) -> Self {
|
||||
match value {
|
||||
Value::I32(val) => Self::I32(val),
|
||||
Value::I64(val) => Self::I64(val),
|
||||
Value::F32(val) => Self::F32(val.into()),
|
||||
Value::F64(val) => Self::F64(val.into()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<wasmi::RuntimeValue> for Value {
|
||||
fn from(value: wasmi::RuntimeValue) -> Self {
|
||||
match value {
|
||||
wasmi::RuntimeValue::I32(val) => Self::I32(val),
|
||||
wasmi::RuntimeValue::I64(val) => Self::I64(val),
|
||||
wasmi::RuntimeValue::F32(val) => Self::F32(val.into()),
|
||||
wasmi::RuntimeValue::F64(val) => Self::F64(val.into()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<ValueType> for wasmi::ValueType {
|
||||
fn from(value: ValueType) -> Self {
|
||||
match value {
|
||||
ValueType::I32 => Self::I32,
|
||||
ValueType::I64 => Self::I64,
|
||||
ValueType::F32 => Self::F32,
|
||||
ValueType::F64 => Self::F64,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<wasmi::ValueType> for ValueType {
|
||||
fn from(value: wasmi::ValueType) -> Self {
|
||||
match value {
|
||||
wasmi::ValueType::I32 => Self::I32,
|
||||
wasmi::ValueType::I64 => Self::I64,
|
||||
wasmi::ValueType::F32 => Self::F32,
|
||||
wasmi::ValueType::F64 => Self::F64,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Signature> for wasmi::Signature {
|
||||
fn from(sig: Signature) -> Self {
|
||||
let args = sig.args.iter().map(|a| (*a).into()).collect::<Vec<_>>();
|
||||
wasmi::Signature::new(args, sig.return_value.map(Into::into))
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&wasmi::Signature> for Signature {
|
||||
fn from(sig: &wasmi::Signature) -> Self {
|
||||
Signature::new(
|
||||
sig.params().into_iter().copied().map(Into::into).collect::<Vec<_>>(),
|
||||
sig.return_type().map(Into::into),
|
||||
)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user