I think the best way is to use "jit", if && does not work then maybe @Gordon can look into it?
If the performance in not good enough I'd use Inline C by doing the math inside native method with just data passed in/out.
"compiled" is a dead end IMO, only if you cannot easily restructure the code and really need to call into other js methods or access js variables then it makes sense looking into it.
In my case I wanted to code SWD protocol in pure JS. After prototype which is available here https://github.com/fanoush/EspruinoBoards/blob/master/STLINKV2/swd.js I tried to use "compiled" for some parts to speed it up but quickly hit some limitations and also noticed that the native binary code crashes in other device due to EXPTR being different. My current WIP code snapshot is here https://gist.github.com/fanoush/4a5dcf777503461297cedf7e21e3c6b3 lines 44-139 contain bits inspired from JS compiler output. I wanted to use Pin objects so the native code works both on STM32 and nrf52 platforms without coding native GPIO HW stuff for each platform.
© Espruino, powered by microcosm.
Report a problem