Skip to content

Commit

Permalink
Implement EnvLen + Index
Browse files Browse the repository at this point in the history
  • Loading branch information
Kmeakin committed Jan 17, 2023
1 parent 0ac2984 commit e91303c
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion fathom/src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
//! and [`SliceEnv`], but when we need to copy environments often, we use a
//! [`SharedEnv`] to increase the amount of sharing at the expense of locality.
use std::{fmt, ops::Add};
use std::fmt;
use std::ops::Add;

/// Underlying variable representation.
type RawVar = u16;
Expand Down Expand Up @@ -133,6 +134,13 @@ pub fn levels() -> impl Iterator<Item = Level> {
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
pub struct EnvLen(RawVar);

impl Add<Index> for EnvLen {
type Output = Self;
fn add(self, rhs: Index) -> Self::Output {
Self(self.0 + rhs.0) // FIXME: check overflow?
}
}

impl EnvLen {
/// Construct a new, empty environment.
pub fn new() -> EnvLen {
Expand Down

0 comments on commit e91303c

Please sign in to comment.