summaryrefslogtreecommitdiffstats
path: root/third_party/rust/jsparagus-stencil/src/env_coord.rs
blob: 257afbeb398662b18e973d960e9eec62bd39c7d4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
//! (EnvironmentSlot,EnvironmentHops) pair represent the reference to a slot in
//! an environment object in the environment chain.
//!
//! See the SMDOC comment in m-c/js/src/vm/EnvironmentObject.h for the details
//! about environment object and environment chain.

/// Slot in the environmentslot object.
#[derive(Clone, Copy, Debug, PartialEq, Eq, Ord, PartialOrd)]
pub struct EnvironmentSlot {
    slot: u32,
}

impl EnvironmentSlot {
    pub fn new(slot: u32) -> Self {
        Self { slot }
    }

    pub fn next(&mut self) {
        self.slot += 1;
    }
}

impl From<EnvironmentSlot> for u32 {
    fn from(slot: EnvironmentSlot) -> u32 {
        slot.slot
    }
}

/// The number of environment objects to skip (hop) on the environment chain in
/// order to find the associated environment object.
#[derive(Clone, Copy, Debug, PartialEq, Eq, Ord, PartialOrd)]
pub struct EnvironmentHops {
    hops: u8,
}

impl EnvironmentHops {
    pub fn new(hops: u8) -> Self {
        Self { hops }
    }

    pub fn next(&mut self) {
        self.hops += 1;
    }
}

impl From<EnvironmentHops> for u8 {
    fn from(hops: EnvironmentHops) -> u8 {
        hops.hops
    }
}