Jeff Hui

Follow @jeffh on Micro.blog.

Compilers (pt 2)

Fast compilers tend to reduce the amount of memory that is generated for ASTs. That can mean simple things like not generating all lever tokens at once. Although trying to have a single representation for an AST node is difficult. Sometimes a c-styled unions is needed. Unfortunately go doesn’t support that. But better or worse, using unsafe pointers can allow us to do so.

unsafe

 

I’m not really sure of the implications to the GC, but it can be a clever way to pack more information in the same. It’s nice that go can do this even if it’s significantly uglier. An interface can be built to hide this detail (by returning a pointer).

Not sure if it’s reasonable to do in Swift without exposing UnsafeMutablePointer<T> as it’s API or using classes (which may require more memory overhead?).