looklook 0.6.0

Descriptive signal synthesiser.
// Copyright 2026 Gabriel Bjørnager Jensen.
//
// This file is part of LOOKLOOK.
//
// LOOKLOOK is free software: you can redistribute
// it and/or modify it under the terms of the GNU
// Affero General Public License as published by
// the Free Software Foundation, either version 3
// of the License, or (at your option) any later
// version.
//
// LOOKLOOK is distributed in the hope that it will
// be useful, but WITHOUT ANY WARRANTY; without
// even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Affero General Public License for more details.
//
// You should have received a copy of the GNU Af-
// fero General Public License along with LOOKLOOK.
// If not, see <https://www.gnu.org/licenses/>.

//! The [`TraceMode`] enumeration.

/// A tracing mode.
#[repr(u16)]
#[derive(Copy, Debug)]
#[derive_const(
	Clone,
	Default,
	Eq,
	Ord,
	PartialEq,
	PartialOrd,
)]
pub enum TraceMode {
	/// Tracing disabled.
	#[default]
	NoTrace          = 0b0000_0000_0000_0000,

	/// Trace control flow.
	TraceFlow        = 0b0100_0000_0000_0000,

	/// Trace all instructions.
	TraceInstruction = 0b1000_0000_0000_0000,
}

impl TraceMode {
	/// Reinterprets a [`u16`] scalar as a tracing mode.
	///
	/// # Panics
	///
	/// This method will panic if the provided value is
	/// an undefined tracing mode.
	#[inline]
	#[must_use]
	#[track_caller]
	pub const fn from_u16(mut value: u16) -> Self {
		// Mask away unused bytes.
		value &= 0b1100_0000_0000_0000;

		match value {
			0b0000_0000_0000_0000 => Self::NoTrace,
			0b0100_0000_0000_0000 => Self::TraceFlow,
			0b1000_0000_0000_0000 => Self::TraceInstruction,

			_ => {
				panic!("undefined tracing mode");
			}
		}
	}

	/// Reinterprets the tracing mode as a [`u16`] scalar.
	#[inline(always)]
	#[must_use]
	pub const fn as_u16(self) -> u16 {
		self as u16
	}
}