4 ms·
Interpreting Go
- pcwalton 7y agoInterpreting Go is a good idea. In fact, a JIT for Go would be a very interesting idea as well. In a language that makes heavy use of virtual dispatch like Go does (via interfaces), you can often get a lot of mileage out of speculative devirtualization. With a JIT you can easily observe the concrete types that flow through each call site, allowing for optimizations you can't easily do with AOT compilation (without PGO, anyway). You can even do aggressive optimizations like observing that only one type that's currently loaded in the program conforms to an interface and devirtualize accordingly, knowing that you can undo that optimization if more code gets loaded later on that invalidates this assumption.
- tedunangst 7y agoDropping this here: https://github.com/gijit/gi https://github.com/gijit/gi
- eatonphil 7y agoWoah! That is an awesome project. Surprised this is the first time hearing of it. Thanks.
- tedunangst 7y agoThere is also the https://github.com/cosmos72/gomacro https://github.com/cosmos72/gomacro interpreter if you were unaware.
- eatonphil 7y agoI have been watching that one closely. :)
- Sir_Cmpwn 7y agoCould you use this to make a Go REPL?
- minxomat 7y agoYaegi is a full go interpreter with a repl: https://blog.containo.us/announcing-yaegi-263a1e2d070a https://blog.containo.us/announcing-yaegi-263a1e2d070a
- eatonphil 7y agoLike the sibling mentions, yaegi seems to do that today (though I haven't used it). The method I wrote about doesn't seem particularly any more conducive to making a REPL than progressively building a valid Go program with each line and compiling/running that (since Go's compiler is very fast). However, there may be some benefits to prototyping in an environment like this where you can ignore types for a bit.
- teichmann 7y agoGomacro provides an interactive REPL https://github.com/cosmos72/gomacro https://github.com/cosmos72/gomacro.
- pfalafel 7y agoI would like to call interpreted Go code from compiled Go code, say, like: run("dynamic.goi"). Would I be able to call back into the compiled code from the interpreted code? Can the two parts share variable state?
- eatonphil 7y agoExposing an "FFI" is definitely a step along the way in any project like this, though I've never personally found it particularly straightforward (or fun). It does open up the floodgates for functionality though.