mirror of
https://github.com/exoticorn/microw8.git
synced 2026-11-16 07:17:19 +01:00
Compare commits
3
Commits
b7e8ddf0f1
...
26206a312a
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
26206a312a | ||
|
|
6a75988489 | ||
|
|
397ff19d80 |
No files matched your search
Generated
+54
@@ -674,6 +674,15 @@ version = "0.11.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e"
|
||||
|
||||
[[package]]
|
||||
name = "heck"
|
||||
version = "0.3.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6d621efb26863f0e9924c6ac577e8275e5e6b77455db64ffa6c65c904e9e132c"
|
||||
dependencies = [
|
||||
"unicode-segmentation",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "hermit-abi"
|
||||
version = "0.1.19"
|
||||
@@ -698,6 +707,12 @@ version = "2.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4"
|
||||
|
||||
[[package]]
|
||||
name = "id-arena"
|
||||
version = "2.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "25a2bc672d1148e28034f176e01fffebb08b35768468cc954630da77a1449005"
|
||||
|
||||
[[package]]
|
||||
name = "indexmap"
|
||||
version = "1.7.0"
|
||||
@@ -1529,6 +1544,12 @@ version = "1.15.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "dcf81ac59edc17cc8697ff311e8f5ef2d99fcbd9817b34cec66f90b6c3dfd987"
|
||||
|
||||
[[package]]
|
||||
name = "unicode-segmentation"
|
||||
version = "1.8.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8895849a949e7845e06bd6dc1aa51731a103c42707010a5b591c0038fb73385b"
|
||||
|
||||
[[package]]
|
||||
name = "unicode-width"
|
||||
version = "0.1.9"
|
||||
@@ -1585,6 +1606,7 @@ dependencies = [
|
||||
"pbr",
|
||||
"pico-args",
|
||||
"upkr",
|
||||
"walrus",
|
||||
"wasm-encoder",
|
||||
"wasmparser 0.81.0",
|
||||
]
|
||||
@@ -1618,6 +1640,32 @@ dependencies = [
|
||||
"winapi-util",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "walrus"
|
||||
version = "0.19.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4eb08e48cde54c05f363d984bb54ce374f49e242def9468d2e1b6c2372d291f8"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"id-arena",
|
||||
"leb128",
|
||||
"log",
|
||||
"walrus-macro",
|
||||
"wasmparser 0.77.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "walrus-macro"
|
||||
version = "0.19.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0a6e5bd22c71e77d60140b0bd5be56155a37e5bd14e24f5f87298040d0cc40d7"
|
||||
dependencies = [
|
||||
"heck",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasi"
|
||||
version = "0.10.2+wasi-snapshot-preview1"
|
||||
@@ -1687,6 +1735,12 @@ dependencies = [
|
||||
"leb128",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasmparser"
|
||||
version = "0.77.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b35c86d22e720a07d954ebbed772d01180501afe7d03d464f413bb5f8914a8d6"
|
||||
|
||||
[[package]]
|
||||
name = "wasmparser"
|
||||
version = "0.80.2"
|
||||
|
||||
@@ -13,7 +13,11 @@ data 0x20000 {
|
||||
i8(14, 10, 10, 10) // scroll down 2 lines
|
||||
i8(31, 40, 3, 14, 10, 15, 0xf0) "Other colors"
|
||||
i8(24, 0xb0) "inverted"
|
||||
i8(13, 10, 8, 8) "->"
|
||||
i8(10, 10, 9, 9, 1) "|<-"
|
||||
i8(5, 31, 7, 28+17, 15, 0xe3) "Graphics text!"
|
||||
i8(5, 31, 6, 28+16, 15, 0xe5) "Graphics text!"
|
||||
i8(4, 24, 14, 10, 0x90, 0x80, 0xf1)
|
||||
i8(31, 37, 29, 0xf1, 0x80, 0x90)
|
||||
i8(0)
|
||||
}
|
||||
@@ -1,2 +1,3 @@
|
||||
rustc --target=wasm32-unknown-unknown --crate-type cdylib -C opt-level="z" -C "link-args=--import-memory --initial-memory=262144 -zstack-size=65536" -o tunnel.wasm tunnel.rs && \
|
||||
uw8 filter-exports tunnel.wasm tunnel.wasm && \
|
||||
wasm-opt -Oz -o tunnel.wasm tunnel.wasm
|
||||
@@ -5,8 +5,8 @@ A nightly rust compiler is needed for the unstable sqrtf32
|
||||
intrinsic.
|
||||
|
||||
Simply compiling with rustc as shown in build.sh results in a
|
||||
342 byte tunnel.wasm. Using wasm-opt this can be reduced to
|
||||
243 bytes.
|
||||
371 byte tunnel.wasm. Using wasm-opt this can be reduced to
|
||||
260 bytes.
|
||||
|
||||
When you disassemble this wasm file using wasm2wat you can see
|
||||
these globals and exports:
|
||||
@@ -18,8 +18,10 @@ these globals and exports:
|
||||
|
||||
They are meant to be used for heap allocations and stack for any
|
||||
values that are not simple scalars (i32, f32, etc.). Since our
|
||||
code doesn't actually use any of that, we can just delete them
|
||||
in a text editor and assemble the code again with wat2wasm.
|
||||
code doesn't actually use any of that, the globals are only
|
||||
referenced by the exports and we can remove them using
|
||||
'uw8 filter-exports' (preferably before running wasm-opt) which
|
||||
removes all exports except those used by the MicroW8 platform.
|
||||
|
||||
This gives us a 199 byte wasm file. Running this through
|
||||
uw8-tool pack brings us to the final size of 137 bytes.
|
||||
This gives us a 216 byte wasm file. Running this through
|
||||
uw8 pack brings us to the final size of 119 bytes.
|
||||
+11
-3
@@ -9,12 +9,20 @@ mod env {
|
||||
extern "C" {
|
||||
pub fn atan2(x: f32, y: f32) -> f32;
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
pub fn time() -> f32;
|
||||
}
|
||||
}
|
||||
|
||||
fn atan2(x: f32, y: f32) -> f32 {
|
||||
unsafe { env::atan2(x, y) }
|
||||
}
|
||||
|
||||
fn time() -> f32 {
|
||||
unsafe { env::time() }
|
||||
}
|
||||
|
||||
fn sqrt(v: f32) -> f32 {
|
||||
unsafe { core::intrinsics::sqrtf32(v) }
|
||||
}
|
||||
@@ -29,14 +37,14 @@ fn ftoi(v: f32) -> i32 {
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub fn tic(time: i32) {
|
||||
pub fn upd() {
|
||||
for i in 0..320 * 240 {
|
||||
let t = time as f32 / 10 as f32;
|
||||
let t = time() * 63 as f32;
|
||||
let x = (i % 320 - 160) as f32;
|
||||
let y = (i / 320 - 120) as f32;
|
||||
let d = 40000 as f32 / sqrt(x * x + y * y + 1 as f32);
|
||||
let u = atan2(x, y) * 512f32 / 3.141;
|
||||
let c = (ftoi(d + t * 2 as f32) ^ ftoi(u + t)) as u8;
|
||||
let c = (ftoi(d + t * 2 as f32) ^ ftoi(u + t)) as u8 >> 4;
|
||||
unsafe {
|
||||
*((120 + i) as *mut u8) = c;
|
||||
}
|
||||
|
||||
Binary file not shown.
Binary file not shown.
@@ -326,7 +326,7 @@ fn printSingleChar(char: i32) {
|
||||
|
||||
if char == 4 | char == 5 {
|
||||
graphicsText = char == 5;
|
||||
textCursorX = 0;
|
||||
textCursorX = 0;
|
||||
textCursorY = 0;
|
||||
return;
|
||||
}
|
||||
@@ -341,6 +341,9 @@ fn printSingleChar(char: i32) {
|
||||
}
|
||||
|
||||
if char == 9 {
|
||||
if !graphicsText & textCursorX >= 320 {
|
||||
printChar(0xd0a);
|
||||
}
|
||||
textCursorX = textCursorX + 8;
|
||||
return;
|
||||
}
|
||||
@@ -406,6 +409,10 @@ fn printSingleChar(char: i32) {
|
||||
return;
|
||||
}
|
||||
|
||||
if char < 31 {
|
||||
return;
|
||||
}
|
||||
|
||||
drawChar(char);
|
||||
}
|
||||
|
||||
|
||||
@@ -120,7 +120,7 @@ possible but no examples are provided, yet.
|
||||
|
||||
## Examples
|
||||
* [Fireworks](v0.1pre5#AgwvgP+M59snqjl4CMKw5sqm1Zw9yJCbSviMjeLUdHus2a3yl/a99+uiBeqZgP/2jqSjrLjRk73COMM6OSLpsxK8ugT1kuk/q4hQUqqPpGozHoa0laulzGGcahzdfdJsYaK1sIdeIYS9M5PnJx/Wk9H+PvWEPy2Zvv7I6IW7Fg==) (127 bytes): Some fireworks to welcome 2022.
|
||||
* [Skip Ahead](v0.1pre4#AiP94km33q5hBFbBcKl2W1ZMY67wHByUz15/qRHIr71Dvq8bTVux/DXZzSTKU5MufRXxnGEn6mOul4dil/5WLT1Y+Y/4TGd1E3U4rQaxlpcKObxc5YLdr4xo6jyBND96a569LoECv6Q4EIqxJi+3QPE21r/++js41XsBLr44X/O2XpP3kHQva3B8o6duD5WkLCf7PhsxjTBeND1ADIaJe05JCrBim18RPY9VYFmltqQ9gVzbxE/ZpojR/GJ4aCbx0hRn73RPhpA7Cd4jk0AVSOeRx+7kuHrLzpaeqeYWK5pYd/4Rv+8=) (230 bytes): A port of my [TIC-80 256byte game](http://tic80.com/play?cart=1735) from LoveByte'21
|
||||
* [Skip Ahead](v0.1pre5#AgyfpZ80wkW28kiUZ9VIK4v+RPnVxqjK1dz2BcDoNyQPsS2g4OgEzkTe6jyoAfFOmqKrS8SM2aRljBal9mjNn8i4fP9eBK+RehQKxxGtJa9FqftvqEnh3ez1YaYxqj7jgTdzJ/WAYVmKMovBT1myrX3FamqKSOgMsNedLhVTLAhQup3sNcYEjGNo8b0HZ5+AgMgCwYRGCe//XQOMAaAAzqDILgmpEZ/43RKHcQpHEQwbURfNQJpadJe2sz3q5FlQnTGXQ9oSMokidhlC+aR/IpNHieuBGLhFZ2GfnwVQ0geBbQpTPA==) (229 bytes): A port of my [TIC-80 256byte game](http://tic80.com/play?cart=1735) from LoveByte'21
|
||||
* [OhNoAnotherTunnel](v0.1pre4#Ag95rdCB5Ww5NofyQaKF4P1mrNRso4azgiem4hK99Gh8OMzSpFq3NsNDo7O7pqln10D11l9uXr/ritw7OEzKwbEfCdvaRnS2Z0Kz0iDEZt/gIqOdvFmxsL1MjPQ4XInPbUJpQUonhQq29oP2omFabnQxn0bzoK7mZjcwc5GetHG+hGajkJcRr8oOnjfCol8RD+ha33GYtPnut+GLe4ktzf5UxZwGs6oT9qqC61lRDakN) (177 bytes): A port of my [entry](http://tic80.com/play?cart=1871) in the Outline'21 bytebattle final
|
||||
* [Technotunnel](v0.1pre4#AqL8HeK1M9dn2nWNIF5vaq/Vh64pMt5nJIFoFKpBMPUsGtDtpqjo1JbT9LzPhAxCqJ7Yh4TA6oTGd4xhLowf+cWZMY73+7AZmfXJJsBi4cej/hH+4wlAgxFIrnOYnr/18IpnZbsHf0eGm1BhahX74+cVR0TRmNQmYC7GhCNS3mv/3MJn74lCj7t28aBJPjEZhP9fGXdG2u5Egh/Tjdg=) (158 bytes): A port of my [entry](https://tic80.com/play?cart=1873) in the Outline'21 bytebattle quater final
|
||||
* [Font & Palette](v0.1pre4#AgKaeeOuwg5gCKvFIeiitEwMpUI2rymEcu+DDB1vMu9uBoufvUxIr4Y5p4Jj2ukoNO4PE7QS5cN1ZyDMCRfSzYIGZxKlN2J6NKEWK7KVPk9wVUgn1Ip+hsMinWgEO8ETKfPuHoIa4kjI+ULFOMad7vd3rt/lh1Vy9w+R2MXG/7T61d3c7C6KY+eQNS0eW3ys4iU8R6SycuWZuuZ2Sg3Qxp826s+Kt+2qBojpzNOSoyFqyrVyYMTKEkSl0BZOj59Cs1hPm5bq0F1MmVhGAzMhW9V4YeAe): Just a simple viewer for the default font and palette.
|
||||
|
||||
@@ -1 +1 @@
|
||||
<!doctype html><html><head><meta charset="utf8"><title>MicroW8</title><link href="https://fonts.googleapis.com/css2?family=Josefin+Sans:wght@500&display=swap" rel="stylesheet"><style>body,canvas,html{margin:0;padding:0}html{background-color:#202024;color:#808070;font-family:Josefin Sans,Verdana,Arial Black,sans-serif}body,html{height:100%}body{display:grid;grid-template-rows:1fr 0fr}#centered{align-self:center;justify-self:center}.footer{color:#202420}a{color:#303630}a:hover{color:#405040}#screen{background-color:#202428;border:4px solid #303040;box-shadow:5px 5px 20px #000;cursor:none;height:240px;image-rendering:pixelated;width:320px}#message,#screen{margin-bottom:8px}.error{color:#e04030}button{background-color:#303440;border:1px solid #404040;border-radius:4px;color:#808070;font-family:inherit;padding:4px}button:hover{background-color:#202010}button:active{background-color:#504450}@media (min-width:680px) and (min-height:560px){#screen{height:480px;width:640px}}@media (min-width:1000px) and (min-height:800px){#screen{height:720px;width:960px}}</style></head><body> <div id="centered"> <canvas id="screen" width="320" height="240"></canvas> <div id="message"></div> <button id="cartButton">Load cart...</button> </div> <div id="footer"> <a href="http://unlicense.org/" ref="license">Unlicense</a> </div> </body><script type="module">function A(A){return A&&A.__esModule?A.default:A}function e(A,e){let t=A?`${A} bytes`:"Insert cart";e&&(t+=` - <span class="error">${e.replaceAll("<","<")}</span>`),document.getElementById("message").innerHTML=t}let t,a,B=document.getElementById("screen"),n=B.getContext("2d"),s=n.createImageData(320,240),r=A=>new Uint8Array(A),g=A=>new Uint32Array(A),i=0,o=A=>{let e,t="keydown"==A.type;switch(A.code){case"ArrowUp":e=1;break;case"ArrowDown":e=2;break;case"ArrowLeft":e=4;break;case"ArrowRight":e=8;break;case"KeyZ":e=16;break;case"KeyX":e=32;break;case"KeyA":e=64;break;case"KeyS":e=128;break;case"KeyR":t&&Q(a)}t?i|=e:i&=~e};async function Q(o,I){t&&(t(),t=null);let E=o.byteLength;if(e(E),0==E)return;a=o;let f=window.location.pathname;if(E<=1024&&!I){let A="";for(let e of r(o))A+=String.fromCharCode(e);f+="#"+btoa(A),f!=window.location.pathname+window.location.hash&&history.pushState(null,null,f)}B.width=B.width;try{let B,I=new WebAssembly.Memory({initial:4,maximum:4}),f=r(I.buffer),l={env:{memory:I}},c=A=>{if(0!=r(A)[0]){f.set(r(A));let e=B.exports.load_uw8(A.byteLength);A=new ArrayBuffer(e),r(A).set(f.slice(0,e))}return A},w=async A=>(await WebAssembly.instantiate(A,l)).instance,C=async A=>w(c(await(await fetch(A)).arrayBuffer()));B=await C(A("data:application/wasm;base64,AGFzbQEAAAABFQRgAX8Bf2ACf38Bf2ADf39%2FAGAAAAIPAQNlbnYGbWVtb3J5AgAEAwkIAAABAgEAAAMGEAN%2FAUEAC38BQQALfwFBAAsHGQIIbG9hZF91dzgAAAp1bmNvbXByZXNzAAQIAQcKngUIxwEBB39BAC0AAEEBayIBQQBIBEAgAA8LQYDAByAAaiECIAFBAXEEQEEBQYHABxAEIQIFQYDAB0EAIAAQAwtBAEGAhA9BCBADQYiEDyEDQQghBEGBwAchBQNAIAUgAkggAyMATiAFLQAAIAMtAABMcnEEQCAEIAQgBRACIgZqIQQgAyMASCAFLQAAIAMtAABGcQRAIAMgAxABaiEDCyAFIAZqIQUMAQsgAyMASARAIAQgBCADEAIiB2ohBCADIAdqIQMMAQsLIAQLPAEEfyAAIQEDQCACIAFBAWoiAS0AACIEQf8AcSADdHIhAiADQQdqIQMgBEEHdQ0ACyABQQFqIABrIAJqCxIBAX8gACABIAEQASICEAMgAgskAANAIAJBAEoEQCAAIAJBAWsiAmogASACai0AADoAAAwBCwsLqQEBBn8gACQBQQAkAgNAIANBgAE6AICADyADQQFqIgNBgQNIDQALAkADQEEAEAYiBQRAIAQEf0EBBUGAAhAGCwRAQYECEAVBAWsiAkUNAwtBwQIQBSEGA0AgASABIAJrLQAAOgAAIAFBAWohASAGQQFrIgYNAAsFQQEhBwNAIAdBAXQgBxAGciIHQYACSA0ACyABIAc6AAAgAUEBaiEBCyAFIQQMAAsLIAELNAECfwNAIAAgAmoQBgRAIAEgACACakEgahAGIAJ0ciEBIAJBAWohAgwBCwsgAUEBIAJ0cgtxAQR%2FA0AjAkGAIEgEQCMCQQh0IwEtAAByJAIjAUEBaiQBDAELCyMCQf8BcSICIAAtAICADyIBIwJBCHUiA2xBgAIgAWsgA2wgAWsgAiABSCIEG2okAiAAIAFBByAEQYECbGogAWtBBHVqOgCAgA8gBAsMAEEAQYCEDxAEJAALC9IDAQBBAAvLA6eP%2Fw9olPgPXPcNZ6GH4sK0YVAeGZhY8FzSxDxK%2Fvv32QOMdeZ4QLHNI9NAW9hr%2B1lpXqgkXw%2FZJ2xueSKrTWbsgq9bIaIhjByG5VC2EE%2Bp0mUsRwQzi7oRDC02b4ywHappXJZHhDLuZKhnjylLE4X%2F9%2FZ66bwxYl1h%2BNAL%2BQh0zt3iSqNerI7l0QMOySt%2FPOFO3hXwdaMgxln646dVGVLPhHQbMoREgNzLIYMv4gBUU6Cr%2BR0QYi3tDAXJ4SoSxKCyLsv7cfb5Cl%2BYC5Jus5xElZgiDlIIHBqFDldTRQ5nBJl5es0ZDmEl3WiHmM1UA8QeePxqNrYic7ifdP3EBFW5S6xR2jJ3ck%2BXX1DdwcNjNkIkxbPKNFOeqWZ%2FJ72Bz14fhYzfrX%2FfCvJQ2mBNrPbSIjF%2B6V1RUKuyzvSVyFXaomCpe3Y3V7yP5iFDf7QCB30gL0F9spf8BoPYv9hjE6Q3ZkqKBvEmZicrDv16JtFEfFeGz74RiGn3in3LRJfDC6flml3%2F7XqPZEDOkp7EYlesgbP3QvOHwrGA75RCRmGCkYt5vQiaDM%2F6Ya1SMp%2B0hSKoL1CaVam1YNyC2eUiph32Ag6cicueJ5xp%2Bg%3D%3D"));for(let A of["acos","asin","atan","atan2","cos","exp","log","sin","tan","pow"])l.env[A]=Math[A];for(let A=9;A<64;++A)l.env["reserved"+A]=()=>{};for(let A=0;A<16;++A)l.env["g_reserved"+A]=0;o=c(o);let F=await C(A("data:;base64,AgFf66NqjQm1RVA7%2FWfb4C0%2BTA8LutuPaAHz4fa5oCzbkHhWsZUVePi8p20pjRHxmDqBeUOdUnmHX83Xxgm9rht1GyuBT3N4l%2BgGrbeXBp70xTvMpXc8lgT%2FVKybwLspVjaUPL%2BpZdeFBlaL5aubw7XIK26IrZLLKYfvEi6NGr7whGnp0IVuNcEOqNgM8EAxp5O6ADjHuESbFE6vurZab%2FlfpAspg6l9o4kGHKaKaqfMnBP4a%2Bl0BCDLUb3GO6Pw7x1Lip6pfVMGv7%2BVJtQCHbZ9cmjISnoIGulDmsO1OieU7OJakcZU2rR%2FVWqITAAFdxA2A%2FvpYZyLbzHnyPhQR64Mj%2FzRbxt0pfAnakTQCff31vGt2ZCAOJDwFGhasayLine truncated
|
||||
<!doctype html><html><head><meta charset="utf8"><title>MicroW8</title><link href="https://fonts.googleapis.com/css2?family=Josefin+Sans:wght@500&display=swap" rel="stylesheet"><style>body,canvas,html{margin:0;padding:0}html{background-color:#202024;color:#808070;font-family:Josefin Sans,Verdana,Arial Black,sans-serif}body,html{height:100%}body{display:grid;grid-template-rows:1fr 0fr}#centered{align-self:center;justify-self:center}.footer{color:#202420}a{color:#303630}a:hover{color:#405040}#screen{background-color:#202428;border:4px solid #303040;box-shadow:5px 5px 20px #000;cursor:none;height:240px;image-rendering:pixelated;width:320px}#message,#screen{margin-bottom:8px}.error{color:#e04030}button{background-color:#303440;border:1px solid #404040;border-radius:4px;color:#808070;font-family:inherit;padding:4px}button:hover{background-color:#202010}button:active{background-color:#504450}@media (min-width:680px) and (min-height:560px){#screen{height:480px;width:640px}}@media (min-width:1000px) and (min-height:800px){#screen{height:720px;width:960px}}</style></head><body> <div id="centered"> <canvas id="screen" width="320" height="240"></canvas> <div id="message"></div> <button id="cartButton">Load cart...</button> </div> <div id="footer"> <a href="http://unlicense.org/" ref="license">Unlicense</a> </div> </body><script type="module">function A(A){return A&&A.__esModule?A.default:A}function e(A,e){let t=A?`${A} bytes`:"Insert cart";e&&(t+=` - <span class="error">${e.replaceAll("<","<")}</span>`),document.getElementById("message").innerHTML=t}let t,B,a=document.getElementById("screen"),r=a.getContext("2d"),n=r.createImageData(320,240),s=A=>new Uint8Array(A),F=A=>new Uint32Array(A),o=0,i=A=>{let e,t="keydown"==A.type;switch(A.code){case"ArrowUp":e=1;break;case"ArrowDown":e=2;break;case"ArrowLeft":e=4;break;case"ArrowRight":e=8;break;case"KeyZ":e=16;break;case"KeyX":e=32;break;case"KeyA":e=64;break;case"KeyS":e=128;break;case"KeyR":t&&Q(B)}t?o|=e:o&=~e};async function Q(i,E){t&&(t(),t=null);let c=i.byteLength;if(e(c),0==c)return;B=i;let l=window.location.pathname;if(c<=1024&&!E){let A="";for(let e of s(i))A+=String.fromCharCode(e);l+="#"+btoa(A),l!=window.location.pathname+window.location.hash&&history.pushState(null,null,l)}a.width=a.width;try{let a,E=new WebAssembly.Memory({initial:4,maximum:4}),l=s(E.buffer),I={env:{memory:E}},f=A=>{if(0!=s(A)[0]){l.set(s(A));let e=a.exports.load_uw8(A.byteLength);A=new ArrayBuffer(e),s(A).set(l.slice(0,e))}return A},g=async A=>(await WebAssembly.instantiate(A,I)).instance,w=async A=>g(f(await(await fetch(A)).arrayBuffer()));a=await w(A("data:application/wasm;base64,AGFzbQEAAAABFQRgAX8Bf2ACf38Bf2ADf39%2FAGAAAAIPAQNlbnYGbWVtb3J5AgAEAwkIAAABAgEAAAMGEAN%2FAUEAC38BQQALfwFBAAsHGQIIbG9hZF91dzgAAAp1bmNvbXByZXNzAAQIAQcKngUIxwEBB39BAC0AAEEBayIBQQBIBEAgAA8LQYDAByAAaiECIAFBAXEEQEEBQYHABxAEIQIFQYDAB0EAIAAQAwtBAEGAhA9BCBADQYiEDyEDQQghBEGBwAchBQNAIAUgAkggAyMATiAFLQAAIAMtAABMcnEEQCAEIAQgBRACIgZqIQQgAyMASCAFLQAAIAMtAABGcQRAIAMgAxABaiEDCyAFIAZqIQUMAQsgAyMASARAIAQgBCADEAIiB2ohBCADIAdqIQMMAQsLIAQLPAEEfyAAIQEDQCACIAFBAWoiAS0AACIEQf8AcSADdHIhAiADQQdqIQMgBEEHdQ0ACyABQQFqIABrIAJqCxIBAX8gACABIAEQASICEAMgAgskAANAIAJBAEoEQCAAIAJBAWsiAmogASACai0AADoAAAwBCwsLqQEBBn8gACQBQQAkAgNAIANBgAE6AICADyADQQFqIgNBgQNIDQALAkADQEEAEAYiBQRAIAQEf0EBBUGAAhAGCwRAQYECEAVBAWsiAkUNAwtBwQIQBSEGA0AgASABIAJrLQAAOgAAIAFBAWohASAGQQFrIgYNAAsFQQEhBwNAIAdBAXQgBxAGciIHQYACSA0ACyABIAc6AAAgAUEBaiEBCyAFIQQMAAsLIAELNAECfwNAIAAgAmoQBgRAIAEgACACakEgahAGIAJ0ciEBIAJBAWohAgwBCwsgAUEBIAJ0cgtxAQR%2FA0AjAkGAIEgEQCMCQQh0IwEtAAByJAIjAUEBaiQBDAELCyMCQf8BcSICIAAtAICADyIBIwJBCHUiA2xBgAIgAWsgA2wgAWsgAiABSCIEG2okAiAAIAFBByAEQYECbGogAWtBBHVqOgCAgA8gBAsMAEEAQYCEDxAEJAALC9IDAQBBAAvLA6eP%2Fw9olPgPXPcNZ6GH4sK0YVAeGZhY8FzSxDxK%2Fvv32QOMdeZ4QLHNI9NAW9hr%2B1lpXqgkXw%2FZJ2xueSKrTWbsgq9bIaIhjByG5VC2EE%2Bp0mUsRwQzi7oRDC02b4ywHappXJZHhDLuZKhnjylLE4X%2F9%2FZ66bwxYl1h%2BNAL%2BQh0zt3iSqNerI7l0QMOySt%2FPOFO3hXwdaMgxln646dVGVLPhHQbMoREgNzLIYMv4gBUU6Cr%2BR0QYi3tDAXJ4SoSxKCyLsv7cfb5Cl%2BYC5Jus5xElZgiDlIIHBqFDldTRQ5nBJl5es0ZDmEl3WiHmM1UA8QeePxqNrYic7ifdP3EBFW5S6xR2jJ3ck%2BXX1DdwcNjNkIkxbPKNFOeqWZ%2FJ72Bz14fhYzfrX%2FfCvJQ2mBNrPbSIjF%2B6V1RUKuyzvSVyFXaomCpe3Y3V7yP5iFDf7QCB30gL0F9spf8BoPYv9hjE6Q3ZkqKBvEmZicrDv16JtFEfFeGz74RiGn3in3LRJfDC6flml3%2F7XqPZEDOkp7EYlesgbP3QvOHwrGA75RCRmGCkYt5vQiaDM%2F6Ya1SMp%2B0hSKoL1CaVam1YNyC2eUiph32Ag6cicueJ5xp%2Bg%3D%3D"));for(let A of["acos","asin","atan","atan2","cos","exp","log","sin","tan","pow"])I.env[A]=Math[A];for(let A=9;A<64;++A)I.env["reserved"+A]=()=>{};for(let A=0;A<16;++A)I.env["g_reserved"+A]=0;i=f(i);let C=await w(A("data:;base64,AnevpqDvapimRNPOGhqee07n%2Bv1yTm1n5XES6y7%2BqPUQFqw5livsDo%2Fkram7E1zzZg6qmLzXsUswfnD9AZjEuJOrUjm2TzbQ%2BWO1hv6bvL0OA5NLPFH8ZGmL%2BQuU9%2BzJKrrbrtlCG5CF9XtS0qCkoIio9oeYfmSVxOA0y%2FJSfYQk40bvdrHXrFnxJFiottxFT%2FLepVgrZE1lBV2uUHz%2Fm8jczeF0kKEUpYn4qQfne4XupG2DSs0kLa3WXNHBwG0ViOo4f1B4B4X%2F1rf9O1yJZwLAqxFM1w2EeBreIqf9raWm6MMcuP8Q%2Bs5SmF1qu1YfCCyRNpKXp%2F3s3pdHfSBqlRkEL4jCiZWjXvWtvWJtnL6gyrjr4ZA2KREn7GNxZLine truncated
|
||||
+16
-5
@@ -19,16 +19,18 @@ fn main() -> Result<()> {
|
||||
match args.subcommand()?.as_ref().map(|s| s.as_str()) {
|
||||
Some("run") => run(args),
|
||||
Some("pack") => pack(args),
|
||||
Some(other) => {
|
||||
eprintln!("Unknown command '{}'", other);
|
||||
process::exit(1);
|
||||
}
|
||||
None => {
|
||||
Some("filter-exports") => filter_exports(args),
|
||||
Some("help") | None => {
|
||||
println!("Usage:");
|
||||
println!(" uw8 run [-w/--watch] [-p/--pack] [-u/--uncompressed] [-l/--level] [-o/--output <out-file>] <file>");
|
||||
println!(" uw8 pack [-u/--uncompressed] [-l/--level] <in-file> <out-file>");
|
||||
println!(" uw8 filter-exports <in-wasm> <out-wasm>");
|
||||
Ok(())
|
||||
}
|
||||
Some(other) => {
|
||||
eprintln!("Unknown command '{}'", other);
|
||||
process::exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -153,3 +155,12 @@ fn pack(mut args: Arguments) -> Result<()> {
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn filter_exports(mut args: Arguments) -> Result<()> {
|
||||
let in_file = args.free_from_os_str::<PathBuf, bool>(|s| Ok(s.into()))?;
|
||||
let out_file = args.free_from_os_str::<PathBuf, bool>(|s| Ok(s.into()))?;
|
||||
|
||||
uw8_tool::filter_exports(&in_file, &out_file)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
Generated
+99
-1
@@ -56,6 +56,21 @@ dependencies = [
|
||||
"lazy_static",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "heck"
|
||||
version = "0.3.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6d621efb26863f0e9924c6ac577e8275e5e6b77455db64ffa6c65c904e9e132c"
|
||||
dependencies = [
|
||||
"unicode-segmentation",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "id-arena"
|
||||
version = "2.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "25a2bc672d1148e28034f176e01fffebb08b35768468cc954630da77a1449005"
|
||||
|
||||
[[package]]
|
||||
name = "lazy_static"
|
||||
version = "1.4.0"
|
||||
@@ -74,6 +89,15 @@ version = "0.2.112"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1b03d17f364a3a042d5e5d46b053bbbf82c92c9430c592dd4c064dc6ee997125"
|
||||
|
||||
[[package]]
|
||||
name = "log"
|
||||
version = "0.4.14"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "51b9bbe6c47d51fc3e1a9b945965946b4c44142ab8792c50835a980d362c2710"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num-traits"
|
||||
version = "0.2.14"
|
||||
@@ -101,6 +125,24 @@ version = "0.4.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "db8bcd96cb740d03149cbad5518db9fd87126a10ab519c011893b1754134c468"
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.36"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c7342d5883fbccae1cc37a2353b09c87c9b0f3afd73f5fb9bba687a1f733b029"
|
||||
dependencies = [
|
||||
"unicode-xid",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quote"
|
||||
version = "1.0.14"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "47aa80447ce4daf1717500037052af176af5d38cc3e571d9ec1c7353fc10c87d"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "sacabase"
|
||||
version = "2.0.0"
|
||||
@@ -110,6 +152,17 @@ dependencies = [
|
||||
"num-traits",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "1.0.84"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ecb2e6da8ee5eb9a61068762a32fa9619cc591ceb055b3687f4cd4051ec2e06b"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"unicode-xid",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "time"
|
||||
version = "0.1.44"
|
||||
@@ -121,6 +174,18 @@ dependencies = [
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "unicode-segmentation"
|
||||
version = "1.8.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8895849a949e7845e06bd6dc1aa51731a103c42707010a5b591c0038fb73385b"
|
||||
|
||||
[[package]]
|
||||
name = "unicode-xid"
|
||||
version = "0.2.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3"
|
||||
|
||||
[[package]]
|
||||
name = "upkr"
|
||||
version = "0.1.0"
|
||||
@@ -140,8 +205,35 @@ dependencies = [
|
||||
"pbr",
|
||||
"pico-args",
|
||||
"upkr",
|
||||
"walrus",
|
||||
"wasm-encoder",
|
||||
"wasmparser",
|
||||
"wasmparser 0.81.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "walrus"
|
||||
version = "0.19.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4eb08e48cde54c05f363d984bb54ce374f49e242def9468d2e1b6c2372d291f8"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"id-arena",
|
||||
"leb128",
|
||||
"log",
|
||||
"walrus-macro",
|
||||
"wasmparser 0.77.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "walrus-macro"
|
||||
version = "0.19.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0a6e5bd22c71e77d60140b0bd5be56155a37e5bd14e24f5f87298040d0cc40d7"
|
||||
dependencies = [
|
||||
"heck",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -159,6 +251,12 @@ dependencies = [
|
||||
"leb128",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasmparser"
|
||||
version = "0.77.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b35c86d22e720a07d954ebbed772d01180501afe7d03d464f413bb5f8914a8d6"
|
||||
|
||||
[[package]]
|
||||
name = "wasmparser"
|
||||
version = "0.81.0"
|
||||
|
||||
@@ -8,6 +8,7 @@ edition = "2021"
|
||||
[dependencies]
|
||||
wasmparser = "0.81"
|
||||
wasm-encoder = "0.8"
|
||||
walrus = "0.19"
|
||||
anyhow = "1"
|
||||
pico-args = "0.4"
|
||||
upkr = { git = "https://github.com/exoticorn/upkr.git", rev = "2e7983fc" }
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
mod base_module;
|
||||
mod pack;
|
||||
mod filter_exports;
|
||||
|
||||
pub use base_module::BaseModule;
|
||||
pub use pack::{pack, pack_file, unpack, unpack_file, PackConfig};
|
||||
pub use filter_exports::filter_exports;
|
||||
@@ -27,6 +27,11 @@ fn main() -> Result<()> {
|
||||
let dest: PathBuf = args.free_from_str()?;
|
||||
uw8_tool::unpack_file(&source, &dest)?;
|
||||
}
|
||||
"filter-exports" => {
|
||||
let source: PathBuf = args.free_from_str()?;
|
||||
let dest: PathBuf = args.free_from_str()?;
|
||||
uw8_tool::filter_exports(&source, &dest)?;
|
||||
}
|
||||
_ => {
|
||||
eprintln!("Unknown subcommand '{}'", cmd);
|
||||
print_help();
|
||||
@@ -44,6 +49,7 @@ fn print_help() {
|
||||
"Usage:
|
||||
uw8-tool make-base <version>
|
||||
uw8-tool pack <wasm file> <uw8 file>
|
||||
uw8-tool unpack <uw8 file> <wasm file>"
|
||||
uw8-tool unpack <uw8 file> <wasm file>
|
||||
uw8-tool filter-exports <wasm file> <wasm file>"
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user