Add parsing pointer-type
This commit is contained in:
parent
c9b363d9e8
commit
3b43689650
@ -28,6 +28,7 @@ pub enum TypeKind {
|
||||
Array(Box<TypeKind>, u64),
|
||||
Custom(String),
|
||||
Borrow(Box<TypeKind>, bool),
|
||||
Ptr(Box<TypeKind>),
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
|
@ -35,6 +35,10 @@ impl Parse for Type {
|
||||
|
||||
let inner = stream.parse::<Type>()?;
|
||||
TypeKind::Borrow(Box::new(inner.0), mutable)
|
||||
} else if let Some(Token::Star) = stream.peek() {
|
||||
stream.expect(Token::Star)?;
|
||||
let inner = stream.parse::<Type>()?;
|
||||
TypeKind::Ptr(Box::new(inner.0))
|
||||
} else {
|
||||
if let Some(Token::Identifier(ident)) = stream.next() {
|
||||
match &*ident {
|
||||
|
@ -293,6 +293,9 @@ impl From<ast::TypeKind> for mir::TypeKind {
|
||||
ast::TypeKind::Borrow(type_kind, mutable) => {
|
||||
mir::TypeKind::Borrow(Box::new(mir::TypeKind::from(*type_kind.clone())), *mutable)
|
||||
}
|
||||
ast::TypeKind::Ptr(type_kind) => {
|
||||
mir::TypeKind::Ptr(Box::new(mir::TypeKind::from(*type_kind.clone())))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
10
reid_src/ptr.reid
Normal file
10
reid_src/ptr.reid
Normal file
@ -0,0 +1,10 @@
|
||||
// Arithmetic, function calls and imports!
|
||||
|
||||
|
||||
extern fn malloc(size: u64) -> *u8;
|
||||
|
||||
fn main() -> u16 {
|
||||
let ptr = malloc(4);
|
||||
|
||||
return ptr[0];
|
||||
}
|
Loading…
Reference in New Issue
Block a user