on master help sign in
commit995260a1ef528d13ee96257780ff4fbef6d19247 authoriko <mail@iko.soy> dateSun 27 Oct 2024, 15:45 (2 years ago) parent828fc7d
13 files changed+182−186
hello.nock nock/Cargo.lock+52−156 nock/Cargo.toml−17 nock/hello.hoon+1−1 nock/src/lib.rs+5−10 nock/src/main.rs−2 wock-web/.gitignore+6 wock-web/Cargo.toml+35 wock-web/build.sh+3 wock-web/index.html+9 wock-web/script.mjs+15 wock-web/src/lib.rs+56 nock/src/utils.rs → wock-web/src/utils.rs
hello.nocknew file

Binary file not shown.

nock/Cargo.lock+52−156
@@ -4,9 +4,9 @@ version = 3
44
55[[package]]
66name = "anstream"
7−version = "0.6.15"
7+version = "0.6.17"
88source = "registry+https://github.com/rust-lang/crates.io-index"
9−checksum = "64e15c1ab1f89faffbf04a634d5e1962e9074f2741eef6d97f3c4e322426d526"
9+checksum = "23a1e53f0f5d86382dafe1cf314783b2044280f406e7e1506368220ad11b1338"
1010dependencies = [
1111 "anstyle",
1212 "anstyle-parse",
@@ -19,43 +19,43 @@ dependencies = [
1919
2020[[package]]
2121name = "anstyle"
22−version = "1.0.8"
22+version = "1.0.9"
2323source = "registry+https://github.com/rust-lang/crates.io-index"
24−checksum = "1bec1de6f59aedf83baf9ff929c98f2ad654b97c9510f4e70cf6f661d49fd5b1"
24+checksum = "8365de52b16c035ff4fcafe0092ba9390540e3e352870ac09933bebcaa2c8c56"
2525
2626[[package]]
2727name = "anstyle-parse"
28−version = "0.2.5"
28+version = "0.2.6"
2929source = "registry+https://github.com/rust-lang/crates.io-index"
30−checksum = "eb47de1e80c2b463c735db5b217a0ddc39d612e7ac9e2e96a5aed1f57616c1cb"
30+checksum = "3b2d16507662817a6a20a9ea92df6652ee4f94f914589377d69f3b21bc5798a9"
3131dependencies = [
3232 "utf8parse",
3333]
3434
3535[[package]]
3636name = "anstyle-query"
37−version = "1.1.1"
37+version = "1.1.2"
3838source = "registry+https://github.com/rust-lang/crates.io-index"
39−checksum = "6d36fc52c7f6c869915e99412912f22093507da8d9e942ceaf66fe4b7c14422a"
39+checksum = "79947af37f4177cfead1110013d678905c37501914fba0efea834c3fe9a8d60c"
4040dependencies = [
41− "windows-sys 0.52.0",
41+ "windows-sys 0.59.0",
4242]
4343
4444[[package]]
4545name = "anstyle-wincon"
46−version = "3.0.4"
46+version = "3.0.6"
4747source = "registry+https://github.com/rust-lang/crates.io-index"
48−checksum = "5bf74e1b6e971609db8ca7a9ce79fd5768ab6ae46441c572e46cf596f59e57f8"
48+checksum = "2109dbce0e72be3ec00bed26e6a7479ca384ad226efdd66db8fa2e3a38c83125"
4949dependencies = [
5050 "anstyle",
51− "windows-sys 0.52.0",
51+ "windows-sys 0.59.0",
5252]
5353
5454[[package]]
5555name = "autocfg"
56−version = "1.3.0"
56+version = "1.4.0"
5757source = "registry+https://github.com/rust-lang/crates.io-index"
58−checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0"
58+checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26"
5959
6060[[package]]
6161name = "bit-vec"
@@ -89,9 +89,9 @@ checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c"
8989
9090[[package]]
9191name = "cc"
92−version = "1.1.13"
92+version = "1.1.31"
9393source = "registry+https://github.com/rust-lang/crates.io-index"
94−checksum = "72db2f7947ecee9b03b510377e8bb9077afa27176fdbff55c51027e976fdcc48"
94+checksum = "c2e7962b54006dcfcc61cb72735f4d89bb97061dd6a7ed882ec6b8ee53714c6f"
9595dependencies = [
9696 "shlex",
9797]
@@ -104,9 +104,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
104104
105105[[package]]
106106name = "clap"
107−version = "4.5.16"
107+version = "4.5.20"
108108source = "registry+https://github.com/rust-lang/crates.io-index"
109−checksum = "ed6719fffa43d0d87e5fd8caeab59be1554fb028cd30edc88fc4369b17971019"
109+checksum = "b97f376d85a664d5837dbae44bf546e6477a679ff6610010f17276f686d867e8"
110110dependencies = [
111111 "clap_builder",
112112 "clap_derive",
@@ -114,9 +114,9 @@ dependencies = [
114114
115115[[package]]
116116name = "clap_builder"
117−version = "4.5.15"
117+version = "4.5.20"
118118source = "registry+https://github.com/rust-lang/crates.io-index"
119−checksum = "216aec2b177652e3846684cbfe25c9964d18ec45234f0f5da5157b207ed1aab6"
119+checksum = "19bc80abd44e4bed93ca373a0704ccbd1b710dc5749406201bb018272808dc54"
120120dependencies = [
121121 "anstream",
122122 "anstyle",
@@ -126,9 +126,9 @@ dependencies = [
126126
127127[[package]]
128128name = "clap_derive"
129−version = "4.5.13"
129+version = "4.5.18"
130130source = "registry+https://github.com/rust-lang/crates.io-index"
131−checksum = "501d359d5f3dcaf6ecdeee48833ae73ec6e42723a1e52419c79abf9507eec0a0"
131+checksum = "4ac6a0c7b1a9e9a5186361f67dfa1b88213572f427fb9ab038efb2bd8c582dab"
132132dependencies = [
133133 "heck",
134134 "proc-macro2",
@@ -144,9 +144,9 @@ checksum = "1462739cb27611015575c0c11df5df7601141071f07518d56fcc1be504cbec97"
144144
145145[[package]]
146146name = "colorchoice"
147−version = "1.0.2"
147+version = "1.0.3"
148148source = "registry+https://github.com/rust-lang/crates.io-index"
149−checksum = "d3fd119d74b830634cea2a0f58bbd0d54540518a14397557951e79340abc28c0"
149+checksum = "5b63caa9aa9397e2d9480a9b13673856c78d8ac123288526c37d7839f2a86990"
150150
151151[[package]]
152152name = "colored"
@@ -158,16 +158,6 @@ dependencies = [
158158 "windows-sys 0.48.0",
159159]
160160
161−[[package]]
162−name = "console_error_panic_hook"
163−version = "0.1.7"
164−source = "registry+https://github.com/rust-lang/crates.io-index"
165−checksum = "a06aeb73f470f66dcdbf7223caeebb85984942f22f1adb2a088cf9668146bbbc"
166−dependencies = [
167− "cfg-if",
168− "wasm-bindgen",
169−]
170−
171161[[package]]
172162name = "fplist"
173163version = "0.2.1"
@@ -194,9 +184,9 @@ checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf"
194184
195185[[package]]
196186name = "js-sys"
197−version = "0.3.70"
187+version = "0.3.72"
198188source = "registry+https://github.com/rust-lang/crates.io-index"
199−checksum = "1868808506b929d7b0cfa8f75951347aa71bb21144b7791bae35d9bccfcfe37a"
189+checksum = "6a88f1bda2bd75b0452a14784937d796722fdebfe50df998aeb3f0b7603019a9"
200190dependencies = [
201191 "wasm-bindgen",
202192]
@@ -209,9 +199,9 @@ checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe"
209199
210200[[package]]
211201name = "libc"
212−version = "0.2.158"
202+version = "0.2.161"
213203source = "registry+https://github.com/rust-lang/crates.io-index"
214−checksum = "d8adc4bb1803a324070e64a98ae98f38934d91957a99cfb3a43dcbc01bc56439"
204+checksum = "8e9489c2807c139ffd9c1794f4af0ebe86a828db53ecdc7fea2111d0fed085d1"
215205
216206[[package]]
217207name = "log"
@@ -219,16 +209,6 @@ version = "0.4.22"
219209source = "registry+https://github.com/rust-lang/crates.io-index"
220210checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24"
221211
222−[[package]]
223−name = "minicov"
224−version = "0.3.5"
225−source = "registry+https://github.com/rust-lang/crates.io-index"
226−checksum = "5c71e683cd655513b99affab7d317deb690528255a0d5f717f1024093c12b169"
227−dependencies = [
228− "cc",
229− "walkdir",
230−]
231−
232212[[package]]
233213name = "murmur3"
234214version = "0.5.2"
@@ -243,7 +223,6 @@ dependencies = [
243223 "bitter",
244224 "bitvec",
245225 "clap",
246− "console_error_panic_hook",
247226 "fplist",
248227 "murmur3",
249228 "num-bigint",
@@ -251,8 +230,6 @@ dependencies = [
251230 "num-traits",
252231 "spinoff",
253232 "stacker",
254− "wasm-bindgen",
255− "wasm-bindgen-test",
256233 "web-sys",
257234 "xxhash-rust",
258235]
@@ -287,9 +264,9 @@ dependencies = [
287264
288265[[package]]
289266name = "once_cell"
290−version = "1.19.0"
267+version = "1.20.2"
291268source = "registry+https://github.com/rust-lang/crates.io-index"
292−checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92"
269+checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775"
293270
294271[[package]]
295272name = "paste"
@@ -299,27 +276,27 @@ checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a"
299276
300277[[package]]
301278name = "proc-macro2"
302−version = "1.0.86"
279+version = "1.0.89"
303280source = "registry+https://github.com/rust-lang/crates.io-index"
304−checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77"
281+checksum = "f139b0662de085916d1fb67d2b4169d1addddda1919e696f3252b740b629986e"
305282dependencies = [
306283 "unicode-ident",
307284]
308285
309286[[package]]
310287name = "psm"
311−version = "0.1.21"
288+version = "0.1.23"
312289source = "registry+https://github.com/rust-lang/crates.io-index"
313−checksum = "5787f7cda34e3033a72192c018bc5883100330f362ef279a8cbccfce8bb4e874"
290+checksum = "aa37f80ca58604976033fae9515a8a2989fc13797d953f7c04fb8fa36a11f205"
314291dependencies = [
315292 "cc",
316293]
317294
318295[[package]]
319296name = "quote"
320−version = "1.0.36"
297+version = "1.0.37"
321298source = "registry+https://github.com/rust-lang/crates.io-index"
322−checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7"
299+checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af"
323300dependencies = [
324301 "proc-macro2",
325302]
@@ -330,21 +307,6 @@ version = "0.7.0"
330307source = "registry+https://github.com/rust-lang/crates.io-index"
331308checksum = "dc33ff2d4973d518d823d61aa239014831e521c75da58e3df4840d3f47749d09"
332309
333−[[package]]
334−name = "same-file"
335−version = "1.0.6"
336−source = "registry+https://github.com/rust-lang/crates.io-index"
337−checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502"
338−dependencies = [
339− "winapi-util",
340−]
341−
342−[[package]]
343−name = "scoped-tls"
344−version = "1.0.1"
345−source = "registry+https://github.com/rust-lang/crates.io-index"
346−checksum = "e1cf6437eb19a8f4a6cc0f7dca544973b0b78843adbfeb3683d1a94a0024a294"
347−
348310[[package]]
349311name = "shlex"
350312version = "1.3.0"
@@ -383,9 +345,9 @@ checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f"
383345
384346[[package]]
385347name = "syn"
386−version = "2.0.74"
348+version = "2.0.85"
387349source = "registry+https://github.com/rust-lang/crates.io-index"
388−checksum = "1fceb41e3d546d0bd83421d3409b1460cc7444cd389341a4c880fe7a042cb3d7"
350+checksum = "5023162dfcd14ef8f32034d8bcd4cc5ddc61ef7a247c024a33e24e1f24d21b56"
389351dependencies = [
390352 "proc-macro2",
391353 "quote",
@@ -400,9 +362,9 @@ checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369"
400362
401363[[package]]
402364name = "unicode-ident"
403−version = "1.0.12"
365+version = "1.0.13"
404366source = "registry+https://github.com/rust-lang/crates.io-index"
405−checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b"
367+checksum = "e91b56cd4cadaeb79bbf1a5645f6b4f8dc5bde8834ad5894a8db35fda9efa1fe"
406368
407369[[package]]
408370name = "utf8parse"
@@ -410,21 +372,11 @@ version = "0.2.2"
410372source = "registry+https://github.com/rust-lang/crates.io-index"
411373checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821"
412374
413−[[package]]
414−name = "walkdir"
415−version = "2.5.0"
416−source = "registry+https://github.com/rust-lang/crates.io-index"
417−checksum = "29790946404f91d9c5d06f9874efddea1dc06c5efe94541a7d6863108e3a5e4b"
418−dependencies = [
419− "same-file",
420− "winapi-util",
421−]
422−
423375[[package]]
424376name = "wasm-bindgen"
425−version = "0.2.93"
377+version = "0.2.95"
426378source = "registry+https://github.com/rust-lang/crates.io-index"
427−checksum = "a82edfc16a6c469f5f44dc7b571814045d60404b55a0ee849f9bcfa2e63dd9b5"
379+checksum = "128d1e363af62632b8eb57219c8fd7877144af57558fb2ef0368d0087bddeb2e"
428380dependencies = [
429381 "cfg-if",
430382 "once_cell",
@@ -433,9 +385,9 @@ dependencies = [
433385
434386[[package]]
435387name = "wasm-bindgen-backend"
436−version = "0.2.93"
388+version = "0.2.95"
437389source = "registry+https://github.com/rust-lang/crates.io-index"
438−checksum = "9de396da306523044d3302746f1208fa71d7532227f15e347e2d93e4145dd77b"
390+checksum = "cb6dd4d3ca0ddffd1dd1c9c04f94b868c37ff5fac97c30b97cff2d74fce3a358"
439391dependencies = [
440392 "bumpalo",
441393 "log",
@@ -446,23 +398,11 @@ dependencies = [
446398 "wasm-bindgen-shared",
447399]
448400
449−[[package]]
450−name = "wasm-bindgen-futures"
451−version = "0.4.43"
452−source = "registry+https://github.com/rust-lang/crates.io-index"
453−checksum = "61e9300f63a621e96ed275155c108eb6f843b6a26d053f122ab69724559dc8ed"
454−dependencies = [
455− "cfg-if",
456− "js-sys",
457− "wasm-bindgen",
458− "web-sys",
459−]
460−
461401[[package]]
462402name = "wasm-bindgen-macro"
463−version = "0.2.93"
403+version = "0.2.95"
464404source = "registry+https://github.com/rust-lang/crates.io-index"
465−checksum = "585c4c91a46b072c92e908d99cb1dcdf95c5218eeb6f3bf1efa991ee7a68cccf"
405+checksum = "e79384be7f8f5a9dd5d7167216f022090cf1f9ec128e6e6a482a2cb5c5422c56"
466406dependencies = [
467407 "quote",
468408 "wasm-bindgen-macro-support",
@@ -470,9 +410,9 @@ dependencies = [
470410
471411[[package]]
472412name = "wasm-bindgen-macro-support"
473−version = "0.2.93"
413+version = "0.2.95"
474414source = "registry+https://github.com/rust-lang/crates.io-index"
475−checksum = "afc340c74d9005395cf9dd098506f7f44e38f2b4a21c6aaacf9a105ea5e1e836"
415+checksum = "26c6ab57572f7a24a4985830b120de1594465e5d500f24afe89e16b4e833ef68"
476416dependencies = [
477417 "proc-macro2",
478418 "quote",
@@ -483,55 +423,20 @@ dependencies = [
483423
484424[[package]]
485425name = "wasm-bindgen-shared"
486−version = "0.2.93"
487−source = "registry+https://github.com/rust-lang/crates.io-index"
488−checksum = "c62a0a307cb4a311d3a07867860911ca130c3494e8c2719593806c08bc5d0484"
489−
490−[[package]]
491−name = "wasm-bindgen-test"
492−version = "0.3.43"
426+version = "0.2.95"
493427source = "registry+https://github.com/rust-lang/crates.io-index"
494−checksum = "68497a05fb21143a08a7d24fc81763384a3072ee43c44e86aad1744d6adef9d9"
495−dependencies = [
496− "console_error_panic_hook",
497− "js-sys",
498− "minicov",
499− "scoped-tls",
500− "wasm-bindgen",
501− "wasm-bindgen-futures",
502− "wasm-bindgen-test-macro",
503−]
504−
505−[[package]]
506−name = "wasm-bindgen-test-macro"
507−version = "0.3.43"
508−source = "registry+https://github.com/rust-lang/crates.io-index"
509−checksum = "4b8220be1fa9e4c889b30fd207d4906657e7e90b12e0e6b0c8b8d8709f5de021"
510−dependencies = [
511− "proc-macro2",
512− "quote",
513− "syn",
514−]
428+checksum = "65fc09f10666a9f147042251e0dda9c18f166ff7de300607007e96bdebc1068d"
515429
516430[[package]]
517431name = "web-sys"
518−version = "0.3.70"
432+version = "0.3.72"
519433source = "registry+https://github.com/rust-lang/crates.io-index"
520−checksum = "26fdeaafd9bd129f65e7c031593c24d62186301e0c72c8978fa1678be7d532c0"
434+checksum = "f6488b90108c040df0fe62fa815cbdee25124641df01814dd7282749234c6112"
521435dependencies = [
522436 "js-sys",
523437 "wasm-bindgen",
524438]
525439
526−[[package]]
527−name = "winapi-util"
528−version = "0.1.9"
529−source = "registry+https://github.com/rust-lang/crates.io-index"
530−checksum = "cf221c93e13a30d793f7645a0e7762c55d169dbb0a49671918a2319d289b10bb"
531−dependencies = [
532− "windows-sys 0.59.0",
533−]
534−
535440[[package]]
536441name = "windows-sys"
537442version = "0.48.0"
@@ -541,15 +446,6 @@ dependencies = [
541446 "windows-targets 0.48.5",
542447]
543448
544−[[package]]
545−name = "windows-sys"
546−version = "0.52.0"
547−source = "registry+https://github.com/rust-lang/crates.io-index"
548−checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d"
549−dependencies = [
550− "windows-targets 0.52.6",
551−]
552−
553449[[package]]
554450name = "windows-sys"
555451version = "0.59.0"
nock/Cargo.toml−17
@@ -4,20 +4,7 @@ version = "0.1.0"
44authors = ["iko <mail@iko.soy>"]
55edition = "2021"
66
7−[lib]
8−crate-type = ["cdylib", "rlib"]
9−
10−[features]
11−default = ["console_error_panic_hook"]
12−
137[dependencies]
14−wasm-bindgen = "0.2.84"
15−
16−# The `console_error_panic_hook` crate provides better debugging of panics by
17−# logging them with `console.error`. This is great for development, but requires
18−# all the `std::fmt` and `std::panicking` infrastructure, so isn't great for
19−# code size when deploying.
20−console_error_panic_hook = { version = "0.1.7", optional = true }
218num-bigint = "0.4.6"
229num-traits = "0.2.19"
2310bitter = "0.7.0"
@@ -35,9 +22,6 @@ fplist = "0.2.1"
3522version = "0.8.5"
3623features = ["xxh3"]
3724
38−[dev-dependencies]
39−wasm-bindgen-test = "0.3.34"
40−
4125[profile.release]
4226# Tell `rustc` to optimize for small code size.
4327opt-level = 3
@@ -49,4 +33,3 @@ path = "src/main.rs"
4933[[bin]]
5034name = "hash-gate"
5135path = "src/hash-gate.rs"
52−
nock/hello.hoon+1−1
@@ -1 +1 @@
1−|=(x=@t (crip (weld "Hello, " (trip !!))))
1+|=(x=@t (crip (weld "Hello, " (trip x))))
nock/src/lib.rs+5−10
@@ -1,19 +1,14 @@
11#![feature(iter_intersperse)]
22#![feature(let_chains)]
33#![feature(iter_repeat_n)]
4+
5+use std::rc::Rc;
6+
7+use noun::Noun;
48pub mod cue;
59pub mod interpreter;
610pub mod jam;
711mod jets;
812pub mod noun;
9−mod utils;
10−
11−use wasm_bindgen::prelude::*;
12−
13−#[wasm_bindgen]
14−extern "C" {
15− fn alert(s: &str);
16−}
1713
18−#[wasm_bindgen]
19−pub fn greet() {}
14+pub type Vase = (Rc<Noun>, Rc<Noun>);
nock/src/main.rs−2
@@ -145,8 +145,6 @@ fn main() -> Result<(), std::io::Error> {
145145 Ok(())
146146}
147147
148−type Vase = (Rc<Noun>, Rc<Noun>);
149−
150148/// Reads a `vase` from a `.nock` file.
151149fn read_nock(nock_file: &PathBuf) -> Result<Vase, std::io::Error> {
152150 let nock = cue_bytes(&read_file(nock_file)?);
wock-web/.gitignorenew file+6
@@ -0,0 +1,6 @@
1+/target
2+**/*.rs.bk
3+Cargo.lock
4+bin/
5+pkg/
6+wasm-pack.log
wock-web/Cargo.tomlnew file+35
@@ -0,0 +1,35 @@
1+[package]
2+name = "wock-web"
3+version = "0.1.0"
4+authors = ["iko <mail@iko.soy>"]
5+edition = "2018"
6+
7+[lib]
8+crate-type = ["cdylib", "rlib"]
9+
10+[features]
11+default = ["console_error_panic_hook"]
12+
13+[dependencies]
14+wasm-bindgen = "0.2.84"
15+nock = { path = "../nock" }
16+
17+# The `console_error_panic_hook` crate provides better debugging of panics by
18+# logging them with `console.error`. This is great for development, but requires
19+# all the `std::fmt` and `std::panicking` infrastructure, so isn't great for
20+# code size when deploying.
21+console_error_panic_hook = { version = "0.1.7", optional = true }
22+wasm-bindgen-futures = "0.4.45"
23+js-sys = "0.3.72"
24+gloo = "0.11.0"
25+
26+[dependencies.web-sys]
27+version = "0.3.72"
28+features = ['Headers', 'Request', 'RequestInit', 'RequestMode', 'Response', 'Window', 'Blob']
29+
30+[dev-dependencies]
31+wasm-bindgen-test = "0.3.34"
32+
33+[profile.release]
34+# Tell `rustc` to optimize for small code size.
35+opt-level = "s"
wock-web/build.shnew file+3
@@ -0,0 +1,3 @@
1+#!/bin/sh
2+
3+wasm-pack build --no-typescript --no-pack --target=web
wock-web/index.htmlnew file+9
@@ -0,0 +1,9 @@
1+<html>
2+ <head>
3+ <meta content="text/html;charset=utf-8" http-equiv="Content-Type"/>
4+ </head>
5+ <body>
6+ <input id="input"></input>
7+ <script type="module" src="script.mjs?src=/hello.nock"></script>
8+ </body>
9+</html>
wock-web/script.mjsnew file+15
@@ -0,0 +1,15 @@
1+import init, { main } from './pkg/wock_web.js';
2+
3+const initPromise = init()
4+
5+// window.document.c
6+
7+const src = new URL(import.meta.url).searchParams.get("src")
8+
9+if (src === null) {
10+ console.error("src query parameter not specified.")
11+}
12+
13+await initPromise
14+await main(src)
15+
wock-web/src/lib.rsnew file+56
@@ -0,0 +1,56 @@
1+mod utils;
2+
3+use std::rc::Rc;
4+
5+use nock::{
6+ cue::cue_bytes,
7+ interpreter::{generate_interpreter_context, slam},
8+ noun::Noun,
9+};
10+use wasm_bindgen::prelude::*;
11+use wasm_bindgen_futures::JsFuture;
12+
13+#[wasm_bindgen]
14+extern "C" {
15+ fn alert(s: &str);
16+
17+ #[wasm_bindgen(js_namespace = console)]
18+ fn log(s: &str);
19+}
20+
21+#[wasm_bindgen]
22+pub fn greet() {
23+ alert("Hello, wock-web!");
24+}
25+
26+#[wasm_bindgen]
27+pub async fn main(path: &str) {
28+ let nock = load_nock(path).await;
29+
30+ let mut ctx = generate_interpreter_context();
31+ let bar = slam(&mut ctx, &nock, &Rc::new(Noun::from_bytes(b"Curtis"))).unwrap();
32+
33+ let foo = bar.as_bytes().unwrap();
34+ let qux = String::from_utf8(foo).unwrap();
35+
36+ log(&*qux);
37+}
38+
39+pub async fn load_nock(path: &str) -> Rc<Noun> {
40+ let window = web_sys::window().unwrap();
41+
42+ let resp = JsFuture::from(window.fetch_with_str(path)).await.unwrap();
43+ assert!(resp.is_instance_of::<web_sys::Response>());
44+ let resp: web_sys::Response = resp.dyn_into().unwrap();
45+ let blob = JsFuture::from(resp.blob().unwrap()).await.unwrap();
46+ assert!(blob.is_instance_of::<web_sys::Blob>());
47+ let blob: web_sys::Blob = blob.dyn_into().unwrap();
48+
49+ let nock =
50+ js_sys::Uint8Array::new(&JsFuture::from(blob.array_buffer()).await.unwrap()).to_vec();
51+
52+ let nock = cue_bytes(&*nock);
53+ let (_typ, nok) = nock.as_cell().unwrap();
54+
55+ nok.clone()
56+}
nock/src/utils.rs → wock-web/src/utils.rsrenamed

The content is the same.