feat: tuples and unit values - #1
Merged
Merged
Conversation
- created `cst::Tuple` and implemented parsing
- altered expression prefix parsing to look ahead when `(` is encountered
- if `)` is encountered, parse as `cst::Tuple` (zero-item tuple)
- try parse `cst::Expression` (both `cst::Tuple` and `cst::Parenthesis`)
expect this next
- if `)` is encountered, parse as `cst::Parenthesis` (parenthesised
expression)
- if `,` is encountered, parse as `cst::Tuple` (tuple expression with
at least one field and a trailing comma)
- allow `cst::Parenthesis` to be parsed from pre-existing parts
Welcome to Codecov 🎉Once you merge this PR into your default branch, you're all set! Codecov will compare coverage reports and display results in all future pull requests. ℹ️ You can also turn on project coverage checks and project coverage reporting on Pull Request comment Thanks for integrating Codecov - We've got you covered ☂️ |
- used in function signatures - may represent a named type (`i8`) or a tuple type (`(i8, bool)`) - `ast_gen` updated to enforce `CstType::Named` variant when lowering
- allows for different kinds of types to be used - `Ast::Named`: named types by `StringId` (`i8`) - `Ast::Tuple`: tuple of types (`(i8, bool)`)
- support lowering tuple expressions from `cst`
- represents a collection of expressions - currently only used for `ast::Tuple`, but can be used in the future for array initialisation
- create `Type::Tuple`
- implement tuple solving in type solver
- introduce `Aggregate` constraint (corresponds with a collection of
expressions, such as a tuple instantiation)
- introduce `Tuple` solution, which is similar to `Type::Tuple` except
the values are `TypeVarId` (can be partially solved)
- new rules:
- `Solution::Tuple` and `Solution::Type`: values are zipped and
merged, then `Solution::Type` is emitted
- `Solution::Tuple` and `Solution::Tuple`: values are merged, and if
all have solutions then `Solution::Type` is emitted, otherwise
`Solution::Tuple` is emitted with merged values
- `Types` - add `size_of` to calculate the size in bytes of a type - add `offset_of` to calculate offset of a field in a type - add `ty` field to `mir::Aggregate` - change `resolve_rvalue` to `store_rvalue`, providing a pointer to write the value into - implement codegen for `RValue::Aggregate`
- remove `cst::Unit` - in `codegen`, when determining return type of function, use `void` if `()` would've been used
- add `tok::Dot` with highest precedence - create `Field` nodes through CST/AST/HIR - add `Constraint::Field` constraint, and update solver to process it - add `Projection::Field` to `MIR`
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.
Types
added
Type::Tupleadded
size_ofto calculate size of a typeadded
offset_ofto calculate offset of a field within a typeLexer
tok::DotCST
added
Tuple<T>, which supports parsing tuple-like structures from tokens()T, separated by commasT, must be terminated with a trailing commaadded
Expression::Tuplevariant which containsTuple<Expression>, to allow for tuple expressions ((1, true, 3))added
Expression::Fieldvariant which contains anExpression, and ausizeas the field keyadded
CstTypeto represent a wider range of typesCstType::Named(tok::Ident): named types (i8)CstType::Tuple(Tuple<CstType>): tuple types ((i8, bool, i8))AST
added
AstType, which is similar toCstTypeAstType::Named(StringId): named typesAstType::Tuple(Vec<AstTypeId>): tuple typesadded
Expression::FieldHIR
added
Expression::Aggregate, which represents a collection of expressionsadded
Expression::FieldTHIR
added
Constraint::AggregateandSolution::Tupleto the solveradded
Constraint::Fieldand associated logic to the solveradded rules to solver to handle
(Solution::Tuple, Solution::Type)and(Solution::Tuple, Solution::Tuple)updated
IncompatibleKindconvention to use_____Solution(Solution)(egReferenceSolution) to indicate that a given solution did not fulfil some expectation (eg solution was expected to be a reference)MIR
added
RValue::Aggregate, lowered fromthir::Expression::Aggregateadded
Projection::FieldCodegen
change
resolve_rvaluetostore_rvalue, and provide a pointer to store the value intolower
RValue::Aggregatelower
Projection::Field