From 45d75bb5523acd5f51aba70a2ebac0b093185dfc Mon Sep 17 00:00:00 2001 From: John Date: Mon, 22 Apr 2024 21:44:12 -0500 Subject: [PATCH] cl-structures: Make Span and Loc functions const (now you can make a const Span!) --- compiler/cl-structures/src/span.rs | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/compiler/cl-structures/src/span.rs b/compiler/cl-structures/src/span.rs index 8f03b38..3ecc132 100644 --- a/compiler/cl-structures/src/span.rs +++ b/compiler/cl-structures/src/span.rs @@ -8,24 +8,33 @@ pub struct Span { pub head: Loc, pub tail: Loc, } -pub fn Span(head: Loc, tail: Loc) -> Span { +pub const fn Span(head: Loc, tail: Loc) -> Span { Span { head, tail } } +impl Span { + pub const fn dummy() -> Self { + Span { head: Loc::dummy(), tail: Loc::dummy() } + } +} + /// Stores a read-only (line, column) location in a token stream #[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct Loc { line: u32, col: u32, } -pub fn Loc(line: u32, col: u32) -> Loc { +pub const fn Loc(line: u32, col: u32) -> Loc { Loc { line, col } } impl Loc { - pub fn line(self) -> u32 { + pub const fn dummy() -> Self { + Loc { line: 0, col: 0 } + } + pub const fn line(self) -> u32 { self.line } - pub fn col(self) -> u32 { + pub const fn col(self) -> u32 { self.col } }