• Yes, I noticed this. A watchdog timer seems to kick in after around 1 sec if you're executing a particularly heavy bit of JS.

    jsiLoop handles all available events and then returns - potentially it could be rewritten to execute just one event at a time and return, which would help a small amount.

    However Espruino must execute entire blocks of code at once. It's just the way it's written - it uses the main execution stack for parsing and to store program state, so it can't magically jump out of execution and resume where it left off.

    I don't see there's any way around it without implementing separate stacks and context switching (but there doesn't seem to be enough RAM for that). I guess esp8266 itself might provide some context switching functions (as it does seem to have an OS under the hood), but you're the ESP8266 guru :)

    If there's no context switching, it'd be easiest to have Espruino as the main loop - you could hack a function into the parser such that it called into the ESP8266 OS every few milliseconds - but having it completely stop execution and return every few ms isn't an option.

    It's actually pretty surprising that ESP8266 works that way - things like the Nordic chips handle all the radio-specific stuff via interrupts, and leave user code running unprivileged (which is much more sensible from a developer's point of view).

    Just to add - of course anything is possible and the parser could be drastically rewritten, but it'd be a lot of work, and the act of resuming after having 'yielded' would be very slow.

About

Avatar for Gordon @Gordon started