Semantic AST-based code generation

Also a lot of bugfixes