Track various symbols in the parse stage of Slang

This commit is contained in:
2026-01-02 17:06:43 -07:00
parent 6dc4342ac3
commit 4ff0ff1b66
4 changed files with 163 additions and 31 deletions

View File

@@ -127,6 +127,52 @@ impl<'a> std::fmt::Display for Math<'a> {
}
}
impl<'a> Math<'a> {
/// Returns the name of this math function (e.g., "acos", "sin", "sqrt", etc.)
pub fn name(&self) -> &'static str {
match self {
Math::Acos(_) => "acos",
Math::Asin(_) => "asin",
Math::Atan(_) => "atan",
Math::Atan2(_, _) => "atan2",
Math::Abs(_) => "abs",
Math::Ceil(_) => "ceil",
Math::Cos(_) => "cos",
Math::Floor(_) => "floor",
Math::Log(_) => "log",
Math::Max(_, _) => "max",
Math::Min(_, _) => "min",
Math::Rand => "rand",
Math::Sin(_) => "sin",
Math::Sqrt(_) => "sqrt",
Math::Tan(_) => "tan",
Math::Trunc(_) => "trunc",
}
}
/// Returns the number of arguments this math function expects
pub fn arg_count(&self) -> usize {
match self {
Math::Acos(_) => 1,
Math::Asin(_) => 1,
Math::Atan(_) => 1,
Math::Atan2(_, _) => 2,
Math::Abs(_) => 1,
Math::Ceil(_) => 1,
Math::Cos(_) => 1,
Math::Floor(_) => 1,
Math::Log(_) => 1,
Math::Max(_, _) => 2,
Math::Min(_, _) => 2,
Math::Rand => 0,
Math::Sin(_) => 1,
Math::Sqrt(_) => 1,
Math::Tan(_) => 1,
Math::Trunc(_) => 1,
}
}
}
documented! {
#[derive(Debug, PartialEq, Eq)]
pub enum System<'a> {
@@ -297,6 +343,48 @@ impl<'a> std::fmt::Display for System<'a> {
}
}
impl<'a> System<'a> {
/// Returns the name of this syscall (e.g., "yield", "sleep", "hash", etc.)
pub fn name(&self) -> &'static str {
match self {
System::Yield => "yield",
System::Sleep(_) => "sleep",
System::Clr(_) => "clr",
System::Hash(_) => "hash",
System::LoadFromDevice(_, _) => "loadFromDevice",
System::LoadBatch(_, _, _) => "loadBatch",
System::LoadBatchNamed(_, _, _, _) => "loadBatchNamed",
System::SetOnDevice(_, _, _) => "setOnDevice",
System::SetOnDeviceBatched(_, _, _) => "setOnDeviceBatched",
System::SetOnDeviceBatchedNamed(_, _, _, _) => "setOnDeviceBatchedNamed",
System::LoadSlot(_, _, _) => "loadSlot",
System::SetSlot(_, _, _, _) => "setSlot",
System::LoadReagent(_, _, _) => "loadReagent",
System::Rmap(_, _) => "rmap",
}
}
/// Returns the number of arguments this syscall expects
pub fn arg_count(&self) -> usize {
match self {
System::Yield => 0,
System::Sleep(_) => 1,
System::Clr(_) => 1,
System::Hash(_) => 1,
System::LoadFromDevice(_, _) => 2,
System::LoadBatch(_, _, _) => 3,
System::LoadBatchNamed(_, _, _, _) => 4,
System::SetOnDevice(_, _, _) => 3,
System::SetOnDeviceBatched(_, _, _) => 3,
System::SetOnDeviceBatchedNamed(_, _, _, _) => 4,
System::LoadSlot(_, _, _) => 3,
System::SetSlot(_, _, _, _) => 4,
System::LoadReagent(_, _, _) => 3,
System::Rmap(_, _) => 2,
}
}
}
#[allow(clippy::large_enum_variant)]
#[derive(Debug, PartialEq, Eq)]
/// This represents built in functions that cannot be overwritten, but can be invoked by the user as functions.