-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
be92ba0
commit 32cbe7e
Showing
13 changed files
with
232 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
use crate::Symbol; | ||
|
||
#[derive(Debug)] | ||
pub struct Struct { | ||
pub name: &'static str, | ||
pub constructor: Option<Symbol>, | ||
pub methods: &'static [Symbol], | ||
} | ||
|
||
pub enum Inventory { | ||
Symbol(Symbol), | ||
Struct(Struct), | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
use proc_macro2::TokenStream as TokenStream2; | ||
use syn::ItemImpl; | ||
|
||
use crate::util::{self, Result}; | ||
|
||
pub fn handle(impl_: ItemImpl) -> Result<TokenStream2> { | ||
if impl_.generics.params.first().is_some() { | ||
return Err(util::Error::Generics); | ||
} | ||
|
||
if impl_.generics.where_clause.is_some() { | ||
return Err(util::Error::WhereClause); | ||
} | ||
|
||
let self_ty = match *impl_.self_ty { | ||
syn::Type::Path(ref type_path) => type_path.path.clone(), | ||
_ => return Err(util::Error::UnsupportedType), | ||
}; | ||
|
||
let ref ty_str @ _ = self_ty.get_ident().unwrap(); | ||
|
||
// TODO: | ||
// - create a new quoted function for each method and codegen using fn_::handle | ||
// where first arg is self ptr and rest are method args | ||
// - constructor is a simply special case with no self ptr. | ||
// - we also need to be aware of &mut self and Self types. | ||
|
||
Ok(quote::quote! { | ||
#impl_ | ||
|
||
const _: () = { | ||
// Assert that the type implements `BindgenType`. | ||
const fn _assert_impl<T: ::deno_bindgen::BindgenType>() {} | ||
_assert_impl::<#ty_str>(); | ||
|
||
#[deno_bindgen::linkme::distributed_slice(deno_bindgen::INVENTORY)] | ||
pub static _B: deno_bindgen::Inventory = deno_bindgen::Inventory::Struct( | ||
deno_bindgen::inventory::Struct { | ||
name: stringify!(#ty_str), | ||
constructor: None, | ||
methods: &[], | ||
} | ||
); | ||
}; | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
use proc_macro2::TokenStream as TokenStream2; | ||
use syn::ItemStruct; | ||
|
||
use crate::util::{self, Result}; | ||
|
||
pub fn handle(struct_: ItemStruct) -> Result<TokenStream2> { | ||
if struct_.generics.params.first().is_some() { | ||
return Err(util::Error::Generics); | ||
} | ||
|
||
if struct_.generics.where_clause.is_some() { | ||
return Err(util::Error::WhereClause); | ||
} | ||
|
||
let ref ty_str @ _ = struct_.ident; | ||
Ok(quote::quote! { | ||
#struct_ | ||
|
||
impl ::deno_bindgen::BindgenType for #ty_str { | ||
fn type_name() -> &'static str { | ||
stringify!(#ty_str) | ||
} | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.