• Is there some stack check now at runtime

    There is, yes - basically whenever it recurses it checks, and tries to leave 256 bytes free.

    process.memory().stackEndAddress returns LINKER_END_VAR

    LINKER_END_VAR is end, which is realistically the end of the stack. Unless I'm wrong (which is very possible), since we have no malloc the stack runs from the top of memory, all the way down to the last allocated variable.

    __StackLimit is something specific to Nordic's SDK (and no other platforms) so I don't tend to use it. If I did, we'd just end up wasting RAM though.

    Not sure what was the reason to provide this feature exactly

    Someone wanted to store a bunch of data in 'free' RAM. IMO it should be removed - there are definitely more helpful things that could be added instead.

    variables are used without initialisation

    Thanks! I've just filed an issue for this: https://github.com/espruino/Espruino/iss­ues/1696

    That's a bug in the BLE code really - it's expecting to run after code has been loaded into the variables (so there's something there to read). Just moving the jsvar init earlier for that platform will fix the crash but the BLE code won't work because it's going to be looking at a bunch of empty JsVars.

    JsVar sizing

    ... I do like the idea of changing the amount of variables based maybe on a define for the amount of stack we want, but it'd be nice to have something that worked nicely multiplatform (at least on ARM). The original Espruino is based on STM32F103RCT6 (256k/48k), but in literally every board I've tested the chip was actually a STM32F103RDT6 (384k/64k). I never took advantage of that just in case, but it'd be great to have something that could take advantage of it at runtime.

    I'm a bit concered that Linux has a way of altering memory size, as does ESP32, and now this. And they're all IFDEF'd at the top of jsvInit. IMO it'd be nice to just pass in a pointer as well as size and handle it in the platform-specific main (although the Linux stuff would have to stay as that does some weird 'magic').

About

Avatar for Gordon @Gordon started