Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Mypyc C Code Generator

Jukka Lehtosalo edited this pageOct 24, 2022 ·2 revisions

Mypyc compiles a function into two functions, a native function anda wrapper function:

  • The native function takes a fixed number of C arguments with thecorrect C types. It assumes that all argument have correct types.

  • The wrapper function conforms to the Python C API calling conventionand takes an arbitrary set of arguments as Python objects. It processes the arguments,checks their types, unboxes values with special representations andcalls the native function. The return value from the native functionis translated back to a Python object ("boxing").

Calls to other compiled functions don't go through the Python modulenamespace but directly call the target native C function. This makescalls very fast compared to CPython. This is calledearly binding.

Currently early binding is only possible between modules that are compiled together.If you, for example, install a module compiled with mypyc using pip, and useit in your code, calls to the installed module will use slow Python-levelcalls.

The generated code does runtime type checking so that it can assume thatvalues always have the declared types. Whenever accessing CPythonvalues which might have unexpected types we need to insert a runtimetype check operation. For example, when getting a list item we need toinsert a runtime type check (an unbox or a cast operation), sincePython lists can contain arbitrary objects.

The generated code uses various helpers defined inmypyc/lib-rt/CPy.h. The implementations are in various.c filesundermypyc/lib-rt.

Clone this wiki locally

[8]ページ先頭

©2009-2025 Movatter.jp