From b528e965c5af00352506b6a93bcc0e87e5f3da98 Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Thu, 26 Mar 2020 11:24:10 +0100 Subject: [PATCH] chore(interface-types) Move the `instruction.rs` module in `instructions/mod.rs`. --- src/interpreter/instruction.rs | 125 --------------------------- src/interpreter/instructions/mod.rs | 129 +++++++++++++++++++++++++++- src/interpreter/mod.rs | 3 +- 3 files changed, 126 insertions(+), 131 deletions(-) delete mode 100644 src/interpreter/instruction.rs diff --git a/src/interpreter/instruction.rs b/src/interpreter/instruction.rs deleted file mode 100644 index 712a6ea..0000000 --- a/src/interpreter/instruction.rs +++ /dev/null @@ -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, -} diff --git a/src/interpreter/instructions/mod.rs b/src/interpreter/instructions/mod.rs index 9d7f072..42e2dad 100644 --- a/src/interpreter/instructions/mod.rs +++ b/src/interpreter/instructions/mod.rs @@ -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>( diff --git a/src/interpreter/mod.rs b/src/interpreter/mod.rs index 22252ae..408d06c 100644 --- a/src/interpreter/mod.rs +++ b/src/interpreter/mod.rs @@ -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;