nyar_wasm/wasi_values/
mod.rs1use crate::{
2 encoder::WastEncoder,
3 helpers::{EmitConstant, ToWasiType},
4 ArrayValue, WasiArrayType, WasiType,
5};
6use std::{
7 cmp::Ordering,
8 fmt::Write,
9 hash::{Hash, Hasher},
10};
11
12mod arithmetic;
13
14pub mod array;
15pub mod record;
16
17#[derive(Debug, Clone)]
19pub enum WasiValue {
20 Boolean(bool),
22 Integer8(i8),
24 Integer16(i16),
26 Integer32(i32),
28 Integer64(i64),
30 Unsigned8(u8),
32 Unsigned16(u16),
34 Unsigned32(u32),
36 Unsigned64(u64),
38 Float32(f32),
40 Float64(f64),
42 DynamicArray(ArrayValue),
43}
44
45impl EmitConstant for WasiValue {
46 fn emit_constant<W: Write>(&self, w: &mut WastEncoder<W>) -> std::fmt::Result {
47 match self {
48 Self::Boolean(v) => write!(w, "i32.const {}", if *v { 1 } else { 0 })?,
49 Self::Integer8(v) => write!(w, "i32.const {}", v)?,
50 Self::Integer16(v) => write!(w, "i32.const {}", v)?,
51 Self::Integer32(v) => write!(w, "i32.const {}", v)?,
52 Self::Integer64(v) => write!(w, "i64.const {}", v)?,
53 Self::Unsigned8(v) => write!(w, "i32.const {}", v)?,
54 Self::Unsigned16(v) => write!(w, "i32.const {}", v)?,
55 Self::Unsigned32(v) => write!(w, "i32.const {}", v)?,
56 Self::Unsigned64(v) => write!(w, "i64.const {}", v)?,
57 Self::Float32(v) => write!(w, "f32.const {}", v)?,
58 Self::Float64(v) => write!(w, "f64.const {}", v)?,
59 Self::DynamicArray(v) => v.emit_constant(w)?,
60 }
61 Ok(())
62 }
63}