Add parsing pointer-type

This commit is contained in:
Sofia 2025-07-21 13:23:14 +03:00
parent c9b363d9e8
commit 3b43689650
4 changed files with 18 additions and 0 deletions

View File

@ -28,6 +28,7 @@ pub enum TypeKind {
Array(Box<TypeKind>, u64),
Custom(String),
Borrow(Box<TypeKind>, bool),
Ptr(Box<TypeKind>),
}
#[derive(Debug, Clone)]

View File

@ -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 {

View File

@ -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
View 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];
}