emscripten-core / emscripten-core/emscripten
Add simpler mechanism for define new JS preprocessor functions/macros.
- Dominant language
- C++
- Stars
- 27.6k
- Forks
- 3.6k
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 105
Description
Currently we have a fixed set of processor macros/function that are mostly defined in `parseTools.js`
Adding new macros in JS libraries is possible, but its rather ugly syntax, and has some limitations:
```
{{{
globalThis.newMacro = () = { .. }
}}}
```
A major drawback (IIUC) of doing this is that the macros are not available during preprocessing since macros expansion happens after preprocessing. So to use these macros in a preprocessor directive one would need define them in a separate file that is loaded first. e.g. `--js-library=my_macros.js --js-library=my_library.js`. Here the macros defined in `my_macros.js` would be available in `my_library.js`.
One way to improve this would be to allow `my_library.js` to somehow `#include "my_macros.js"` .. however that isn't currently how the #include directive works. Currently #include files are placed directly into the output file and don't have macros expanded, so we would need somekind of new #include mechanism.
Contributor guide
Assessment
This issue has not been assessed yet.