Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
neri committed Mar 6, 2024
1 parent 5e92736 commit cd4b4eb
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 28 deletions.
8 changes: 4 additions & 4 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ fn make_opcode(os: &mut File, lines: &[String]) {
"//
// This file is automatically generated at build time. DO NOT EDIT DIRECTLY.
//
use crate::{{leb128::*, CompileErrorKind, WasmMemArg, WasmBlockType, BrTableVec}};
use crate::{{leb128::*, BrTableVec, WasmBlockType, WasmCompileErrorKind, WasmMemArg}};
use core::fmt;
/// WebAssembly Opcode
Expand All @@ -200,7 +200,7 @@ pub enum WasmOpcode {{
"}}
impl WasmOpcode {{
pub fn fetch(reader: &mut Leb128Reader) -> Result<Self, CompileErrorKind> {{
pub fn fetch(reader: &mut Leb128Reader) -> Result<Self, WasmCompileErrorKind> {{
let leading = reader.read_byte()?;
match leading {{
"
Expand Down Expand Up @@ -292,7 +292,7 @@ impl WasmOpcode {{

writeln!(
os,
" _ => Err(CompileErrorKind::InvalidBytecode2(leading, trailing))
" _ => Err(WasmCompileErrorKind::InvalidBytecode2(leading, trailing))
}}
}}",
)
Expand All @@ -301,7 +301,7 @@ impl WasmOpcode {{

write!(
os,
" _ => Err(CompileErrorKind::InvalidBytecode(leading))
" _ => Err(WasmCompileErrorKind::InvalidBytecode(leading))
}}
}}
Expand Down
5 changes: 2 additions & 3 deletions lib/wami_macro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ macro_rules! unexpected_token {

fn is_primitive(value: &str) -> bool {
let primitive_types = [
"bool", "isize", "usize", "i8", "u8", "i16", "u16", "i32", "u32", "i64", "u64", "f32",
"f64",
"bool", "i8", "u8", "i16", "u16", "i32", "u32", "i64", "u64", "f32", "f64",
];

primitive_types.contains(&value)
Expand Down Expand Up @@ -141,7 +140,7 @@ fn reduce_path(path: &Path) -> String {
fn type_to_signature(ident: &str) -> &str {
match ident {
"void" => "v",
"bool" | "i8" | "u8" | "i16" | "u16" | "isize" | "usize" | "i32" | "u32" => "i",
"bool" | "i8" | "u8" | "i16" | "u16" | "i32" | "u32" => "i",
"u64" | "i64" => "l",
"f32" => "f",
"f64" => "d",
Expand Down
3 changes: 1 addition & 2 deletions sample/hello/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
use wami::prelude::*;

fn main() {
let bin = include_bytes!("../hello.wasm");
let instance = WebAssembly::instantiate(bin, &Env {}).unwrap();
let instance = WebAssembly::instantiate(include_bytes!("../hello.wasm"), &Env {}).unwrap();

assert_eq!(instance.exports().add(123, 456).unwrap(), 123 + 456);
}
Expand Down
18 changes: 10 additions & 8 deletions src/_generated/opcode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1863,7 +1863,7 @@ impl WasmOpcode {
// 0xFB 0x1E `i31.get_u` (Gc)
0x1e => Ok(Self::I31GetU),

_ => Err(WasmCompileErrorKind::InvalidBytecode2(leading, trailing)),
_ => Err(WasmCompileErrorKind::InvalidBytecode2(leading, trailing))
}
}
0xFC => {
Expand Down Expand Up @@ -1931,7 +1931,7 @@ impl WasmOpcode {
// 0xFC 0x11 `table.fill` u32 (ReferenceTypes)
0x11 => Ok(Self::TableFill(reader.read()?)),

_ => Err(WasmCompileErrorKind::InvalidBytecode2(leading, trailing)),
_ => Err(WasmCompileErrorKind::InvalidBytecode2(leading, trailing))
}
}
0xFD => {
Expand Down Expand Up @@ -2708,7 +2708,7 @@ impl WasmOpcode {
// 0xFD 0x114 `f32x4.relaxed_dot_bf16x8_add_f32x4` (RelaxedSimd)
0x114 => Ok(Self::F32x4RelaxedDotBf16x8AddF32x4),

_ => Err(WasmCompileErrorKind::InvalidBytecode2(leading, trailing)),
_ => Err(WasmCompileErrorKind::InvalidBytecode2(leading, trailing))
}
}
0xFE => {
Expand Down Expand Up @@ -2915,10 +2915,10 @@ impl WasmOpcode {
// 0xFE 0x4E `i64.atomic.rmw32.cmpxchg_u` (Threads)
0x4e => Ok(Self::I64AtomicRmw32CmpxchgU),

_ => Err(WasmCompileErrorKind::InvalidBytecode2(leading, trailing)),
_ => Err(WasmCompileErrorKind::InvalidBytecode2(leading, trailing))
}
}
_ => Err(WasmCompileErrorKind::InvalidBytecode(leading)),
_ => Err(WasmCompileErrorKind::InvalidBytecode(leading))
}
}

Expand Down Expand Up @@ -3493,22 +3493,24 @@ impl WasmOpcode {
Self::V128Xor => WasmMnemonic::V128Xor,
Self::Zi32x4RelaxedTruncF32x4S => WasmMnemonic::Zi32x4RelaxedTruncF32x4S,
Self::Zi8x16RelaxedSwizzle => WasmMnemonic::Zi8x16RelaxedSwizzle,

}
}

}

impl fmt::Display for WasmOpcode {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
_ => f.write_str(self.as_str()),
_ => f.write_str(self.as_str())
}
}
}

impl fmt::Debug for WasmOpcode {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
_ => f.write_str(self.as_str()),
_ => f.write_str(self.as_str())
}
}
}
Expand Down Expand Up @@ -5215,7 +5217,7 @@ impl WasmMnemonic {
Self::Zi8x16RelaxedSwizzle => "Zi8x16.relaxed_swizzle",
}
}

pub const fn proposal(&self) -> WasmProposal {
match self {
Self::AnyConvertExtern => WasmProposal::Gc,
Expand Down
20 changes: 10 additions & 10 deletions src/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,21 +297,21 @@ impl DerefMut for SharedDataStore {
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
pub struct WasmPtr<T> {
repr: u32,
_phantom: PhantomData<T>,
_phantom: PhantomData<*const T>,
}

impl<T> WasmPtr<T> {
#[inline]
pub const fn from_usize(value: usize) -> Self {
pub const fn from_u32(value: u32) -> Self {
Self {
repr: value as u32,
repr: value,
_phantom: PhantomData,
}
}

#[inline]
pub const fn as_usize(&self) -> usize {
self.repr as usize
pub const fn as_u32(&self) -> u32 {
self.repr
}
}

Expand All @@ -326,21 +326,21 @@ impl<T> From<WasmPtr<T>> for WasmValue {
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
pub struct WasmPtrMut<T> {
repr: u32,
_phantom: PhantomData<T>,
_phantom: PhantomData<*mut T>,
}

impl<T> WasmPtrMut<T> {
#[inline]
pub const fn from_usize(value: usize) -> Self {
pub const fn from_u32(value: u32) -> Self {
Self {
repr: value as u32,
repr: value,
_phantom: PhantomData,
}
}

#[inline]
pub const fn as_usize(&self) -> usize {
self.repr as usize
pub const fn as_u32(&self) -> u32 {
self.repr
}
}

Expand Down
4 changes: 3 additions & 1 deletion src/wasm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,9 @@ impl WasmModule {
.memories
.get_mut(memidx)
.ok_or(WasmCompileErrorKind::InvalidData)?;
memory.write_slice(offset, src).unwrap();
memory
.write_slice(offset, src)
.map_err(|_| WasmCompileErrorKind::InvalidData)?
}
Ok(())
}
Expand Down

0 comments on commit cd4b4eb

Please sign in to comment.