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
//! Cards for the two ways to designate a value, and for a finished run.
use malevich::Theme;
use super::{html, render};
use crate::{Element, Emittable, Run, Symbol, Value};
impl<E: Element + Emittable> Value<'_, E>
where
f64: From<E>,
{
/// Renders the proxy's stored payload as a self-contained HTML
/// card.
///
/// The payload shown is the recorded one: a leaf's constant, a
/// parameter's record-site initial, or an input's default. Live
/// parameter payloads belong to the caller's
/// [`Parameters`](crate::Parameters) and are read by [`Symbol`].
pub fn to_html(&self, theme: Theme) -> String {
let Some(payload) = self.payload() else {
let header = format!(
"value \u{b7} {} \u{b7} not yet computed",
render::shape_text(&self.shape())
);
return html::card(
theme,
&html::escape(&header),
"<div>run <code>forward</code> to give this value a payload</div>",
);
};
render::payload_card(theme, "value", &payload)
}
/// Displays the value when it is the last expression in an Evcxr
/// cell.
pub fn evcxr_display(&self) {
let plain = match self.payload() {
Some(payload) => render::payload_text("value", &payload),
None => format!(
"value {} not yet computed",
render::shape_text(&self.shape())
),
};
html::show(&self.to_html(Theme::detect()), &plain);
}
}
impl Symbol {
/// Renders the symbol as a self-contained HTML card.
///
/// A symbol is a detached name and carries no payload of its own,
/// so the card says what it is and how to read through it rather
/// than inventing a value.
pub fn to_html(&self, theme: Theme) -> String {
html::card(
theme,
"symbol",
"<div>a detached name; <code>parameters.of(symbol)</code> and \
<code>run.of(symbol)</code> read through it, and \
<code>tape.resolve(symbol)</code> reenters recording</div>",
)
}
/// Displays the symbol when it is the last expression in an Evcxr
/// cell.
pub fn evcxr_display(&self) {
html::show(
&self.to_html(Theme::detect()),
"symbol \u{b7} a detached name; read through parameters, runs, and fields",
);
}
}
impl<E: Element> Run<E>
where
f64: From<E>,
{
/// Renders the run as a self-contained HTML card.
///
/// A run holds a value per node, so the card shows the profile of
/// their magnitudes: the shape of the forward pass, where it grew,
/// and whether anything went non-finite.
pub fn to_html(&self, theme: Theme) -> String {
super::field::profile_card(theme, "run", self.field())
}
/// Displays the run when it is the last expression in an Evcxr
/// cell.
pub fn evcxr_display(&self) {
html::show(
&self.to_html(Theme::detect()),
&super::field::profile_text("run", self.field()),
);
}
}
#[cfg(test)]
#[path = "tests/value_tests.rs"]
mod tests;