Show HN: Go playground powered by WASM that runs in the browser
go-playground-wasm.vercel.app
go-playground-wasm.vercel.app
Here's the source code (https://github.com/zackradisic/go-playground-wasm) if you would like to look at it and do something similar with your own projects.
I'm really excited for the future of goscript, Go is a great candidate for a scripting language thanks to its minimalistic design choices.
Strange things are afoot at the Circle K.
Perhaps someone can shed more light on how exactly it works
The Rc module with the impl - https://doc.rust-lang.org/alloc/rc/
Further docs on Rc- https://doc.rust-lang.org/book/ch15-04-rc.html
[Error] TypeError: i64 not allowed as return type or argument to an imported function
[f] ut (framework-a4fd281a1981cd6d009d.js:1:16748)
[f] mt (framework-a4fd281a1981cd6d009d.js:1:17899)
[f] L (framework-a4fd281a1981cd6d009d.js:1:115080)
[f] W (framework-a4fd281a1981cd6d009d.js:1:2282)
[f] Jt (framework-a4fd281a1981cd6d009d.js:1:23856)
[f] Zt (framework-a4fd281a1981cd6d009d.js:1:23074)
[N] Zt
[f] (anonymous function) (framework-a4fd281a1981cd6d009d.js:1:128011)
[f] F (framework-a4fd281a1981cd6d009d.js:1:114857)
[f] Xt (framework-a4fd281a1981cd6d009d.js:1:22889)
[N] Xt
I get that error when I click “Run” with the sample code in Safari.Nice project. Thanks for sharing.
#!/usr/bin/env bash
{
find . -name "*.go" -print
echo package.json
} | entr bash -c '
set -euxo pipefail
clear
go fmt
clear
go build
:
'
You can make it fancier like adding cd into "${BASH_SOURCE[0]%/*}", etcThere seems to be another interpreter that seems to be able to provide some autocomplete using some other third party tool, but it seemed to run from beginning every time (same effect as `go run`) and I havent tried it.
Each cell runs in a 0.3 secs on Linux, but 3 seconds + on Windows.
If you want just straight terminal check out Gomacro, that's a interpreter that runs really fast, didn't find any differences to compiled Go.
I’ve been falling more and more in love with wasm … so many possibilities :)
Plus their own (simplified) subset of the standard library, which is getting more comprehensive over time, but is nowhere near complete yet.
There are 3 big reasons for large Go binaries.
1. Unicode data is ~1 MB. It's needed to implement all the unicode-aware string functions like strings.EqualFold()
2. reflection. For reflection to work, every struct used in a Go program needs to have a description information that tells names and types of all fields. This adds up
3. Precise garbage collector also requires struct descriptions like reflection but even more information like: layout of stack frame for every function.
Those are problems that could, in theory, be worked-around.
A build could exclude Unicode info and functions that require it.
A different garbage collector could be used that doesn't require knowing layout of structs and stack frames.
Reflection could be changed to require explicit opt-in (99% of structs are not reflected upon).
Realistically none of that will happen in the official Go implementation. For better or worse most of the work is sponsored by Google and Google runs Go on servers. With 512 MB of memory, it makes little difference if your binary is 10 MB vs 9 MB, especially if you compete with even more bloat (in runtime memory use, not necessarily binary size) of Java / Python / Ruby / Node.
There are a couple of not-very-mature Go-like implementation that are trying to address this (tinygo, emgo) but they have long way to go.
The others - GC and unicode data - can be addressed through changes to WebAssembly in theory.
For Zig, I developed a custom compression algorithm[0] for the Unicode data files needed to implement the same string functions - reducing the data size down to just 58 KiB. The same could certainly be applied to Go.
[0] https://devlog.hexops.com/2021/unicode-data-file-compression
I will have to check out emgo; first time I’m hearing about it.
I've lost track of the process (there were several proposals) so I'm not sure where we're at now.
I guess not much changed, so the current state of WASM is mostly for porting and running non-JS code (such as Go's here) in the browser.
It's also faster than JS (if passed through an optimizing compiler) so it might be useful for non-IO-bound code.
Outside the browser it's being used as a sort of universal bytecode (a la JVM). https://wasmer.io/
it actually powers some of the courses in go that I've written as well
neat project too!