Skip to content

Rouslan/nativecompile

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

65 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

JIT Python compiler

CPython 3.4 is required. Higher versions are unlikely to work.

The compiler supports the x86 and x86-64 instruction sets.


Basic Usage:

>>> import nativecompile
>>> mcode = nativecompile.compile('print("Hello World!")')
>>> mcode()
Hello World!


Compiling Modules:

By default, imported modules are not compiled. To have modules automatically
compiled, the nativecompile.importer module supplies the function
install_importer. install_importer must be called before any module you wish to
compile is imported for the first time. It makes no difference whether the
module is imported inside or outside of compiled code. The compiling importer
can be removed with uninstall_importer.

Usage:

>>> import nativecompile
>>> import nativecompile.importer
>>> nativecompile.importer.install_importer()
>>> import mymodule
>>> mcode = nativecompile.compile('mymodule.myfunction()')
>>> mcode()

Calling install_importer will install a path hook (see
http://www.python.org/dev/peps/pep-0302 for details) that handles any python
module inside a folder (the hook does not currently handle modules inside ZIP
files). Any module that is handled by another path or meta-path hook will not be
compiled (but will still run).

This is a very unsophisticated compiler. No type inference and very little
optimization is done. However, this does remove the overhead of the interpreter
loop and thus should result in a modest performance boost.

About

Compile Python bytecode into executable machine code

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published