1 - not sure if "typically" but yes it can run from RAM or from flash. When in ram the parsed string of each function is in RAM (possibly minified and tokenized) as a variable. in javascript there is no big difference between variable referencing integer value, string or function object
if loaded from flash the difference is that function object has pointer to string of the body which is in flash, also plain strings work like that not just functions so if code in flash has var s = "very long string .. " than the string is also in flash, not in ram
the size is basically determined by trial and error - you check how much free RAM you have with everything built in + CPU stack and you divide size of free ram by variable size. For PUCKJS with 2756 variables it needs 35828 bytes of RAM (out of 64KB), the rest is for static C data, CPU stack and bluetooth - NRF softdevice
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
1 - not sure if "typically" but yes it can run from RAM or from flash. When in ram the parsed string of each function is in RAM (possibly minified and tokenized) as a variable. in javascript there is no big difference between variable referencing integer value, string or function object
if loaded from flash the difference is that function object has pointer to string of the body which is in flash, also plain strings work like that not just functions so if code in flash has
var s = "very long string .. "
than the string is also in flash, not in ram2 it is based on number of variables (=
JSVAR_CACHE_SIZE
) see https://github.com/espruino/Espruino/blob/master/src/jsutils.h#L1953 there is no performance penalty when running from internal flash, there is small one when running from SPI flash (Bangle watches)
the size is defined in board files like this https://github.com/espruino/Espruino/blob/master/boards/PUCKJS.py#L25
the size is basically determined by trial and error - you check how much free RAM you have with everything built in + CPU stack and you divide size of free ram by variable size. For PUCKJS with 2756 variables it needs 35828 bytes of RAM (out of 64KB), the rest is for static C data, CPU stack and bluetooth - NRF softdevice