Ogo is an experimental go compiler. It is written in go, and compiles go to C, and invokes a C compiler to compile that. It is not close to complete, and may never be. Its primary goal is not to be a good (or complete) go compiler, but to be a platform for experimentation with extensions to the go language.
Ogo is also intended to be the name of a temporary language, which will have some degree of generics support. This language has yet to be defined. It is intended to be "temporary" in the sense that I expect that either its ideas will be incorporated into go itself, or it will be abandoned eventually. Until either of those happen, it will need a separate name to distinguish ogo programs (with generics) from go programs.
The design structure is to implement ogo primarily as a series of go-to-go AST transformations, labeled (g2g) below. Thus the C pretty printer (and type checker, etc) will only need to handle a simpler subset of the language.
-
Parse go files (easy---use standard
go/parser
) -
(g2g) Track go imports and combine into a single main file (reasonably easy). This simplifies the transformations considerably. It's never going to be a fast way to compile things, but we've already got a fast go compiler.
In the following to-do list, some of the tasks require that others be done first, but I haven't tabulated dependencies. Many (particularly of the g2g variety) can be implemented independently.
-
Finish C pretty printer using the ordinary go AST, with a subset of the go syntax.
-
(g2g) Eliminate
if foo := bar(); foo
idiom. -
(g2g) Eliminate
for a:=b; a<N; a++
idiom in favor of while-loop for statements. -
(g2g) Eliminate range statements over slices in for loops in favor of explicit indexing and checking the length.
-
(g2g) Implement type checker, producing a map holding types of every expression in the program.
-
(g2g) Add type casts to literals, e.g. transforming
0
intoint(0)
, etc. -
(g2g) Add type signatures to every
var
statement. -
(g2g) Eliminate the
:=
operator in favor ofvar
statements with types. -
(g2g) Eliminate
&
operator on local variables directly, changing said local variables into pointer allocated with new. -
Implement
string
type -
(g2g) Change multiple return to return a single struct type
-
Use Boehm garbage collector
-
Implement
type
as a builtin data type, and implement new in the ogo language using this as its argument. In C,type
will be a struct type, that will hold the size of the type, its name, and eventually a bunch of pointers to its methods, equal to NULL if the method hasn't been defined (so we can examine this to figure out interfaces it satisfies). -
Implement
make
in ogo -
Implement
copy
in ogo -
Implement
append
in ogo -
Implement slices
-
Implement interfaces
-
(g2g) Transform interfaces than incorporate other interfaces into simple flat interfaces (basically just copying over the methods).
-
(g2g) Make all type-casting explicit, i.e. insert a type cast when a concrete type is passed to an
interface
argument of a function or method.
These are items that would be required to make ogo
a valid Go1
compiler, that I don't have plans to implement (ever). If they
interest you, however, you could work on them.
-
Implement
map
-
Implement goroutines
-
Implement
chan
-
Precise garbage collection
-
Implement
defer
-
Implement
recover
-
Implement
reflect
-
Implement nested
struct
types