Python compilation

The ppci.lang.python module can be used to translate python code into wasm, ir or machine code.

ppci.lang.python.python_to_ir(f, functions=None)

Compile a piece of python code to an ir module.

Parameters:f (file-like-object) – a file like object containing the python code
Returns:A ppci.ir.Module module
>>> import io
>>> from ppci.lang.python import python_to_ir
>>> f = io.StringIO("def calc(x: int) -> int: return x + 133")
>>> python_to_ir(f) 
<ppci.ir.Module object at ...>
ppci.lang.python.ir_to_python(ir_modules, f, reporter=None)

Convert ir-code to python code

ppci.lang.python.load_py(f, functions=None, reporter=None)

Load a type annotated python file.

Parameters:f – a file like object containing the python source code.
ppci.lang.python.python_to_wasm(code)

Compile Python code to wasm, by using Python’s ast parser and compiling a very specific subset to WASM instructions.