A lot has been written about a go "interpreter", for a number of very different reasons, namely:
1. For use in an interactive Read/Eval/Print/Loop (REPL)
2. In a debugger
3. In an IDE (and possibly combining aspects 1 & 2)
4. As an embedded or extension language in another subsystem such as lower-level tracing
5. For experimenting with alternate implementations or implementations of various constructs (e.g. slices)
For 3, let me put in a plug for
https://code.google.com/p/go-play . Measured against a real IDE this code this is meager. But measured against the "present" and the go playground I think it fares okay. If I can figure out how to submit patches, I'll do that for the small improvements I have made to indentation handling and error location reporting. What go-play currently lacks is the websocket communication in the "present" package. However, simple tests with chrome 27.0.1453.81 (Official Build 198567) and go's websocket gives me an error:
WebSocket connection to 'ws://localhost:23456/sendRecvText' failed: Invalid UTF-8 sequence in header value
Contributions here to get this last important piece into go-play would be welcome.
At any rate, following the suggestion that old misc/goplay be have another home, it now has. And thus, I agree that gosource/misc/goplay should be deleted since everything it had to offer is in go-play, while go-play offers more.
Now coming back to uses 1-3. Recently there was the suggestion to look at ssa/interp. And the question was asked whether it could handle code fragments instead of a full program. Having looked a little at that code, it doesn't look to me as what I'd use for the basis as an interpreter for 1-3. Rather, my thought would be to base a simple interpreter off of the AST (go/ast). Why?
Well first there is that issue of code fragments. Something working off of an AST wouldn't have that problem. Second, looking at the SSA code in a cursory way I couldn't figure out how to get source-code position information. Given the stated goal: "to facilitate construction of source analysis tools.", I'm probably missing something; I would imagine position information useful to have for source-code analysis.
In contrast, each AST node has position information:
http://godoc.org/go/ast#Node How rigorously and accurately that information is maintained is a separate question.
Given that SSA must mangle the source code more than the AST, (in fact the SSA *starts* with the AST), the SSA representation is less likely to correspond to the code in the way that a naive programmer thinks of it with respect to control constructs, variable names or having a one-to-one mapping of code construct with position in the source code.
(But again I hesitate since this seems to contradict its stated goal as a source-analysis tool.)
So as I look at the "interpreter" suggestions so far, I am kind of surprised to see something along the lines of building an interpreter off of the AST missing.
Lastly, some questions regarding comments in ssa/interp (which has been recently moved to
http://godoc.org/code.google.com/p/go.tools/ssa)
1.
http://godoc.org/code.google.com/p/go.tools/ssa/interp says:
Unsafe operations, including all uses of unsafe.Pointer, are impossible to support given the "boxed" value representation we have chosen.
What does it mean the "boxed" value representation?
2. "sync/atomic" operations are not currently atomic due to the "boxed" value representation: it is not possible to read, modify and write an interface value atomically. As a consequence, Mutexes are currently broken. TODO(adonovan): provide a metacircular implementation of Mutex avoiding the broken atomic primitives.
There is that "boxed" value representation thing again. But now there is "metacircular implementation of Mutex avoiding the broken atomic primitives". What does that mean? Anyone care to venture a guess?