Skip to content

Instantly share code, notes, and snippets.

View CensoredUsername's full-sized avatar

CensoredUsername CensoredUsername

View GitHub Profile
extern crate proc_macro;
use quote::quote;
use proc_macro2::{TokenTree, TokenStream};
#[proc_macro]
pub fn why(tokens: proc_macro::TokenStream) -> proc_macro::TokenStream {
use quote::ToTokens;
let a = quote! { 1 + 2 };
// delimit a to maintain correct precedence behaviour
$ cargo build
Compiling normal_macro v0.1.0 (C:\Users\Maurits\Projects\macro_bug\normal_macro)
error[E0425]: cannot find value `a` in this scope
--> src\main.rs:5:43
|
5 | ($test:expr) => {proc_macro::forward!($test)}
| ^^^^^ not found in this scope
...
12 | println!("{}", forward!(a));
| ----------- in this macro invocation
const float EPSILON = 0.01;
const float MAX_DISTANCE = 100.;
const float SCREEN_DISTANCE = 2.;
const int MAX_ITER = 100;
// why o why does webGL not support inverse(mat3);
mat3 inv(mat3 m) {
float a00 = m[0][0], a01 = m[0][1], a02 = m[0][2];
float a10 = m[1][0], a11 = m[1][1], a12 = m[1][2];
float a20 = m[2][0], a21 = m[2][1], a22 = m[2][2];
; excerpt from loop_notrash as it got inlined in here
loc_140001050:
xor esi, esi
xor eax, eax
loc_140001054:
mov rcx, rax
lea rax, [rcx+rsi*2-2]
mov rdx, rsi
nop
$ cargo bench
Finished release [optimized] target(s) in 0.0 secs
Running target\release\deps\benching-22b624a5099107eb.exe
running 2 tests
test tests::loop_notrash ... bench: 1,053,106 ns/iter (+/- 162,958)
test tests::loop_trash ... bench: 1,458,335 ns/iter (+/- 149,239)
test result: ok. 0 passed; 0 failed; 0 ignored; 2 measured