Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Enable generated interpreter cases to be composed from multiple inputs #102020

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
jbower-fb opened this issue Feb 18, 2023 · 2 comments
Closed

Enable generated interpreter cases to be composed from multiple inputs #102020

jbower-fb opened this issue Feb 18, 2023 · 2 comments
Labels
type-feature A feature request or enhancement

Comments

@jbower-fb
Copy link
Contributor

Feature or enhancement

Enable instruction definitions for generate_cases.py to be spread across multiple files.

Pitch

This would allow projects like Cinder to alter/add instructions while still being able to use the base bytecodes.c without modification. Thus we can minimize the amount of conflict when merging upstream, and avoid copying/forked code if Cinder's features are moved into a standalone module.

In the attached PR I've put together an implementation that allows multiple inputs to be passed to generate_cases.py by using -i multiple times. E.g.:

$ generate_cases.py -i bytecodes.c -i cinder-bytecodes.c -o generated.c.h

The input files are mostly processed as if they were concatenated together, although for each file parsing is only carried out between the BEGIN/END BYTECODES markers.

I've also added a new override keyword which can prefix instruction definitions to indicate the intent to completely replace an existing definition. E.g.:

inst(NOP, (--)) {
}

// Only this version is used during generation.
override inst(NOP, (--)) {
  magic();
}

// Error - NOP already exists but "override" not specified.
inst(NOP, (--)) {
  magic();
}

// Error - no existing ZOP to override.
override inst(ZOP, (--)) {
}

Overrides allow us to introduce changes to a small number of instructions which currently need to behave slightly differently in Cinder. The override keyword allows the parser to both enforce only explicitly allowed overrides occur, and there are no "false" overrides. This will quickly reveal if a new instruction is introduced in the base definition which unexpectedly conflicts with something Cinder added, and similarly if something Cinder overrode is removed.

Previous discussion

The idea of using multiple files to generate the interpreter was briefly discussed around the faster-cpython project.

@jbower-fb jbower-fb added the type-feature A feature request or enhancement label Feb 18, 2023
@terryjreedy
Copy link
Member

This looks like a preliminary version of #102021, to which you added a PR. Should this be closed?

@carljm
Copy link
Member

carljm commented Feb 20, 2023

Yes, I saw @jbower-fb mentioned elsewhere that GitHub was having issues and returning a lot of 500 errors at the time this was filed, looks like that resulted in accidentally filing a duplicate. Closing.

@carljm carljm closed this as completed Feb 20, 2023
@carljm carljm closed this as not planned Won't fix, can't repro, duplicate, stale Feb 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-feature A feature request or enhancement
Projects
None yet
Development

No branches or pull requests

3 participants