Hacker News new | ask | show | jobs
by puddums 3120 days ago
python has a concept of "extending" and also "embedding". It looks like they are looking at embedding[0], which enables you use the normal CPython interpreter from within another program. (So no, not writing a new Python interpreter in Rust).

Sample snippet from python docs:

-----

So if you are embedding Python, you are providing your own main program. One of the things this main program has to do is initialize the Python interpreter. At the very least, you have to call the function Py_Initialize(). There are optional calls to pass command line arguments to Python. Then later you can call the interpreter from any part of the application.

There are several different ways to call the interpreter: you can pass a string containing Python statements to PyRun_SimpleString(), <...etc..>

-----

[0] https://docs.python.org/3/extending/embedding.html

1 comments

If interested, you can see their work-in-progress main.rs in the related code revision[0], which includes their Rust code calling down to the C function Py_Initialize() to spin up the now-embedded CPython interpreter that is living "inside" a Rust program:

    unsafe {
        Py_Initialize();
        PySys_SetArgv(args.len() as c_int,
                      argv.as_ptr());
        PyEval_InitThreads();
        let _thread_state = PyEval_SaveThread();
    }
----

[0] https://phab.mercurial-scm.org/D1581#change-t24aVkGEJ5Xh