feat: a lot

This commit is contained in:
2025-08-06 18:30:19 +08:00
parent 32c602f21c
commit f946cb2fd1
22 changed files with 735 additions and 591 deletions

View File

@@ -3,7 +3,7 @@
//! The IR provides a simplified, language-agnostic representation of Nix expressions,
//! serving as a bridge between the high-level representation (HIR) and the low-level
//! representation (LIR). It defines the fundamental building blocks like expression IDs,
//! function IDs, and structures for various expression types (e.g., binary operations,
//! argument indexes, and structures for various expression types (e.g., binary operations,
//! attribute sets, function calls).
//!
//! These structures are designed to be generic and reusable across different stages of
@@ -18,35 +18,40 @@ use nixjit_value::Const as PubConst;
/// A type-safe wrapper for an index into an expression table.
#[repr(transparent)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[derive(Debug, PartialEq, Eq, Hash)]
pub struct ExprId(usize);
impl From<usize> for ExprId {
fn from(id: usize) -> Self {
ExprId(id)
impl ExprId {
#[inline(always)]
pub unsafe fn clone(&self) -> Self {
Self(self.0)
}
#[inline(always)]
pub unsafe fn raw(self) -> usize {
self.0
}
#[inline(always)]
pub unsafe fn from(id: usize) -> Self {
Self(id)
}
}
impl From<ExprId> for usize {
fn from(id: ExprId) -> Self {
id.0
}
}
/// A type-safe wrapper for an index into a function table.
/// A type-safe wrapper for an index into a primop (builtin function) table.
#[repr(transparent)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct FuncId(usize);
pub struct PrimOpId(usize);
impl From<usize> for FuncId {
fn from(id: usize) -> Self {
FuncId(id)
impl PrimOpId {
#[inline(always)]
pub unsafe fn raw(self) -> usize {
self.0
}
}
impl From<FuncId> for usize {
fn from(id: FuncId) -> Self {
id.0
#[inline(always)]
pub unsafe fn from(id: usize) -> Self {
Self(id)
}
}
@@ -55,15 +60,15 @@ impl From<FuncId> for usize {
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct ArgIdx(usize);
impl From<usize> for ArgIdx {
fn from(id: usize) -> Self {
ArgIdx(id)
impl ArgIdx {
#[inline(always)]
pub unsafe fn raw(self) -> usize {
self.0
}
}
impl From<ArgIdx> for usize {
fn from(id: ArgIdx) -> Self {
id.0
#[inline(always)]
pub unsafe fn from(idx: usize) -> Self {
Self(idx)
}
}
@@ -79,7 +84,7 @@ pub struct AttrSet {
}
/// Represents a key in an attribute path.
#[derive(Clone, Debug, TryUnwrap)]
#[derive(Debug, TryUnwrap)]
pub enum Attr {
/// A dynamic attribute key, which is an expression that must evaluate to a string.
Dynamic(ExprId),
@@ -234,6 +239,14 @@ pub struct Call {
pub args: Vec<ExprId>,
}
// Represents a primitive operation (builtin function)
#[derive(Debug, Clone, Copy)]
pub struct PrimOp {
pub name: &'static str,
pub id: PrimOpId,
pub arity: usize,
}
/// Represents a `with` expression.
#[derive(Debug)]
pub struct With {