Capture correct return type
This commit is contained in:
@@ -2,21 +2,21 @@ extern crate proc_macro;
|
|||||||
|
|
||||||
use proc_macro::TokenStream;
|
use proc_macro::TokenStream;
|
||||||
use quote::quote;
|
use quote::quote;
|
||||||
use syn::{FnArg, ArgCaptured, Pat, PatIdent, TypeReference, Type, Token};
|
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
use syn::{ArgCaptured, FnArg, Pat, PatIdent, Token, Type, TypeReference};
|
||||||
|
|
||||||
#[proc_macro_attribute]
|
#[proc_macro_attribute]
|
||||||
pub fn wasi_common_cbindgen(attr: TokenStream, function: TokenStream) -> TokenStream {
|
pub fn wasi_common_cbindgen(attr: TokenStream, function: TokenStream) -> TokenStream {
|
||||||
assert!(attr.is_empty());
|
assert!(attr.is_empty());
|
||||||
|
|
||||||
let function = syn::parse_macro_input!(function as syn::ItemFn);
|
let function = syn::parse_macro_input!(function as syn::ItemFn);
|
||||||
|
|
||||||
// generate C fn name prefixed with __wasi_
|
// generate C fn name prefixed with __wasi_
|
||||||
let ident = &function.ident;
|
let ident = &function.ident;
|
||||||
let concatenated = format!("__wasi_{}", ident);
|
let concatenated = format!("__wasi_{}", ident);
|
||||||
let c_fn_ident = syn::Ident::new(&concatenated, ident.span());
|
let c_fn_ident = syn::Ident::new(&concatenated, ident.span());
|
||||||
|
|
||||||
// capture signature
|
// capture input args
|
||||||
let mut arg_ident = Vec::new();
|
let mut arg_ident = Vec::new();
|
||||||
let mut arg_type = Vec::new();
|
let mut arg_type = Vec::new();
|
||||||
for input in &function.decl.inputs {
|
for input in &function.decl.inputs {
|
||||||
@@ -43,8 +43,8 @@ pub fn wasi_common_cbindgen(attr: TokenStream, function: TokenStream) -> TokenSt
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
println!("{:#?}", arg_ident);
|
// capture output arg
|
||||||
println!("{:#?}", arg_type);
|
let output = &function.decl.output;
|
||||||
|
|
||||||
let result = quote! {
|
let result = quote! {
|
||||||
#function
|
#function
|
||||||
@@ -53,7 +53,8 @@ pub fn wasi_common_cbindgen(attr: TokenStream, function: TokenStream) -> TokenSt
|
|||||||
#(
|
#(
|
||||||
#arg_ident: #arg_type,
|
#arg_ident: #arg_type,
|
||||||
)*
|
)*
|
||||||
) {
|
) #output {
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user