Fork me on GitHub
#off-topic
<
2018-08-25
>
benzap17:08:19

Been thinking about creating a wast-to-wasm assembler in clojure(script), from which I can then write an intermediate language for writing a subset of clojure

benzap17:08:28

I'm trying to figure out if it would be a bad idea

benzap17:08:17

I think the assembler has straightforward guidelines, but I feel like getting clojure's persistent data collections into webassembly is next to impossible without some more radical design decisions

benzap17:08:30

Also, a gc that is somewhat performant, and small

benzap17:08:26

I could try stealing some ideas from the rust crew, since they designed a new allocator specifically for wasm, but then it would be a matter of developing a good gc. I'd probably focus on just getting it functionality correct before attempting to optimize it

benzap17:08:09

But the big question is... what do I name my project? I've had a bad track record, so i'd be open to some suggestions

Empperi20:08:39

Clogasm? 🙂

benzap01:08:50

I'll think on it...

benzap01:08:56

Maybe since i'll be making an intermediate to build up to clojure, i could step the letter down to blojure

john01:08:51

ClojureWast

john01:08:20

ClojureWasm

john01:08:10

clobber 🙂

benzap17:08:23

I'm thinking i'll name it gizzard, since the library digests wat into wasm

benzap17:08:35

then I could name the language intermediate after an eagle

john17:08:41

I like it

john17:08:02

But I don't understand why you need a wast to wasm compiler. Hasn't somebody already built that?

john17:08:24

I'm betting they'll build those into browser directly one day too anyway

john17:08:02

as a native function

john17:08:07

looks like a thing called wabt will do it. Looking at the source code for this demo: https://cdn.rawgit.com/WebAssembly/wabt/aae5a4b7/demo/wat2wasm/

john17:08:31

function compile() {
  outputEl.textContent = '';
  var binaryOutput;
  try {
    var module = wabt.parseWat('test.wast', watEditor.getValue());
    module.resolveNames();
    module.validate();
    var binaryOutput = module.toBinary({log: true, write_debug_names:true});
    outputEl.textContent = binaryOutput.log;
    binaryBuffer = binaryOutput.buffer;
    var blob = new Blob([binaryOutput.buffer]);
    if (binaryBlobUrl) {
      URL.revokeObjectURL(binaryBlobUrl);
    }
    binaryBlobUrl = URL.createObjectURL(blob);
    downloadLink.setAttribute('href', binaryBlobUrl);
    downloadEl.classList.remove('disabled');
  } catch (e) {
    outputEl.textContent += e.toString();
    downloadEl.classList.add('disabled');
  } finally {
    if (module) module.destroy();
  }
}

function run() {
  jsLogEl.textContent = '';
  if (binaryBuffer === null) return;
  try {
    let wasm = new WebAssembly.Module(binaryBuffer);
    let js = jsEditor.getValue();
    let fn = new Function('wasmModule', 'console', js + '//# sourceURL=demo.js');
    fn(wasm, wrappedConsole);
  } catch (e) {
    jsLogEl.textContent += String(e);
  }
}

benzap18:08:00

yeah, it does exist. I just wanted to learn more about wat and the binary format

john18:08:25

no better way to do it than that! 🙂

john18:08:05

But I guess that's the actual wasm runtime

john18:08:26

You're just trying to go from wast to valid wasm code

benzap19:08:26

Interesting, I can definitely draw some inspiration from that

benzap19:08:29

Building a webasm VM in java doesn't sound too crazy I guess lol

john19:08:47

make sure it does the streaming compilation thing

john19:08:10

so that our macrologized wast forms start evaling as soon as they hit the vm 🙂

benzap19:08:15

haha, that would be insane!

john19:08:56

apparently this hullabaloo about liftoff is all about this streaming compilation stuff https://jaxenter.com/v8-javascript-liftoff-148475.html

john19:08:21

I guess it was one of the original wasm design goals - to allow this streaming compilation model, so things can start happening before later bits are available

john19:08:35

Seems like it could tie into a repl model

john19:08:04

incremental compilation and execution

john20:08:57

Yeah, I've been wondering about an allocation/free scheme for both cljs and wasm wast on SharedArrayBuffers

john20:08:42

If the allocation/free scheme is lockfree, I'm thinking different environments can operate on the same buffer if they all implement the same lockfree protocol

john21:08:36

I'm working on an algorithm right now. I'm going to try to rewrite it with comments on https://www.maria.cloud and then people can just play with it or fork it off maria.cloud.