forked from M-Labs/nac3
lyken
fdfc80ca5f
Based on 01c96396: core/irrt: add Slice and Range and part of 8f9d2d82: core/ndstrides: implement ndarray indexing. Needed for implementing general ndarray indexing. Currently IRRT slice and range have nothing to do with NAC3's slice and range. The IRRT slice and range are currently there to implement ndarray specific features. However, in the future their definitions may be used to replace that of NAC3's. (NAC3's range is a [i32 x 3], IRRT's range is a proper struct. NAC3 does not have a slice struct).
48 lines
1.4 KiB
Rust
48 lines
1.4 KiB
Rust
use inkwell::{context::Context, values::BasicValue};
|
|
|
|
use super::types::ProxyType;
|
|
use crate::codegen::CodeGenerator;
|
|
pub use array::*;
|
|
pub use list::*;
|
|
pub use range::*;
|
|
|
|
mod array;
|
|
mod list;
|
|
pub mod ndarray;
|
|
mod range;
|
|
pub mod utils;
|
|
|
|
/// A LLVM type that is used to represent a non-primitive value in NAC3.
|
|
pub trait ProxyValue<'ctx>: Into<Self::Base> {
|
|
/// The type of LLVM values represented by this instance. This is usually the
|
|
/// [LLVM pointer type][PointerValue].
|
|
type Base: BasicValue<'ctx>;
|
|
|
|
/// The type of this value.
|
|
type Type: ProxyType<'ctx, Value = Self>;
|
|
|
|
/// Checks whether `value` can be represented by this [`ProxyValue`].
|
|
fn is_instance<G: CodeGenerator + ?Sized>(
|
|
generator: &G,
|
|
ctx: &'ctx Context,
|
|
value: impl BasicValue<'ctx>,
|
|
) -> Result<(), String> {
|
|
Self::Type::is_type(generator, ctx, value.as_basic_value_enum().get_type())
|
|
}
|
|
|
|
/// Checks whether `value` can be represented by this [`ProxyValue`].
|
|
fn is_representable<G: CodeGenerator + ?Sized>(
|
|
generator: &G,
|
|
ctx: &'ctx Context,
|
|
value: Self::Base,
|
|
) -> Result<(), String> {
|
|
Self::is_instance(generator, ctx, value.as_basic_value_enum())
|
|
}
|
|
|
|
/// Returns the [type][ProxyType] of this value.
|
|
fn get_type(&self) -> Self::Type;
|
|
|
|
/// Returns the [base value][Self::Base] of this proxy.
|
|
fn as_base_value(&self) -> Self::Base;
|
|
}
|