9 ms·
I Wrote a WebAssembly VM in C
- hemant1041 2y agoThis was a great read! Really cool to see someone dive deep into WebAssembly by building an interpreter from scratch.
- deleted 2y ago[deleted]
- deleted 2y ago[deleted]
- hemant1041 2y agoAsd
- hemant1041 2y ago?
- deleted 2y ago[deleted]
- hemant1041 2y agoTest
- hemant1041 2y agoTest 2
- hemant1041 2y agoTest 3
- hemant1041 2y agoTest 4
- hemant1041 2y agoTest 5
- hemant1041 2y agoTest 6
- hemant1041 2y agoTest 7
- hemant1041 2y agoTest 8
- hemant1041 2y agotest 9
- hemant1041 2y agoTest 10
- hemant1041 2y agoTest
- hemant1041 2y agoAnother test comment
- pdubroy 2y agoThis is great! The WebAssembly Core Specification is actually quite readable, although some of the language can be a bit intimidating if you're not used to reading programming language papers. If anyone is looking for a slightly more accessible way to learn WebAssembly, you might enjoy WebAssembly from the Ground Up: https://wasmgroundup.com https://wasmgroundup.com (Disclaimer: I'm one of the authors)
- MuffinFlavored 2y agoI know one of WebAssembly's biggest features by design is security / "sandbox". But I've always gotten confused with... it is secure because by default it can't do much. I don't quite understand how to view WebAssembly. You write in one language, it compiles things like basic math (nothing with network or filesystem) to another and it runs in an interpreter. I feel like I have a severe lack/misunderstanding. There's a ton of hype for years, lots of investment... but it isn't like any case where you want to add Lua to an app you can add WebAssembly/vice versa?
- jeroenhd 2y agoWebAssembly can communicate through buffers. WebAssembly can also import foreign functions (Javascript functions in the browser). You can get output by reading the buffer at the end of execution/when receiving callbacks. So, for instance, you pass a few frames worth of buffers to WASM, WASM renders pixels into the buffers, calls a callback, and the Javascript reads data from the buffer (sending it to a <canvas> or similar). The benefit of WASM is that it can't be very malicious by itself. It requires the runtime to provide it with exported functions and callbacks to do any file I/O, network I/O, or spawning new tasks. Lua and similar tools can go deep into the runtime they exist in, altering system state and messing with system memory if they want to, while WASM can only interact with the specific API surface you provide it. That makes WASM less powerful, but more predictable, and in my opinion better for building integrations with as there is no risk of internal APIs being accessed (that you will be blamed for if they break in an update).
- panic 2y ago
- deivid 2y agoThis is a really nice write up! It's giving me motivation to go back to my WASM implementation
- syrusakbary 2y agoThis is an interesting approach, great work! For anyone that wants to check where the meat is at, is mostly in this file: https://github.com/irrio/semblance/blob/main/src/wrun.c https://github.com/irrio/semblance/blob/main/src/wrun.c Thinking out loud, I think it would have been a great idea to conform with the Wasm-C-API (https://github.com/WebAssembly/wasm-c-api https://github.com/WebAssembly/wasm-c-api) as a standard interface for the project (which most of the Wasm runtimes: Wasmer, V8, wasmi, etc. have adopted), as the API is already in C and it would make it easier to try for developers familiar with that API. Note for the author: if you feel familiar enough with Wasm and you would like to contribute into Wasmer, we would also welcome any patches or improvements. Keep up the work work!
- oguz-ismail 2y ago> Wasmer > Installed-Size: 266 MB What the hell
- syrusakbary 2y agoIndeed, we need to improve further the base binary size! Most of the size comes from the LLVM backend, which is a bit heavy. Wasmer ships many backends by default, and if you were to use Wasmer headless that would be just a bit less than a Mb. If you want, you can always customize the build with only the backends that you are interested in using. Note: I've seen some builds of LLVM under 5-10Mb, but those require heavy customization. Is clear that we have still some work to do to reduce size on the general build!
- CyberDildonics 2y agoSo you are shipping all of llvm?
- dapperdrake 2y agoWell, if you want to just-in-time compile, then it seems like a compiler is one way to go. They are now in the size realm of Lisp and Smalltalk. Forth may lean towards the lighter side.
- pcmoore 2y agoI found this article very interesting with regards direct WASM interpretation: https://arxiv.org/abs/2205.01183 https://arxiv.org/abs/2205.01183 I produced https://github.com/peterseymour/winter https://github.com/peterseymour/winter on the back of it and learnt WASM is not as simple as it should be.
- whizzter 2y agoOne tip for the author from another one, the spec-test contains various weird forms of textual wasm that isn't obvious how to compile but the wast2json converter can produce a simpler JSON desc accompanies by regular binary wasm files.
- bhelx 2y agoSame tip here. We did this with Chicory: https://github.com/dylibso/chicory https://github.com/dylibso/chicory I'd follow on that, the earlier you can get this test-suite running the better for the iteration speed and correctness of your project. It took a bit of time to make everything work, but once we did, we very quickly got to the point of running anything. The test-suite is certainly incomplete but gets you 95% there: https://github.com/WebAssembly/testsuite https://github.com/WebAssembly/testsuite
- _cogg 2y agoThank you! Not the author, but I'm also building a compiler. I've stumbled across these tests before and mostly just been irritated and confused about what to do with them.
- davexunit 2y agoThis was a fun read! I wrote a Wasm interpreter in Scheme awhile back so it makes me happy to see more people writing their own. It is less difficult than you might think. I encourage others to give the spec a look and give it a try. No need to implement every instruction, just enough to have fun.
- greasy 2y agoThis is awesome.
- autumnlani 2y agoThis is awesome. Nicely done
- abnercoimbre 2y agoTake a look at Orca [0] since I think you'd be a great contributor there. [0] https://orca-app.dev https://orca-app.dev
- UncleEntity 2y agoHeh, I also made the decision to focus on one project instead of hopping between new and shiny with the exception that I'm getting our AI overloads to do all the yak shaving -- which is frustrating to say the least... --edit-- Oh, and I also was going to suggest using a library like libffi to make calls into C so you can do multiple arguments and whatnot.
- Jyaif 2y agoRegarding using WebAssembly as a plugin API, like for zed: how do plugin developers debug their code? Is there a way for them to do breakpoint debugging for example? What happens if their code crash, do they get a stacktrace?
- dapperdrake 2y agoHere is a more controversial point: Are you interested in adding a preliminary tail-call instruction? The WASM spec people rejected it for being too "high-level". But the C committee also rejected proposals from Dennis Ritchie. My money is still on Ritchie. Rob Pike's money seems to be on Ritchie direction as well. Otherwise, why create Golang? Tail-calls are only high-level if calls are high-level.
- tlively 2y agoThe WebAssembly tail call proposal has been accepted, finished, and implemented for over two years now. https://github.com/WebAssembly/meetings/blob/main/main/2023/CG-01-17.md https://github.com/WebAssembly/meetings/blob/main/main/2023/...
- davexunit 2y agoAnd WebKit finally shipped it recently! Love return_call and friends.
- doctor_radium 2y agoNewbie questions: How do you debug an interpreter when you aren't coding for it directly? How far does fuzzing strings of opcodes get you? How much practical difference is there between a server side WASM engine and a browser-based one? How much work would be involved converting one to the other?
- OhNoNotAgain_99 2y ago[dead]
- deleted 2y ago[deleted]
- hemant1041 2y agoTest
- hemant1041 2y agoTesting
- hemant1041 2y agoHi