MCPcopy Create free account
hub / github.com/bytecodealliance/wasmtime / val

Function val

crates/wast/src/core.rs:7–48  ·  view source on GitHub ↗

Translate from a `script::Value` to a `RuntimeValue`.

(ctx: &mut WastContext, v: &CoreConst)

Source from the content-addressed store, hash-verified

5
6/// Translate from a `script::Value` to a `RuntimeValue`.
7pub fn val(ctx: &mut WastContext, v: &CoreConst) -> Result<Val> {
8 use CoreConst::*;
9
10 Ok(match v {
11 I32 { value } => Val::I32(value.0),
12 I64 { value } => Val::I64(value.0),
13 F32 { value } => Val::F32(value.to_bits()),
14 F64 { value } => Val::F64(value.to_bits()),
15 V128(value) => Val::V128(value.to_u128().into()),
16 FuncRef {
17 value: None | Some(json_from_wast::FuncRef::Null),
18 } => Val::FuncRef(None),
19
20 ExternRef {
21 value: None | Some(json_from_wast::ExternRef::Null),
22 } => Val::ExternRef(None),
23 ExternRef {
24 value: Some(json_from_wast::ExternRef::Host(x)),
25 } => Val::ExternRef(if let Some(rt) = ctx.async_runtime.as_ref() {
26 Some(rt.block_on(wasmtime::ExternRef::new_async(&mut ctx.core_store, x.0))?)
27 } else {
28 Some(wasmtime::ExternRef::new(&mut ctx.core_store, x.0)?)
29 }),
30
31 AnyRef {
32 value: None | Some(json_from_wast::AnyRef::Null),
33 } => Val::AnyRef(None),
34 AnyRef {
35 value: Some(json_from_wast::AnyRef::Host(x)),
36 } => {
37 let x = if let Some(rt) = ctx.async_runtime.as_ref() {
38 rt.block_on(wasmtime::ExternRef::new_async(&mut ctx.core_store, x.0))?
39 } else {
40 wasmtime::ExternRef::new(&mut ctx.core_store, x.0)?
41 };
42 let x = wasmtime::AnyRef::convert_extern(&mut ctx.core_store, x)?;
43 Val::AnyRef(Some(x))
44 }
45 NullRef => Val::AnyRef(None),
46 other => bail!("couldn't convert {other:?} to a runtime value"),
47 })
48}
49
50fn extract_lane_as_i8(bytes: u128, lane: usize) -> i8 {
51 (bytes >> (lane * 8)) as i8

Callers 1

perform_actionMethod · 0.70

Calls 9

OkFunction · 0.85
FuncRefClass · 0.85
block_onMethod · 0.80
V128Class · 0.50
ExternRefClass · 0.50
newFunction · 0.50
AnyRefClass · 0.50
to_bitsMethod · 0.45
as_refMethod · 0.45

Tested by

no test coverage detected