Skip to main content

runmat_runtime/native/
source.rs

1/// Stable source location. It contains no host path or Rust string layout.
2#[repr(C)]
3#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
4pub struct NativeSourceLocation {
5    pub source: u32,
6    pub reserved: u32,
7    pub start: u64,
8    pub end: u64,
9}
10
11/// Borrowed UTF-8 bytes owned by the executable product.
12#[repr(C)]
13#[derive(Clone, Copy, Debug)]
14pub struct NativeUtf8 {
15    pub bytes: *const u8,
16    pub len: usize,
17}
18
19impl Default for NativeUtf8 {
20    fn default() -> Self {
21        Self {
22            bytes: std::ptr::null(),
23            len: 0,
24        }
25    }
26}
27
28impl NativeUtf8 {
29    pub fn validate(self) -> Result<(), super::NativeAbiError> {
30        super::validation::validate_slice("native.utf8", self.bytes, self.len)
31    }
32}
33
34impl NativeSourceLocation {
35    pub fn validate(self) -> Result<(), super::NativeAbiError> {
36        if self.reserved != 0 {
37            return Err(super::NativeAbiError::new(
38                "native.source_location.reserved",
39                "reserved bits must be zero for this ABI revision",
40            ));
41        }
42        if self.end < self.start {
43            return Err(super::NativeAbiError::new(
44                "native.source_location",
45                "source range end precedes its start",
46            ));
47        }
48        Ok(())
49    }
50}
51
52impl NativeSourceMapEntry {
53    pub fn validate(self) -> Result<(), super::NativeAbiError> {
54        if self.reserved != 0 {
55            return Err(super::NativeAbiError::new(
56                "native.source_map_entry.reserved",
57                "reserved bits must be zero for this ABI revision",
58            ));
59        }
60        self.owner_identity.validate()?;
61        self.relative_path.validate()?;
62        self.display_name.validate()
63    }
64}
65
66/// Path-independent source-map projection for diagnostics and stack traces.
67#[repr(C)]
68#[derive(Clone, Copy, Debug, Default)]
69pub struct NativeSourceMapEntry {
70    pub source: u32,
71    pub reserved: u32,
72    pub owner_identity: NativeUtf8,
73    pub relative_path: NativeUtf8,
74    pub display_name: NativeUtf8,
75}
76
77#[repr(C)]
78#[derive(Clone, Copy, Debug)]
79pub struct NativeSourceMapView {
80    pub entries: *const NativeSourceMapEntry,
81    pub count: usize,
82}
83
84impl Default for NativeSourceMapView {
85    fn default() -> Self {
86        Self {
87            entries: std::ptr::null(),
88            count: 0,
89        }
90    }
91}