Fork me on GitHub

flatorize_c: Generate fast C code

by Guillaume Lathoud [1], April 2013, November 2014

This page presents a plugin method flatorize.getCodeC() (GitHub source) that goes on top of flatorize (see the main article, GitHub source).

See also:

Contents #

HOWTO: 2-step example #

Here is an expression definition that uses complex numbers (details in the main article):

// f:

A call to flatorize():

// note the type declarations, ignored by JavaScript but used later for C
f2 = flatorize('a:[2 float],b:[2 float],c:[2 float]->d:[2 float]',f);

...generates flatorized JavaScript code:

// f2.getDirect():

Then, a call to flatorize.getCodeC():

...generates f2_obj.code, a JavaScript string containing the C code below:

(This code, as a few others below, was produced and inserted as you loaded the page.)

Having the intermediate flatorized implementation f2 can be useful to build other flatorized implementations, i.e. to write well-encapsulated, maintainable code using many small functions.

HOWTO: 1-step shortcut #

If an intermediate flatorized implementation is not needed, one can directly create C code in a single step:

HOWTO: generate boilerplate code#

JavaScript helper methods f2_obj.helper_*() generate boilerplate C code, especially useful to manage array inputs/output:

f2_obj.helper_h() returns a JavaScript string containing this C code:

f2_obj.helper_c() returns a JavaScript string containing the C code below. Instead of the default file name "helper.h" you can optionally specify another file name using f2_obj.helper_c({ helper_h_name : "another_name.h" })