looklook 0.8.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 ver-
// sion.
//
// LOOKLOOK is distributed in the hope that it will be useful, but WITHOUT ANY WAR-
// RANTY; 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 Affero General Public License along
// with LOOKLOOK. If not, see <https://www.gnu.org/licenses/>.

//! The [`Op`] type.

use crate::vm::{Exception, Long, Vm};

/// An instructed operation.
#[derive(Copy, Debug)]
#[derive_const(Clone)]
pub struct Op {
	/// The instruction.
	instruction: Long,

	/// The operator.
	f: fn(&mut Vm, Long) -> Result<(), Exception>,
}

impl Op {
	/// Constructs a new operation.
	#[inline]
	#[must_use]
	pub const fn new(f: fn(&mut Vm, Long) -> Result<(), Exception>, instruction: Long) -> Self {
		Self { instruction, f }
	}

	/// Executes the operation.
	///
	/// # Errors
	///
	/// This method forwards any errors from `f`.
	#[inline]
	pub fn exec(&self, vm: &mut Vm) -> Result<(), Exception> {
		(self.f)(vm, self.instruction)
	}

	/// Retrieves the instruction.
	#[inline]
	#[must_use]
	pub const fn instruction(&self) -> Long {
		self.instruction
	}
}