flatorize_c
: Generate fast C codeby 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:
asm.js
plugin.asm.js
, C and D (source on GitHub).asm.js
, C, D…; GitHub).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 flatorize
d implementation f2
can be useful to build other flatorize
d implementations, i.e. to write well-encapsulated, maintainable code using many small functions.
If an intermediate flatorize
d implementation is not needed, one can directly create C code in a single step:
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" })