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()
    Advertisements
    This entry was posted in python. Bookmark the permalink.

    Leave a Reply

    Fill in your details below or click an icon to log in:

    WordPress.com Logo

    You are commenting using your WordPress.com account. Log Out / Change )

    Twitter picture

    You are commenting using your Twitter account. Log Out / Change )

    Facebook photo

    You are commenting using your Facebook account. Log Out / Change )

    Google+ photo

    You are commenting using your Google+ account. Log Out / Change )

    Connecting to %s