diff --git a/bent/Cargo.toml b/bent/Cargo.toml index 7c3fd50..e00aed4 100644 --- a/bent/Cargo.toml +++ b/bent/Cargo.toml @@ -10,4 +10,11 @@ keywords.workspace = true # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +[lib] +crate-type = ["cdylib"] + [dependencies] +wasm-bindgen = "0.2" + +[profile.release] +lto = true diff --git a/bent/assets/bent.svg b/bent/assets/bent.svg new file mode 100644 index 0000000..60b8b98 --- /dev/null +++ b/bent/assets/bent.svg @@ -0,0 +1,12 @@ + + + + + \ No newline at end of file diff --git a/bent/assets/path-generator.py b/bent/assets/path-generator.py new file mode 100644 index 0000000..1af8d68 --- /dev/null +++ b/bent/assets/path-generator.py @@ -0,0 +1,15 @@ +p = lambda x: print(x, end=" ") + + +def line(coords: tuple[tuple[int]]): + p(f"M {coords[0][0]} {coords[0][1]} L {coords[1][0]} {coords[1][1]}") + + +n = 100 +line(((0, 0), (n, n))) +line(((n, 0), (0, n))) +for i in range(1, n): + line(((i, 0), (n - i, n))) + line(((0, i), (n, n - i))) + +print() diff --git a/bent/index.html b/bent/index.html new file mode 100644 index 0000000..6a253de --- /dev/null +++ b/bent/index.html @@ -0,0 +1,36 @@ + + + + + + BENT + + + + + + + +
+

BENT

+
+ +
+

+ + +

+ + +
+ + + \ No newline at end of file diff --git a/bent/src/js.rs b/bent/src/js.rs new file mode 100644 index 0000000..a78e4b1 --- /dev/null +++ b/bent/src/js.rs @@ -0,0 +1,7 @@ +use wasm_bindgen::prelude::*; + +#[wasm_bindgen] +extern "C" { + #[wasm_bindgen(js_namespace = console)] + pub fn log(a: &str); +} diff --git a/bent/src/lib.rs b/bent/src/lib.rs new file mode 100644 index 0000000..d26acc3 --- /dev/null +++ b/bent/src/lib.rs @@ -0,0 +1,10 @@ +use wasm_bindgen::prelude::*; +#[allow(unused_macros)] +#[macro_use] +pub mod macros; +pub mod js; + +#[wasm_bindgen] +pub fn greet(name: &str) { + println!("Hello, {name}!"); +} diff --git a/bent/src/macros.rs b/bent/src/macros.rs new file mode 100644 index 0000000..7d9c941 --- /dev/null +++ b/bent/src/macros.rs @@ -0,0 +1,27 @@ +macro_rules! println { + ($($t:tt)*) => (crate::js::log(&format_args!($($t)*).to_string())) +} + +macro_rules! dbg { + // NOTE: We cannot use `concat!` to make a static string as a format argument + // of `eprintln!` because `file!` could contain a `{` or + // `$val` expression could be a block (`{ .. }`), in which case the `eprintln!` + // will be malformed. + () => { + println!("[{}:{}:{}]", file!(), line!(), column!()) + }; + ($val:expr $(,)?) => { + // Use of `match` here is intentional because it affects the lifetimes + // of temporaries - https://stackoverflow.com/a/48732525/1063961 + match $val { + tmp => { + println!("[{}:{}:{}] {} = {:#?}", + file!(), line!(), column!(), stringify!($val), &tmp); + tmp + } + } + }; + ($($val:expr),+ $(,)?) => { + ($(dbg!($val)),+,) + }; +} diff --git a/bent/src/main.rs b/bent/src/main.rs deleted file mode 100644 index e7a11a9..0000000 --- a/bent/src/main.rs +++ /dev/null @@ -1,3 +0,0 @@ -fn main() { - println!("Hello, world!"); -}