Comparison of nlr implementations

C programming, build, interpreter/VM.
Target audience: MicroPython Developers.
Post Reply
colinhogben
Posts: 5
Joined: Fri Apr 15, 2016 11:27 am
Location: Abingdon, UK

Comparison of nlr implementations

Post by colinhogben » Sun May 15, 2016 10:05 am

What are the advantages of using the assembler implementations of non-local return as opposed to the setjmp/longjmp implementation? Are the assembler versions better (e.g. faster or using fewer resources) or are there circumstances where setjmp does not work correctly? For the mbed port, I'm using the setjmp implementation because the online compiler is ARMCC which is not configured to accept GNU assembler syntax.

pfalcon
Posts: 1155
Joined: Fri Feb 28, 2014 2:05 pm

Re: Comparison of nlr implementations

Post by pfalcon » Wed May 18, 2016 11:38 am

nlr_* set of functions is special-tailored functions for the functionality MicroPython needs and thus allows to squeeze every CPU cycle out of otherwise expensive operations of exception handling. setjmp/longjmp are generic functions which work on the "best effort" basis. They were added initially to allow for quick porting to different Unix architectures.
There's also a caveat that setjmp-based implementation of nlr_push is actually a macro and there were cases of setjmp-based ports being broken by peculiar usages of nlr_push. They were fixed and no hard to support for setjmp cases surfaced further, but if you ask for a complete picture, that's it.
Awesome MicroPython list
Pycopy - A better MicroPython https://github.com/pfalcon/micropython
MicroPython standard library for all ports and forks - https://github.com/pfalcon/micropython-lib
More up to date docs - http://pycopy.readthedocs.io/

colinhogben
Posts: 5
Joined: Fri Apr 15, 2016 11:27 am
Location: Abingdon, UK

Re: Comparison of nlr implementations

Post by colinhogben » Wed May 18, 2016 1:07 pm

Many thanks for the explanation.

Post Reply