aver/nan_value.rs
1//! NaN-boxed compact Value representation — thin re-export layer.
2//!
3//! The core NanValue, Arena, and supporting types now live in the
4//! `aver_memory` crate. This module defines `AverTypes` that plugs
5//! `FunctionValue` and `PersistentMap` into the generic arena,
6//! provides type aliases so existing
7//! `use crate::nan_value::{Arena, NanValue, ...}` continues to work,
8//! and keeps the `convert` (Value <-> NanValue) and `tests` submodules
9//! that depend on runtime-specific types.
10
11use std::sync::Arc as Rc;
12
13use crate::value::FunctionValue;
14
15// ---------------------------------------------------------------------------
16// Re-exports from aver_memory (everything the rest of aver-lang needs)
17// ---------------------------------------------------------------------------
18
19pub use aver_memory::{
20 // Bit-layout constants needed by convert.rs and downstream code
21 ARENA_REF_BIT,
22 AllocSpace,
23 ArenaIntRef,
24 ArenaList,
25 ArenaTypes,
26 ArenaUsage,
27 FnValueName,
28 IMM_FALSE,
29 IMM_TRUE,
30 IMM_UNIT,
31 INT_INLINE_MAX,
32 INT_INLINE_MIN,
33 MapLike,
34 NanString,
35 NanValue,
36 PersistentMap,
37 SYMBOL_BUILTIN,
38 SYMBOL_FN,
39 SYMBOL_NAMESPACE,
40 SYMBOL_NULLARY_VARIANT,
41 TAG_ERR,
42 TAG_IMMEDIATE,
43 TAG_INLINE_VARIANT,
44 TAG_INT,
45 TAG_LIST,
46 TAG_MAP,
47 TAG_NONE,
48 TAG_OK,
49 TAG_RECORD,
50 TAG_SOME,
51 TAG_STRING,
52 TAG_SYMBOL,
53 TAG_TUPLE,
54 TAG_VARIANT,
55 TAG_VECTOR,
56 WRAP_ERR,
57 WRAP_OK,
58 WRAP_SOME,
59};
60
61// ---------------------------------------------------------------------------
62// Aver-specific concrete types
63// ---------------------------------------------------------------------------
64
65/// Concrete arena types for the Aver runtime.
66#[derive(Clone, Debug)]
67pub struct AverTypes;
68
69impl ArenaTypes for AverTypes {
70 type Fn = FunctionValue;
71 type Map = PersistentMap;
72}
73
74// -- FnValueName for FunctionValue -----------------------------------------
75
76impl FnValueName for FunctionValue {
77 fn name(&self) -> &str {
78 &self.name
79 }
80}
81
82// ---------------------------------------------------------------------------
83// Type aliases — these make existing code work unchanged
84// ---------------------------------------------------------------------------
85
86pub type Arena = aver_memory::Arena<AverTypes>;
87pub type ArenaEntry = aver_memory::ArenaEntry<AverTypes>;
88pub type ArenaSymbol = aver_memory::ArenaSymbol<AverTypes>;
89
90// ---------------------------------------------------------------------------
91// Extension trait for Value <-> NanValue conversion
92// ---------------------------------------------------------------------------
93
94#[cfg(feature = "runtime")]
95pub use convert::NanValueConvert;
96
97#[cfg(feature = "runtime")]
98mod convert;
99
100#[cfg(feature = "runtime")]
101pub use int_ext::NanIntExt;
102
103#[cfg(feature = "runtime")]
104mod int_ext;
105
106#[cfg(test)]
107#[allow(clippy::approx_constant)]
108mod tests;