Partially refactor magma bindings with cffi, try defining some functions dynamically with exec to save code repetition.