#![allow(dead_code)]
#![allow(clippy::struct_field_names)]
use core::ffi::c_void;
use crate::types::lean_object;
#[repr(C)]
pub(crate) struct LeanObjectRepr {
pub(crate) m_rc: i32,
pub(crate) m_cs_sz: u16,
pub(crate) m_other: u8,
pub(crate) m_tag: u8,
}
#[repr(C)]
pub(crate) struct LeanCtorObjectRepr {
pub(crate) header: LeanObjectRepr,
pub(crate) objs: [*mut lean_object; 0],
}
#[repr(C)]
pub(crate) struct LeanArrayObjectRepr {
pub(crate) header: LeanObjectRepr,
pub(crate) size: usize,
pub(crate) capacity: usize,
pub(crate) data: [*mut lean_object; 0],
}
#[repr(C)]
pub(crate) struct LeanSArrayObjectRepr {
pub(crate) header: LeanObjectRepr,
pub(crate) size: usize,
pub(crate) capacity: usize,
pub(crate) data: [u8; 0],
}
#[repr(C)]
pub(crate) struct LeanStringObjectRepr {
pub(crate) header: LeanObjectRepr,
pub(crate) size: usize,
pub(crate) capacity: usize,
pub(crate) length: usize,
pub(crate) data: [u8; 0],
}
#[repr(C)]
pub(crate) struct LeanClosureObjectRepr {
pub(crate) header: LeanObjectRepr,
pub(crate) fun: *mut c_void,
pub(crate) arity: u16,
pub(crate) num_fixed: u16,
pub(crate) objs: [*mut lean_object; 0],
}
#[repr(C)]
pub(crate) struct LeanRefObjectRepr {
pub(crate) header: LeanObjectRepr,
pub(crate) value: *mut lean_object,
}
#[repr(C)]
pub(crate) struct LeanThunkObjectRepr {
pub(crate) header: LeanObjectRepr,
pub(crate) value: *mut lean_object,
pub(crate) closure: *mut lean_object,
}
#[repr(C)]
pub(crate) struct LeanTaskObjectRepr {
pub(crate) header: LeanObjectRepr,
pub(crate) value: *mut lean_object,
pub(crate) imp: *mut c_void,
}
#[repr(C)]
pub(crate) struct LeanPromiseObjectRepr {
pub(crate) header: LeanObjectRepr,
pub(crate) result: *mut c_void,
}
#[repr(C)]
pub(crate) struct LeanExternalObjectRepr {
pub(crate) header: LeanObjectRepr,
pub(crate) class: *mut c_void,
pub(crate) data: *mut c_void,
}
#[cfg(test)]
mod tests {
use super::*;
use core::mem::{align_of, size_of};
#[test]
fn header_repr_matches_lean_h() {
assert_eq!(size_of::<LeanObjectRepr>(), 8);
assert_eq!(align_of::<LeanObjectRepr>(), 4);
}
#[test]
fn ctor_repr_has_just_a_header() {
assert_eq!(size_of::<LeanCtorObjectRepr>(), size_of::<LeanObjectRepr>());
}
#[test]
fn array_repr_header_plus_two_words() {
assert_eq!(
size_of::<LeanArrayObjectRepr>(),
size_of::<LeanObjectRepr>() + 2 * size_of::<usize>()
);
}
#[test]
fn string_repr_header_plus_three_words() {
assert_eq!(
size_of::<LeanStringObjectRepr>(),
size_of::<LeanObjectRepr>() + 3 * size_of::<usize>()
);
}
#[test]
fn closure_repr_header_plus_fun_plus_arities() {
let unpadded = size_of::<LeanObjectRepr>() + size_of::<*mut core::ffi::c_void>() + 2 * size_of::<u16>();
let pointer_align = align_of::<*mut core::ffi::c_void>();
assert_eq!(
size_of::<LeanClosureObjectRepr>(),
unpadded.next_multiple_of(pointer_align)
);
}
}