feat: stack var (WIP)

This commit is contained in:
2025-08-09 08:12:53 +08:00
parent fd182b6233
commit d8ad7fe904
36 changed files with 1521 additions and 1058 deletions

View File

@@ -9,5 +9,4 @@ derive_more = { version = "2.0", features = ["full"] }
hashbrown = "0.15"
rnix = "0.12"
nixjit_error = { path = "../nixjit_error" }
nixjit_value = { path = "../nixjit_value" }

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,
//! argument indexes, and structures for various expression types (e.g., binary operations,
//! argument indices, 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,9 +18,9 @@ use nixjit_value::Const as PubConst;
/// A type-safe wrapper for an index into an expression table.
///
/// Using a newtype wrapper like this prevents accidentally mixing up different kinds of indices.
/// Using a newtype wrapper to prevent accidentally mixing up different kinds of indices.
#[repr(transparent)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct ExprId(usize);
impl ExprId {
@@ -38,7 +38,7 @@ impl ExprId {
/// # Safety
/// The caller must ensure that the provided index is valid for the expression table.
#[inline(always)]
pub unsafe fn from(id: usize) -> Self {
pub unsafe fn from_raw(id: usize) -> Self {
Self(id)
}
}
@@ -63,17 +63,17 @@ impl PrimOpId {
/// # Safety
/// The caller must ensure that the provided index is valid.
#[inline(always)]
pub unsafe fn from(id: usize) -> Self {
pub unsafe fn from_raw(id: usize) -> Self {
Self(id)
}
}
/// A type-safe wrapper for an index into a function's argument list.
/// A type-safe wrapper for an index into a function's dependency stack.
#[repr(transparent)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct ArgIdx(usize);
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct StackIdx(usize);
impl ArgIdx {
impl StackIdx {
/// Returns the raw `usize` index.
///
/// # Safety
@@ -83,16 +83,19 @@ impl ArgIdx {
self.0
}
/// Creates an `ArgIdx` from a raw `usize` index.
/// Creates an `StackIdx` from a raw `usize` index.
///
/// # Safety
/// The caller must ensure that the provided index is valid.
#[inline(always)]
pub unsafe fn from(idx: usize) -> Self {
pub unsafe fn from_raw(idx: usize) -> Self {
Self(idx)
}
}
#[derive(Clone, Copy, Debug)]
pub struct Arg;
/// Represents a Nix attribute set.
#[derive(Debug, Default)]
pub struct AttrSet {
@@ -100,8 +103,6 @@ pub struct AttrSet {
pub stcs: HashMap<String, ExprId>,
/// Dynamically computed attributes, where both the key and value are expressions.
pub dyns: Vec<(ExprId, ExprId)>,
/// `true` if this is a recursive attribute set (`rec { ... }`).
pub rec: bool,
}
/// Represents a key in an attribute path.
@@ -265,16 +266,7 @@ pub struct Param {
pub struct Call {
/// The expression that evaluates to the function to be called.
pub func: ExprId,
/// The list of arguments to pass to the function.
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,
pub arg: ExprId,
}
/// Represents a `with` expression.