Monday, October 10, 2011

cpython source code study note





Python 2.7.2 source code
  • main():Modules/python.c 
  • Py_Main():Modules/main.c
  • Py_Initialize(): Python/pythonrun.c
    • PyRun_SimpleFileExFlags
    • PyRun_FileExFlags
      • PyParser_ASTFromFile returns AST module
        • Parser build CST: PyParser_ParseFileFlagsEx: Parser/parsetok.c
        • Transform CST to AST: PyAST_FromNode(): Python/ast.c
      • run_mod(mod) 
        • PyAST_Compile(mod) compile AST into byte code
        • PyEval_EvalCode runs the byte code
    • create first interpreter PyInterperterState_New()
    • create first thread PyThreadState_New()
    • initialize __builtin__ module: _PyBuiltin_Init()
    • initialize sys module: _PySys_init()

No comments:

Post a Comment