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