
Walt: JavaScript-like syntax for WebAssembly - jedisct1
https://github.com/ballercat/walt
======
TekMol
I was excited at first. Compile Javascript like code into WebAssembly text
format? Zero dependencies? Count me in!

I thought: Great! Let's try it! So how do I use it? How do I hand over a
string of Walt and get a string of WebAssemblyText back?

I though there is a javascript file somewhere in the project that has a
compile() function that does that.

And then I clicked on the Quick Start Guide and it looks much more
complicated. It tells me to install node, npm, webpack, walt-compiler, walt-
loader... set up a project with a certain structure, create a landing page...

Help :) That's not what I want. I just want a function that takes a string and
returns a string.

Would it be possible to just offer a javascript file to be used directly in
the Browser? That exports a function which translates your JS dialect to
WasmText?

Is that file somewhere in there maybe?

~~~
manigandham
Yes, that's the compiler:
[https://github.com/ballercat/walt/tree/master/packages/walt-...](https://github.com/ballercat/walt/tree/master/packages/walt-
compiler)

It's written in JS so you'll need node to run it, and npm is a package manager
for node so you should use that to install and call it.

If you just want a hosted site to play with code, it's linked right at the
top: [https://ballercat.github.io/walt/](https://ballercat.github.io/walt/)

~~~
TekMol

        It's written in JS so you'll need node to run it
    

I happily run JS in my browser all day. Why do I need node for this code?

~~~
manigandham
Because different runtimes support different features and performance (like
dealing with files and disk access) but I already posted the link for the
browser version in that comment.

~~~
cousin_it
I think that's not quite what was asked for. What was asked for is one JS file
with a function that takes a string and returns a string. Not a node package,
not a website. Check out Three.js, it's a big library which can be used as one
file three.min.js.

~~~
gchq-7703
If you check the `dist` folder within the linked Git repository you can see a
`walt.min.js` file[0]. You should be able to include that file and try out the
package in your browser in a similar way to how you use `three.min.js`.

[0]
[https://github.com/ballercat/walt/blob/master/packages/walt-...](https://github.com/ballercat/walt/blob/master/packages/walt-
compiler/dist/walt.min.js)

------
PaulBGD_
What's the difference between this and something like AssemblyScript?:
[https://github.com/AssemblyScript/assemblyscript](https://github.com/AssemblyScript/assemblyscript)

EDIT: I see that this project actually existed slightly before AssemblyScript.
Still seems like two very similar projects.

~~~
abuldauskas
I wrote/maintain Walt. This question comes up a bunch.

The two projects are really similar no doubt. I can't speak for
AssemblyScript, but my own motivation was simple. I wanted to learn
WebAssembly and I wanted an accessible platform to do so with. At the time
this wasn't really possible, tools like emscripten took forever to set up and
were clunky to use. Plus I knew C already, I wanted to learn WebAssembly
instead.

So where Walt is an attempt to write WebAssembly with a familiar syntax,
AssemblyScript is an attempt to compile TypeScript to WebAssembly. To do so
AssemblyScript comes with many more niceties/features out of the box IIRC,
like optional(?) GC for example. Walt makes no such attempts and takes a more
DIY approach.

Walt also has language extensions, via customizable syntax and compiler
pipeline, where AssemblyScript is a TypeScript compiler more or less. My hope
is that this allows for a babel-like situation for WebAssembly in the future
via the tooling setup for Walt. I don't think this is a goal of
AssemblyScript.

~~~
danShumway
> _Walt also has language extensions_

IMO this is a good decision. I much prefer a platform with a small API than I
can personally extend over a large platform that has specific customization
options or lots of extra features that all just "kind of" solve whatever
problem I have.

Reading this makes me more interested in the project than I was before.

One quick recommendation, it was kind of hard to find the documentation for
the Webpack free compiler ([https://www.npmjs.com/package/walt-
compiler](https://www.npmjs.com/package/walt-compiler)). This is purely
anecdotal, but I suspect that at least some of the people who are turned on by
having a low-level library that doesn't include Typescript niceties will be
turned off by seeing the quick-start immediately say to install Webpack. Might
be a good idea to have the compiler documentation inside the wiki alongside
the quick-start?

------
__s
I've been going with Lua for writing raw webassembly

Assembler setup:
[https://github.com/serprex/luwa/blob/master/rt/make.lua](https://github.com/serprex/luwa/blob/master/rt/make.lua)
Resulting code for a gc looks like this:
[https://github.com/serprex/luwa/blob/master/rt/gc.lua](https://github.com/serprex/luwa/blob/master/rt/gc.lua)

& it leaves the full Lua language at my disposal for metaproramming. At the
end of a day a human usable assembler needs to be a macro assembler

It'd be neat to have a JS macroassembler, could then have the host browser
runtime compile wasm modules dynamically

~~~
jnbiche
> Resulting code for a gc looks like this:
> [https://github.com/serprex/luwa/blob/master/rt/gc.lua](https://github.com/serprex/luwa/blob/master/rt/gc.lua)

Nice! That's a compact gc, perfect for browsers.

------
ArtWomb
Are people really editing .wat files by hand to eek out the last bit of
performance? Seems like you would need instruction level profiling to do it
justice

Wasabi: A Framework for Dynamically Analyzing WebAssembly

[https://arxiv.org/pdf/1808.10652.pdf](https://arxiv.org/pdf/1808.10652.pdf)

~~~
scrollaway
Do web assembly files really have a .wat extension? This can't _not_ be an
easter egg reference to the famous talk, right? :)

~~~
Touche
Should have gone with .wtf. WebAssembly Text Format.

~~~
scrollaway
.wtf will always be Warcraft Text Files for me. Nothing like editing that
Config.wtf file when playing WoW...

------
branksy
Fascinating! Serious question: could this turn JavaScript (technically Walt)
into a serious language for scientific computation? That now runs in any
browser?

E.g. Python is used a lot together with NumPy/SciPy, but for performance the
actual computation in NumPy/SciPy is done in C since Python is too slow. Would
it be possible to create Walt-native versions of NumPy and SciPy... e.g.
NumWalt and SciWalt? Or even Jupyter notebooks based on Walt?

~~~
mr_toad
You could just port the C libraries that Python uses.

You might want to check that you’re actually gaining any performance, the JIT
compilations of JavaScript aren’t often slow.

------
jeffmcmahan
This looks great. I've been looking for a project like this for a while - a
simple language in which I can write hot code and compile it straight to web
assembly for use in existing node and web projects.

However, I wonder whether Walt is markedly faster than JIT-compiled
javascript? Have you benchmarked the performance gain?

~~~
abuldauskas
I have not, this has been requested quite a bit though. My focus is currently
on making sure the toolchain is stable and performant itself. It's likely that
the performance of the compiled code is on par with other wasm vs JS
comparisons though.

------
kgraves
Superb! I would love to see native programs being ported using traditional JS
to the browser, perhaps this is a step closer for a clone of Photoshop in the
open web!

I like the progress of where webassembly is heading! :)

------
nojvek
This is amazing. Yes! I’ve always wanted something like this.

I wonder if we could make a boiled down typescript language server that would
give excellent code completion and squiggles for Walt.

------
AzzieElbab
Full circle?

------
iddan
Glad I took part of this project early and got the possibility to focus it to
great goals

------
kolderman
Doesn't JavaScript compile down to WebAss? Isn't that the point?

~~~
jniedrauer
WASM is a very new standard. Some JavaScript implementations do compile to
machine code at run time, but JavaScript does not "compile down to WebAss".

------
fnord77
I'd rather use Rust than javascript 8 days a week

~~~
thrower123
I wasted too much time trying to look if there was a way javascript date
objects would report there being eight days in a week...

------
xaduha
Let a thousand flowers bloom and all that, but come on. That particular flower
is a freaking baobab already. I assume it's mostly for use outside of
browsers.

------
artursapek
> Highlights:

> No C/C++ or Rust required, just typed JavaScript.

That's not a flaw...!

~~~
fizzbuzzbazz2
It all depends which of all these ugly langages you are the least
uncomfortable with. I hear they even use js for servers now. Rise and fall...
lol

~~~
DoctorOW
Honestly I thought you referring to Rust as an ugly language would send more
replies your way.

