7. Types¶
Syntax
Type::= |EqualityType|UnionType|SingleTypeSingleType::=NamedType|ReferenceType|TupleType|FunctionType|TokenMacroInvocation|NeverType|AccessType|ArrayType|ParenthesisedType|ImplicitFunctionType|ImplicitFunctionCall|ExpressionInType|TypeMacroInvocation
7.1. Named Types¶
Syntax
NamedType::=Name
Examples
i32
Data
Foo
7.2. Reference Types¶
Warning
This is a work in progress.
Syntax
ReferenceType::= &ReferenceModifier? mut?Type
Examples
&raw mut i32
&rc User
&mut i32
7.3. Access Types¶
Syntax
AccessType::=Type::Name
Examples
llvm::AttributeKind
7.4. Tuple Types¶
Syntax
TupleType::= (TupleTypeBody? )TupleTypeBody::=SimpleTypeParameter,SimpleTypeParameterList?
Examples
(i32, char, str)
(count: i32, lookup: char, message: str)
7.5. Function Types¶
Syntax
FunctionType::= (SimpleTypeParameterList?) ->Type
Examples
(i32, str) -> i32
(offset: i32, message: str) -> i32
7.6. Never Types¶
Syntax
NeverType ::=
!
Examples
panic := (message: str) -> ! {
}
7.7. Array Types¶
Syntax
ArrayType::= [TypeLengthSpecifier? ]LengthSpecifier::= ;Expression
Examples
[i32]
[i32; 3]
[i32; 3 + 4]
7.8. Parenthesised Types¶
Syntax
ParenthesisedType::= (Type)
Examples
(i32 | i64)
7.9. Equality Types¶
Warning
This is a work in progress.
Syntax
EqualityType::=SingleType(~SingleType)*
Examples
Lhs ~ Rhs
7.10. Union of Types¶
Warning
This is not implemented yet.
Syntax
UnionType::=SingleType(|SingleType)*
Examples
i8 | i16 | i32 | i64
7.11. Implicit Function Types¶
Syntax
ImplicitFunctionType::= <TypeParameterList? > ->Type
Examples
<T> -> T
<T := i32, U> -> (T, U)
7.11.1. Type Parameters¶
Syntax
SimpleTypeParameterList::=SimpleTypeParameter(,SimpleTypeParameter)? ,?SimpleTypeParameter::=Name(:Type) |TypeTypeParameterList::=TypeParameter(,TypeParameter)? ,?TypeParameter::=MacroInvocationHeader?TypeParameterContentTypeParameterContent::=Name:Type? =Type|Name:Type|Name
7.12. Implicit Function Call¶
Syntax
ImplicitFunctionCall::=ImplicitFunctionCallSubject<TypeArgumentList? >ImplicitFunctionCallSubject::=Type|NonDeclarativeExpression
Examples
Data := struct<T>(
id: i32,
data: T,
)
foo := <T> => (data: Data<T>) -> i32 => {
data.get_id()
}
7.12.1. Type Arguments¶
Syntax
TypeArgumentList::=TypeArgument(,TypeArgument)? ,?TypeArgument::=MacroInvocationHeader?Name(=Type)?
7.13. Expressions in Types¶
Syntax
ExpressionInType::= {NonDeclarativeExpression} |Literal
Examples
bar := (arg: { foo() }) => {
...
}
foo := () -> 1 => {
1
}
7.14. Macro Invocations as Types¶
syntax
TypeMacroInvocation::=MacroInvocationHeaderSingleType
Examples
Foo := struct<#constrain T>(
)
Foo := type #c_union f32 | i32 | i64