cairo_lang_sierra_to_casm/environment/
ap_tracking.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
use cairo_lang_casm::ap_change::{ApChange, ApChangeError};

use super::ApTracking;

/// Updates the function level ap_tracking based on ap_change.
pub fn update_ap_tracking(
    ap_tracking: ApTracking,
    ap_change: ApChange,
) -> Result<ApTracking, ApChangeError> {
    Ok(match (ap_tracking, ap_change) {
        (ApTracking::Enabled { ap_change: current, base }, ApChange::Known(change)) => {
            ApTracking::Enabled {
                ap_change: current.checked_add(change).ok_or(ApChangeError::OffsetOverflow)?,
                base,
            }
        }
        _ => ApTracking::Disabled,
    })
}