3 ms·
Well, the Go runtime is written in Go itself. And you can write Go without the runtime, the same way the compiler is. The hard part is that the runtime is inde
by dullgiulio 9y ago
Well, the Go runtime is written in Go itself. And you can write Go without the runtime, the same way the compiler is.
The hard part is that the runtime is indeed build on OS primitives (syscall mostly), that you have to implement yourself.
You have to forgo all the niceties of having a runtime but you can do it. Definitely not the most productive use of Go, but it's fun and you learn a lot.
- weberc2 9y ago> And you can write Go without the runtime, the same way the compiler is. The compiler does depend on the runtime AFAIK > The hard part is that the runtime is indeed build on OS primitives (syscall mostly), that you have to implement yourself. This is what I was referring to. I don't know how you would do this without patching the language.
- pjmlp 9y agoBy using a mix of cross-compiling and some Assembly help, just like C needs some help beyond what ANSI C specifies.
- 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.