From a704d04a2c2c4821e54acab652bbc81b4fbd7059 Mon Sep 17 00:00:00 2001 From: me Date: Wed, 24 Dec 2025 23:43:34 +0200 Subject: [PATCH] trim deps and make wasm --- .gitignore | 3 + Cargo.lock | 253 +----------------------------------------- Cargo.toml | 8 +- Makefile | 5 +- game.ayin | 2 +- html/index.html | 13 +++ src/ast/types.rs | 12 +- src/lib.rs | 2 +- src/main.rs | 81 ++++++++------ src/parser/scanner.rs | 6 +- 10 files changed, 90 insertions(+), 295 deletions(-) create mode 100644 html/index.html diff --git a/.gitignore b/.gitignore index ea8c4bf..76c9940 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,4 @@ /target +html/*.js +html/*.wasm +html/assets diff --git a/Cargo.lock b/Cargo.lock index 011d4f2..66f9126 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -46,65 +46,12 @@ version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4b46cbb362ab8752921c97e041f5e366ee6297bd428a31275b9fcf1e380f7299" -[[package]] -name = "anstream" -version = "0.6.21" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43d5b281e737544384e969a5ccad3f1cdd24b48086a0fc1b2a5262a26b8f4f4a" -dependencies = [ - "anstyle", - "anstyle-parse", - "anstyle-query", - "anstyle-wincon", - "colorchoice", - "is_terminal_polyfill", - "utf8parse", -] - [[package]] name = "anstyle" version = "1.0.13" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5192cca8006f1fd4f7237516f40fa183bb07f8fbdfedaa0036de5ea9b0b45e78" -[[package]] -name = "anstyle-parse" -version = "0.2.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e7644824f0aa2c7b9384579234ef10eb7efb6a0deb83f9630a49594dd9c15c2" -dependencies = [ - "utf8parse", -] - -[[package]] -name = "anstyle-query" -version = "1.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "40c48f72fd53cd289104fc64099abca73db4166ad86ea0b4341abe65af83dadc" -dependencies = [ - "windows-sys 0.61.2", -] - -[[package]] -name = "anstyle-wincon" -version = "3.0.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "291e6a250ff86cd4a820112fb8898808a366d8f9f58ce16d1f538353ad55747d" -dependencies = [ - "anstyle", - "once_cell_polyfill", - "windows-sys 0.61.2", -] - -[[package]] -name = "ar_archive_writer" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0c269894b6fe5e9d7ada0cf69b5bf847ff35bc25fc271f08e1d080fce80339a" -dependencies = [ - "object", -] - [[package]] name = "autocfg" version = "1.5.0" @@ -115,16 +62,12 @@ checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8" name = "ayin-lang" version = "0.1.0" dependencies = [ - "chumsky", "criterion", - "env_logger", "gamepads", "hotwatch", "insta", - "log", "lyn", "macroquad", - "thiserror", ] [[package]] @@ -163,16 +106,6 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "37b2a672a2cb129a2e41c10b1224bb368f9f37a2b16b612598138befd7b37eb5" -[[package]] -name = "cc" -version = "1.2.49" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90583009037521a116abf44494efecd645ba48b6622457080f080b85544e2215" -dependencies = [ - "find-msvc-tools", - "shlex", -] - [[package]] name = "cfg-if" version = "1.0.4" @@ -185,20 +118,6 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724" -[[package]] -name = "chumsky" -version = "0.11.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "acc17a6284abccac6e50db35c1cee87f605474a72939b959a3a67d9371800efd" -dependencies = [ - "hashbrown", - "regex-automata 0.3.9", - "serde", - "stacker", - "unicode-ident", - "unicode-segmentation", -] - [[package]] name = "ciborium" version = "0.2.2" @@ -257,12 +176,6 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3d7b894f5411737b7867f4827955924d7c254fc9f4d91a6aad6b097804b1018b" -[[package]] -name = "colorchoice" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b05b61dc5112cbb17e4b6cd61790d9845d13888356391624cbe7e41efeac1e75" - [[package]] name = "console" version = "0.15.11" @@ -395,19 +308,6 @@ dependencies = [ "regex", ] -[[package]] -name = "env_logger" -version = "0.11.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "13c863f0904021b108aa8b2f55046443e6b1ebde8fd4a15c399893aae4fa069f" -dependencies = [ - "anstream", - "anstyle", - "env_filter", - "jiff", - "log", -] - [[package]] name = "equivalent" version = "1.0.2" @@ -444,12 +344,6 @@ dependencies = [ "windows-sys 0.60.2", ] -[[package]] -name = "find-msvc-tools" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3a3076410a55c90011c298b04d0cfa770b00fa04e1e3c97d3f6c9de105a03844" - [[package]] name = "flate2" version = "1.1.5" @@ -499,10 +393,7 @@ checksum = "c8c912fc0a5052c6e8fefe36bd3965be5aec4edcedff198461c697c916f50556" dependencies = [ "android_logger", "gilrs", - "js-sys", "log", - "wasm-bindgen", - "web-sys", ] [[package]] @@ -643,12 +534,6 @@ dependencies = [ "mach2", ] -[[package]] -name = "is_terminal_polyfill" -version = "1.70.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a6cb138bb79a146c1bd460005623e142ef0181e3d0219cb493e02f7d08a35695" - [[package]] name = "itertools" version = "0.13.0" @@ -664,30 +549,6 @@ version = "1.0.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7ee5b5339afb4c41626dde77b7a611bd4f2c202b897852b4bcf5d03eddc61010" -[[package]] -name = "jiff" -version = "0.2.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49cce2b81f2098e7e3efc35bc2e0a6b7abec9d34128283d7a26fa8f32a6dbb35" -dependencies = [ - "jiff-static", - "log", - "portable-atomic", - "portable-atomic-util", - "serde_core", -] - -[[package]] -name = "jiff-static" -version = "0.2.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "980af8b43c3ad5d8d349ace167ec8170839f753a42d233ba19e08afe1850fa69" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - [[package]] name = "js-sys" version = "0.3.83" @@ -912,27 +773,12 @@ dependencies = [ "malloc_buf", ] -[[package]] -name = "object" -version = "0.32.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" -dependencies = [ - "memchr", -] - [[package]] name = "once_cell" version = "1.21.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d" -[[package]] -name = "once_cell_polyfill" -version = "1.70.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "384b8ab6d37215f3c5301a95a4accb5d64aa607f1fcb26a11b5303878451b4fe" - [[package]] name = "oorandom" version = "11.1.5" @@ -1009,21 +855,6 @@ dependencies = [ "miniz_oxide", ] -[[package]] -name = "portable-atomic" -version = "1.11.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f84267b20a16ea918e43c6a88433c2d54fa145c92a811b5b047ccbe153674483" - -[[package]] -name = "portable-atomic-util" -version = "0.2.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d8a2f0d8d040d7848a709caf78912debcc3f33ee4b3cac47d73d1e1069e83507" -dependencies = [ - "portable-atomic", -] - [[package]] name = "proc-macro2" version = "1.0.103" @@ -1033,16 +864,6 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "psm" -version = "0.1.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d11f2fedc3b7dafdc2851bc52f277377c5473d378859be234bc7ebb593144d01" -dependencies = [ - "ar_archive_writer", - "cc", -] - [[package]] name = "quad-rand" version = "0.2.3" @@ -1104,19 +925,8 @@ checksum = "843bc0191f75f3e22651ae5f1e72939ab2f72a4bc30fa80a066bd66edefc24d4" dependencies = [ "aho-corasick", "memchr", - "regex-automata 0.4.13", - "regex-syntax 0.8.8", -] - -[[package]] -name = "regex-automata" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "59b23e92ee4318893fa3fe3e6fb365258efbfe6ac6ab30f090cdcbb7aa37efa9" -dependencies = [ - "aho-corasick", - "memchr", - "regex-syntax 0.7.5", + "regex-automata", + "regex-syntax", ] [[package]] @@ -1127,15 +937,9 @@ checksum = "5276caf25ac86c8d810222b3dbb938e512c55c6831a10f3e6ed1c93b84041f1c" dependencies = [ "aho-corasick", "memchr", - "regex-syntax 0.8.8", + "regex-syntax", ] -[[package]] -name = "regex-syntax" -version = "0.7.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dbb5fb1acd8a1a18b3dd5be62d25485eb770e05afb408a9627d14d451bae12da" - [[package]] name = "regex-syntax" version = "0.8.8" @@ -1212,12 +1016,6 @@ dependencies = [ "serde_core", ] -[[package]] -name = "shlex" -version = "1.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" - [[package]] name = "simd-adler32" version = "0.3.8" @@ -1236,19 +1034,6 @@ version = "1.15.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "67b1b7a3b5fe4f1376887184045fcf45c69e92af734b7aaddc05fb777b6fbd03" -[[package]] -name = "stacker" -version = "0.1.22" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e1f8b29fb42aafcea4edeeb6b2f2d7ecd0d969c48b4cf0d2e64aafc471dd6e59" -dependencies = [ - "cc", - "cfg-if", - "libc", - "psm", - "windows-sys 0.59.0", -] - [[package]] name = "syn" version = "2.0.111" @@ -1260,26 +1045,6 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "thiserror" -version = "1.0.69" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6aaf5339b578ea85b50e080feb250a3e8ae8cfcdff9a461c9ec2904bc923f52" -dependencies = [ - "thiserror-impl", -] - -[[package]] -name = "thiserror-impl" -version = "1.0.69" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - [[package]] name = "tinytemplate" version = "1.2.1" @@ -1302,18 +1067,6 @@ version = "1.0.22" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9312f7c4f6ff9069b165498234ce8be658059c6728633667c526e27dc2cf1df5" -[[package]] -name = "unicode-segmentation" -version = "1.12.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6ccf251212114b54433ec949fd6a7841275f9ada20dddd2f29e9ceea4501493" - -[[package]] -name = "utf8parse" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" - [[package]] name = "uuid" version = "1.19.0" diff --git a/Cargo.toml b/Cargo.toml index b5f52b8..145abf9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,13 +21,11 @@ name = "benchmark" harness = false [dependencies] -thiserror = "1" -env_logger = "0.11.8" -log = "0.4.27" macroquad = "0.4.14" lyn = "0.1.0" -chumsky = "0.11.2" -gamepads = "0.1.7" +gamepads = { version = "*", default-features = false } + +[target.'cfg(not(target_arch = "wasm32"))'.dependencies] hotwatch = "0.5.0" [dev-dependencies] diff --git a/Makefile b/Makefile index 598e494..a6c4a6e 100644 --- a/Makefile +++ b/Makefile @@ -21,4 +21,7 @@ review: .PHONY: wasm wasm: - cargo build --target wasm32-unknown-unknown + cargo build --target wasm32-unknown-unknown --release + cp target/wasm32-unknown-unknown/release/ayin.wasm html/ + cp -r assets/ html/ + (cd html/ && wget https://not-fl3.github.io/miniquad-samples/mq_js_bundle.js -O mq_js_bundle.js) diff --git a/game.ayin b/game.ayin index f8fb8a3..05755ab 100644 --- a/game.ayin +++ b/game.ayin @@ -21,7 +21,7 @@ let setup = fn() { .x: (screen_size - dim.w) - dim.w, .y: dim.h * 5, }, - .speed: 260, + .speed: 220, .shot: 1, .shot_timer: 0, }, diff --git a/html/index.html b/html/index.html new file mode 100644 index 0000000..ae90851 --- /dev/null +++ b/html/index.html @@ -0,0 +1,13 @@ + + + + + + Ayin + + + + + + + diff --git a/src/ast/types.rs b/src/ast/types.rs index 8ecc45a..56f9f21 100644 --- a/src/ast/types.rs +++ b/src/ast/types.rs @@ -247,8 +247,16 @@ impl Record { pub const UNIT_VALUE: Value = Value::Record(Record(BTreeMap::new())); pub const UNIT: Expr = Expr::Value(UNIT_VALUE); -#[derive(PartialEq, Debug, thiserror::Error)] pub enum Error { - #[error("Label not found: {0:?}")] LabelNotFound(Label), } + +impl std::fmt::Display for Error { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + Error::LabelNotFound(a) => { + write!(f, "Label not found: {a:?}") + } + } + } +} diff --git a/src/lib.rs b/src/lib.rs index fbed26a..213bdbc 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -105,7 +105,7 @@ let setup = fn() { .b: 254, }, .dir: 1, - }; + } } let update = fn(state) { diff --git a/src/main.rs b/src/main.rs index ef26277..f55fa92 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,10 +1,10 @@ use ayin::runtime::*; +#[cfg(not(target_arch = "wasm32"))] use hotwatch::{self}; use macroquad::prelude::*; -use std::{ - sync::{Arc, RwLock}, - time::Duration, -}; +use std::sync::{Arc, RwLock}; +#[cfg(not(target_arch = "wasm32"))] +use std::time::Duration; fn window_conf() -> Conf { Conf { @@ -18,40 +18,15 @@ fn window_conf() -> Conf { #[macroquad::main(window_conf)] async fn main() { - env_logger::init(); info!("Hello, 👁️‍🗨️!"); if screen_width() < SCREEN_WIDTH { request_new_screen_size(SCREEN_WIDTH as f32, SCREEN_HEIGHT as f32); } rand::srand(macroquad::miniquad::date::now() as _); - let args: Vec = std::env::args().collect(); - let file = args[1].clone(); + let reader = hotwatch(); - let writer = Arc::new(RwLock::new(None)); - let reader = writer.clone(); - let mut hotwatch = hotwatch::Hotwatch::new_with_custom_delay(Duration::from_millis(100)) - .expect("hotwatch failed to initialize!"); - hotwatch - .watch(file.clone(), move |event: hotwatch::Event| { - if let hotwatch::EventKind::Modify(_) = event.kind { - match std::fs::read_to_string(file.clone()) { - Err(err) => println!("Error: {err:#?}"), - Ok(txt) => match ayin::parser::parse_file(txt) { - Err(err) => println!("Error: {err:#?}"), - Ok(program) => { - let mut w = writer.write().unwrap(); - *w = Some(program); - } - }, - } - } - }) - .expect("failed to watch file!"); - - let file = args[1].clone(); - - match std::fs::read_to_string(file) { + match read_file() { Err(err) => println!("Error: {err:#?}"), Ok(txt) => match ayin::parser::parse_file(txt) { Err(err) => println!("Error: {err:#?}"), @@ -82,3 +57,47 @@ async fn main() { }, } } + +#[cfg(not(target_arch = "wasm32"))] +fn read_file() -> std::io::Result { + let args: Vec = std::env::args().collect(); + let file = args[1].clone(); + std::fs::read_to_string(file) +} +#[cfg(target_arch = "wasm32")] +fn read_file() -> std::io::Result { + Ok(include_str!("../game.ayin").to_string()) +} + +#[cfg(not(target_arch = "wasm32"))] +fn hotwatch() -> Arc>> { + let writer = Arc::new(RwLock::new(None)); + let reader = writer.clone(); + let args: Vec = std::env::args().collect(); + let file = args[1].clone(); + let mut hotwatch = hotwatch::Hotwatch::new_with_custom_delay(Duration::from_millis(100)) + .expect("hotwatch failed to initialize!"); + hotwatch + .watch(file.clone(), move |event: hotwatch::Event| { + if let hotwatch::EventKind::Modify(_) = event.kind { + match std::fs::read_to_string(file.clone()) { + Err(err) => println!("Error: {err:#?}"), + Ok(txt) => match ayin::parser::parse_file(txt) { + Err(err) => println!("Error: {err:#?}"), + Ok(program) => { + let mut w = writer.write().unwrap(); + *w = Some(program); + } + }, + } + } + }) + .expect("failed to watch file!"); + reader +} +#[cfg(target_arch = "wasm32")] +fn hotwatch() -> Arc>> { + let writer = Arc::new(RwLock::new(None)); + let reader = writer.clone(); + reader +} diff --git a/src/parser/scanner.rs b/src/parser/scanner.rs index 62a632f..452e15f 100644 --- a/src/parser/scanner.rs +++ b/src/parser/scanner.rs @@ -1,6 +1,4 @@ use super::types::*; -use chumsky::text::Char; -use log; use lyn; pub struct Scanner { @@ -251,7 +249,7 @@ pub fn scan(source: String) -> Tokens { '#' => { let mut str = "".to_string(); while let Some(ch) = scanner.pop() { - if ch.is_newline() { + if *ch == '\n' { break; } str.push(*ch); @@ -316,7 +314,7 @@ pub fn scan(source: String) -> Tokens { } // error _ => { - log::error!("Unexpected character: {c}"); + println!("Unexpected character: {c}"); } } } else {