From 849af629110cd4d69f33524e646d7222bebdfb36 Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Fri, 29 Mar 2019 15:52:41 +0100 Subject: [PATCH] feat(runtime-c-api) Finish to extract last pieces of code. --- lib/runtime-c-api/src/lib.rs | 89 --------------------------------- lib/runtime-c-api/src/module.rs | 3 +- lib/runtime-c-api/src/value.rs | 86 +++++++++++++++++++++++++++++++ 3 files changed, 88 insertions(+), 90 deletions(-) diff --git a/lib/runtime-c-api/src/lib.rs b/lib/runtime-c-api/src/lib.rs index 2baa9b273..aa6455f60 100644 --- a/lib/runtime-c-api/src/lib.rs +++ b/lib/runtime-c-api/src/lib.rs @@ -2,8 +2,6 @@ extern crate wasmer_runtime; extern crate wasmer_runtime_core; use libc::{uint32_t, uint8_t}; -use wasmer_runtime::Value; -use wasmer_runtime_core::types::Type; pub mod error; pub mod export; @@ -15,9 +13,6 @@ pub mod module; pub mod table; pub mod value; -use instance::wasmer_instance_t; -use value::{wasmer_value, wasmer_value_t, wasmer_value_tag}; - #[allow(non_camel_case_types)] #[repr(C)] pub enum wasmer_result_t { @@ -42,87 +37,3 @@ pub struct wasmer_byte_array { bytes: *const uint8_t, bytes_len: uint32_t, } - -impl From for Value { - fn from(v: wasmer_value_t) -> Self { - unsafe { - match v { - wasmer_value_t { - tag: wasmer_value_tag::WASM_I32, - value: wasmer_value { I32 }, - } => Value::I32(I32), - wasmer_value_t { - tag: wasmer_value_tag::WASM_I64, - value: wasmer_value { I64 }, - } => Value::I64(I64), - wasmer_value_t { - tag: wasmer_value_tag::WASM_F32, - value: wasmer_value { F32 }, - } => Value::F32(F32), - wasmer_value_t { - tag: wasmer_value_tag::WASM_F64, - value: wasmer_value { F64 }, - } => Value::F64(F64), - _ => panic!("not implemented"), - } - } - } -} - -impl From for wasmer_value_t { - fn from(val: Value) -> Self { - match val { - Value::I32(x) => wasmer_value_t { - tag: wasmer_value_tag::WASM_I32, - value: wasmer_value { I32: x }, - }, - Value::I64(x) => wasmer_value_t { - tag: wasmer_value_tag::WASM_I64, - value: wasmer_value { I64: x }, - }, - Value::F32(x) => wasmer_value_t { - tag: wasmer_value_tag::WASM_F32, - value: wasmer_value { F32: x }, - }, - Value::F64(x) => wasmer_value_t { - tag: wasmer_value_tag::WASM_F64, - value: wasmer_value { F64: x }, - }, - } - } -} - -impl From for wasmer_value_tag { - fn from(ty: Type) -> Self { - match ty { - Type::I32 => wasmer_value_tag::WASM_I32, - Type::I64 => wasmer_value_tag::WASM_I64, - Type::F32 => wasmer_value_tag::WASM_F32, - Type::F64 => wasmer_value_tag::WASM_F64, - _ => panic!("not implemented"), - } - } -} - -impl From for Type { - fn from(v: wasmer_value_tag) -> Self { - match v { - wasmer_value_tag::WASM_I32 => Type::I32, - wasmer_value_tag::WASM_I64 => Type::I64, - wasmer_value_tag::WASM_F32 => Type::F32, - wasmer_value_tag::WASM_F64 => Type::F64, - _ => panic!("not implemented"), - } - } -} - -impl From<&wasmer_runtime::wasm::Type> for wasmer_value_tag { - fn from(ty: &Type) -> Self { - match *ty { - Type::I32 => wasmer_value_tag::WASM_I32, - Type::I64 => wasmer_value_tag::WASM_I64, - Type::F32 => wasmer_value_tag::WASM_F32, - Type::F64 => wasmer_value_tag::WASM_F64, - } - } -} diff --git a/lib/runtime-c-api/src/module.rs b/lib/runtime-c-api/src/module.rs index 0e4961ab1..42d9815a6 100644 --- a/lib/runtime-c-api/src/module.rs +++ b/lib/runtime-c-api/src/module.rs @@ -4,7 +4,8 @@ use crate::{ error::{update_last_error, CApiError}, export::wasmer_import_export_kind, import::wasmer_import_t, - wasmer_byte_array, wasmer_instance_t, wasmer_result_t, + instance::wasmer_instance_t, + wasmer_byte_array, wasmer_result_t, }; use libc::{c_int, uint32_t, uint8_t}; use std::{collections::HashMap, slice}; diff --git a/lib/runtime-c-api/src/value.rs b/lib/runtime-c-api/src/value.rs index fc4e791a0..03a03dc5f 100644 --- a/lib/runtime-c-api/src/value.rs +++ b/lib/runtime-c-api/src/value.rs @@ -1,6 +1,8 @@ //! Wasm values. use libc::{int32_t, int64_t}; +use wasmer_runtime::Value; +use wasmer_runtime_core::types::Type; #[allow(non_camel_case_types)] #[repr(u32)] @@ -27,3 +29,87 @@ pub struct wasmer_value_t { pub tag: wasmer_value_tag, pub value: wasmer_value, } + +impl From for Value { + fn from(v: wasmer_value_t) -> Self { + unsafe { + match v { + wasmer_value_t { + tag: wasmer_value_tag::WASM_I32, + value: wasmer_value { I32 }, + } => Value::I32(I32), + wasmer_value_t { + tag: wasmer_value_tag::WASM_I64, + value: wasmer_value { I64 }, + } => Value::I64(I64), + wasmer_value_t { + tag: wasmer_value_tag::WASM_F32, + value: wasmer_value { F32 }, + } => Value::F32(F32), + wasmer_value_t { + tag: wasmer_value_tag::WASM_F64, + value: wasmer_value { F64 }, + } => Value::F64(F64), + _ => panic!("not implemented"), + } + } + } +} + +impl From for wasmer_value_t { + fn from(val: Value) -> Self { + match val { + Value::I32(x) => wasmer_value_t { + tag: wasmer_value_tag::WASM_I32, + value: wasmer_value { I32: x }, + }, + Value::I64(x) => wasmer_value_t { + tag: wasmer_value_tag::WASM_I64, + value: wasmer_value { I64: x }, + }, + Value::F32(x) => wasmer_value_t { + tag: wasmer_value_tag::WASM_F32, + value: wasmer_value { F32: x }, + }, + Value::F64(x) => wasmer_value_t { + tag: wasmer_value_tag::WASM_F64, + value: wasmer_value { F64: x }, + }, + } + } +} + +impl From for wasmer_value_tag { + fn from(ty: Type) -> Self { + match ty { + Type::I32 => wasmer_value_tag::WASM_I32, + Type::I64 => wasmer_value_tag::WASM_I64, + Type::F32 => wasmer_value_tag::WASM_F32, + Type::F64 => wasmer_value_tag::WASM_F64, + _ => panic!("not implemented"), + } + } +} + +impl From for Type { + fn from(v: wasmer_value_tag) -> Self { + match v { + wasmer_value_tag::WASM_I32 => Type::I32, + wasmer_value_tag::WASM_I64 => Type::I64, + wasmer_value_tag::WASM_F32 => Type::F32, + wasmer_value_tag::WASM_F64 => Type::F64, + _ => panic!("not implemented"), + } + } +} + +impl From<&wasmer_runtime::wasm::Type> for wasmer_value_tag { + fn from(ty: &Type) -> Self { + match *ty { + Type::I32 => wasmer_value_tag::WASM_I32, + Type::I64 => wasmer_value_tag::WASM_I64, + Type::F32 => wasmer_value_tag::WASM_F32, + Type::F64 => wasmer_value_tag::WASM_F64, + } + } +}