mirror of
				https://github.com/bspeice/qadapt
				synced 2025-10-31 09:30:37 -04:00 
			
		
		
		
	Start work on a procedural macro
Turns out the system still needs some work.
This commit is contained in:
		
							
								
								
									
										3
									
								
								qadapt-macro/.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								qadapt-macro/.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @ -0,0 +1,3 @@ | ||||
| /target | ||||
| **/*.rs.bk | ||||
| Cargo.lock | ||||
							
								
								
									
										9
									
								
								qadapt-macro/Cargo.toml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								qadapt-macro/Cargo.toml
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,9 @@ | ||||
| [package] | ||||
| name = "qadapt-macro" | ||||
| version = "0.1.0" | ||||
| authors = ["Bradlee Speice <bradlee@speice.io>"] | ||||
|  | ||||
| [lib] | ||||
| proc-macro = true | ||||
|  | ||||
| [dependencies] | ||||
							
								
								
									
										31
									
								
								qadapt-macro/src/lib.rs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										31
									
								
								qadapt-macro/src/lib.rs
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,31 @@ | ||||
| //! Helper macros to use with the QADAPT allocator system | ||||
| //!  | ||||
| //! This crate is unusable on its own, but because `proc_macro` crates | ||||
| //! can't export non-proc-macro symbols, we have to go through an extra step | ||||
| //! to move these up. | ||||
| //!  | ||||
| //! Ultimately, this does actually work because we don't need to actually use | ||||
| //! references to the underlying functionality here, we just need to know | ||||
| //! where they will ultimately end up at. | ||||
| // TODO: This causes issues, but I can't track down why | ||||
| // #![deny(missing_docs)] | ||||
| extern crate proc_macro; | ||||
|  | ||||
| use proc_macro::TokenTree; | ||||
| use proc_macro::TokenStream; | ||||
|  | ||||
| /// Set up the QADAPT allocator to trigger a panic if any allocations happen during | ||||
| /// this function. Race conditions between threads are not checked, this macro will | ||||
| /// only work as intended in a single-threaded or otherwise synchronized environment. | ||||
| #[proc_macro_attribute] | ||||
| pub fn allocate_panic(_attr: TokenStream, item: TokenStream) -> TokenStream { | ||||
|     let ret = item.clone(); | ||||
|  | ||||
|     let mut token_iter = item.into_iter(); | ||||
|     match token_iter.next() { | ||||
|         Some(TokenTree::Ident(ref i)) if i.to_string() == "fn" => (), | ||||
|         _ => panic!("#[allocate_panic] macro can only be applied to functions") | ||||
|     } | ||||
|  | ||||
|     ret | ||||
| } | ||||
		Reference in New Issue
	
	Block a user