chore(interface-types) Move the instruction.rs module in instructions/mod.rs.

This commit is contained in:
Ivan Enderlin 2020-03-26 11:24:10 +01:00
parent bddb4e90ee
commit b528e965c5
3 changed files with 126 additions and 131 deletions

View File

@ -1,125 +0,0 @@
//use crate::ast::InterfaceType;
/// Represents all the possible WIT instructions.
#[derive(PartialEq, Debug, Clone, Copy)]
pub enum Instruction {
/// The `arg.get` instruction.
ArgumentGet {
/// The argument index.
index: u32,
},
/// The `call-core` instruction.
CallCore {
/// The function index.
function_index: usize,
},
/// The `s8.from_i32` instruction.
S8FromI32,
/// The `s8.from_i64` instruction.
S8FromI64,
/// The `s16.from_i32` instruction.
S16FromI32,
/// The `s16.from_i64` instruction.
S16FromI64,
/// The `s32.from_i32` instruction.
S32FromI32,
/// The `s32.from_i64` instruction.
S32FromI64,
/// The `s64.from_i32` instruction.
S64FromI32,
/// The `s64.from_i64` instruction.
S64FromI64,
/// The `i32.from_s8` instruction.
I32FromS8,
/// The `i32.from_s16` instruction.
I32FromS16,
/// The `i32.from_s32` instruction.
I32FromS32,
/// The `i32.from_s64` instruction.
I32FromS64,
/// The `i64.from_s8` instruction.
I64FromS8,
/// The `i64.from_s16` instruction.
I64FromS16,
/// The `i64.from_s32` instruction.
I64FromS32,
/// The `i64.from_s64` instruction.
I64FromS64,
/// The `u8.from_i32` instruction.
U8FromI32,
/// The `u8.from_i64` instruction.
U8FromI64,
/// The `u16.from_i32` instruction.
U16FromI32,
/// The `u16.from_i64` instruction.
U16FromI64,
/// The `u32.from_i32` instruction.
U32FromI32,
/// The `u32.from_i64` instruction.
U32FromI64,
/// The `u64.from_i32` instruction.
U64FromI32,
/// The `u64.from_i64` instruction.
U64FromI64,
/// The `i32.from_u8` instruction.
I32FromU8,
/// The `i32.from_u16` instruction.
I32FromU16,
/// The `i32.from_u32` instruction.
I32FromU32,
/// The `i32.from_u64` instruction.
I32FromU64,
/// The `i64.from_u8` instruction.
I64FromU8,
/// The `i64.from_u16` instruction.
I64FromU16,
/// The `i64.from_u32` instruction.
I64FromU32,
/// The `i64.from_u64` instruction.
I64FromU64,
/// The `string.lift_memory` instruction.
StringLiftMemory,
/// The `string.lower_memory` instruction.
StringLowerMemory {
/// The allocator function index.
allocator_index: u32,
},
/// The `string.size` instruction.
StringSize,
}

View File

@ -5,10 +5,7 @@ mod strings;
use crate::{
errors::{InstructionError, InstructionErrorKind, InstructionResult, WasmValueNativeCastError},
interpreter::{
wasm::values::{InterfaceValue, NativeType},
Instruction,
},
interpreter::wasm::values::{InterfaceValue, NativeType},
};
pub(crate) use argument_get::argument_get;
pub(crate) use call_core::call_core;
@ -16,6 +13,130 @@ pub(crate) use numbers::*;
use std::convert::TryFrom;
pub(crate) use strings::*;
/// Represents all the possible WIT instructions.
#[derive(PartialEq, Debug, Clone, Copy)]
pub enum Instruction {
/// The `arg.get` instruction.
ArgumentGet {
/// The argument index.
index: u32,
},
/// The `call-core` instruction.
CallCore {
/// The function index.
function_index: usize,
},
/// The `s8.from_i32` instruction.
S8FromI32,
/// The `s8.from_i64` instruction.
S8FromI64,
/// The `s16.from_i32` instruction.
S16FromI32,
/// The `s16.from_i64` instruction.
S16FromI64,
/// The `s32.from_i32` instruction.
S32FromI32,
/// The `s32.from_i64` instruction.
S32FromI64,
/// The `s64.from_i32` instruction.
S64FromI32,
/// The `s64.from_i64` instruction.
S64FromI64,
/// The `i32.from_s8` instruction.
I32FromS8,
/// The `i32.from_s16` instruction.
I32FromS16,
/// The `i32.from_s32` instruction.
I32FromS32,
/// The `i32.from_s64` instruction.
I32FromS64,
/// The `i64.from_s8` instruction.
I64FromS8,
/// The `i64.from_s16` instruction.
I64FromS16,
/// The `i64.from_s32` instruction.
I64FromS32,
/// The `i64.from_s64` instruction.
I64FromS64,
/// The `u8.from_i32` instruction.
U8FromI32,
/// The `u8.from_i64` instruction.
U8FromI64,
/// The `u16.from_i32` instruction.
U16FromI32,
/// The `u16.from_i64` instruction.
U16FromI64,
/// The `u32.from_i32` instruction.
U32FromI32,
/// The `u32.from_i64` instruction.
U32FromI64,
/// The `u64.from_i32` instruction.
U64FromI32,
/// The `u64.from_i64` instruction.
U64FromI64,
/// The `i32.from_u8` instruction.
I32FromU8,
/// The `i32.from_u16` instruction.
I32FromU16,
/// The `i32.from_u32` instruction.
I32FromU32,
/// The `i32.from_u64` instruction.
I32FromU64,
/// The `i64.from_u8` instruction.
I64FromU8,
/// The `i64.from_u16` instruction.
I64FromU16,
/// The `i64.from_u32` instruction.
I64FromU32,
/// The `i64.from_u64` instruction.
I64FromU64,
/// The `string.lift_memory` instruction.
StringLiftMemory,
/// The `string.lower_memory` instruction.
StringLowerMemory {
/// The allocator function index.
allocator_index: u32,
},
/// The `string.size` instruction.
StringSize,
}
/// Just a short helper to map the error of a cast from an
/// `InterfaceValue` to a native value.
pub(crate) fn to_native<'a, T>(

View File

@ -1,12 +1,11 @@
//! A stack-based interpreter to execute instructions of WIT adapters.
mod instruction;
mod instructions;
pub mod stack;
pub mod wasm;
use crate::errors::{InstructionResult, InterpreterResult};
pub use instruction::Instruction;
pub use instructions::Instruction;
use stack::Stack;
use std::{convert::TryFrom, marker::PhantomData};
use wasm::values::InterfaceValue;