diff --git a/.gitignore b/.gitignore index ea8c4bf..9e6e17c 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ /target +.cargo/ +.vscode/ diff --git a/platform/.gitignore b/platform/.gitignore index 917660a..a6f89c2 100644 --- a/platform/.gitignore +++ b/platform/.gitignore @@ -1 +1 @@ -*.wasm \ No newline at end of file +/target/ \ No newline at end of file diff --git a/platform/Cargo.lock b/platform/Cargo.lock new file mode 100644 index 0000000..e8b57da --- /dev/null +++ b/platform/Cargo.lock @@ -0,0 +1,227 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "ahash" +version = "0.3.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8fd72866655d1904d6b0997d0b07ba561047d070fbe29de039031c641b61217" +dependencies = [ + "const-random", +] + +[[package]] +name = "anyhow" +version = "1.0.47" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38d9ff5d688f1c13395289f67db01d4826b46dd694e7580accdc3e8430f2d98e" + +[[package]] +name = "ariadne" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7080ae01b2f0c312065d4914cd0f0de045eb8832e9415b355106a6cff3073cb4" +dependencies = [ + "yansi", +] + +[[package]] +name = "autocfg" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" + +[[package]] +name = "cc" +version = "1.0.72" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22a9137b95ea06864e018375b72adfb7db6e6f68cfc8df5a04d00288050485ee" + +[[package]] +name = "cdivsufsort" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "edefce019197609da416762da75bb000bbd2224b2d89a7e722c2296cbff79b8c" +dependencies = [ + "cc", + "sacabase", +] + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "chumsky" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c2d3efff85e8572b1c3fa0127706af58c4fff8458f8d9436d54b1e97573c7a3f" +dependencies = [ + "ahash", +] + +[[package]] +name = "const-random" +version = "0.1.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f590d95d011aa80b063ffe3253422ed5aa462af4e9867d43ce8337562bac77c4" +dependencies = [ + "const-random-macro", + "proc-macro-hack", +] + +[[package]] +name = "const-random-macro" +version = "0.1.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "615f6e27d000a2bffbc7f2f6a8669179378fa27ee4d0a509e985dfc0a7defb40" +dependencies = [ + "getrandom", + "lazy_static", + "proc-macro-hack", + "tiny-keccak", +] + +[[package]] +name = "crunchy" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" + +[[package]] +name = "curlywas" +version = "0.1.0" +source = "git+https://github.com/exoticorn/curlywas.git?rev=788a565#788a5657b535448f0532b1481fbfe9a77ee3b5e1" +dependencies = [ + "anyhow", + "ariadne", + "chumsky", + "wasm-encoder", + "wasmparser", +] + +[[package]] +name = "getrandom" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7fcd999463524c52659517fe2cea98493cfe485d10565e7b0fb07dbba7ad2753" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + +[[package]] +name = "lazy_static" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" + +[[package]] +name = "leb128" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "884e2677b40cc8c339eaefcb701c32ef1fd2493d71118dc0ca4b6a736c93bd67" + +[[package]] +name = "libc" +version = "0.2.108" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8521a1b57e76b1ec69af7599e75e38e7b7fad6610f037db8c79b127201b5d119" + +[[package]] +name = "num-traits" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a64b1ec5cda2586e284722486d802acf1f7dbdc623e2bfc57e65ca1cd099290" +dependencies = [ + "autocfg", +] + +[[package]] +name = "pico-args" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db8bcd96cb740d03149cbad5518db9fd87126a10ab519c011893b1754134c468" + +[[package]] +name = "platform" +version = "0.1.0" +dependencies = [ + "anyhow", + "curlywas", + "uw8-tool", +] + +[[package]] +name = "proc-macro-hack" +version = "0.5.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dbf0c48bc1d91375ae5c3cd81e3722dff1abcf81a30960240640d223f59fe0e5" + +[[package]] +name = "sacabase" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9883fc3d6ce3d78bb54d908602f8bc1f7b5f983afe601dabe083009d86267a84" +dependencies = [ + "num-traits", +] + +[[package]] +name = "tiny-keccak" +version = "2.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2c9d3793400a45f954c52e73d068316d76b6f4e36977e3fcebb13a2721e80237" +dependencies = [ + "crunchy", +] + +[[package]] +name = "upkr" +version = "0.1.0" +source = "git+https://github.com/exoticorn/upkr.git?rev=479a2e2#479a2e2c899a7aa24fa1fd9b4ebd371f8bc39f8e" +dependencies = [ + "cdivsufsort", +] + +[[package]] +name = "uw8-tool" +version = "0.1.0" +dependencies = [ + "anyhow", + "pico-args", + "upkr", + "wasm-encoder", + "wasmparser", +] + +[[package]] +name = "wasi" +version = "0.10.2+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6" + +[[package]] +name = "wasm-encoder" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db0c351632e46cc06a58a696a6c11e4cf90cad4b9f8f07a0b59128d616c29bb0" +dependencies = [ + "leb128", +] + +[[package]] +name = "wasmparser" +version = "0.81.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "98930446519f63d00a836efdc22f67766ceae8dbcc1571379f2bcabc6b2b9abc" + +[[package]] +name = "yansi" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fc79f4a1e39857fc00c3f662cbf2651c771f00e9c15fe2abc341806bd46bd71" diff --git a/platform/Cargo.toml b/platform/Cargo.toml new file mode 100644 index 0000000..c1b5c57 --- /dev/null +++ b/platform/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name = "platform" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +curlywas = { git="https://github.com/exoticorn/curlywas.git", rev="788a565" } +uw8-tool = { path="../uw8-tool" } +anyhow = "1" \ No newline at end of file diff --git a/platform/bin/loader.wasm b/platform/bin/loader.wasm new file mode 100644 index 0000000..516bf44 Binary files /dev/null and b/platform/bin/loader.wasm differ diff --git a/platform/bin/platform.uw8 b/platform/bin/platform.uw8 new file mode 100644 index 0000000..811e189 Binary files /dev/null and b/platform/bin/platform.uw8 differ diff --git a/platform/makefile b/platform/makefile deleted file mode 100644 index b61c4d6..0000000 --- a/platform/makefile +++ /dev/null @@ -1,7 +0,0 @@ -all: loader.wasm platform.wasm - -loader.wasm: loader.cwa - curlywas loader.cwa - -platform.wasm: platform.cwa - curlywas platform.cwa \ No newline at end of file diff --git a/platform/loader.cwa b/platform/src/loader.cwa similarity index 99% rename from platform/loader.cwa rename to platform/src/loader.cwa index 84afe31..8b7f67f 100644 --- a/platform/loader.cwa +++ b/platform/src/loader.cwa @@ -186,5 +186,5 @@ start fn unpack_base() { } data 0 { - file("../uw8-tool/base.upk") + file("../target/base.upk") } \ No newline at end of file diff --git a/platform/src/main.rs b/platform/src/main.rs new file mode 100644 index 0000000..2223965 --- /dev/null +++ b/platform/src/main.rs @@ -0,0 +1,16 @@ +use std::{fs::File, path::Path}; +use std::io::prelude::*; + +use anyhow::Result; + +fn main() -> Result<()> { + uw8_tool::BaseModule::create_binary(&Path::new("target/base.upk"))?; + + let loader = curlywas::compile_file("src/loader.cwa")?; + File::create("bin/loader.wasm")?.write_all(&loader)?; + + let platform = curlywas::compile_file("src/platform.cwa")?; + File::create("bin/platform.uw8")?.write_all(&platform)?; + + Ok(()) +} diff --git a/platform/platform.cwa b/platform/src/platform.cwa similarity index 100% rename from platform/platform.cwa rename to platform/src/platform.cwa diff --git a/src/lib.rs b/src/lib.rs index 68f3e5e..46352db 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -28,7 +28,7 @@ impl MicroW8 { let engine = wasmtime::Engine::default(); let loader_module = - wasmtime::Module::new(&engine, include_bytes!("../platform/loader.wasm"))?; + wasmtime::Module::new(&engine, include_bytes!("../platform/bin/loader.wasm"))?; let mut window = Window::new("MicroW8", 320, 240, WindowOptions::default())?; window.limit_update_rate(Some(std::time::Duration::from_micros(16666))); @@ -74,7 +74,7 @@ impl MicroW8 { let loader_instance = linker.instantiate(&mut store, &self.loader_module)?; let load_uw8 = loader_instance.get_typed_func::(&mut store, "load_uw8")?; - let platform_data = include_bytes!("../platform/platform.wasm"); + let platform_data = include_bytes!("../platform/bin/platform.uw8"); memory.data_mut(&mut store)[..platform_data.len()].copy_from_slice(platform_data); let platform_length = load_uw8.call(&mut store, platform_data.len() as i32)? as u32 as usize; let platform_module = wasmtime::Module::new(&self.engine, &memory.data(&store)[..platform_length])?; diff --git a/web/src/main.js b/web/src/main.js index dd45607..d9c05a3 100644 --- a/web/src/main.js +++ b/web/src/main.js @@ -1,5 +1,5 @@ -import loaderUrl from "data-url:../../platform/loader.wasm"; -import platformUrl from "data-url:../../platform/platform.wasm"; +import loaderUrl from "data-url:../../platform/bin/loader.wasm"; +import platformUrl from "data-url:../../platform/bin/platform.uw8"; function setMessage(size, error) { let html = size ? `${size} bytes` : 'Insert cart';