2021-10-21 05:03:25 what will you use wasm+forth for, remexre 2021-10-21 08:02:09 "looks like I might be back in forth-land soon". when you let forth into your life once it tends to sneak back in over time 2021-10-21 08:02:58 like heroin 2021-10-21 08:03:02 If it's "terribly inefficient" I'd want to know how JITs differ 2021-10-21 08:03:16 I'm assuming it supports JITs, maybe I'm wrong about that 2021-10-21 08:03:26 f-a: Yep and just as harmful 2021-10-21 11:03:16 f-a: I'm experimenting (https://git.sr.ht/~remexre/sylvan) with large-scale changes to a language I help maintain (https://github.com/melt-umn/silver/) 2021-10-21 11:03:53 oh, terribly inefficient wasn't at Forth writing code at runtime on a traditional architecture 2021-10-21 11:03:56 but on WASM in particular 2021-10-21 11:04:29 thanks 2021-10-21 11:04:44 you're doing the moral equivalent of writing out a new .so / .dll and dlopen()ing it 2021-10-21 11:05:03 and the new code isn't running in the same address space unless you set up shared memory 2021-10-21 11:05:23 so like, not great to do to every word lol 2021-10-21 11:07:24 is it hard to compile WASM source generated at run time? 2021-10-21 11:08:07 not particularly, but you're not loading new code into the same program, you're creating a new program that possibly has some shared memory 2021-10-21 11:22:50 remexre: Yeah I got that (terribly inefficient on WASM), I mean surely there is a way of writing modifying instructions because of JITs 2021-10-21 11:38:20 veltas: Are there any JITs for Wasm? I know QEMU for WASM is a plain interpreter there 2021-10-21 11:41:45 QEMU for WASM? that's a thing? 2021-10-21 11:43:08 remexre: I believe wasmtime is a JIT. 2021-10-21 11:43:36 Sorry, we're talking JITs that run _in_ Wasm, not that run Wasm 2021-10-21 11:43:46 ohhh. 2021-10-21 11:43:55 Should be more clear given that I have no clue how to Google for the former anyway lol 2021-10-21 11:44:00 my bad my bad. 2021-10-21 11:44:42 so, I don't think that there are any JITs that run in WASM, because WASM is harvard by design. 2021-10-21 11:44:47 you can't build self-modifying code in WASM. 2021-10-21 11:46:19 WASM is structured instead of "loosey goosey". we can delimit blocks, conditionals, loops, etc. 2021-10-21 11:46:55 hmm 2021-10-21 11:47:35 can you have a function call a new program that was assembled at run time? ie jump back and forth between modules 2021-10-21 11:47:49 nnnope. 2021-10-21 11:48:20 sooooooo jump to the new program and stay there forever? 2021-10-21 11:48:46 you can't assemble new programs at runtime. 2021-10-21 11:49:01 iirc. 2021-10-21 11:49:14 like, WASM can only see its data space, not its code space. 2021-10-21 11:55:46 so if you assemble a new program at runtime, what happens then? old program gets unloaded and new program can be started or new program gets started on new thread or what? 2021-10-21 11:57:33 new thread, ish 2021-10-21 12:18:05 again, iirc, you _can't_ assemble a new program at runtime. 2021-10-21 12:18:12 there's no way for you to. 2021-10-21 12:18:19 uh load it into a new Module 2021-10-21 12:18:46 you can do that _from_ WASM? 2021-10-21 12:19:14 you need a bit of js glue code, but wasm can be the one "calling the shots" for it 2021-10-21 12:19:51 right, I'm just talking about stuff you can do _within_ WASM. you can 100% do that outside of WASM, even do self-modifying code if need be. 2021-10-21 12:20:23 if you define extensions to the interpreter or external functions you can call, you can trivially do self-modifying code. 2021-10-21 12:20:44 well, you still can't do self-modifying code within a module 2021-10-21 12:20:55 unless I'm missing something, in which case I'll use that thing :) 2021-10-21 12:24:04 I'm not familiar with whatever interpreter you're using but I imagine you could "insert" bytecode into certain ranges that was sourced from a memory segment. 2021-10-21 12:24:26 via that interpreter's functions. 2021-10-21 12:33:40 I mean ideally whatever I'd do would work in browsers still 2021-10-21 12:33:58 (if only for ease of demos) 2021-10-21 12:44:46 fwiw I'm working on a harvard-only environment right now and have resigned myself to writing some form of interpreter. 2021-10-21 12:47:02 like, ITC Forth-looking? 2021-10-21 12:47:36 kiiiiiiinda? 2021-10-21 12:47:55 the environment has six commands and uses structured control flow. 2021-10-21 12:48:44 []01<> 2021-10-21 12:49:04 oh hey, is that the language I think it is :) 2021-10-21 12:49:30 hahaha, not brainfuck, but it's much worse. 2021-10-21 12:49:41 instead of a tape, it operates on a deque of bits. 2021-10-21 12:49:51 huh 2021-10-21 12:50:09 [ dequeues a bit and proceeds if it's a 1, jumps to the matching ] if it's a 0. 2021-10-21 12:50:17 0 and 1 enqueue their respective bits. 2021-10-21 12:50:33 < and > "roll" the deque by dequeueing from the head or tail and enqueueing to the tail or head. 2021-10-21 12:51:10 huh 2021-10-21 12:51:18 recently converted some BF source to it to compute a byte-wrapped factorial. it works. 2021-10-21 12:51:20 sounds tricky to compile to indeed :) 2021-10-21 12:51:33 you'd think, but there are some common structures that don't really "change". 2021-10-21 12:51:40 dropping a bit, for example. 2021-10-21 12:51:44 [0<] 2021-10-21 12:52:15 an 'if' statement is just that 'drop bit' with some code in the middle. [ ... 0<] 2021-10-21 12:53:16 an 'if/else' statement is that 'drop bit' with a flag that's passed between branches. 1[<[0<] ... 00<]<[ ... 0<] 2021-10-21 12:54:10 a 'while' statement is just a condition followed by a loop with the condition at the end. ... [ ... ]. 2021-10-21 12:55:51 you can apply some pretty dumb pattern matching to batch all of these up into a token-based IR, and then compile that IR. 2021-10-21 12:57:30 huh, okay 2021-10-21 12:59:39 some common primitives like popping and pushing bytes, adding numbers together, etc. can be defined in the IR. but they always need to have some implementation in the core primitives. 2021-10-21 12:59:51 that way some dude writing a trivial interpreter can still run your stuff. 2021-10-21 13:02:02 because it's a deque, you can write pick and roll pretty trivially, along with swap, dup, drop, etc. 2021-10-21 13:02:16 the IR has primitives to work on common byte and word boundaries. 2021-10-21 13:04:05 https://hastebin.com/jequnuzuke.py here's some shitty python code to check whether a run of bits contains all zeroes. 2021-10-21 13:04:15 well, it generates the code to run that check. 2021-10-21 13:30:49 imode, oh woops misread what you said about WASM 2021-10-21 13:31:05 np!