New type GenericParam represents a generic parameter.

This commit is contained in:
Jason Orendorff
2022-05-07 16:16:42 -05:00
committed by Emilio Cobos Álvarez
parent 13c0a4a2e8
commit c732069b2e
28 changed files with 462 additions and 103 deletions
+15
View File
@@ -0,0 +1,15 @@
#[repr(transparent)]
pub struct CArrayString<const CAP: usize> {
pub chars: [i8; CAP],
}
pub const TITLE_SIZE: usize = 80;
#[repr(C)]
pub struct Book {
pub title: CArrayString<TITLE_SIZE>,
pub author: CArrayString<40>,
}
#[no_mangle]
pub extern "C" fn root(a: *mut Book) {}
+17
View File
@@ -0,0 +1,17 @@
#[repr(C)]
pub struct ArrayVec<T, const CAP: usize> {
// the `len` first elements of the array are initialized
xs: [T; CAP],
len: u32,
}
#[no_mangle]
pub unsafe extern "C" fn push(v: *mut ArrayVec<*mut u8, 100>, elem: *mut u8) -> i32 {
if (*v).len < 100 {
(*v).xs[(*v).len] = elem;
(*v).len += 1;
1
} else {
0
}
}