diff --git a/reid/src/ast/mod.rs b/reid/src/ast/mod.rs index 219851d..5f50386 100644 --- a/reid/src/ast/mod.rs +++ b/reid/src/ast/mod.rs @@ -28,6 +28,7 @@ pub enum TypeKind { Array(Box, u64), Custom(String), Borrow(Box, bool), + Ptr(Box), } #[derive(Debug, Clone)] diff --git a/reid/src/ast/parse.rs b/reid/src/ast/parse.rs index 02525ef..2d26bec 100644 --- a/reid/src/ast/parse.rs +++ b/reid/src/ast/parse.rs @@ -35,6 +35,10 @@ impl Parse for Type { let inner = stream.parse::()?; TypeKind::Borrow(Box::new(inner.0), mutable) + } else if let Some(Token::Star) = stream.peek() { + stream.expect(Token::Star)?; + let inner = stream.parse::()?; + TypeKind::Ptr(Box::new(inner.0)) } else { if let Some(Token::Identifier(ident)) = stream.next() { match &*ident { diff --git a/reid/src/ast/process.rs b/reid/src/ast/process.rs index 6d67098..fdb06a9 100644 --- a/reid/src/ast/process.rs +++ b/reid/src/ast/process.rs @@ -293,6 +293,9 @@ impl From 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()))) + } } } } diff --git a/reid_src/ptr.reid b/reid_src/ptr.reid new file mode 100644 index 0000000..f8392e2 --- /dev/null +++ b/reid_src/ptr.reid @@ -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]; +}