boa-cat 0.3.0

Tree-walking ECMAScript interpreter built on ecma-syntax-cat. v0.3.0 adds accessor-property support at the engine level: `Object::with_accessor(key, AccessorPair)` installs a getter/setter pair, and `obj.key` / `obj.key = value` dispatch through the pair instead of doing plain data read/write. Embedders (web-api-cat etc.) can now wire DOM accessors like `document.cookie` via native getter/setter functions. Object-literal `{ get x() {} }` syntax remains gated on ecma-parse-cat learning to emit `ObjectPropertyKind::Get/Set` (the engine handles those AST variants already).
//! Step-budget newtype.  Every evaluator function spends one unit of fuel
//! per call; when fuel runs out, evaluation aborts with
//! [`Error::FuelExhausted`].
//!
//! [`Error::FuelExhausted`]: crate::error::Error::FuelExhausted

use crate::error::Error;

/// A fuel budget.  Construct with [`Fuel::new`]; spend with [`Fuel::spend`].
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct Fuel {
    limit: u64,
    remaining: u64,
}

impl Fuel {
    /// A fresh budget of `limit` steps.
    #[must_use]
    pub fn new(limit: u64) -> Self {
        Self {
            limit,
            remaining: limit,
        }
    }

    /// The original budget.
    #[must_use]
    pub fn limit(&self) -> u64 {
        self.limit
    }

    /// Steps still available.
    #[must_use]
    pub fn remaining(&self) -> u64 {
        self.remaining
    }

    /// Spend one unit; returns [`Error::FuelExhausted`] when exhausted.
    ///
    /// # Errors
    ///
    /// [`Error::FuelExhausted`] when there is no remaining fuel.
    pub fn spend(self) -> Result<Self, Error> {
        match self.remaining {
            0 => Err(Error::FuelExhausted { limit: self.limit }),
            n => Ok(Self {
                limit: self.limit,
                remaining: n - 1,
            }),
        }
    }
}