C++ standalone working in devices2

There will probably be a few minor changes to make to get C++ standalone working, but maybe we should go ahead and merge and delete the devices2 branch now? Perhaps a bit more testing first. Once that's done we can think about refactoring some of the uglier bits of codegen stuff?