Saturday, March 14, 2015

CPython inside Rusthon


Normally when mixing C++ with CPython you compile your C++ code and load it as an extension module. Sometimes, but less often CPython is embedded inside a C++ program. To interact with the Python interpreter from C++ requires writing verbose C-API calls all over the place. Rusthon simplifies using the C-API with special syntax ->, dedicated to PyObjects, that will generate the required PyObject_XXX calls for you.

simple tutorial: cpython_embed.md

The simple tutorial above shows you how to call methods on PyObject's and convert the return value to a C++ native type. Below shows how to use Go style channels to send PyObject's around to different threads created with spawn (c++11 std::thread).

multi-threaded GIL example: cpython_multithreaded.md

with gil:
    value = pyob->pymethod( cppob.cppmethod() as pyint ) as int
above example shows different calling styles for the PyObject and C++ object. note: as pyint becomes PyInt_FromLong from the CPython C-API, this is used to convert the return value of `cppmethod` to a PyObject.

Sunday, March 1, 2015

Literate Programming


Literate Programming, invented by Donald Knuth, makes programs human readable, secure and of higher quality.

Rusthon's multi-language markdown allows you use literate programming for mixing: python, c++, c, java, nim, rust, go, javascript and html. The transpiler/markdown-parser also acts as a compiler frontend to: gcc, g++, java, rustc, and go. This allows you to create multiple compiled executeables from a single markdown.

The source code of Rusthon itself is now mostly written in markdown, the main modules are: