Work done in collaboration with Graham Sanderson and Peter Harper. Signed-off-by: Damien George <damien@micropython.org>