ArrayLen::{get_length -> length}

This commit is contained in:
lyken 2024-08-28 12:01:12 +08:00
parent 88b51acd0e
commit 2e4a33d6ee
No known key found for this signature in database
GPG Key ID: 3BD5FC6AC8325DD8
1 changed files with 8 additions and 8 deletions

View File

@ -12,7 +12,7 @@ use super::*;
/// Trait for Rust structs identifying length values for [`Array`].
pub trait ArrayLen: fmt::Debug + Clone + Copy {
fn get_length(&self) -> u32;
fn length(&self) -> u32;
}
/// A statically known length.
@ -24,13 +24,13 @@ pub struct Len<const N: u32>;
pub struct AnyLen(pub u32);
impl<const N: u32> ArrayLen for Len<N> {
fn get_length(&self) -> u32 {
fn length(&self) -> u32 {
N
}
}
impl ArrayLen for AnyLen {
fn get_length(&self) -> u32 {
fn length(&self) -> u32 {
self.0
}
}
@ -49,7 +49,7 @@ pub struct Array<Len, Item> {
impl<'ctx, Len: ArrayLen, Item: ModelBase<'ctx>> ModelBase<'ctx> for Array<Len, Item> {
fn get_type_impl(&self, size_t: IntType<'ctx>, ctx: &'ctx Context) -> BasicTypeEnum<'ctx> {
let item = self.item.get_type_impl(size_t, ctx);
item.array_type(self.len.get_length()).into()
item.array_type(self.len.length()).into()
}
fn check_type_impl(
@ -62,11 +62,11 @@ impl<'ctx, Len: ArrayLen, Item: ModelBase<'ctx>> ModelBase<'ctx> for Array<Len,
return Err(ModelError(format!("Expecting ArrayType, but got {ty:?}")));
};
if ty.len() != self.len.get_length() {
if ty.len() != self.len.length() {
return Err(ModelError(format!(
"Expecting ArrayType with size {}, but got an ArrayType with size {}",
ty.len(),
self.len.get_length()
self.len.length()
)));
}
@ -99,9 +99,9 @@ impl<'ctx, Len: ArrayLen, Item: Model<'ctx>> Instance<'ctx, Ptr<Array<Len, Item>
/// Like `gep` but `i` is a constant.
pub fn gep_const(&self, ctx: &CodeGenContext<'ctx, '_>, i: u64) -> Instance<'ctx, Ptr<Item>> {
assert!(
i < u64::from(self.model.0.len.get_length()),
i < u64::from(self.model.0.len.length()),
"Index {i} is out of bounds. Array length = {}",
self.model.0.len.get_length()
self.model.0.len.length()
);
let i = ctx.ctx.i32_type().const_int(i, false);