1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
//! # lambda-ref-cat
//!
//! Lambda calculus with mutable reference cells and a pure-functional mark-
//! sweep garbage collector, built on [`comp_cat_rs`]. Spike 2 of a web-
//! engine reformulation targeting Tauri.
//!
//! ## Quick start
//!
//! ```
//! # fn main() -> Result<(), lambda_ref_cat::error::Error> {
//! use lambda_ref_cat::run;
//!
//! let value = run(r"let r = ref (\x. x) in r := (\y. y) ; !r").run()?;
//! assert_eq!(format!("{value}"), "\\y. y");
//! # Ok(())
//! # }
//! ```
//!
//! ## Grammar
//!
//! ```text
//! expr ::= seq_expr
//! seq_expr ::= right_expr (";" right_expr)*
//! right_expr ::= lambda | let | fix | assign_expr
//! lambda ::= "\" ident "." expr
//! let ::= "let" ident "=" expr "in" expr
//! fix ::= "fix" ident "." expr
//! assign_expr ::= app_expr (":=" right_expr)?
//! app_expr ::= atom atom*
//! atom ::= ident | "(" expr ")" | "ref" atom | "!" atom
//! ```
//!
//! [`Io`]: comp_cat_rs::effect::io::Io
//! [`Fuel`]: crate::eval::Fuel
use Io;
use crateEnv;
use crateError;
use crateFuel;
use crateHeap;
use crateValue;
/// Default step budget used by [`run`].
pub const DEFAULT_FUEL: u64 = 10_000;
/// Lex, parse, and evaluate `source` with the default fuel budget, returning
/// just the resulting value.
///
/// # Errors
///
/// Any of the underlying passes can fail; see [`Error`].
///
/// # Examples
///
/// ```
/// # fn main() -> Result<(), lambda_ref_cat::error::Error> {
/// use lambda_ref_cat::run;
///
/// let value = run(r"!ref (\x. x)").run()?;
/// assert_eq!(format!("{value}"), "\\x. x");
/// # Ok(())
/// # }
/// ```
/// Lex, parse, and evaluate `source` with a caller-supplied fuel budget.
///
/// # Errors
///
/// Same as [`run`].
///
/// # Examples
///
/// ```
/// # fn main() -> Result<(), lambda_ref_cat::error::Error> {
/// use lambda_ref_cat::eval::Fuel;
/// use lambda_ref_cat::run_with_fuel;
///
/// let value = run_with_fuel(r"ref (\x. x)", Fuel::new(100)).run()?;
/// // The result is a fresh reference; the cell contents are not displayed.
/// assert!(format!("{value}").starts_with("ref("));
/// # Ok(())
/// # }
/// ```
/// Lex, parse, and evaluate `source`, returning both the value and the final
/// heap. Useful for tests that want to verify garbage-collection behaviour.
///
/// # Errors
///
/// Same as [`run`].
///
/// # Examples
///
/// ```
/// # fn main() -> Result<(), lambda_ref_cat::error::Error> {
/// use lambda_ref_cat::eval::Fuel;
/// use lambda_ref_cat::run_inspecting;
///
/// let (_value, heap) = run_inspecting(r"ref (\x. x)", Fuel::new(100)).run()?;
/// assert_eq!(heap.len(), 1);
/// # Ok(())
/// # }
/// ```