use crate::counting::CountingFlags;
use crate::id::{DefinitionId, NameId};
use crate::line::LineContent;
use crate::value::{Value, ValueType};
#[derive(Debug, Clone, PartialEq)]
pub struct ContainerDef {
pub id: DefinitionId,
pub scope_id: DefinitionId,
pub name: Option<NameId>,
pub bytecode: Vec<u8>,
pub counting_flags: CountingFlags,
pub path_hash: i32,
pub param_count: u8,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct SlotInfo {
pub index: u8,
pub name: String,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct SourceLocation {
pub file: String,
pub range_start: u32,
pub range_end: u32,
}
#[derive(Debug, Clone, PartialEq)]
pub struct LineEntry {
pub content: LineContent,
pub flags: crate::LineFlags,
pub source_hash: u64,
pub audio_ref: Option<String>,
pub slot_info: Vec<SlotInfo>,
pub source_location: Option<SourceLocation>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct LocaleLineEntry {
pub content: LineContent,
pub audio_ref: Option<String>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct LocaleScopeTable {
pub scope_id: DefinitionId,
pub lines: Vec<LocaleLineEntry>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct LocaleData {
pub locale_tag: String,
pub base_checksum: u32,
pub line_tables: Vec<LocaleScopeTable>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct ScopeLineTable {
pub scope_id: DefinitionId,
pub lines: Vec<LineEntry>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct GlobalVarDef {
pub id: DefinitionId,
pub name: NameId,
pub value_type: ValueType,
pub default_value: Value,
pub mutable: bool,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ListDef {
pub id: DefinitionId,
pub name: NameId,
pub items: Vec<(NameId, i32)>,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct ListItemDef {
pub id: DefinitionId,
pub origin: DefinitionId,
pub ordinal: i32,
pub name: NameId,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct AddressDef {
pub id: DefinitionId,
pub container_id: DefinitionId,
pub byte_offset: u32,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct AddressPath {
pub path: NameId,
pub target: DefinitionId,
}
pub fn content_hash(text: &str) -> u64 {
use std::hash::{Hash, Hasher};
let mut hasher = std::collections::hash_map::DefaultHasher::new();
text.hash(&mut hasher);
hasher.finish()
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct ExternalFnDef {
pub id: DefinitionId,
pub name: NameId,
pub arg_count: u8,
pub fallback: Option<DefinitionId>,
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn content_hash_deterministic() {
let a = content_hash("Hello, world!");
let b = content_hash("Hello, world!");
assert_eq!(a, b);
}
#[test]
fn content_hash_non_zero_for_non_empty() {
assert_ne!(content_hash("some text"), 0);
assert_ne!(content_hash("x"), 0);
}
#[test]
fn content_hash_differs_for_different_input() {
assert_ne!(content_hash("hello"), content_hash("world"));
}
}