Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upGitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign up
At the moment,
_sreis a modified version of_sre.pyfrom an old version of PyPy: https://github.com/nikhaldi/_sre.py.This is s l o w. If you ctrl-C rustpython while it's running a decently complex script, there's a good chance that the traceback from the
KeyboardInterruptwill have originated somewhere in_sre.py. While it's definitely feasible to implement_srein Rust -- I was able to modify the constant-generation script to output Rust instead of C code -- both the C and Python versions of_sredon't really lend well to translation to Rust. The C version (_sre.c/sre_lib.h) uses lots of pointer arithmetic and a kind of "as long as we own an active reference to the str object, we can send pointers anywhere we want" approach that doesn't jive well with Rust's memory-safety rules. The Python version (Lib/_sre.pyin the RustPython source tree) uses enough nested references (context.x_stack[n].context is context), generator functions, and dynamic typing that it's also tricky to translate to Rust.If anyone wants to take a stab at this, I've left a scaffold of the implementation in the
_sre-wipbranch, that has the SRE constants available to Rust, and some of my sketches for how it might work, but no real functionality. Be warned, either route you go to emulate is tricky, so feel free to try whichever approach you think would be easier.