Skip to content

Conversation

@lysnikolaou
Copy link
Member

@lysnikolaou lysnikolaou commented Mar 22, 2020

Expose pegen as a C API and as a Python-leve module:

  • Use trailer meta for a function that calls the start rule. (In the future we could add more parse_* functions that use other rules)
  • Expose four C API functions that return either a mod_ty or a PyCodeObject *
  • Expose two Python-level functions that return an AST object
  • Extension module and C API does not get generated, but is hand-written
  • Rewrite of run_parser* functions

This is getting bigger and bigger, so I'm opening this WIP PR, so that it becomes a bit easier to follow what's going on.

Feedback is needed once more.

Closes #6.

pablogsal and others added 3 commits March 20, 2020 23:56
    * Use @trailer for the generated C API functions
    * Use EXTENSION_SUFFIX for the generated Python-level module
    * Expose four C API functions that return either a mod_ty or a
      PyCodeObject *
    * Expose two Python-level functions that return an AST object
    * Extension modules does not get generated anymore
    * Complete rewrite of run_parser* functions
    * Use trailer meta for only one function that calls the start_rule
@gvanrossum
Copy link

I'll have a look at the code soon. Right now I notice that (on my Mac) make test inside the Tools/peg_generator directory segfaults. This is using Python 3.8.2.

@lysnikolaou
Copy link
Member Author

lysnikolaou commented Mar 22, 2020

I'll have a look at the code soon. Right now I notice that (on my Mac) make test inside the Tools/peg_generator directory segfaults. This is using Python 3.8.2.

I'm on it.

EDIT: Fixed in a5bb3a2.

Copy link

@gvanrossum gvanrossum left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great progress. But I think we need some refactoring. (Some you may be able to put off to another PR.)

Also, I'm sorry that there's so much duplicate code between here and Tools/peg_generator -- hopefully this is temporary!

Copy link

@gvanrossum gvanrossum left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR is getting so large, maybe finish these nits, land, and start another iteration with the API inmprovements?

@lysnikolaou
Copy link
Member Author

lysnikolaou commented Mar 23, 2020

Should we merge this now?

Note that pegen tests pass and all the other will fail one way or the other.

Copy link

@gvanrossum gvanrossum left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, let's land this one!

@lysnikolaou lysnikolaou changed the title WIP: Work on exposing a C API for pegen Expose a C API for pegen Mar 23, 2020
@lysnikolaou lysnikolaou merged commit 0c7a382 into pegen Mar 23, 2020
@lysnikolaou lysnikolaou deleted the c_api_lys branch March 23, 2020 18:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add an API that invokes the new and the old parsers explicitly

4 participants