Browse Source

wiggle: wip!!

pch/resource_table
Pat Hickey 11 months ago
parent
commit
28039d55a6
  1. 4
      crates/wiggle/generate/src/codegen_settings.rs
  2. 17
      crates/wiggle/generate/src/config.rs
  3. 2
      crates/wiggle/macro/src/lib.rs

4
crates/wiggle/generate/src/codegen_settings.rs

@ -19,6 +19,8 @@ pub struct CodegenSettings {
/// Determine whether the context structure will use `&mut self` (true) or
/// simply `&self`.
pub mutable: bool,
/// Do
pub resource_table: bool,
}
impl CodegenSettings {
pub fn new(
@ -28,6 +30,7 @@ impl CodegenSettings {
wasmtime: bool,
tracing: &TracingConf,
mutable: bool,
resource_table: bool,
) -> Result<Self, Error> {
let errors = ErrorTransform::new(error_conf, doc)?;
Ok(Self {
@ -36,6 +39,7 @@ impl CodegenSettings {
wasmtime,
tracing: tracing.clone(),
mutable,
resource_table,
})
}
pub fn get_async(&self, module: &Module, func: &InterfaceFunc) -> Asyncness {

17
crates/wiggle/generate/src/config.rs

@ -17,6 +17,7 @@ pub struct Config {
pub wasmtime: bool,
pub tracing: TracingConf,
pub mutable: bool,
pub resource_table: bool,
}
mod kw {
@ -30,6 +31,7 @@ mod kw {
syn::custom_keyword!(tracing);
syn::custom_keyword!(disable_for);
syn::custom_keyword!(trappable);
syn::custom_keyword!(resource_table);
}
#[derive(Debug, Clone)]
@ -40,6 +42,7 @@ pub enum ConfigField {
Wasmtime(bool),
Tracing(TracingConf),
Mutable(bool),
ResourceTable(bool),
}
impl Parse for ConfigField {
@ -90,6 +93,12 @@ impl Parse for ConfigField {
input.parse::<kw::mutable>()?;
input.parse::<Token![:]>()?;
Ok(ConfigField::Mutable(input.parse::<syn::LitBool>()?.value))
} else if lookahead.peek(kw::resource_table) {
input.parse::<kw::resource_table>()?;
input.parse::<Token![:]>()?;
Ok(ConfigField::ResourceTable(
input.parse::<syn::LitBool>()?.value,
))
} else {
Err(lookahead.error())
}
@ -104,6 +113,7 @@ impl Config {
let mut wasmtime = None;
let mut tracing = None;
let mut mutable = None;
let mut resource_table = None;
for f in fields {
match f {
ConfigField::Witx(c) => {
@ -142,6 +152,12 @@ impl Config {
}
mutable = Some(c);
}
ConfigField::ResourceTable(c) => {
if resource_table.is_some() {
return Err(Error::new(err_loc, "duplicate `resource_table` field"));
}
resource_table = Some(c);
}
}
}
Ok(Config {
@ -153,6 +169,7 @@ impl Config {
wasmtime: wasmtime.unwrap_or(true),
tracing: tracing.unwrap_or_default(),
mutable: mutable.unwrap_or(true),
resource_table: mutable.unwrap_or_default(),
})
}

2
crates/wiggle/macro/src/lib.rs

@ -158,6 +158,7 @@ pub fn from_witx(args: TokenStream) -> TokenStream {
config.wasmtime,
&config.tracing,
config.mutable,
config.resource_table,
)
.expect("validating codegen settings");
@ -200,6 +201,7 @@ pub fn wasmtime_integration(args: TokenStream) -> TokenStream {
true,
&config.c.tracing,
config.c.mutable,
config.c.resource_table,
)
.expect("validating codegen settings");

Loading…
Cancel
Save