ArrayLen::{get_length -> length}
This commit is contained in:
parent
88b51acd0e
commit
2e4a33d6ee
|
@ -12,7 +12,7 @@ use super::*;
|
||||||
|
|
||||||
/// Trait for Rust structs identifying length values for [`Array`].
|
/// Trait for Rust structs identifying length values for [`Array`].
|
||||||
pub trait ArrayLen: fmt::Debug + Clone + Copy {
|
pub trait ArrayLen: fmt::Debug + Clone + Copy {
|
||||||
fn get_length(&self) -> u32;
|
fn length(&self) -> u32;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A statically known length.
|
/// A statically known length.
|
||||||
|
@ -24,13 +24,13 @@ pub struct Len<const N: u32>;
|
||||||
pub struct AnyLen(pub u32);
|
pub struct AnyLen(pub u32);
|
||||||
|
|
||||||
impl<const N: u32> ArrayLen for Len<N> {
|
impl<const N: u32> ArrayLen for Len<N> {
|
||||||
fn get_length(&self) -> u32 {
|
fn length(&self) -> u32 {
|
||||||
N
|
N
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ArrayLen for AnyLen {
|
impl ArrayLen for AnyLen {
|
||||||
fn get_length(&self) -> u32 {
|
fn length(&self) -> u32 {
|
||||||
self.0
|
self.0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -49,7 +49,7 @@ pub struct Array<Len, Item> {
|
||||||
impl<'ctx, Len: ArrayLen, Item: ModelBase<'ctx>> ModelBase<'ctx> for 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> {
|
fn get_type_impl(&self, size_t: IntType<'ctx>, ctx: &'ctx Context) -> BasicTypeEnum<'ctx> {
|
||||||
let item = self.item.get_type_impl(size_t, 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(
|
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:?}")));
|
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!(
|
return Err(ModelError(format!(
|
||||||
"Expecting ArrayType with size {}, but got an ArrayType with size {}",
|
"Expecting ArrayType with size {}, but got an ArrayType with size {}",
|
||||||
ty.len(),
|
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.
|
/// Like `gep` but `i` is a constant.
|
||||||
pub fn gep_const(&self, ctx: &CodeGenContext<'ctx, '_>, i: u64) -> Instance<'ctx, Ptr<Item>> {
|
pub fn gep_const(&self, ctx: &CodeGenContext<'ctx, '_>, i: u64) -> Instance<'ctx, Ptr<Item>> {
|
||||||
assert!(
|
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 = {}",
|
"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);
|
let i = ctx.ctx.i32_type().const_int(i, false);
|
||||||
|
|
Loading…
Reference in New Issue