port most of PythonGenerator.hx