values stuff i wrote when i woke up
This commit is contained in:
parent
ccfd46cd21
commit
d5bc2400c9
8 changed files with 78 additions and 31 deletions
|
|
@ -50,7 +50,7 @@ impl EvalStateBuilder {
|
||||||
sys::nix_eval_state_builder_new(ctx.as_ptr(), store.as_ptr())
|
sys::nix_eval_state_builder_new(ctx.as_ptr(), store.as_ptr())
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
sys::nix_eval_state_builder_load(context, builder);
|
// sys::nix_eval_state_builder_load(context, builder);
|
||||||
// sys::nix_flake_settings_add_to_eval_state_builder(context, settings, builder);
|
// sys::nix_flake_settings_add_to_eval_state_builder(context, settings, builder);
|
||||||
|
|
||||||
Ok(EvalStateBuilder {
|
Ok(EvalStateBuilder {
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ use crate::{EvalState, NixideResult, StorePath};
|
||||||
pub struct RealisedString<'a> {
|
pub struct RealisedString<'a> {
|
||||||
inner: RefCell<NonNull<sys::nix_realised_string>>,
|
inner: RefCell<NonNull<sys::nix_realised_string>>,
|
||||||
pub path: StorePath,
|
pub path: StorePath,
|
||||||
pub children: LazyArray<StorePath, &'a dyn Fn(usize) -> StorePath>,
|
pub children: LazyArray<StorePath, Box<dyn Fn(usize) -> StorePath + 'a>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> AsInnerPtr<sys::nix_realised_string> for RealisedString<'a> {
|
impl<'a> AsInnerPtr<sys::nix_realised_string> for RealisedString<'a> {
|
||||||
|
|
@ -76,12 +76,13 @@ impl<'a> RealisedString<'a> {
|
||||||
|
|
||||||
let size = unsafe { sys::nix_realised_string_get_store_path_count(inner.as_ptr()) };
|
let size = unsafe { sys::nix_realised_string_get_store_path_count(inner.as_ptr()) };
|
||||||
|
|
||||||
let delegate = &|_| StorePath::fake_path(unsafe { state.store_ref() }).unwrap();
|
|
||||||
|
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
inner: cell,
|
inner: cell,
|
||||||
path: Self::parse_path(inner.as_ptr(), state),
|
path: Self::parse_path(inner.as_ptr(), state),
|
||||||
children: LazyArray::new(size, &delegate),
|
children: LazyArray::new(
|
||||||
|
size,
|
||||||
|
Box::new(|_| StorePath::fake_path(unsafe { state.store_ref() }).unwrap()),
|
||||||
|
),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,30 +7,38 @@ use crate::sys;
|
||||||
use crate::util::wrappers::AsInnerPtr;
|
use crate::util::wrappers::AsInnerPtr;
|
||||||
use crate::util::{panic_issue_call_failed, wrap};
|
use crate::util::{panic_issue_call_failed, wrap};
|
||||||
|
|
||||||
|
pub use crate::expr::values::{NixBool, NixFloat, NixInt, NixString, NixValue};
|
||||||
|
|
||||||
/// A Nix value
|
/// A Nix value
|
||||||
///
|
///
|
||||||
/// This represents any value in the Nix language, including primitives,
|
/// This represents any value in the Nix language, including primitives,
|
||||||
/// collections, and functions.
|
/// collections, and functions.
|
||||||
pub struct Value<'a> {
|
///
|
||||||
pub(crate) inner: NonNull<sys::nix_value>,
|
/// ```cpp
|
||||||
state: &'a EvalState,
|
/// pub const ValueType_NIX_TYPE_THUNK: ValueType = 0;
|
||||||
}
|
/// pub const ValueType_NIX_TYPE_INT: ValueType = 1;
|
||||||
|
/// pub const ValueType_NIX_TYPE_FLOAT: ValueType = 2;
|
||||||
impl<'a> AsInnerPtr<sys::nix_value> for Value<'a> {
|
/// pub const ValueType_NIX_TYPE_BOOL: ValueType = 3;
|
||||||
#[inline]
|
/// pub const ValueType_NIX_TYPE_STRING: ValueType = 4;
|
||||||
unsafe fn as_ptr(&self) -> *mut sys::nix_value {
|
/// pub const ValueType_NIX_TYPE_PATH: ValueType = 5;
|
||||||
self.inner.as_ptr()
|
/// pub const ValueType_NIX_TYPE_NULL: ValueType = 6;
|
||||||
}
|
/// pub const ValueType_NIX_TYPE_ATTRS: ValueType = 7;
|
||||||
|
/// pub const ValueType_NIX_TYPE_LIST: ValueType = 8;
|
||||||
#[inline]
|
/// pub const ValueType_NIX_TYPE_FUNCTION: ValueType = 9;
|
||||||
unsafe fn as_ref(&self) -> &sys::nix_value {
|
/// pub const ValueType_NIX_TYPE_EXTERNAL: ValueType = 10;
|
||||||
unsafe { self.inner.as_ref() }
|
/// ```
|
||||||
}
|
pub enum Value {
|
||||||
|
// Thunk(NixThunk),
|
||||||
#[inline]
|
Int(NixInt),
|
||||||
unsafe fn as_mut(&mut self) -> &mut sys::nix_value {
|
Float(NixFloat),
|
||||||
unsafe { self.inner.as_mut() }
|
Bool(NixBool),
|
||||||
}
|
String(NixString),
|
||||||
|
// Path(NixPath),
|
||||||
|
// Null(NixNull),
|
||||||
|
// Attrs(NixAttrs),
|
||||||
|
// List(NixList),
|
||||||
|
// Function(NixFunction),
|
||||||
|
// External(NixExternal),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Value<'a> {
|
impl<'a> Value<'a> {
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,15 @@ pub struct NixBool {
|
||||||
value: bool,
|
value: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Drop for NixBool {
|
||||||
|
fn drop(&mut self) {
|
||||||
|
let ctx = ErrorContext::new();
|
||||||
|
unsafe {
|
||||||
|
sys::nix_value_decref(ctx.as_ptr(), self.as_ptr());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Display for NixBool {
|
impl Display for NixBool {
|
||||||
fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
|
fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
|
||||||
write!(f, "<bool>")
|
write!(f, "<bool>")
|
||||||
|
|
@ -44,7 +53,7 @@ impl AsInnerPtr<sys::nix_value> for NixBool {
|
||||||
|
|
||||||
impl NixValue for NixBool {
|
impl NixValue for NixBool {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn get_enum_id(&self) -> sys::ValueType {
|
fn id(&self) -> sys::ValueType {
|
||||||
sys::ValueType_NIX_TYPE_BOOL
|
sys::ValueType_NIX_TYPE_BOOL
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,15 @@ pub struct NixFloat {
|
||||||
value: f64,
|
value: f64,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Drop for NixFloat {
|
||||||
|
fn drop(&mut self) {
|
||||||
|
let ctx = ErrorContext::new();
|
||||||
|
unsafe {
|
||||||
|
sys::nix_value_decref(ctx.as_ptr(), self.as_ptr());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Display for NixFloat {
|
impl Display for NixFloat {
|
||||||
fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
|
fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
|
||||||
write!(f, "<float>")
|
write!(f, "<float>")
|
||||||
|
|
@ -43,7 +52,7 @@ impl AsInnerPtr<sys::nix_value> for NixFloat {
|
||||||
|
|
||||||
impl NixValue for NixFloat {
|
impl NixValue for NixFloat {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn get_enum_id(&self) -> sys::ValueType {
|
fn id(&self) -> sys::ValueType {
|
||||||
sys::ValueType_NIX_TYPE_FLOAT
|
sys::ValueType_NIX_TYPE_FLOAT
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,15 @@ pub struct NixInt {
|
||||||
value: i64,
|
value: i64,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Drop for NixInt {
|
||||||
|
fn drop(&mut self) {
|
||||||
|
let ctx = ErrorContext::new();
|
||||||
|
unsafe {
|
||||||
|
sys::nix_value_decref(ctx.as_ptr(), self.as_ptr());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Display for NixInt {
|
impl Display for NixInt {
|
||||||
fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
|
fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
|
||||||
write!(f, "<int>")
|
write!(f, "<int>")
|
||||||
|
|
@ -43,7 +52,7 @@ impl AsInnerPtr<sys::nix_value> for NixInt {
|
||||||
|
|
||||||
impl NixValue for NixInt {
|
impl NixValue for NixInt {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn get_enum_id(&self) -> sys::ValueType {
|
fn id(&self) -> sys::ValueType {
|
||||||
sys::ValueType_NIX_TYPE_INT
|
sys::ValueType_NIX_TYPE_INT
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -21,9 +21,10 @@ use std::ptr::NonNull;
|
||||||
use crate::sys;
|
use crate::sys;
|
||||||
use crate::util::wrappers::AsInnerPtr;
|
use crate::util::wrappers::AsInnerPtr;
|
||||||
|
|
||||||
pub trait NixValue: Display + Debug + AsInnerPtr<sys::nix_value> {
|
pub trait NixValue: Drop + Display + Debug + AsInnerPtr<sys::nix_value> {
|
||||||
/// TODO
|
/// TODO
|
||||||
fn get_enum_id(&self) -> sys::ValueType;
|
fn id(&self) -> sys::ValueType;
|
||||||
|
|
||||||
|
/// TODO
|
||||||
fn new(inner: NonNull<sys::nix_value>) -> Self;
|
fn new(inner: NonNull<sys::nix_value>) -> Self;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ use std::fmt::{Debug, Display, Formatter, Result as FmtResult};
|
||||||
use std::ptr::NonNull;
|
use std::ptr::NonNull;
|
||||||
|
|
||||||
use super::NixValue;
|
use super::NixValue;
|
||||||
|
use crate::errors::ErrorContext;
|
||||||
use crate::expr::RealisedString;
|
use crate::expr::RealisedString;
|
||||||
use crate::util::panic_issue_call_failed;
|
use crate::util::panic_issue_call_failed;
|
||||||
use crate::util::wrap;
|
use crate::util::wrap;
|
||||||
|
|
@ -14,6 +15,15 @@ pub struct NixString {
|
||||||
value: String,
|
value: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Drop for NixString {
|
||||||
|
fn drop(&mut self) {
|
||||||
|
let ctx = ErrorContext::new();
|
||||||
|
unsafe {
|
||||||
|
sys::nix_value_decref(ctx.as_ptr(), self.as_ptr());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Display for NixString {
|
impl Display for NixString {
|
||||||
fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
|
fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
|
||||||
write!(f, "<string>")
|
write!(f, "<string>")
|
||||||
|
|
@ -45,7 +55,7 @@ impl AsInnerPtr<sys::nix_value> for NixString {
|
||||||
|
|
||||||
impl NixValue for NixString {
|
impl NixValue for NixString {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn get_enum_id(&self) -> sys::ValueType {
|
fn id(&self) -> sys::ValueType {
|
||||||
sys::ValueType_NIX_TYPE_STRING
|
sys::ValueType_NIX_TYPE_STRING
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue