The C++11 specification defined [[attributes]]
which can be used to specify/influence implementation-defined behavior. Cheerp supports this for specifying whether you're writing C++ code meant to be compiled into [[cheerp::genericjs]]
or [[cheerp::wasm]]
code. This results in your C++ code being compiled into the .js
or .wasm
output of the compiler respectively. (Right?)
My question: What attributes does Cheerp know and what do they all do?
So far, I've seen the following attributes:
[[cheerp::genericjs]]
[[cheerp::wasm]]
[[cheerp::asmjs]]
[[cheerp::client_layout]]
[[cheerp::static]]
[[cheerp::jsexport]]
The ones that are meant to be used by users are:
cheerp::genericjs
: compile the associated item (class/struct definition, global, or function) to JavaScript, using the object memory model
cheerp::wasm
: compile the associated item (class/struct definition, global, or function) to WebAssembli OR asm.js, using the linear memory model.
cheerp::asmjs
is an alias of cheerp::wasm
and considered obsoleted (but kept for backward compatibility). The actual output (wasm or asm.js) depends on command line flags
client::jsexport
: export the associated item (function or class/struct) so that it can be used from external JavaScript code
The other attributes you mention do exist, but you should almost never use them yourself. Their meaning is this:
cheerp::static
: tell the compiler that the associated method of a client class is static (example: Date.now()
). Used in the implementation of various browser apischeerp::client_layout
: tell the compiler that this class/struct has an external layout defined in external JavaScript. You never need to use this if you inherit your client classes from client::Object
(which you should), because derived classes inherit this attribute