I help out every once and a while on the AssemblyScript team with like issues, docs, and things. And made wasmboy, which uses AssemblyScript: https://github.com/torch2424/wasmBoy
Incredibly, the segment below is valid TypeScript.
@inline
function rot(x: u32, y: u32, v: u32): void {
var a = max<i32>((v >>> 24) - BIT_ROT, 0);
set(x, y, (a << 24) | (v & 0x00ffffff));
}
You must be working on a different set of problems than me to be able to identify this as vanilla TypeScript.
Not given the context of a file extension, I would forgive anyone for mistaking this to be some kind of low level driver code and be confused on source language.
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.
Your project is weird to begin with, and then "knew C already" makes it even weirder. The whole point of WebAssembly was to find some way to get away from JavaScript, and to support languages like C. Here you are, going right back to the JavaScript that we've been trying to escape for the past 23 years.
Also, on your page you say that "A competent Front-end engineer should be able to edit WebAssembly as easily as any other systems programmer." The "any other" seems to imply that a "Front-end engineer" is a "systems programmer". This is typically not the case.
You'll have to excuse HN Guy that assumes that every project on GitHub is done to try and take over the world and not because, you know, learning is fun. So keep on doing weird things with your weird and awesome language.
I may be in the minority then: one of the big advantages, for me, of WASM is that I can use not-Javascript in the browser. Some of the issues I have with JS are an artifact of being one of the first things to run in the browser (e.g. atrocious standard library) and some are just baked in poor designs (e.g. implicit type casting, == vs ===).
Oh gosh, let's not forget what happens when you try to use map and parseInt together.
Sure, but you're putting a workaround in – there really shouldn't be any need for that no-op arrow function. But you do actually need it in order to drop all but the first arguments.
This doesn't work because map() stuffs a counter into the second argument of parseInt(), which is expecting a radix for its second argument. So the iterations of the map go like this:
…and so on, which obviously gives garbage results. JavaScript is littered with these kinds of weird edge cases. Even your example with the workaround isn't 100% reliable, it's browser-dependent – when you have leading zeros in your strings, some browsers will interpret them as octal, and some won't.
Language version dependent rather than browser dependent.
It may seem the same (after all, different browsers implement different versions of the language), but it's a bit different, if you say 'browser-dependent' it makes it sound like there is no standard when in fact, the leading zero behaviour hasn't been the case since ecmascript 5. You'll struggle to find a browser in common use that doesn't support at least ecmascript 5. It's as browser-dependent as the array.map function which was added at the same time.
Your example code would never have the leading 0 problem since you're using array.map and array.map didn't exist in the engines that had that leading 0 'feature'.
What a weird argument. C is not "better" than Javascript, it is vastly worse for the vast majority of current Javascript uses - where raw performance is a less important consideration than development time.
Javascript is far from perfect, but it has improved by leaps and bounds the last few years. WebAssembly is great, but a variant of Javascript or other high-level languages will continue to dominate web development, not C. People aren't going to "escape" from Javascript to C, except certain niches where performance is vital.
If you like your JavaScript, you can keep your JavaScript. You have no reason to care about WebAssembly. Why would you build a JavaScript imitation on WebAssembly when you can just use JavaScipt?
That's the thing though. We are all "us" here. We can all compile whatever we want to WebAssembly, that's the point of WebAssembly. One way of doing things doesn't take away from another.
You might like a JavaScript-like language but want to get rid of the garbage collector, or work closer to the bare metal than Javascript currently allows.
It's not a JavaScript imitation. This is a JavaScript-like syntax for writing WebAssembly. Other than that, (excepting the closure helper) it's 1-to-1 WebAssembly.
Not everyone enjoys writing verbose S-Expressions [1], even if it makes for a good canonical format.
If you despise JavaScript so much that you can't bear the thought of something that vaguely looks like JavaScript, then don't worry there are other "skins" for writing WebAssembly [2-4] and it should not be too hard to write your own.
Finally, nobody owns WebAssembly. It's for clever people like yourself just as much as it is for dirty JavaScript programmers like me.
> The whole point of WebAssembly was to find some way to get away from JavaScript
The goal is to "Define a portable, size- and load-time-efficient binary format to serve as a compilation target which can be compiled to execute at native speed by taking advantage of common hardware capabilities...."[0].
Everything old is new again, and the Wheel of Time turns, and ages come and pass, leaving memories that become legend. Legends fade to myth, and even myth is long forgotten when the Age that gave it birth comes again. In one Age, called the third age by some, an Age yet to come, an age long past, a virtual machine specification was created in an attempt to achieve the goal of write-once, run everywhere code. The specification was not the beginning. There are neither beginnings or endings to the turning of the Wheel of Time. But it was a beginning.
In the beginning Assembly became bytecode and CPUs included interpreters via microcode, then everything was supposed to be executed directly by hardware gates, now Assembly has become another form of bytecode and all major CPUs have reverted back to microcode.
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). 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?
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
Binary size would probably be the main thing you'd want to optimize for. Which, at least a few months ago when I tried the wasm32 target in rustc, is a big issue.
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.
Dismissive non-constructive feedback about projects like this is stupid and IMHO makes people not want to post their projects here.
Your statement and question could have been conveyed like this:
> From my perspective this looks a lot like ASM.js implemented on top of web assembly, but web assembly was meant to replace ASM.js?
The difference is that "congratulations I guess" makes your entire statement and question blatantly communicate "what you did is worthless" when clearly the author had _some_ valid reason to do it, otherwise they wouldn't have.
> Dismissive non-constructive feedback about projects like this is stupid and IMHO makes people not want to post their projects here.
Well, you can interpret my comment as "stupid", which is your right, but it wasn't my intent. And your rebuttal wasn't constructive either. It would have been more useful to highlight the differences between that project and ASM.js. Nowhere in my message I described that project at "worthless", it's your interpretation and it's just wrong IMHO.
The response explained why your post was not great and then elaborated on how you could have done it better. That’s pretty much the text book definition of constructive.
> The response explained why your post was not great and then elaborated on how you could have done it better. That’s pretty much the text book definition of constructive.
Since when personal attacks are deemed constructive? There is nothing constructive in his patronizing comment. How about one of you formulates a technical rebuttal to my initial statement as I asked and you quit being meta?
You both could've done better in constructing your responses. He explained why yours was lacking, you explained why his was lacking. You both made valid points.
As for actually answering your question, probably only Walt's author could answer that. Unfortunately, due to your condescending choice of phrasing, he may choose to not engage in discussion with you, thinking that you're not sincerely interested in his answer.
I hope he looks past that and does answer you, as I'm sure others are wondering similarly.
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?
Programming languages are tools, not religions. If a project like this can help people use and understand their tools that is a good thing. Reacting as if the infidel language is defiling the sacred is absurd and indefensible from a practical standpoint.
I'd agree with you except that any language that requires the "let" keyword is absurd and indefensible. And this is one of many religious-like language wars out there.
Well yes... unless you realize that ours is a fashion-driven industry, where technical choices are not made based on technical merits but via a popularity contest. From a practical standpoint, complaining about propagation of bad choices is absolutely defensible.
Or, to put in another way: today you don't complain about crap tech pushing out good tech, tomorrow half of the jobs in your field require you work with the crap tech.
WebAssembly's goal is to provide a simple VM with performance good enough for the web to compete with native programs and to unlock use cases that are not possible to run efficiently in JavaScript.
The syntax that the developer see is totally irrelevant here.
He not only mentioned syntax but design too. Clearly JavaScript's lack of int (for example, to mention a design decision of JS) is one of the reasons of its poor performance, not to mention its weak typing approach.
While I have similar feelings, I also think the mark of success for WebAssembly will be if it succeeds in freeing developers to do web stuff in the language of their choice.
Even if that choice is a familiar JavaScript-like language, it still proves the point that the web is now open to whatever the developer wants. So in that sense, I applaud and welcome things like this.
Please do port all of most-hated languages to run with WebAssembly and create new ones that I also don't like. It more or less means that languages I love can be ported and that new ones I will love can be created.
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?
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.
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.
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`.
You don't need node to compile WASM or deliver it to the browser, either.
The only reason this "needs" NPM is because it's become convention that all javascript projects need NPM and some related toolchain regardless of their complexity.
No, the convention is that Javascript projects are distributed as source rather than as "binaries" (single minified JS files.) Source code generally needs a build tool. NPM is a build tool.
It doesn't translate to wasm text format, but to wasm binary format. The walt-compiler (https://github.com/ballercat/walt/tree/master/packages/walt-...) readme shows how to use it to compile text into a a buffer which you can write to disk or instantiate into a webassembly module.
It doesn't translate to wasm text format,
but to wasm binary format.
Oh, ok. That is interesting too. But I would have liked to build a tool where I type Walt on the left and see the resulting WASMtext on the right. So this seems to not be a solution for that.
Your argument is valid, the QuickStart example isn’t wrong though. Webpack is somewhat the bundling standard in front end. What they showed, I can easily get it working in a large project without a lot of kungfu.
If you want the walt->wasm function, it’s usually the loader.
And yes, you can invoke the loader standalone.
Perhaps they should give a much simpler example and then later a webpack example.
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! :)
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?
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.
112 comments
[ 4.0 ms ] story [ 278 ms ] threadEDIT: I see that this project actually existed slightly before AssemblyScript. Still seems like two very similar projects.
That said, the familiar tooling, editor support, are wins over other WASM options.
[0] https://github.com/AssemblyScript/assemblyscript/blob/master...
But that being said, usually when people are interested in the language, we usually direct them to the "n-body" example: https://github.com/AssemblyScript/assemblyscript/blob/master... . Which kind of looks more typescript-y :)
Also, just to stay on topic, I think walt is awesome. Stoked to see so many projects coming up with a "Wasm for JS devs" approach/story.
Not given the context of a file extension, I would forgive anyone for mistaking this to be some kind of low level driver code and be confused on source language.
It is so impressive that this is valid TS though!
[edit: code formatting]
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.
Also, on your page you say that "A competent Front-end engineer should be able to edit WebAssembly as easily as any other systems programmer." The "any other" seems to imply that a "Front-end engineer" is a "systems programmer". This is typically not the case.
It's has been a weird and interesting project, but that's not really a bad thing is it.
Oh gosh, let's not forget what happens when you try to use map and parseInt together.
Returns
[1,2,3,4,5,6,7,8,9,10]
["1", "2", "3", "4", "5", "6", "7", "8", "9", "10"].map(parseInt);
This is simple, straightforward, and wrong:
This doesn't work because map() stuffs a counter into the second argument of parseInt(), which is expecting a radix for its second argument. So the iterations of the map go like this: …and so on, which obviously gives garbage results. JavaScript is littered with these kinds of weird edge cases. Even your example with the workaround isn't 100% reliable, it's browser-dependent – when you have leading zeros in your strings, some browsers will interpret them as octal, and some won't.Language version dependent rather than browser dependent.
It may seem the same (after all, different browsers implement different versions of the language), but it's a bit different, if you say 'browser-dependent' it makes it sound like there is no standard when in fact, the leading zero behaviour hasn't been the case since ecmascript 5. You'll struggle to find a browser in common use that doesn't support at least ecmascript 5. It's as browser-dependent as the array.map function which was added at the same time.
Your example code would never have the leading 0 problem since you're using array.map and array.map didn't exist in the engines that had that leading 0 'feature'.
Javascript is far from perfect, but it has improved by leaps and bounds the last few years. WebAssembly is great, but a variant of Javascript or other high-level languages will continue to dominate web development, not C. People aren't going to "escape" from Javascript to C, except certain niches where performance is vital.
If you like your JavaScript, you can keep your JavaScript. You have no reason to care about WebAssembly. Why would you build a JavaScript imitation on WebAssembly when you can just use JavaScipt?
WebAssembly is for the rest of us.
WebAssembly is for everyone.
Not everyone enjoys writing verbose S-Expressions [1], even if it makes for a good canonical format.
If you despise JavaScript so much that you can't bear the thought of something that vaguely looks like JavaScript, then don't worry there are other "skins" for writing WebAssembly [2-4] and it should not be too hard to write your own.
Finally, nobody owns WebAssembly. It's for clever people like yourself just as much as it is for dirty JavaScript programmers like me.
[1] https://developer.mozilla.org/en-US/docs/WebAssembly/Text_fo...
[2] https://github.com/tmcw/wah
[3] https://github.com/serprex/luwa
[4] https://medium.com/cirru-project/webassembly-s-expression-an...
The goal is to "Define a portable, size- and load-time-efficient binary format to serve as a compilation target which can be compiled to execute at native speed by taking advantage of common hardware capabilities...."[0].
[0] https://webassembly.org/docs/high-level-goals/
In the beginning Assembly became bytecode and CPUs included interpreters via microcode, then everything was supposed to be executed directly by hardware gates, now Assembly has become another form of bytecode and all major CPUs have reverted back to microcode.
Same applies to GPUs.
Everything old is new again, indeed.
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). 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?
Wasabi: A Framework for Dynamically Analyzing WebAssembly
https://arxiv.org/pdf/1808.10652.pdf
> No C/C++ or Rust required, just typed JavaScript.
That's not a flaw...!
Assembler setup: 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
& 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
Use fengari (https://fengari.io/) to run your lua assembler?
Nice! That's a compact gc, perfect for browsers.
Your statement and question could have been conveyed like this:
> From my perspective this looks a lot like ASM.js implemented on top of web assembly, but web assembly was meant to replace ASM.js?
The difference is that "congratulations I guess" makes your entire statement and question blatantly communicate "what you did is worthless" when clearly the author had _some_ valid reason to do it, otherwise they wouldn't have.
Well, you can interpret my comment as "stupid", which is your right, but it wasn't my intent. And your rebuttal wasn't constructive either. It would have been more useful to highlight the differences between that project and ASM.js. Nowhere in my message I described that project at "worthless", it's your interpretation and it's just wrong IMHO.
Since when personal attacks are deemed constructive? There is nothing constructive in his patronizing comment. How about one of you formulates a technical rebuttal to my initial statement as I asked and you quit being meta?
As for actually answering your question, probably only Walt's author could answer that. Unfortunately, due to your condescending choice of phrasing, he may choose to not engage in discussion with you, thinking that you're not sincerely interested in his answer.
I hope he looks past that and does answer you, as I'm sure others are wondering similarly.
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?
Or even figure out how to run a Python interpreter + WASM-compiled C extensions together to be able to use Numpy, Scipy, etc.
You might want to check that you’re actually gaining any performance, the JIT compilations of JavaScript aren’t often slow.
I would seriously like to see you defend this viewpoint.
Or, to put in another way: today you don't complain about crap tech pushing out good tech, tomorrow half of the jobs in your field require you work with the crap tech.
WebAssembly's goal is to provide a simple VM with performance good enough for the web to compete with native programs and to unlock use cases that are not possible to run efficiently in JavaScript.
The syntax that the developer see is totally irrelevant here.
Even if that choice is a familiar JavaScript-like language, it still proves the point that the web is now open to whatever the developer wants. So in that sense, I applaud and welcome things like this.
Please do port all of most-hated languages to run with WebAssembly and create new ones that I also don't like. It more or less means that languages I love can be ported and that new ones I will love can be created.
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?
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/
The next paragraph of the comment you replied to answers that — you don’t, you can use https://ballercat.github.io/walt/ in your browser.
[0] https://github.com/ballercat/walt/blob/master/packages/walt-...
The only reason this "needs" NPM is because it's become convention that all javascript projects need NPM and some related toolchain regardless of their complexity.
[1] https://github.com/WebAssembly/wabt
It's not the interface that I would like to use. I want to write Walt on the left and instantly see the WasmT on the right.
Also, that tool does not work here. It gives me 'Uncaught ReferenceError: getAST is not defined' as soon as I type something in the code tab.
Perhaps you should try unpkg:
And if that doesn't work, perhaps you can submit an issue or a PR.https://jsbin.com/nisoget/edit?html,js,console
This is what makes Hacker News great!
And yes! I think answering these kind of simple questions is important, so thanks for asking them.
I'm already having fun with it.
If you want the walt->wasm function, it’s usually the loader.
And yes, you can invoke the loader standalone.
Perhaps they should give a much simpler example and then later a webpack example.
It’s open source, open a PR may be?
You can then play with the `Walt` global.
I like the progress of where webassembly is heading! :)
However, I wonder whether Walt is markedly faster than JIT-compiled javascript? Have you benchmarked the performance gain?
I wonder if we could make a boiled down typescript language server that would give excellent code completion and squiggles for Walt.