use core::fmt::Display;
use alloc::{borrow::Cow, string::String, vec::Vec};
use crate::TypeHash;
use crate::{OperationCode, OperationReflect, fmt_vararg};
use super::Variable;
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, Clone, TypeHash, PartialEq, Eq, Hash, OperationCode)]
#[operation(opcode_name = NonSemanticOpCode)]
pub enum NonSemantic {
EnterDebugScope,
ExitDebugScope,
Print {
format_string: String,
args: Vec<Variable>,
},
Comment { content: String },
}
impl OperationReflect for NonSemantic {
type OpCode = NonSemanticOpCode;
fn op_code(&self) -> Self::OpCode {
self.__match_opcode()
}
}
impl Display for NonSemantic {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self {
NonSemantic::Print {
format_string,
args,
} => {
write!(f, "print({format_string:?}{})", fmt_vararg(args))
}
NonSemantic::Comment { content } => write!(f, "//{content}"),
_ => Ok(()),
}
}
}
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, Clone, PartialEq, Eq, Hash, TypeHash)]
pub struct SourceLoc {
pub line: u32,
pub column: u32,
pub source: CubeFnSource,
}
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, Clone, PartialEq, Eq, Hash, TypeHash)]
pub struct CubeFnSource {
pub function_name: Cow<'static, str>,
pub file: Cow<'static, str>,
pub source_text: Cow<'static, str>,
pub line: u32,
pub column: u32,
}