Fix wiggle tests

This commit is contained in:
Alex Crichton
2021-02-17 13:42:41 -08:00
committed by Andrew Brown
parent df9c725fa0
commit fa98f0bc91
31 changed files with 236 additions and 239 deletions

View File

@@ -55,6 +55,7 @@ pub fn define_func(
let mod_name = &module.name.as_str(); let mod_name = &module.name.as_str();
let func_name = &func.name.as_str(); let func_name = &func.name.as_str();
quote! { quote! {
#[allow(unreachable_code)] // deals with warnings in noreturn functions
pub fn #ident( pub fn #ident(
ctx: &#ctx_type, ctx: &#ctx_type,
memory: &dyn #rt::GuestMemory, memory: &dyn #rt::GuestMemory,
@@ -215,7 +216,7 @@ impl witx::Bindgen for Rust<'_> {
if func.results.len() > 0 { if func.results.len() > 0 {
results.push(quote!(ret)); results.push(quote!(ret));
} else if func.noreturn { } else if func.noreturn {
self.src.extend(quote!(return Err(ret))); self.src.extend(quote!(return Err(ret);));
} }
} }
@@ -250,7 +251,9 @@ impl witx::Bindgen for Rust<'_> {
Instruction::VariantPayload => results.push(quote!(e)), Instruction::VariantPayload => results.push(quote!(e)),
Instruction::Return { amt: 0 } => {} Instruction::Return { amt: 0 } => {
self.src.extend(quote!(return Ok(())));
}
Instruction::Return { amt: 1 } => { Instruction::Return { amt: 1 } => {
let val = operands.pop().unwrap(); let val = operands.pop().unwrap();
self.src.extend(quote!(return Ok(#val))); self.src.extend(quote!(return Ok(#val)));
@@ -278,6 +281,17 @@ impl witx::Bindgen for Rust<'_> {
}); });
} }
Instruction::Load { ty } => {
let ptr = operands.pop().unwrap();
let wrap_err = wrap_err(&format!("read {}", ty.name.as_str()));
let pointee_type = self.names.type_(&ty.name);
results.push(quote! {
#rt::GuestPtr::<#pointee_type>::new(memory, #ptr as u32)
.read()
.map_err(#wrap_err)?
});
}
Instruction::HandleFromI32 { ty } => { Instruction::HandleFromI32 { ty } => {
let val = operands.pop().unwrap(); let val = operands.pop().unwrap();
let ty = self.names.type_(&ty.name); let ty = self.names.type_(&ty.name);
@@ -294,7 +308,7 @@ impl witx::Bindgen for Rust<'_> {
// Conversions with matching bit-widths but different signededness // Conversions with matching bit-widths but different signededness
// use `as` since we're basically just reinterpreting the bits. // use `as` since we're basically just reinterpreting the bits.
Instruction::U32FromI32 => { Instruction::U32FromI32 | Instruction::UsizeFromI32 => {
let val = operands.pop().unwrap(); let val = operands.pop().unwrap();
results.push(quote!(#val as u32)); results.push(quote!(#val as u32));
} }

View File

@@ -6,8 +6,9 @@ mod module_trait;
mod names; mod names;
mod types; mod types;
use heck::ShoutySnakeCase;
use lifetimes::anon_lifetime; use lifetimes::anon_lifetime;
use proc_macro2::TokenStream; use proc_macro2::{Literal, TokenStream};
use quote::quote; use quote::quote;
pub use config::Config; pub use config::Config;
@@ -24,6 +25,19 @@ pub fn generate(doc: &witx::Document, names: &Names, errs: &ErrorTransform) -> T
let types = doc.typenames().map(|t| define_datatype(&names, &t)); let types = doc.typenames().map(|t| define_datatype(&names, &t));
let constants = doc.constants().map(|c| {
let name = quote::format_ident!(
"{}_{}",
c.ty.as_str().to_shouty_snake_case(),
c.name.as_str().to_shouty_snake_case()
);
let ty = names.type_(&c.ty);
let value = Literal::u64_unsuffixed(c.value);
quote! {
pub const #name: #ty = #value;
}
});
let guest_error_methods = doc.error_types().map(|t| { let guest_error_methods = doc.error_types().map(|t| {
let typename = names.type_ref(&t, anon_lifetime()); let typename = names.type_ref(&t, anon_lifetime());
let err_method = names.guest_error_conversion_method(&t); let err_method = names.guest_error_conversion_method(&t);
@@ -69,6 +83,7 @@ pub fn generate(doc: &witx::Document, names: &Names, errs: &ErrorTransform) -> T
use std::convert::TryFrom; use std::convert::TryFrom;
#(#types)* #(#types)*
#(#constants)*
#guest_error_conversion #guest_error_conversion
#user_error_conversion #user_error_conversion
} }

View File

@@ -9,6 +9,8 @@ use witx::Module;
pub fn passed_by_reference(ty: &witx::Type) -> bool { pub fn passed_by_reference(ty: &witx::Type) -> bool {
match ty { match ty {
witx::Type::Pointer(_) | witx::Type::ConstPointer(_) | witx::Type::List(_) => true, witx::Type::Pointer(_) | witx::Type::ConstPointer(_) | witx::Type::List(_) => true,
witx::Type::Record(r) => r.bitflags_repr().is_none(),
witx::Type::Variant(v) => !v.is_enum(),
_ => false, _ => false,
} }
} }

View File

@@ -65,6 +65,7 @@ pub(super) fn define_variant(names: &Names, name: &witx::Id, v: &witx::Variant)
} }
}); });
let mut extra_derive = quote!();
let enum_try_from = if v.cases.iter().all(|c| c.tref.is_none()) { let enum_try_from = if v.cases.iter().all(|c| c.tref.is_none()) {
let tryfrom_repr_cases = v.cases.iter().enumerate().map(|(i, c)| { let tryfrom_repr_cases = v.cases.iter().enumerate().map(|(i, c)| {
let variant_name = names.enum_variant(&c.name); let variant_name = names.enum_variant(&c.name);
@@ -72,6 +73,7 @@ pub(super) fn define_variant(names: &Names, name: &witx::Id, v: &witx::Variant)
quote!(#n => Ok(#ident::#variant_name)) quote!(#n => Ok(#ident::#variant_name))
}); });
let abi_ty = names.wasm_type(v.tag_repr.into()); let abi_ty = names.wasm_type(v.tag_repr.into());
extra_derive = quote!(, Copy);
quote! { quote! {
impl TryFrom<#tag_ty> for #ident { impl TryFrom<#tag_ty> for #ident {
type Error = #rt::GuestError; type Error = #rt::GuestError;
@@ -97,7 +99,7 @@ pub(super) fn define_variant(names: &Names, name: &witx::Id, v: &witx::Variant)
let (enum_lifetime, extra_derive) = if v.needs_lifetime() { let (enum_lifetime, extra_derive) = if v.needs_lifetime() {
(quote!(<'a>), quote!()) (quote!(<'a>), quote!())
} else { } else {
(quote!(), quote!(, PartialEq)) (quote!(), quote!(, PartialEq #extra_derive))
}; };
quote! { quote! {

View File

@@ -105,7 +105,7 @@ impl ReduceExcusesExcercise {
self.return_ptr_loc.ptr as i32, self.return_ptr_loc.ptr as i32,
); );
assert_eq!(res, Ok(types::Errno::Ok.into()), "reduce excuses errno"); assert_eq!(res, Ok(types::Errno::Ok as i32), "reduce excuses errno");
let expected = *self let expected = *self
.excuse_values .excuse_values
@@ -183,7 +183,7 @@ impl PopulateExcusesExcercise {
self.array_ptr_loc.ptr as i32, self.array_ptr_loc.ptr as i32,
self.elements.len() as i32, self.elements.len() as i32,
); );
assert_eq!(res, Ok(types::Errno::Ok.into()), "populate excuses errno"); assert_eq!(res, Ok(types::Errno::Ok as i32), "populate excuses errno");
let arr: GuestPtr<'_, [GuestPtr<'_, types::Excuse>]> = let arr: GuestPtr<'_, [GuestPtr<'_, types::Excuse>]> =
host_memory.ptr((self.array_ptr_loc.ptr, self.elements.len() as u32)); host_memory.ptr((self.array_ptr_loc.ptr, self.elements.len() as u32));
@@ -309,7 +309,7 @@ impl SumElementsExercise {
self.start_ix as i32, self.start_ix as i32,
self.return_loc.ptr as i32, self.return_loc.ptr as i32,
); );
assert_eq!(res, Ok(types::Errno::Ok.into()), "sum_of_element errno"); assert_eq!(res, Ok(types::Errno::Ok as i32), "sum_of_element errno");
let result_ptr = host_memory.ptr::<i32>(self.return_loc.ptr); let result_ptr = host_memory.ptr::<i32>(self.return_loc.ptr);
let result = result_ptr.read().expect("read result"); let result = result_ptr.read().expect("read result");
@@ -330,7 +330,7 @@ impl SumElementsExercise {
); );
assert_eq!( assert_eq!(
res, res,
Ok(types::Errno::InvalidArg.into()), Ok(types::Errno::InvalidArg as i32),
"out of bounds sum_of_element errno" "out of bounds sum_of_element errno"
); );
@@ -346,7 +346,7 @@ impl SumElementsExercise {
if self.start_ix <= self.end_ix { if self.start_ix <= self.end_ix {
assert_eq!( assert_eq!(
res, res,
Ok(types::Errno::Ok.into()), Ok(types::Errno::Ok as i32),
"expected ok sum_of_elements errno" "expected ok sum_of_elements errno"
); );
let result_ptr = host_memory.ptr::<i32>(self.return_loc.ptr); let result_ptr = host_memory.ptr::<i32>(self.return_loc.ptr);
@@ -367,7 +367,7 @@ impl SumElementsExercise {
} else { } else {
assert_eq!( assert_eq!(
res, res,
Ok(types::Errno::InvalidArg.into()), Ok(types::Errno::InvalidArg as i32),
"expected error out-of-bounds sum_of_elements" "expected error out-of-bounds sum_of_elements"
); );
} }
@@ -384,7 +384,7 @@ impl SumElementsExercise {
); );
assert_eq!( assert_eq!(
res, res,
Ok(types::Errno::InvalidArg.into()), Ok(types::Errno::InvalidArg as i32),
"out of bounds sum_of_elements errno" "out of bounds sum_of_elements errno"
); );
} }

View File

@@ -1,36 +1,36 @@
(use "errno.witx") (use "errno.witx")
(use "excuse.witx") (use "excuse.witx")
(typename $const_excuse_array (array (@witx const_pointer $excuse))) (typename $const_excuse_array (list (@witx const_pointer $excuse)))
(typename $excuse_array (array (@witx pointer $excuse))) (typename $excuse_array (list (@witx pointer $excuse)))
(module $arrays (module $arrays
(@interface func (export "reduce_excuses") (@interface func (export "reduce_excuses")
(param $excuses $const_excuse_array) (param $excuses $const_excuse_array)
(result $error $errno) (result $error (expected $excuse (error $errno)))
(result $reduced $excuse)
) )
(@interface func (export "populate_excuses") (@interface func (export "populate_excuses")
(param $excuses $excuse_array) (param $excuses $excuse_array)
(result $error $errno) (result $error (expected (error $errno)))
) )
) )
(typename $pair_ints (typename $pair_ints
(struct (record
(field $first s32) (field $first s32)
(field $second s32))) (field $second s32)))
(typename $s32 s32)
(module $array_traversal (module $array_traversal
(@interface func (export "sum_of_element") (@interface func (export "sum_of_element")
(param $elements (array $pair_ints)) (param $elements (list $pair_ints))
(param $index (@witx usize)) (param $index (@witx usize))
(result $error $errno) (result $error (expected $s32 (error $errno))))
(result $sum s32))
(@interface func (export "sum_of_elements") (@interface func (export "sum_of_elements")
(param $elements (array $pair_ints)) (param $elements (list $pair_ints))
(param $start (@witx usize)) (param $start (@witx usize))
(param $end (@witx usize)) (param $end (@witx usize))
(result $error $errno) (result $error (expected $s32 (error $errno))))
(result $sum s32))) )

View File

@@ -34,7 +34,7 @@ impl IntFloatExercise {
let e = atoms::int_float_args(&ctx, &host_memory, self.an_int as i32, self.an_float); let e = atoms::int_float_args(&ctx, &host_memory, self.an_int as i32, self.an_float);
assert_eq!(e, Ok(types::Errno::Ok.into()), "int_float_args error"); assert_eq!(e, Ok(types::Errno::Ok as i32), "int_float_args error");
} }
pub fn strat() -> BoxedStrategy<Self> { pub fn strat() -> BoxedStrategy<Self> {
@@ -72,7 +72,7 @@ impl DoubleIntExercise {
.ptr::<types::AliasToFloat>(self.return_loc.ptr) .ptr::<types::AliasToFloat>(self.return_loc.ptr)
.read() .read()
.expect("failed to read return"); .expect("failed to read return");
assert_eq!(e, Ok(types::Errno::Ok.into()), "errno"); assert_eq!(e, Ok(types::Errno::Ok as i32), "errno");
assert_eq!(return_val, (self.input as f32) * 2.0, "return val"); assert_eq!(return_val, (self.input as f32) * 2.0, "return val");
} }

View File

@@ -6,9 +6,8 @@
(@interface func (export "int_float_args") (@interface func (export "int_float_args")
(param $an_int u32) (param $an_int u32)
(param $an_float f32) (param $an_float f32)
(result $error $errno)) (result $error (expected (error $errno))))
(@interface func (export "double_int_return_float") (@interface func (export "double_int_return_float")
(param $an_int u32) (param $an_int u32)
(result $error $errno) (result $error (expected $alias_to_float (error $errno))))
(result $doubled_it $alias_to_float))
) )

View File

@@ -1,5 +1,5 @@
(typename $errno (typename $errno
(enum u32 (enum (@witx tag u32)
;;; Success ;;; Success
$ok $ok
;;; Invalid argument ;;; Invalid argument

View File

@@ -17,11 +17,11 @@ mod convert_just_errno {
// trivial function. // trivial function.
wiggle::from_witx!({ wiggle::from_witx!({
witx_literal: " witx_literal: "
(typename $errno (enum u8 $ok $invalid_arg $picket_line)) (typename $errno (enum (@witx tag u8) $ok $invalid_arg $picket_line))
(module $one_error_conversion (module $one_error_conversion
(@interface func (export \"foo\") (@interface func (export \"foo\")
(param $strike u32) (param $strike u32)
(result $err $errno))) (result $err (expected (error $errno)))))
", ",
ctx: WasiCtx, ctx: WasiCtx,
errors: { errno => RichError }, errors: { errno => RichError },
@@ -68,7 +68,7 @@ mod convert_just_errno {
let r0 = one_error_conversion::foo(&ctx, &host_memory, 0); let r0 = one_error_conversion::foo(&ctx, &host_memory, 0);
assert_eq!( assert_eq!(
r0, r0,
Ok(i32::from(types::Errno::Ok)), Ok(types::Errno::Ok as i32),
"Expected return value for strike=0" "Expected return value for strike=0"
); );
assert!(ctx.log.borrow().is_empty(), "No error log for strike=0"); assert!(ctx.log.borrow().is_empty(), "No error log for strike=0");
@@ -77,7 +77,7 @@ mod convert_just_errno {
let r1 = one_error_conversion::foo(&ctx, &host_memory, 1); let r1 = one_error_conversion::foo(&ctx, &host_memory, 1);
assert_eq!( assert_eq!(
r1, r1,
Ok(i32::from(types::Errno::PicketLine)), Ok(types::Errno::PicketLine as i32),
"Expected return value for strike=1" "Expected return value for strike=1"
); );
assert_eq!( assert_eq!(
@@ -90,7 +90,7 @@ mod convert_just_errno {
let r2 = one_error_conversion::foo(&ctx, &host_memory, 2); let r2 = one_error_conversion::foo(&ctx, &host_memory, 2);
assert_eq!( assert_eq!(
r2, r2,
Ok(i32::from(types::Errno::InvalidArg)), Ok(types::Errno::InvalidArg as i32),
"Expected return value for strike=2" "Expected return value for strike=2"
); );
assert_eq!( assert_eq!(
@@ -120,15 +120,15 @@ mod convert_multiple_error_types {
// Additionally, test that the function "baz" marked noreturn always returns a wiggle::Trap. // Additionally, test that the function "baz" marked noreturn always returns a wiggle::Trap.
wiggle::from_witx!({ wiggle::from_witx!({
witx_literal: " witx_literal: "
(typename $errno (enum u8 $ok $invalid_arg $picket_line)) (typename $errno (enum (@witx tag u8) $ok $invalid_arg $picket_line))
(typename $errno2 (enum u8 $ok $too_much_coffee)) (typename $errno2 (enum (@witx tag u8) $ok $too_much_coffee))
(module $two_error_conversions (module $two_error_conversions
(@interface func (export \"foo\") (@interface func (export \"foo\")
(param $strike u32) (param $strike u32)
(result $err $errno)) (result $err (expected (error $errno))))
(@interface func (export \"bar\") (@interface func (export \"bar\")
(param $drink u32) (param $drink u32)
(result $err $errno2)) (result $err (expected (error $errno2))))
(@interface func (export \"baz\") (@interface func (export \"baz\")
(param $drink u32) (param $drink u32)
(@witx noreturn))) (@witx noreturn)))

View File

@@ -1,5 +1,5 @@
(typename $excuse (typename $excuse
(enum u8 (enum (@witx tag u8)
$dog_ate $dog_ate
$traffic $traffic
$sleeping)) $sleeping))

View File

@@ -75,11 +75,11 @@ impl ConfigureCarExercise {
let res = flags::configure_car( let res = flags::configure_car(
&ctx, &ctx,
&host_memory, &host_memory,
self.old_config.into(), self.old_config.bits() as i32,
self.other_config_by_ptr.ptr as i32, self.other_config_by_ptr.ptr as i32,
self.return_ptr_loc.ptr as i32, self.return_ptr_loc.ptr as i32,
); );
assert_eq!(res, Ok(types::Errno::Ok.into()), "configure car errno"); assert_eq!(res, Ok(types::Errno::Ok as i32), "configure car errno");
let res_config = host_memory let res_config = host_memory
.ptr::<types::CarConfig>(self.return_ptr_loc.ptr) .ptr::<types::CarConfig>(self.return_ptr_loc.ptr)

View File

@@ -1,7 +1,7 @@
(use "errno.witx") (use "errno.witx")
(typename $car_config (typename $car_config
(flags u8 (flags (@witx repr u8)
$automatic $automatic
$awd $awd
$suv)) $suv))
@@ -10,7 +10,6 @@
(@interface func (export "configure_car") (@interface func (export "configure_car")
(param $old_config $car_config) (param $old_config $car_config)
(param $old_config_by_ptr (@witx const_pointer $car_config)) (param $old_config_by_ptr (@witx const_pointer $car_config))
(result $error $errno) (result $error (expected $car_config (error $errno)))
(result $new_config $car_config)
) )
) )

View File

@@ -37,7 +37,7 @@ impl HandleExercise {
let e = handle_examples::fd_create(&ctx, &host_memory, self.return_loc.ptr as i32); let e = handle_examples::fd_create(&ctx, &host_memory, self.return_loc.ptr as i32);
assert_eq!(e, Ok(types::Errno::Ok.into()), "fd_create error"); assert_eq!(e, Ok(types::Errno::Ok as i32), "fd_create error");
let h_got: u32 = host_memory let h_got: u32 = host_memory
.ptr(self.return_loc.ptr) .ptr(self.return_loc.ptr)
@@ -48,13 +48,13 @@ impl HandleExercise {
let e = handle_examples::fd_consume(&ctx, &host_memory, h_got as i32); let e = handle_examples::fd_consume(&ctx, &host_memory, h_got as i32);
assert_eq!(e, Ok(types::Errno::Ok.into()), "fd_consume error"); assert_eq!(e, Ok(types::Errno::Ok as i32), "fd_consume error");
let e = handle_examples::fd_consume(&ctx, &host_memory, h_got as i32 + 1); let e = handle_examples::fd_consume(&ctx, &host_memory, h_got as i32 + 1);
assert_eq!( assert_eq!(
e, e,
Ok(types::Errno::InvalidArg.into()), Ok(types::Errno::InvalidArg as i32),
"fd_consume invalid error" "fd_consume invalid error"
); );
} }

View File

@@ -4,9 +4,8 @@
(module $handle_examples (module $handle_examples
(@interface func (export "fd_create") (@interface func (export "fd_create")
(result $error $errno) (result $error (expected $fd (error $errno))))
(result $fd $fd))
(@interface func (export "fd_consume") (@interface func (export "fd_consume")
(param $fd $fd) (param $fd $fd)
(result $error $errno)) (result $error (expected (error $errno))))
) )

View File

@@ -12,7 +12,7 @@ impl_errno!(types::Errno, types::GuestErrorConversion);
impl<'a> ints::Ints for WasiCtx<'a> { impl<'a> ints::Ints for WasiCtx<'a> {
fn cookie_cutter(&self, init_cookie: types::Cookie) -> Result<types::Bool, types::Errno> { fn cookie_cutter(&self, init_cookie: types::Cookie) -> Result<types::Bool, types::Errno> {
let res = if init_cookie == types::Cookie::START { let res = if init_cookie == types::COOKIE_START {
types::Bool::True types::Bool::True
} else { } else {
types::Bool::False types::Bool::False
@@ -50,10 +50,10 @@ impl CookieCutterExercise {
let res = ints::cookie_cutter( let res = ints::cookie_cutter(
&ctx, &ctx,
&host_memory, &host_memory,
self.cookie.into(), self.cookie as i64,
self.return_ptr_loc.ptr as i32, self.return_ptr_loc.ptr as i32,
); );
assert_eq!(res, Ok(types::Errno::Ok.into()), "cookie cutter errno"); assert_eq!(res, Ok(types::Errno::Ok as i32), "cookie cutter errno");
let is_cookie_start = host_memory let is_cookie_start = host_memory
.ptr::<types::Bool>(self.return_ptr_loc.ptr) .ptr::<types::Bool>(self.return_ptr_loc.ptr)
@@ -66,7 +66,7 @@ impl CookieCutterExercise {
} else { } else {
false false
}, },
self.cookie == types::Cookie::START, self.cookie == types::COOKIE_START,
"returned Bool should test if input was Cookie::START", "returned Bool should test if input was Cookie::START",
); );
} }

View File

@@ -1,18 +1,13 @@
(use "errno.witx") (use "errno.witx")
(typename $cookie (typename $cookie u64)
(int u64 (@witx const $cookie $start 0)
(const $start 0)))
(typename $bool (typename $bool bool)
(enum u8
$false
$true))
(module $ints (module $ints
(@interface func (export "cookie_cutter") (@interface func (export "cookie_cutter")
(param $init_cookie $cookie) (param $init_cookie $cookie)
(result $error $errno) (result $error (expected $bool (error $errno)))
(result $is_start $bool)
) )
) )

View File

@@ -8,7 +8,7 @@ mod enum_test {
wiggle::from_witx!({ wiggle::from_witx!({
witx_literal: witx_literal:
"(typename $self "(typename $self
(enum u8 (enum (@witx tag u8)
$self $self
$2big $2big
) )
@@ -35,7 +35,7 @@ mod module_trait_fn_and_arg_test {
}); });
impl<'a> self_::Self_ for WasiCtx<'a> { impl<'a> self_::Self_ for WasiCtx<'a> {
#[allow(unused_variables)] #[allow(unused_variables)]
fn fn_(&self, use_: u32, virtual_: u32) -> Result<(), ()> { fn fn_(&self, use_: u32, virtual_: u32) {
unimplemented!(); unimplemented!();
} }
} }
@@ -46,7 +46,7 @@ mod struct_test {
wiggle::from_witx!({ wiggle::from_witx!({
witx_literal: witx_literal:
"(typename $self "(typename $self
(struct (record
(field $become s32) (field $become s32)
(field $mut s32) (field $mut s32)
) )

View File

@@ -1,15 +1,15 @@
(typename $union (typename $union
(enum u8 (enum (@witx tag u8)
$self $self
$power $power
) )
) )
(typename $self (typename $self
(union $union (variant (@witx tag $union)
;; A union variant that will expand to a strict keyword `Self`. ;; A union variant that will expand to a strict keyword `Self`.
(field $self (@witx pointer f32)) (case $self (@witx pointer f32))
;; Oh it's true, that there's power in a union! ;; Oh it's true, that there's power in a union!
(field $power (@witx pointer f32)) (case $power (@witx pointer f32))
) )
) )

View File

@@ -152,12 +152,12 @@ impl PointersAndEnumsExercise {
let e = pointers::pointers_and_enums( let e = pointers::pointers_and_enums(
&ctx, &ctx,
&host_memory, &host_memory,
self.input1.into(), self.input1 as i32,
self.input2_loc.ptr as i32, self.input2_loc.ptr as i32,
self.input3_loc.ptr as i32, self.input3_loc.ptr as i32,
self.input4_ptr_loc.ptr as i32, self.input4_ptr_loc.ptr as i32,
); );
assert_eq!(e, Ok(types::Errno::Ok.into()), "errno"); assert_eq!(e, Ok(types::Errno::Ok as i32), "errno");
// Implementation of pointers_and_enums writes input3 to the input2_loc: // Implementation of pointers_and_enums writes input3 to the input2_loc:
let written_to_input2_loc: i32 = host_memory let written_to_input2_loc: i32 = host_memory
@@ -166,8 +166,7 @@ impl PointersAndEnumsExercise {
.expect("input2 ref"); .expect("input2 ref");
assert_eq!( assert_eq!(
written_to_input2_loc, written_to_input2_loc, self.input3 as i32,
self.input3.into(),
"pointers_and_enums written to input2" "pointers_and_enums written to input2"
); );

View File

@@ -7,5 +7,5 @@
(param $an_excuse_by_reference (@witx pointer $excuse)) (param $an_excuse_by_reference (@witx pointer $excuse))
(param $a_lamer_excuse (@witx const_pointer $excuse)) (param $a_lamer_excuse (@witx const_pointer $excuse))
(param $two_layers_of_excuses (@witx pointer (@witx const_pointer $excuse))) (param $two_layers_of_excuses (@witx pointer (@witx const_pointer $excuse)))
(result $error $errno)) (result $error (expected (error $errno))))
) )

View File

@@ -88,7 +88,7 @@ impl HelloStringExercise {
self.test_word.len() as i32, self.test_word.len() as i32,
self.return_ptr_loc.ptr as i32, self.return_ptr_loc.ptr as i32,
); );
assert_eq!(res, Ok(types::Errno::Ok.into()), "hello string errno"); assert_eq!(res, Ok(types::Errno::Ok as i32), "hello string errno");
let given = host_memory let given = host_memory
.ptr::<u32>(self.return_ptr_loc.ptr) .ptr::<u32>(self.return_ptr_loc.ptr)
@@ -209,7 +209,7 @@ impl MultiStringExercise {
self.c.len() as i32, self.c.len() as i32,
self.return_ptr_loc.ptr as i32, self.return_ptr_loc.ptr as i32,
); );
assert_eq!(res, Ok(types::Errno::Ok.into()), "multi string errno"); assert_eq!(res, Ok(types::Errno::Ok as i32), "multi string errno");
let given = host_memory let given = host_memory
.ptr::<u32>(self.return_ptr_loc.ptr) .ptr::<u32>(self.return_ptr_loc.ptr)
@@ -287,7 +287,7 @@ impl OverlappingStringExercise {
a_len - self.offset_c as i32, a_len - self.offset_c as i32,
self.return_ptr_loc.ptr as i32, self.return_ptr_loc.ptr as i32,
); );
assert_eq!(res, Ok(types::Errno::Ok.into()), "multi string errno"); assert_eq!(res, Ok(types::Errno::Ok as i32), "multi string errno");
let given = host_memory let given = host_memory
.ptr::<u32>(self.return_ptr_loc.ptr) .ptr::<u32>(self.return_ptr_loc.ptr)

View File

@@ -1,16 +1,17 @@
(use "errno.witx") (use "errno.witx")
(typename $ret u32)
(module $strings (module $strings
(@interface func (export "hello_string") (@interface func (export "hello_string")
(param $a_string string) (param $a_string string)
(result $error $errno) (result $error (expected $ret (error $errno)))
(result $total_bytes u32)
) )
(@interface func (export "multi_string") (@interface func (export "multi_string")
(param $a string) (param $a string)
(param $b string) (param $b string)
(param $c string) (param $c string)
(result $error $errno) (result $error (expected $ret (error $errno)))
(result $total_bytes u32)
) )
) )

View File

@@ -118,7 +118,7 @@ impl SumOfPairExercise {
self.return_loc.ptr as i32, self.return_loc.ptr as i32,
); );
assert_eq!(sum_err, Ok(types::Errno::Ok.into()), "sum errno"); assert_eq!(sum_err, Ok(types::Errno::Ok as i32), "sum errno");
let return_val: i64 = host_memory let return_val: i64 = host_memory
.ptr(self.return_loc.ptr) .ptr(self.return_loc.ptr)
@@ -218,7 +218,7 @@ impl SumPairPtrsExercise {
assert_eq!( assert_eq!(
res, res,
Ok(types::Errno::Ok.into()), Ok(types::Errno::Ok as i32),
"sum of pair of ptrs errno" "sum of pair of ptrs errno"
); );
@@ -299,7 +299,7 @@ impl SumIntAndPtrExercise {
self.return_loc.ptr as i32, self.return_loc.ptr as i32,
); );
assert_eq!(res, Ok(types::Errno::Ok.into()), "sum of int and ptr errno"); assert_eq!(res, Ok(types::Errno::Ok as i32), "sum of int and ptr errno");
let doubled: i64 = host_memory let doubled: i64 = host_memory
.ptr(self.return_loc.ptr) .ptr(self.return_loc.ptr)
@@ -338,7 +338,7 @@ impl ReturnPairInts {
let err = structs::return_pair_ints(&ctx, &host_memory, self.return_loc.ptr as i32); let err = structs::return_pair_ints(&ctx, &host_memory, self.return_loc.ptr as i32);
assert_eq!(err, Ok(types::Errno::Ok.into()), "return struct errno"); assert_eq!(err, Ok(types::Errno::Ok as i32), "return struct errno");
let return_struct: types::PairInts = host_memory let return_struct: types::PairInts = host_memory
.ptr(self.return_loc.ptr) .ptr(self.return_loc.ptr)
@@ -420,7 +420,7 @@ impl ReturnPairPtrsExercise {
assert_eq!( assert_eq!(
res, res,
Ok(types::Errno::Ok.into()), Ok(types::Errno::Ok as i32),
"return pair of ptrs errno" "return pair of ptrs errno"
); );
@@ -530,7 +530,7 @@ impl SumArrayExercise {
); );
// should be no error - if hostcall did a GuestError it should eprintln it. // should be no error - if hostcall did a GuestError it should eprintln it.
assert_eq!(res, Ok(types::Errno::Ok.into()), "reduce excuses errno"); assert_eq!(res, Ok(types::Errno::Ok as i32), "reduce excuses errno");
// Sum is inputs upcasted to u16 // Sum is inputs upcasted to u16
let expected: u16 = self.inputs.iter().map(|v| *v as u16).sum(); let expected: u16 = self.inputs.iter().map(|v| *v as u16).sum();

View File

@@ -2,49 +2,46 @@
(use "errno.witx") (use "errno.witx")
(typename $pair_ints (typename $pair_ints
(struct (record
(field $first s32) (field $first s32)
(field $second s32))) (field $second s32)))
(typename $pair_int_ptrs (typename $pair_int_ptrs
(struct (record
(field $first (@witx const_pointer s32)) (field $first (@witx const_pointer s32))
(field $second (@witx const_pointer s32)))) (field $second (@witx const_pointer s32))))
(typename $pair_int_and_ptr (typename $pair_int_and_ptr
(struct (record
(field $first (@witx const_pointer s32)) (field $first (@witx const_pointer s32))
(field $second s32))) (field $second s32)))
(typename $some_bytes (array u8)) (typename $some_bytes (list u8))
(typename $struct_of_array (typename $struct_of_array
(struct (record
(field $arr $some_bytes))) (field $arr $some_bytes)))
(typename $s64 s64)
(typename $u16 u16)
(module $structs (module $structs
(@interface func (export "sum_of_pair") (@interface func (export "sum_of_pair")
(param $an_pair $pair_ints) (param $an_pair $pair_ints)
(result $error $errno) (result $error (expected $s64 (error $errno))))
(result $doubled s64))
(@interface func (export "sum_of_pair_of_ptrs") (@interface func (export "sum_of_pair_of_ptrs")
(param $an_pair $pair_int_ptrs) (param $an_pair $pair_int_ptrs)
(result $error $errno) (result $error (expected $s64 (error $errno))))
(result $doubled s64))
(@interface func (export "sum_of_int_and_ptr") (@interface func (export "sum_of_int_and_ptr")
(param $an_pair $pair_int_and_ptr) (param $an_pair $pair_int_and_ptr)
(result $error $errno) (result $error (expected $s64 (error $errno))))
(result $double s64))
(@interface func (export "return_pair_ints") (@interface func (export "return_pair_ints")
(result $error $errno) (result $error (expected $pair_ints (error $errno))))
(result $an_pair $pair_ints))
(@interface func (export "return_pair_of_ptrs") (@interface func (export "return_pair_of_ptrs")
(param $first (@witx const_pointer s32)) (param $first (@witx const_pointer s32))
(param $second (@witx const_pointer s32)) (param $second (@witx const_pointer s32))
(result $error $errno) (result $error (expected $pair_int_ptrs (error $errno))))
(result $an_pair $pair_int_ptrs))
(@interface func (export "sum_array") (@interface func (export "sum_array")
(param $an_arr $struct_of_array) (param $an_arr $struct_of_array)
(result $error $errno) (result $error (expected $u16 (error $errno))))
(result $doubled u16))
) )

View File

@@ -15,7 +15,7 @@
;;; Identifiers for clocks. ;;; Identifiers for clocks.
(typename $clockid (typename $clockid
(enum u32 (enum (@witx tag u32)
;;; The clock measuring real time. Time value zero corresponds with ;;; The clock measuring real time. Time value zero corresponds with
;;; 1970-01-01T00:00:00Z. ;;; 1970-01-01T00:00:00Z.
$realtime $realtime
@@ -36,7 +36,7 @@
;;; API; some are used in higher-level library layers, and others are provided ;;; API; some are used in higher-level library layers, and others are provided
;;; merely for alignment with POSIX. ;;; merely for alignment with POSIX.
(typename $errno (typename $errno
(enum u16 (enum (@witx tag u16)
;;; No error occurred. System call completed successfully. ;;; No error occurred. System call completed successfully.
$success $success
;;; Argument list too long. ;;; Argument list too long.
@@ -196,7 +196,7 @@
;;; File descriptor rights, determining which actions may be performed. ;;; File descriptor rights, determining which actions may be performed.
(typename $rights (typename $rights
(flags u64 (flags (@witx repr u64)
;;; The right to invoke `fd_datasync`. ;;; The right to invoke `fd_datasync`.
;; ;;
;;; If `path_open` is set, includes the right to invoke ;;; If `path_open` is set, includes the right to invoke
@@ -278,7 +278,7 @@
;;; A region of memory for scatter/gather reads. ;;; A region of memory for scatter/gather reads.
(typename $iovec (typename $iovec
(struct (record
;;; The address of the buffer to be filled. ;;; The address of the buffer to be filled.
(field $buf (@witx pointer u8)) (field $buf (@witx pointer u8))
;;; The length of the buffer to be filled. ;;; The length of the buffer to be filled.
@@ -288,7 +288,7 @@
;;; A region of memory for scatter/gather writes. ;;; A region of memory for scatter/gather writes.
(typename $ciovec (typename $ciovec
(struct (record
;;; The address of the buffer to be written. ;;; The address of the buffer to be written.
(field $buf (@witx const_pointer u8)) (field $buf (@witx const_pointer u8))
;;; The length of the buffer to be written. ;;; The length of the buffer to be written.
@@ -296,15 +296,15 @@
) )
) )
(typename $iovec_array (array $iovec)) (typename $iovec_array (list $iovec))
(typename $ciovec_array (array $ciovec)) (typename $ciovec_array (list $ciovec))
;;; Relative offset within a file. ;;; Relative offset within a file.
(typename $filedelta s64) (typename $filedelta s64)
;;; The position relative to which to set the offset of the file descriptor. ;;; The position relative to which to set the offset of the file descriptor.
(typename $whence (typename $whence
(enum u8 (enum (@witx tag u8)
;;; Seek relative to start-of-file. ;;; Seek relative to start-of-file.
$set $set
;;; Seek relative to current position. ;;; Seek relative to current position.
@@ -327,7 +327,7 @@
;;; The type of a file descriptor or file. ;;; The type of a file descriptor or file.
(typename $filetype (typename $filetype
(enum u8 (enum (@witx tag u8)
;;; The type of the file descriptor or file is unknown or is different from any of the other types specified. ;;; The type of the file descriptor or file is unknown or is different from any of the other types specified.
$unknown $unknown
;;; The file descriptor or file refers to a block device inode. ;;; The file descriptor or file refers to a block device inode.
@@ -349,7 +349,7 @@
;;; A directory entry. ;;; A directory entry.
(typename $dirent (typename $dirent
(struct (record
;;; The offset of the next directory entry stored in this directory. ;;; The offset of the next directory entry stored in this directory.
(field $d_next $dircookie) (field $d_next $dircookie)
;;; The serial number of the file referred to by this directory entry. ;;; The serial number of the file referred to by this directory entry.
@@ -363,7 +363,7 @@
;;; File or memory access pattern advisory information. ;;; File or memory access pattern advisory information.
(typename $advice (typename $advice
(enum u8 (enum (@witx tag u8)
;;; The application has no advice to give on its behavior with respect to the specified data. ;;; The application has no advice to give on its behavior with respect to the specified data.
$normal $normal
;;; The application expects to access the specified data sequentially from lower offsets to higher offsets. ;;; The application expects to access the specified data sequentially from lower offsets to higher offsets.
@@ -381,7 +381,7 @@
;;; File descriptor flags. ;;; File descriptor flags.
(typename $fdflags (typename $fdflags
(flags u16 (flags (@witx repr u16)
;;; Append mode: Data written to the file is always appended to the file's end. ;;; Append mode: Data written to the file is always appended to the file's end.
$append $append
;;; Write according to synchronized I/O data integrity completion. Only the data stored in the file is synchronized. ;;; Write according to synchronized I/O data integrity completion. Only the data stored in the file is synchronized.
@@ -399,7 +399,7 @@
;;; File descriptor attributes. ;;; File descriptor attributes.
(typename $fdstat (typename $fdstat
(struct (record
;;; File type. ;;; File type.
(field $fs_filetype $filetype) (field $fs_filetype $filetype)
;;; File descriptor flags. ;;; File descriptor flags.
@@ -418,7 +418,7 @@
;;; Which file time attributes to adjust. ;;; Which file time attributes to adjust.
(typename $fstflags (typename $fstflags
(flags u16 (flags (@witx repr u16)
;;; Adjust the last data access timestamp to the value stored in `filestat::atim`. ;;; Adjust the last data access timestamp to the value stored in `filestat::atim`.
$atim $atim
;;; Adjust the last data access timestamp to the time of clock `clockid::realtime`. ;;; Adjust the last data access timestamp to the time of clock `clockid::realtime`.
@@ -432,7 +432,7 @@
;;; Flags determining the method of how paths are resolved. ;;; Flags determining the method of how paths are resolved.
(typename $lookupflags (typename $lookupflags
(flags u32 (flags (@witx repr u32)
;;; As long as the resolved path corresponds to a symbolic link, it is expanded. ;;; As long as the resolved path corresponds to a symbolic link, it is expanded.
$symlink_follow $symlink_follow
) )
@@ -440,7 +440,7 @@
;;; Open flags used by `path_open`. ;;; Open flags used by `path_open`.
(typename $oflags (typename $oflags
(flags u16 (flags (@witx repr u16)
;;; Create file if it does not exist. ;;; Create file if it does not exist.
$creat $creat
;;; Fail if not a directory. ;;; Fail if not a directory.
@@ -457,7 +457,7 @@
;;; File attributes. ;;; File attributes.
(typename $filestat (typename $filestat
(struct (record
;;; Device ID of device containing the file. ;;; Device ID of device containing the file.
(field $dev $device) (field $dev $device)
;;; File serial number. ;;; File serial number.
@@ -483,7 +483,7 @@
;;; Type of a subscription to an event or its occurrence. ;;; Type of a subscription to an event or its occurrence.
(typename $eventtype (typename $eventtype
(enum u8 (enum (@witx tag u8)
;;; The time value of clock `subscription_clock::id` has ;;; The time value of clock `subscription_clock::id` has
;;; reached timestamp `subscription_clock::timeout`. ;;; reached timestamp `subscription_clock::timeout`.
$clock $clock
@@ -499,7 +499,7 @@
;;; The state of the file descriptor subscribed to with ;;; The state of the file descriptor subscribed to with
;;; `eventtype::fd_read` or `eventtype::fd_write`. ;;; `eventtype::fd_read` or `eventtype::fd_write`.
(typename $eventrwflags (typename $eventrwflags
(flags u16 (flags (@witx repr u16)
;;; The peer of this socket has closed or disconnected. ;;; The peer of this socket has closed or disconnected.
$fd_readwrite_hangup $fd_readwrite_hangup
) )
@@ -508,7 +508,7 @@
;;; The contents of an $event when type is `eventtype::fd_read` or ;;; The contents of an $event when type is `eventtype::fd_read` or
;;; `eventtype::fd_write`. ;;; `eventtype::fd_write`.
(typename $event_fd_readwrite (typename $event_fd_readwrite
(struct (record
;;; The number of bytes available for reading or writing. ;;; The number of bytes available for reading or writing.
(field $nbytes $filesize) (field $nbytes $filesize)
;;; The state of the file descriptor. ;;; The state of the file descriptor.
@@ -518,7 +518,7 @@
;;; An event that occurred. ;;; An event that occurred.
(typename $event (typename $event
(struct (record
;;; User-provided value that got attached to `subscription::userdata`. ;;; User-provided value that got attached to `subscription::userdata`.
(field $userdata $userdata) (field $userdata $userdata)
;;; If non-zero, an error that occurred while processing the subscription request. ;;; If non-zero, an error that occurred while processing the subscription request.
@@ -534,7 +534,7 @@
;;; Flags determining how to interpret the timestamp provided in ;;; Flags determining how to interpret the timestamp provided in
;;; `subscription_clock::timeout`. ;;; `subscription_clock::timeout`.
(typename $subclockflags (typename $subclockflags
(flags u16 (flags (@witx repr u16)
;;; If set, treat the timestamp provided in ;;; If set, treat the timestamp provided in
;;; `subscription_clock::timeout` as an absolute timestamp of clock ;;; `subscription_clock::timeout` as an absolute timestamp of clock
;;; `subscription_clock::id`. If clear, treat the timestamp ;;; `subscription_clock::id`. If clear, treat the timestamp
@@ -546,7 +546,7 @@
;;; The contents of a `subscription` when type is `eventtype::clock`. ;;; The contents of a `subscription` when type is `eventtype::clock`.
(typename $subscription_clock (typename $subscription_clock
(struct (record
;;; The clock against which to compare the timestamp. ;;; The clock against which to compare the timestamp.
(field $id $clockid) (field $id $clockid)
;;; The absolute or relative timestamp. ;;; The absolute or relative timestamp.
@@ -562,7 +562,7 @@
;;; The contents of a `subscription` when type is type is ;;; The contents of a `subscription` when type is type is
;;; `eventtype::fd_read` or `eventtype::fd_write`. ;;; `eventtype::fd_read` or `eventtype::fd_write`.
(typename $subscription_fd_readwrite (typename $subscription_fd_readwrite
(struct (record
;;; The file descriptor on which to wait for it to become ready for reading or writing. ;;; The file descriptor on which to wait for it to become ready for reading or writing.
(field $file_descriptor $fd) (field $file_descriptor $fd)
) )
@@ -570,16 +570,16 @@
;;; The contents of a `subscription`. ;;; The contents of a `subscription`.
(typename $subscription_u (typename $subscription_u
(union $eventtype (union (@witx tag $eventtype)
(field $clock $subscription_clock) $subscription_clock
(field $fd_read $subscription_fd_readwrite) $subscription_fd_readwrite
(field $fd_write $subscription_fd_readwrite) $subscription_fd_readwrite
) )
) )
;;; Subscription to an event. ;;; Subscription to an event.
(typename $subscription (typename $subscription
(struct (record
;;; User-provided value that is attached to the subscription in the ;;; User-provided value that is attached to the subscription in the
;;; implementation and returned through `event::userdata`. ;;; implementation and returned through `event::userdata`.
(field $userdata $userdata) (field $userdata $userdata)
@@ -593,7 +593,7 @@
;;; Signal condition. ;;; Signal condition.
(typename $signal (typename $signal
(enum u8 (enum (@witx tag u8)
;;; No signal. Note that POSIX has special semantics for `kill(pid, 0)`, ;;; No signal. Note that POSIX has special semantics for `kill(pid, 0)`,
;;; so this value is reserved. ;;; so this value is reserved.
$none $none
@@ -606,7 +606,7 @@
;;; Terminal quit signal. ;;; Terminal quit signal.
;;; Action: Terminates the process. ;;; Action: Terminates the process.
$quit $quit
;;; Illegal instruction. ;;; Illegal inrecordion.
;;; Action: Terminates the process. ;;; Action: Terminates the process.
$ill $ill
;;; Trace/breakpoint trap. ;;; Trace/breakpoint trap.
@@ -692,7 +692,7 @@
;;; Flags provided to `sock_recv`. ;;; Flags provided to `sock_recv`.
(typename $riflags (typename $riflags
(flags u16 (flags (@witx repr u16)
;;; Returns the message without removing it from the socket's receive queue. ;;; Returns the message without removing it from the socket's receive queue.
$recv_peek $recv_peek
;;; On byte-stream sockets, block until the full amount of data can be returned. ;;; On byte-stream sockets, block until the full amount of data can be returned.
@@ -702,7 +702,7 @@
;;; Flags returned by `sock_recv`. ;;; Flags returned by `sock_recv`.
(typename $roflags (typename $roflags
(flags u16 (flags (@witx repr u16)
;;; Returned by `sock_recv`: Message data has been truncated. ;;; Returned by `sock_recv`: Message data has been truncated.
$recv_data_truncated $recv_data_truncated
) )
@@ -714,7 +714,7 @@
;;; Which channels on a socket to shut down. ;;; Which channels on a socket to shut down.
(typename $sdflags (typename $sdflags
(flags u8 (flags (@witx repr u8)
;;; Disables further receive operations. ;;; Disables further receive operations.
$rd $rd
;;; Disables further send operations. ;;; Disables further send operations.
@@ -724,7 +724,7 @@
;;; Identifiers for preopened capabilities. ;;; Identifiers for preopened capabilities.
(typename $preopentype (typename $preopentype
(enum u8 (enum (@witx tag u8)
;;; A pre-opened directory. ;;; A pre-opened directory.
$dir $dir
) )
@@ -732,7 +732,7 @@
;;; The contents of a $prestat when type is `preopentype::dir`. ;;; The contents of a $prestat when type is `preopentype::dir`.
(typename $prestat_dir (typename $prestat_dir
(struct (record
;;; The length of the directory name for use with `fd_prestat_dir_name`. ;;; The length of the directory name for use with `fd_prestat_dir_name`.
(field $pr_name_len $size) (field $pr_name_len $size)
) )
@@ -740,7 +740,7 @@
;;; Information about a pre-opened capability. ;;; Information about a pre-opened capability.
(typename $prestat (typename $prestat
(union $preopentype (union (@witx tag $preopentype)
(field $dir $prestat_dir) $prestat_dir
) )
) )

View File

@@ -108,7 +108,7 @@ impl GetTagExercise {
let ctx = WasiCtx::new(); let ctx = WasiCtx::new();
let host_memory = HostMemory::new(); let host_memory = HostMemory::new();
let discriminant: u8 = reason_tag(&self.input).into(); let discriminant = reason_tag(&self.input) as u8;
host_memory host_memory
.ptr(self.input_loc.ptr) .ptr(self.input_loc.ptr)
.write(discriminant) .write(discriminant)
@@ -133,7 +133,7 @@ impl GetTagExercise {
self.return_loc.ptr as i32, self.return_loc.ptr as i32,
); );
assert_eq!(e, Ok(types::Errno::Ok.into()), "get_tag errno"); assert_eq!(e, Ok(types::Errno::Ok as i32), "get_tag errno");
let return_val: types::Excuse = host_memory let return_val: types::Excuse = host_memory
.ptr(self.return_loc.ptr) .ptr(self.return_loc.ptr)
@@ -185,7 +185,7 @@ impl ReasonMultExercise {
let ctx = WasiCtx::new(); let ctx = WasiCtx::new();
let host_memory = HostMemory::new(); let host_memory = HostMemory::new();
let discriminant: u8 = reason_tag(&self.input).into(); let discriminant = reason_tag(&self.input) as u8;
host_memory host_memory
.ptr(self.input_loc.ptr) .ptr(self.input_loc.ptr)
.write(discriminant) .write(discriminant)
@@ -217,7 +217,7 @@ impl ReasonMultExercise {
self.multiply_by as i32, self.multiply_by as i32,
); );
assert_eq!(e, Ok(types::Errno::Ok.into()), "reason_mult errno"); assert_eq!(e, Ok(types::Errno::Ok as i32), "reason_mult errno");
match self.input { match self.input {
types::Reason::DogAte(f) => { types::Reason::DogAte(f) => {

View File

@@ -5,27 +5,26 @@
;; Fight for the full product of your labor! ;; Fight for the full product of your labor!
(typename $reason (typename $reason
(union $excuse (variant (@witx tag $excuse)
(field $dog_ate f32) (case $dog_ate f32)
(field $traffic s32) (case $traffic s32)
(empty $sleeping))) (case $sleeping)))
(typename $reason_mut (typename $reason_mut
(union $excuse (variant (@witx tag $excuse)
(field $dog_ate (@witx pointer f32)) (case $dog_ate (@witx pointer f32))
(field $traffic (@witx pointer s32)) (case $traffic (@witx pointer s32))
(empty $sleeping))) (case $sleeping)))
(module $union_example (module $union_example
(@interface func (export "get_tag") (@interface func (export "get_tag")
(param $r $reason) (param $r $reason)
(result $error $errno) (result $error (expected $excuse (error $errno)))
(result $t $excuse)
) )
(@interface func (export "reason_mult") (@interface func (export "reason_mult")
(param $r $reason_mut) (param $r $reason_mut)
(param $multiply_by u32) (param $multiply_by u32)
(result $error $errno) (result $error (expected (error $errno)))
) )
) )

View File

@@ -322,7 +322,7 @@ impl<'a> crate::wasi_snapshot_preview1::WasiSnapshotPreview1 for WasiCtx<'a> {
unimplemented!("poll_oneoff") unimplemented!("poll_oneoff")
} }
fn proc_exit(&self, _rval: types::Exitcode) -> std::result::Result<(), ()> { fn proc_exit(&self, _rval: types::Exitcode) -> wiggle::Trap {
unimplemented!("proc_exit") unimplemented!("proc_exit")
} }

View File

@@ -17,15 +17,13 @@
(@interface func (export "args_get") (@interface func (export "args_get")
(param $argv (@witx pointer (@witx pointer u8))) (param $argv (@witx pointer (@witx pointer u8)))
(param $argv_buf (@witx pointer u8)) (param $argv_buf (@witx pointer u8))
(result $error $errno) (result $error (expected (error $errno)))
) )
;;; Return command-line argument data sizes. ;;; Return command-line argument data sizes.
(@interface func (export "args_sizes_get") (@interface func (export "args_sizes_get")
(result $error $errno) ;;; Returns the number of arguments and the size of the argument string
;;; The number of arguments. ;;; data, or an error.
(result $argc $size) (result $error (expected (tuple $size $size) (error $errno)))
;;; The size of the argument string data.
(result $argv_buf_size $size)
) )
;;; Read environment variable data. ;;; Read environment variable data.
@@ -33,15 +31,13 @@
(@interface func (export "environ_get") (@interface func (export "environ_get")
(param $environ (@witx pointer (@witx pointer u8))) (param $environ (@witx pointer (@witx pointer u8)))
(param $environ_buf (@witx pointer u8)) (param $environ_buf (@witx pointer u8))
(result $error $errno) (result $error (expected (error $errno)))
) )
;;; Return environment variable data sizes. ;;; Return environment variable data sizes.
(@interface func (export "environ_sizes_get") (@interface func (export "environ_sizes_get")
(result $error $errno) ;;; Returns the number of environment variable arguments and the size of the
;;; The number of environment variable arguments. ;;; environment variable data.
(result $environc $size) (result $error (expected (tuple $size $size) (error $errno)))
;;; The size of the environment variable data.
(result $environ_buf_size $size)
) )
;;; Return the resolution of a clock. ;;; Return the resolution of a clock.
@@ -51,9 +47,8 @@
(@interface func (export "clock_res_get") (@interface func (export "clock_res_get")
;;; The clock for which to return the resolution. ;;; The clock for which to return the resolution.
(param $id $clockid) (param $id $clockid)
(result $error $errno) ;;; The resolution of the clock, or an error if one happened.
;;; The resolution of the clock. (result $error (expected $timestamp (error $errno)))
(result $resolution $timestamp)
) )
;;; Return the time value of a clock. ;;; Return the time value of a clock.
;;; Note: This is similar to `clock_gettime` in POSIX. ;;; Note: This is similar to `clock_gettime` in POSIX.
@@ -62,9 +57,8 @@
(param $id $clockid) (param $id $clockid)
;;; The maximum lag (exclusive) that the returned time value may have, compared to its actual value. ;;; The maximum lag (exclusive) that the returned time value may have, compared to its actual value.
(param $precision $timestamp) (param $precision $timestamp)
(result $error $errno)
;;; The time value of the clock. ;;; The time value of the clock.
(result $time $timestamp) (result $error (expected $timestamp (error $errno)))
) )
;;; Provide file advisory information on a file descriptor. ;;; Provide file advisory information on a file descriptor.
@@ -77,7 +71,7 @@
(param $len $filesize) (param $len $filesize)
;;; The advice. ;;; The advice.
(param $advice $advice) (param $advice $advice)
(result $error $errno) (result $error (expected (error $errno)))
) )
;;; Force the allocation of space in a file. ;;; Force the allocation of space in a file.
@@ -88,30 +82,29 @@
(param $offset $filesize) (param $offset $filesize)
;;; The length of the area that is allocated. ;;; The length of the area that is allocated.
(param $len $filesize) (param $len $filesize)
(result $error $errno) (result $error (expected (error $errno)))
) )
;;; Close a file descriptor. ;;; Close a file descriptor.
;;; Note: This is similar to `close` in POSIX. ;;; Note: This is similar to `close` in POSIX.
(@interface func (export "fd_close") (@interface func (export "fd_close")
(param $fd $fd) (param $fd $fd)
(result $error $errno) (result $error (expected (error $errno)))
) )
;;; Synchronize the data of a file to disk. ;;; Synchronize the data of a file to disk.
;;; Note: This is similar to `fdatasync` in POSIX. ;;; Note: This is similar to `fdatasync` in POSIX.
(@interface func (export "fd_datasync") (@interface func (export "fd_datasync")
(param $fd $fd) (param $fd $fd)
(result $error $errno) (result $error (expected (error $errno)))
) )
;;; Get the attributes of a file descriptor. ;;; Get the attributes of a file descriptor.
;;; Note: This returns similar flags to `fsync(fd, F_GETFL)` in POSIX, as well as additional fields. ;;; Note: This returns similar flags to `fsync(fd, F_GETFL)` in POSIX, as well as additional fields.
(@interface func (export "fd_fdstat_get") (@interface func (export "fd_fdstat_get")
(param $fd $fd) (param $fd $fd)
(result $error $errno)
;;; The buffer where the file descriptor's attributes are stored. ;;; The buffer where the file descriptor's attributes are stored.
(result $stat $fdstat) (result $error (expected $fdstat (error $errno)))
) )
;;; Adjust the flags associated with a file descriptor. ;;; Adjust the flags associated with a file descriptor.
@@ -120,7 +113,7 @@
(param $fd $fd) (param $fd $fd)
;;; The desired values of the file descriptor flags. ;;; The desired values of the file descriptor flags.
(param $flags $fdflags) (param $flags $fdflags)
(result $error $errno) (result $error (expected (error $errno)))
) )
;;; Adjust the rights associated with a file descriptor. ;;; Adjust the rights associated with a file descriptor.
@@ -130,15 +123,14 @@
;;; The desired rights of the file descriptor. ;;; The desired rights of the file descriptor.
(param $fs_rights_base $rights) (param $fs_rights_base $rights)
(param $fs_rights_inheriting $rights) (param $fs_rights_inheriting $rights)
(result $error $errno) (result $error (expected (error $errno)))
) )
;;; Return the attributes of an open file. ;;; Return the attributes of an open file.
(@interface func (export "fd_filestat_get") (@interface func (export "fd_filestat_get")
(param $fd $fd) (param $fd $fd)
(result $error $errno)
;;; The buffer where the file's attributes are stored. ;;; The buffer where the file's attributes are stored.
(result $buf $filestat) (result $error (expected $filestat (error $errno)))
) )
;;; Adjust the size of an open file. If this increases the file's size, the extra bytes are filled with zeros. ;;; Adjust the size of an open file. If this increases the file's size, the extra bytes are filled with zeros.
@@ -147,7 +139,7 @@
(param $fd $fd) (param $fd $fd)
;;; The desired file size. ;;; The desired file size.
(param $size $filesize) (param $size $filesize)
(result $error $errno) (result $error (expected (error $errno)))
) )
;;; Adjust the timestamps of an open file or directory. ;;; Adjust the timestamps of an open file or directory.
@@ -160,7 +152,7 @@
(param $mtim $timestamp) (param $mtim $timestamp)
;;; A bitmask indicating which timestamps to adjust. ;;; A bitmask indicating which timestamps to adjust.
(param $fst_flags $fstflags) (param $fst_flags $fstflags)
(result $error $errno) (result $error (expected (error $errno)))
) )
;;; Read from a file descriptor, without using and updating the file descriptor's offset. ;;; Read from a file descriptor, without using and updating the file descriptor's offset.
@@ -171,17 +163,15 @@
(param $iovs $iovec_array) (param $iovs $iovec_array)
;;; The offset within the file at which to read. ;;; The offset within the file at which to read.
(param $offset $filesize) (param $offset $filesize)
(result $error $errno)
;;; The number of bytes read. ;;; The number of bytes read.
(result $nread $size) (result $error (expected $size (error $errno)))
) )
;;; Return a description of the given preopened file descriptor. ;;; Return a description of the given preopened file descriptor.
(@interface func (export "fd_prestat_get") (@interface func (export "fd_prestat_get")
(param $fd $fd) (param $fd $fd)
(result $error $errno)
;;; The buffer where the description is stored. ;;; The buffer where the description is stored.
(result $buf $prestat) (result $error (expected $prestat (error $errno)))
) )
;;; Return a description of the given preopened file descriptor. ;;; Return a description of the given preopened file descriptor.
@@ -190,7 +180,7 @@
;;; A buffer into which to write the preopened directory name. ;;; A buffer into which to write the preopened directory name.
(param $path (@witx pointer u8)) (param $path (@witx pointer u8))
(param $path_len $size) (param $path_len $size)
(result $error $errno) (result $error (expected (error $errno)))
) )
;;; Write to a file descriptor, without using and updating the file descriptor's offset. ;;; Write to a file descriptor, without using and updating the file descriptor's offset.
@@ -201,9 +191,8 @@
(param $iovs $ciovec_array) (param $iovs $ciovec_array)
;;; The offset within the file at which to write. ;;; The offset within the file at which to write.
(param $offset $filesize) (param $offset $filesize)
(result $error $errno)
;;; The number of bytes written. ;;; The number of bytes written.
(result $nwritten $size) (result $error (expected $size (error $errno)))
) )
;;; Read from a file descriptor. ;;; Read from a file descriptor.
@@ -212,15 +201,14 @@
(param $fd $fd) (param $fd $fd)
;;; List of scatter/gather vectors to which to store data. ;;; List of scatter/gather vectors to which to store data.
(param $iovs $iovec_array) (param $iovs $iovec_array)
(result $error $errno)
;;; The number of bytes read. ;;; The number of bytes read.
(result $nread $size) (result $error (expected $size (error $errno)))
) )
;;; Read directory entries from a directory. ;;; Read directory entries from a directory.
;;; When successful, the contents of the output buffer consist of a sequence of ;;; When successful, the contents of the output buffer consist of a sequence of
;;; directory entries. Each directory entry consists of a dirent_t object, ;;; directory entries. Each directory entry consists of a `dirent` object,
;;; followed by dirent_t::d_namlen bytes holding the name of the directory ;;; followed by `dirent::d_namlen` bytes holding the name of the directory
;;; entry. ;;; entry.
;; ;;
;;; This function fills the output buffer as much as possible, potentially ;;; This function fills the output buffer as much as possible, potentially
@@ -234,9 +222,8 @@
(param $buf_len $size) (param $buf_len $size)
;;; The location within the directory to start reading ;;; The location within the directory to start reading
(param $cookie $dircookie) (param $cookie $dircookie)
(result $error $errno)
;;; The number of bytes stored in the read buffer. If less than the size of the read buffer, the end of the directory has been reached. ;;; The number of bytes stored in the read buffer. If less than the size of the read buffer, the end of the directory has been reached.
(result $bufused $size) (result $error (expected $size (error $errno)))
) )
;;; Atomically replace a file descriptor by renumbering another file descriptor. ;;; Atomically replace a file descriptor by renumbering another file descriptor.
@@ -253,7 +240,7 @@
(param $fd $fd) (param $fd $fd)
;;; The file descriptor to overwrite. ;;; The file descriptor to overwrite.
(param $to $fd) (param $to $fd)
(result $error $errno) (result $error (expected (error $errno)))
) )
;;; Move the offset of a file descriptor. ;;; Move the offset of a file descriptor.
@@ -264,25 +251,23 @@
(param $offset $filedelta) (param $offset $filedelta)
;;; The base from which the offset is relative. ;;; The base from which the offset is relative.
(param $whence $whence) (param $whence $whence)
(result $error $errno)
;;; The new offset of the file descriptor, relative to the start of the file. ;;; The new offset of the file descriptor, relative to the start of the file.
(result $newoffset $filesize) (result $error (expected $filesize (error $errno)))
) )
;;; Synchronize the data and metadata of a file to disk. ;;; Synchronize the data and metadata of a file to disk.
;;; Note: This is similar to `fsync` in POSIX. ;;; Note: This is similar to `fsync` in POSIX.
(@interface func (export "fd_sync") (@interface func (export "fd_sync")
(param $fd $fd) (param $fd $fd)
(result $error $errno) (result $error (expected (error $errno)))
) )
;;; Return the current offset of a file descriptor. ;;; Return the current offset of a file descriptor.
;;; Note: This is similar to `lseek(fd, 0, SEEK_CUR)` in POSIX. ;;; Note: This is similar to `lseek(fd, 0, SEEK_CUR)` in POSIX.
(@interface func (export "fd_tell") (@interface func (export "fd_tell")
(param $fd $fd) (param $fd $fd)
(result $error $errno)
;;; The current offset of the file descriptor, relative to the start of the file. ;;; The current offset of the file descriptor, relative to the start of the file.
(result $offset $filesize) (result $error (expected $filesize (error $errno)))
) )
;;; Write to a file descriptor. ;;; Write to a file descriptor.
@@ -291,9 +276,7 @@
(param $fd $fd) (param $fd $fd)
;;; List of scatter/gather vectors from which to retrieve data. ;;; List of scatter/gather vectors from which to retrieve data.
(param $iovs $ciovec_array) (param $iovs $ciovec_array)
(result $error $errno) (result $error (expected $size (error $errno)))
;;; The number of bytes written.
(result $nwritten $size)
) )
;;; Create a directory. ;;; Create a directory.
@@ -302,7 +285,7 @@
(param $fd $fd) (param $fd $fd)
;;; The path at which to create the directory. ;;; The path at which to create the directory.
(param $path string) (param $path string)
(result $error $errno) (result $error (expected (error $errno)))
) )
;;; Return the attributes of a file or directory. ;;; Return the attributes of a file or directory.
@@ -313,9 +296,8 @@
(param $flags $lookupflags) (param $flags $lookupflags)
;;; The path of the file or directory to inspect. ;;; The path of the file or directory to inspect.
(param $path string) (param $path string)
(result $error $errno)
;;; The buffer where the file's attributes are stored. ;;; The buffer where the file's attributes are stored.
(result $buf $filestat) (result $error (expected $filestat (error $errno)))
) )
;;; Adjust the timestamps of a file or directory. ;;; Adjust the timestamps of a file or directory.
@@ -332,7 +314,7 @@
(param $mtim $timestamp) (param $mtim $timestamp)
;;; A bitmask indicating which timestamps to adjust. ;;; A bitmask indicating which timestamps to adjust.
(param $fst_flags $fstflags) (param $fst_flags $fstflags)
(result $error $errno) (result $error (expected (error $errno)))
) )
;;; Create a hard link. ;;; Create a hard link.
@@ -347,7 +329,7 @@
(param $new_fd $fd) (param $new_fd $fd)
;;; The destination path at which to create the hard link. ;;; The destination path at which to create the hard link.
(param $new_path string) (param $new_path string)
(result $error $errno) (result $error (expected (error $errno)))
) )
;;; Open a file or directory. ;;; Open a file or directory.
@@ -377,11 +359,10 @@
;;; descriptor itself, while the *inheriting* rights are rights that apply to ;;; descriptor itself, while the *inheriting* rights are rights that apply to
;;; file descriptors derived from it. ;;; file descriptors derived from it.
(param $fs_rights_base $rights) (param $fs_rights_base $rights)
(param $fs_rights_inherting $rights) (param $fs_rights_inheriting $rights)
(param $fdflags $fdflags) (param $fdflags $fdflags)
(result $error $errno)
;;; The file descriptor of the file that has been opened. ;;; The file descriptor of the file that has been opened.
(result $opened_fd $fd) (result $error (expected $fd (error $errno)))
) )
;;; Read the contents of a symbolic link. ;;; Read the contents of a symbolic link.
@@ -393,9 +374,8 @@
;;; The buffer to which to write the contents of the symbolic link. ;;; The buffer to which to write the contents of the symbolic link.
(param $buf (@witx pointer u8)) (param $buf (@witx pointer u8))
(param $buf_len $size) (param $buf_len $size)
(result $error $errno)
;;; The number of bytes placed in the buffer. ;;; The number of bytes placed in the buffer.
(result $bufused $size) (result $error (expected $size (error $errno)))
) )
;;; Remove a directory. ;;; Remove a directory.
@@ -405,7 +385,7 @@
(param $fd $fd) (param $fd $fd)
;;; The path to a directory to remove. ;;; The path to a directory to remove.
(param $path string) (param $path string)
(result $error $errno) (result $error (expected (error $errno)))
) )
;;; Rename a file or directory. ;;; Rename a file or directory.
@@ -418,7 +398,7 @@
(param $new_fd $fd) (param $new_fd $fd)
;;; The destination path to which to rename the file or directory. ;;; The destination path to which to rename the file or directory.
(param $new_path string) (param $new_path string)
(result $error $errno) (result $error (expected (error $errno)))
) )
;;; Create a symbolic link. ;;; Create a symbolic link.
@@ -429,7 +409,7 @@
(param $fd $fd) (param $fd $fd)
;;; The destination path at which to create the symbolic link. ;;; The destination path at which to create the symbolic link.
(param $new_path string) (param $new_path string)
(result $error $errno) (result $error (expected (error $errno)))
) )
@@ -440,7 +420,7 @@
(param $fd $fd) (param $fd $fd)
;;; The path to a file to unlink. ;;; The path to a file to unlink.
(param $path string) (param $path string)
(result $error $errno) (result $error (expected (error $errno)))
) )
;;; Concurrently poll for the occurrence of a set of events. ;;; Concurrently poll for the occurrence of a set of events.
@@ -451,9 +431,8 @@
(param $out (@witx pointer $event)) (param $out (@witx pointer $event))
;;; Both the number of subscriptions and events. ;;; Both the number of subscriptions and events.
(param $nsubscriptions $size) (param $nsubscriptions $size)
(result $error $errno)
;;; The number of events stored. ;;; The number of events stored.
(result $nevents $size) (result $error (expected $size (error $errno)))
) )
;;; Terminate the process normally. An exit code of 0 indicates successful ;;; Terminate the process normally. An exit code of 0 indicates successful
@@ -462,6 +441,7 @@
(@interface func (export "proc_exit") (@interface func (export "proc_exit")
;;; The exit code returned by the process. ;;; The exit code returned by the process.
(param $rval $exitcode) (param $rval $exitcode)
(@witx noreturn)
) )
;;; Send a signal to the process of the calling thread. ;;; Send a signal to the process of the calling thread.
@@ -469,13 +449,13 @@
(@interface func (export "proc_raise") (@interface func (export "proc_raise")
;;; The signal condition to trigger. ;;; The signal condition to trigger.
(param $sig $signal) (param $sig $signal)
(result $error $errno) (result $error (expected (error $errno)))
) )
;;; Temporarily yield execution of the calling thread. ;;; Temporarily yield execution of the calling thread.
;;; Note: This is similar to `sched_yield` in POSIX. ;;; Note: This is similar to `sched_yield` in POSIX.
(@interface func (export "sched_yield") (@interface func (export "sched_yield")
(result $error $errno) (result $error (expected (error $errno)))
) )
;;; Write high-quality random data into a buffer. ;;; Write high-quality random data into a buffer.
@@ -488,7 +468,7 @@
;;; The buffer to fill with random data. ;;; The buffer to fill with random data.
(param $buf (@witx pointer u8)) (param $buf (@witx pointer u8))
(param $buf_len $size) (param $buf_len $size)
(result $error $errno) (result $error (expected (error $errno)))
) )
;;; Receive a message from a socket. ;;; Receive a message from a socket.
@@ -500,11 +480,8 @@
(param $ri_data $iovec_array) (param $ri_data $iovec_array)
;;; Message flags. ;;; Message flags.
(param $ri_flags $riflags) (param $ri_flags $riflags)
(result $error $errno) ;;; Number of bytes stored in ri_data and message flags.
;;; Number of bytes stored in ri_data. (result $error (expected (tuple $size $roflags) (error $errno)))
(result $ro_datalen $size)
;;; Message flags.
(result $ro_flags $roflags)
) )
;;; Send a message on a socket. ;;; Send a message on a socket.
@@ -516,9 +493,8 @@
(param $si_data $ciovec_array) (param $si_data $ciovec_array)
;;; Message flags. ;;; Message flags.
(param $si_flags $siflags) (param $si_flags $siflags)
(result $error $errno)
;;; Number of bytes transmitted. ;;; Number of bytes transmitted.
(result $so_datalen $size) (result $error (expected $size (error $errno)))
) )
;;; Shut down socket send and receive channels. ;;; Shut down socket send and receive channels.
@@ -527,6 +503,6 @@
(param $fd $fd) (param $fd $fd)
;;; Which channels on the socket to shut down. ;;; Which channels on the socket to shut down.
(param $how $sdflags) (param $how $sdflags)
(result $error $errno) (result $error (expected (error $errno)))
) )
) )