Adding support for instances (typed constants)#40
Merged
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR adds comprehensive support for instances (typed constants) to the packtype system, allowing users to declare and use structured constant values within packages.
- Adds new
DeclInstancedeclaration type and_pt_attach_instancemethod to handle typed constants - Extends grammar to support both simple enum instances and complex struct instances with field assignments
- Updates SystemVerilog template generation to properly render instance constants
Reviewed Changes
Copilot reviewed 15 out of 15 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/grammar/test_instances.py | New comprehensive test suite covering enum and struct instance parsing |
| packtype/grammar/declarations.py | Adds DeclInstance, FieldAssignment, and FieldAssignments classes |
| packtype/grammar/transformer.py | Updates decl_alias method to handle instance declarations alongside aliases |
| packtype/grammar/packtype.lark | Extends grammar to support field assignments and instance syntax |
| packtype/grammar/grammar.py | Integrates instance processing into the main parsing pipeline |
| packtype/types/package.py | Adds _pt_attach_instance method and _pt_instances property |
| packtype/templates/package.sv.mako | Updates SystemVerilog template to render instance constants |
| packtype/utils/basic.py | Adds get_package utility and updates get_name for scalar types |
| packtype/common/expression.py | Adds support for foreign reference evaluation in expressions |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR adds support for attaching instances of defined types to packages as typed constants:
_pt_attach_instancemethod toPackage, which can be used with the Python syntax to achieve the same thing;