first implementation of code generator. Works for some basic stuff, needs improvement!