-
Notifications
You must be signed in to change notification settings - Fork 80
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
Structs in PIL #1516
base: main
Are you sure you want to change the base?
Structs in PIL #1516
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only very partial review.
ast/src/parsed/display.rs
Outdated
indent( | ||
self.fields | ||
.iter() | ||
.map(|v| format!("{}: {},\n", v.0, v.1)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.map(|v| format!("{}: {},\n", v.0, v.1)) | |
.map(|(name, ty)| format!("{name}: {ty},\n")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Didn't we want to re-use some struct from the trait definition here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TraitFunction
would be the ideal option, so I think we should rename them: #1816
ast/src/analyzed/mod.rs
Outdated
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)] | ||
pub enum TypeConstructor { | ||
Enum(Arc<EnumDeclaration>, EnumVariant), | ||
Struct(Arc<StructDeclaration>, (String, Type)), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A type constructor for struct and a struct expression are the same thing. Is this the case here or do you make a distinction? I have the impression that we don't need struct type constructors but I might be wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I used it mainly in the Statement processor when processing the Struct declaration. TypeDeclaration
declares the new type of the struct and TypeConstructor
, constructed the types of the internal functions (similar to enums wth variants), using the type declarations of each one of the functions inside the declaration.
For example: struct Dot { x: int, y: int }
would give us a TypeDeclaration
Dot
and two TypeConstructor
Dot::x
and Dot::y
.
On the other hand, the Struct expression is used at the time of instantiation, for example let f: int -> Dot = |i| Dot{a: 0, b: i};
is this wrong?
It makes sense that Dot::y
doesn't actually declare any new type (it is more of a renaming of the internal int
type), but my biggest question here is: somehow I have to process the internal types so that they are available later, but if they are not TypeConstructor
, what should they be?
Wait, I just realized that there are some things that don't make sense. I was still mixing up some ideas when I started this PR. I'll let you know when it's ready.
This PR implements structs based on the issue #1016.
To avoid ambiguity with the grammar, for creating an instance of a struct and for accessing its fields, a temporary variation of the grammar is used which should be discussed.Currently, an instance of structX {x: int, y: int}
is created usingX with {x: 1, y:0}
.