replace more custom idents with Names

This commit is contained in:
Pat Hickey
2020-06-22 18:54:07 -07:00
parent 1050c6d99c
commit 09971bc090

View File

@@ -1,5 +1,5 @@
use proc_macro::TokenStream; use proc_macro::TokenStream;
use proc_macro2::{Ident, Span, TokenStream as TokenStream2}; use proc_macro2::{Ident, TokenStream as TokenStream2};
use quote::{format_ident, quote}; use quote::{format_ident, quote};
use syn::parse_macro_input; use syn::parse_macro_input;
use wiggle_generate::Names; use wiggle_generate::Names;
@@ -32,12 +32,14 @@ fn generate(doc: &witx::Document, names: &Names) -> TokenStream2 {
let mut ctor_fields = Vec::new(); let mut ctor_fields = Vec::new();
let mut linker_add = Vec::new(); let mut linker_add = Vec::new();
let runtime = names.runtime_mod();
for module in doc.modules() { for module in doc.modules() {
let module_name = module.name.as_str(); let module_name = module.name.as_str();
let module_id = Ident::new(module_name, Span::call_site()); let module_id = names.module(&module.name);
for func in module.funcs() { for func in module.funcs() {
let name = func.name.as_str(); let name = func.name.as_str();
let name_ident = Ident::new(name, Span::call_site()); let name_ident = names.func(&func.name);
fields.push(quote! { pub #name_ident: wasmtime::Func }); fields.push(quote! { pub #name_ident: wasmtime::Func });
get_exports.push(quote! { #name => Some(&self.#name_ident) }); get_exports.push(quote! { #name => Some(&self.#name_ident) });
ctor_fields.push(name_ident.clone()); ctor_fields.push(name_ident.clone());
@@ -217,8 +219,8 @@ fn generate(doc: &witx::Document, names: &Names) -> TokenStream2 {
// or expose the memory via non-wiggle mechanisms. // or expose the memory via non-wiggle mechanisms.
// Therefore, creating a new BorrowChecker at the // Therefore, creating a new BorrowChecker at the
// root of each function invocation is correct. // root of each function invocation is correct.
let bc = wasmtime_wiggle::BorrowChecker::new(); let bc = #runtime::BorrowChecker::new();
let mem = wasmtime_wiggle::WasmtimeGuestMemory::new( mem, bc ); let mem = #runtime::WasmtimeGuestMemory::new( mem, bc );
wasi_common::wasi::#module_id::#name_ident( wasi_common::wasi::#module_id::#name_ident(
&mut my_cx.borrow_mut(), &mut my_cx.borrow_mut(),
&mem, &mem,
@@ -231,6 +233,8 @@ fn generate(doc: &witx::Document, names: &Names) -> TokenStream2 {
} }
} }
let ctx_type = names.ctx_type();
quote! { quote! {
/// An instantiated instance of the wasi exports. /// An instantiated instance of the wasi exports.
/// ///
@@ -249,7 +253,7 @@ fn generate(doc: &witx::Document, names: &Names) -> TokenStream2 {
/// External values are allocated into the `store` provided and /// External values are allocated into the `store` provided and
/// configuration of the wasi instance itself should be all /// configuration of the wasi instance itself should be all
/// contained in the `cx` parameter. /// contained in the `cx` parameter.
pub fn new(store: &wasmtime::Store, cx: WasiCtx) -> Wasi { pub fn new(store: &wasmtime::Store, cx: #ctx_type) -> Wasi {
let cx = std::rc::Rc::new(std::cell::RefCell::new(cx)); let cx = std::rc::Rc::new(std::cell::RefCell::new(cx));
#(#ctor_externs)* #(#ctor_externs)*