[go-nuts] Re: Code style in golang compiler

2021-02-08 Thread Luke Champine
git blame is instructive here. The commit in question is: https://github.com/golang/go/commit/166b1219b8a5b246c83986c7ecef3d15c85c8150 I can't claim to fully understand the commit message, but I believe that this change will cause the runtime to allocate both values together, rather than separa

[go-nuts] Re: Hacking gc to support methods on builtin types

2021-02-07 Thread Luke Champine
Yep, in fact I have already added min and max functions that return the lesser/greater of their two arguments. Adding builtin functions is much easier than builtin methods, since other builtin functions are already supported by the compiler. You just add a new op type to gc/syntax.go, then add

[go-nuts] Hacking gc to support methods on builtin types

2021-02-07 Thread Luke Champine
Hi all, Recently, I managed to get this to work: x := []int{1, 2, 3} x.reverse() fmt.Println(x) That is, when I run my modified compiler on this code, it prints [3, 2, 1]. Neat! To be clear, I am *not* intending to get this merged upstream -- this is just a fun exercise to learn m