9 ms·
Yaegi – Yet Another Go Interpreter
- penagwin 7y agoAround a ~6MB interpreter for those curious, not bad.
- weberc2 7y agoGenerally the Go runtime (garbage collector, scheduler, allocator, etc) alone is 2-5MB, for additional context.
- f2f 7y agoa bit less: $ cat > t.go package main func main() {} $ go build t.go $ ls -l t -rwxr-xr-x 1 f2f staff 1101432 24 Jul 23:19 t
- zimpenfish 7y agoAnd you can drop that down to ~775k by using `strip`. [rjp@hostname tmp]$ ls -l gosize -rwxr-xr-x 1 rjp rjp 1126905 Jul 25 07:00 gosize [rjp@hostname tmp]$ strip gosize [rjp@hostname tmp]$ ls -l gosize -rwxr-xr-x 1 rjp rjp 793704 Jul 25 07:00 gosize [rjp@hostname tmp]$ go version go version go1.12.7 linux/amd64
- weberc2 7y agoNot sure, but is it possible that the runtime (or parts thereof) isn’t linked in in that example?
- kbd 7y agoProgramming in a language lacking a repl is always uncomfortable. I always wind up making a 'scratch.{ext}' file and running it to test things (scratch.* is in my global gitignore). Happy an interpreter+repl now exists for Go.
- skybrian 7y agoYou can do similar things by writing tests as you go, plus then you can keep the tests if they seem useful.
- kbd 7y agoFor one meaning of "test", sort of, but repls are useful for far more than "do outputs match what I expect". Test writing is not very good for exploratory programming.
- marcrosoft 7y agoTests are perfect for "do outputs match what I expect". If you don't know what you are expecting yet just to `t.Error("")`. When you are done fiddling around and want to solidify what you expect add the `if foo != expectation`.
- jpittis 7y agoTo add to this, editor commands to quickly switch to your test file, auto generate test boilerplate and run the currently highlighted test are super helpful to speed up this loop.
- wc- 7y agoThis sounds really helpful, can you provide any links to read more about setting these helpers up?
- jpittis 7y agoIt completely changed the way I write Go. This is editor specific though. I use Vim for programming Go and have a few custom scripts built on top of https://github.com/fatih/vim-go https://github.com/fatih/vim-go.
- 7y ago
- drinane 7y agoThat's pretty cool. Definitely going to use this on my projects.
- InvOfSmallC 7y agoPlease add generics at least on Yaegi! :P
- stcredzero 7y agoHe doesn't have to: https://github.com/cosmos72/gomacro https://github.com/cosmos72/gomacro
- InvOfSmallC 7y agoI love you
- ausjke 7y agois gomacro better for repl on golang comparing to yaegi? both look well
- ausjke 7y agogophernotes is sort of like a repl under jupyter
- tomphoolery 7y agoYaeji is going to be very happy that an interpreter was named after her! https://soundcloud.com/kraejiyaeji https://soundcloud.com/kraejiyaeji
- hammeiam 7y agoI was thinking the same thing :)
- deleted 7y ago[deleted]
- frou_dh 7y agoFrom the "another" archives, I remember this one, that looks abandoned: https://news.ycombinator.com/item?id=15622894 https://news.ycombinator.com/item?id=15622894 https://neugram.io/ https://neugram.io/ https://github.com/neugram/ng https://github.com/neugram/ng
- ysleepy 7y agoI'd be interested in an opinion of the dev on what was the hardest part to build. I could imagine reflection features or the incremental type checking would be hard to do. But I always see these projects (like cling/ROOT from cern) and think that some subproblems are really hard to do if done incrementally with only local knowledge.
- drinane 7y agoDoes it have any pretty printing capabilities? Repo doesn't seem to...
- webscalist 7y agoYAGNI?
- quickthrower2 7y agoYaegimeister?
- mwkaufma 7y agoBench-marking a fat native call, rather than a purely-interpreted function, is a bit bait-and-switch.
- chrisseaton 7y agoThey do explain it very clearly though, and give a reason why that is what they are interested in for business purposes. Benchmark and optimise for what you're running, right? Better than a Mandelbrot?
- superdimwit 7y agoYeah, but they're just benchmarking a wrapper around gzip. It looks to be around 300 LOC and does very little.. It's a bit deceptive. A large table of benchmarks across different domains and workloads would be more honest.
- the_duke 7y agoThey explain it, but it's still deceptive. I would have expected a honest benchmark result. Which will be much worse than 6%. Which is totally fine! an interpreter will of course be much slower. But this seems like the wrong kind of marketing by omission to me.
- haolez 7y agoIt seems to be from the creators of Traefik, which is another great tool. https://traefik.io/ https://traefik.io/
- childintime 7y agoWasn't clear to me: will it run say a serial port without additional steps?
- forgot_old_user 7y agoWhy would I need a Go Interpreter? What advantage does it provide over using a precompiled binary?
- jessemillar 7y agoI didn't see any while reading through the blog post...
- mcpherrinm 7y agoThere are some circumstances where an interpreter is useful: For example, it should be possible to make better golang repls with an interpreter than with a binary. In a "scripting" scenario, you can load some golang code at runtime without needing to bring the full golang compiler toolchain along, which keeps the nice "single binary" deploys of golang. It may be possible to sandbox scripts as well (though I haven't looked into how that could work with this implementation), which could reduce the risk of running scripts (less likely to shoot yourself in the foot. Probably not a security boundary -just look at how much work goes into safe JS in browsers to have that).
- mhh__ 7y agoSandboxing is possible but only if it brings it's own standard library (I think... I'm not familiar with how go implements io at it's roots)
- stcredzero 7y agoI'm working on an approach for Golang sandboxing which works through whitelisting imports, and munging all references, casting operations, and function calls, which lets one whitelist those as well. I would disallow all io and network access.
- the_duke 7y agoSeems like a wasm interpreter with WASI might be a better approach.
- dilap 7y agoVery cool idea. Doesn't seem ready for prime time yet -- tried running it on a small Go program to score boggle boards, and got errors in the interpreter. Playing around, it seems to have problems assigning int literals to int8 variables, and it seems to sometimes have problems re-assigning pointer values.
- leshow 7y agoLike runhaskell for Go?
- ldez 7y agoNow, you can play with it in the Go Playground https://play.golang.org/p/P--lUj4Vbax https://play.golang.org/p/P--lUj4Vbax