29 ms·
> Well, the Go runtime is written in Go itself. That's a bit of a stretch. The runtime uses special pragmas that are not available to normal programs. I don'
by haberman 9y ago
> Well, the Go runtime is written in Go itself.
That's a bit of a stretch. The runtime uses special pragmas that are not available to normal programs. I don't think it would be possible to write Go's GC in Go unless these special pragmas existed:
https://github.com/golang/go/blob/57df2f802f0417f08100ff8002f3b062e695e148/src/runtime/HACKING.md https://github.com/golang/go/blob/57df2f802f0417f08100ff8002...
Also, there are magical variables in the runtime that the compiler knows about and special-cases: https://github.com/golang/go/blob/57df2f802f0417f08100ff8002f3b062e695e148/src/runtime/mgc.go#L241 https://github.com/golang/go/blob/57df2f802f0417f08100ff8002...
> And you can write Go without the runtime, the same way the compiler is.
How would you write Go without using the GC?
- pjmlp 9y agoThat is the magic of cross compilation. There is already a compiler that knows those special pragmas, one just needs to add a new bare-metal backed to it. As for writing Go without a GC, just like in any other GC enabled systems programming language, by not using language features that require GC in the lowest layer, which the other packages then depend on. Example in Oberon, https://people.inf.ethz.ch/wirth/ProjectOberon/Sources/Kernel.Mod.txt https://people.inf.ethz.ch/wirth/ProjectOberon/Sources/Kerne... Also even ANSI C requires some Assembly or compiler extensions to fully implement libc.