2024-11-01 15:17:00 +08:00
|
|
|
use inkwell::{context::Context, values::BasicValue};
|
2024-10-29 13:57:28 +08:00
|
|
|
|
|
|
|
use super::types::ProxyType;
|
2024-11-01 15:17:00 +08:00
|
|
|
use crate::codegen::CodeGenerator;
|
2024-10-29 13:57:28 +08:00
|
|
|
pub use array::*;
|
|
|
|
pub use list::*;
|
|
|
|
pub use range::*;
|
|
|
|
|
|
|
|
mod array;
|
|
|
|
mod list;
|
2024-12-12 11:30:14 +08:00
|
|
|
pub mod ndarray;
|
2024-10-29 13:57:28 +08:00
|
|
|
mod range;
|
2024-08-24 15:37:45 +08:00
|
|
|
pub mod utils;
|
2024-10-29 13:57:28 +08:00
|
|
|
|
|
|
|
/// 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.
|
2024-11-01 15:17:00 +08:00
|
|
|
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())
|
|
|
|
}
|
2024-10-29 13:57:28 +08:00
|
|
|
|
|
|
|
/// 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;
|
|
|
|
}
|