Skip to main content

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    ArenaList,
24    ArenaTypes,
25    ArenaUsage,
26    FnValueName,
27    IMM_FALSE,
28    IMM_TRUE,
29    IMM_UNIT,
30    INT_INLINE_MAX,
31    INT_INLINE_MIN,
32    MapLike,
33    NanString,
34    NanValue,
35    PersistentMap,
36    SYMBOL_BUILTIN,
37    SYMBOL_FN,
38    SYMBOL_NAMESPACE,
39    SYMBOL_NULLARY_VARIANT,
40    TAG_ERR,
41    TAG_IMMEDIATE,
42    TAG_INLINE_VARIANT,
43    TAG_INT,
44    TAG_LIST,
45    TAG_MAP,
46    TAG_NONE,
47    TAG_OK,
48    TAG_RECORD,
49    TAG_SOME,
50    TAG_STRING,
51    TAG_SYMBOL,
52    TAG_TUPLE,
53    TAG_VARIANT,
54    TAG_VECTOR,
55    WRAP_ERR,
56    WRAP_OK,
57    WRAP_SOME,
58};
59
60// ---------------------------------------------------------------------------
61// Aver-specific concrete types
62// ---------------------------------------------------------------------------
63
64/// Concrete arena types for the Aver runtime.
65#[derive(Clone, Debug)]
66pub struct AverTypes;
67
68impl ArenaTypes for AverTypes {
69    type Fn = FunctionValue;
70    type Map = PersistentMap;
71}
72
73// -- FnValueName for FunctionValue -----------------------------------------
74
75impl FnValueName for FunctionValue {
76    fn name(&self) -> &str {
77        &self.name
78    }
79}
80
81// ---------------------------------------------------------------------------
82// Type aliases — these make existing code work unchanged
83// ---------------------------------------------------------------------------
84
85pub type Arena = aver_memory::Arena<AverTypes>;
86pub type ArenaEntry = aver_memory::ArenaEntry<AverTypes>;
87pub type ArenaSymbol = aver_memory::ArenaSymbol<AverTypes>;
88
89// ---------------------------------------------------------------------------
90// Extension trait for Value <-> NanValue conversion
91// ---------------------------------------------------------------------------
92
93#[cfg(feature = "runtime")]
94pub use convert::NanValueConvert;
95
96#[cfg(feature = "runtime")]
97mod convert;
98
99#[cfg(test)]
100#[allow(clippy::approx_constant)]
101mod tests;