Skip to content

Commit 03b22b2

Browse files
authored
Merge pull request #40 from mjp41/0-pippi-langstrump
Mermaid: Add taint function and more colors to diagrams
2 parents 5fb69bd + 20abbff commit 03b22b2

6 files changed

Lines changed: 305 additions & 32 deletions

File tree

docs/builtin.md

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# Built-in Functions
2+
3+
## Debugging
4+
5+
#### `breakpoint()`
6+
7+
Causes the interpreter to enter *interactive mode*.
8+
9+
#### `unreachable()`
10+
11+
Aborts the interpreter process. It's intended to indicate that an execution branch is not reachable.
12+
13+
## Constructors
14+
15+
#### `region()`
16+
17+
Creates a new region object.
18+
19+
#### `cown(take region)`
20+
21+
Creates a new `cown` object.
22+
23+
The region must have a local reference count of one. The `take` keyword is used to replace the local value with `None`.
24+
25+
### `create(proto)`
26+
27+
Creates a new object from the given prototype.
28+
29+
## Memory Management
30+
31+
#### `freeze(obj)`
32+
33+
Performs a deep freeze of the object and all referenced objects.
34+
35+
This will move the objects out of their current region into the immutable region. Cowns will stop the freeze propagation, as they can be safely shared across threads and behaviors.
36+
37+
## Mermaid
38+
39+
#### `mermaid_hide(obj, ..)`
40+
41+
Hides the given arguments from the mermaid graph.
42+
43+
#### `mermaid_show(obj, ..)`
44+
45+
Shows the given arguments in the mermaid diagram.
46+
47+
#### `mermaid_show_all()`
48+
49+
Makes all nodes visible in the mermaid diagram.
50+
51+
#### `mermaid_show_tainted(obj, ...)`
52+
53+
Draws a mermaid diagram with the given objects marked as tainted. This will show which objects are reachable at this point.
54+
55+
#### `mermaid_taint(obj, ...)`
56+
57+
Marks the given objects as tainted, this will highlight, which nodes are reachable from the given objects.
58+
59+
The tainted status will remain until `mermaid_untaint` is called.
60+
61+
`mermaid_show_tainted()` can be used to only taint the current snapshot.
62+
63+
#### `mermaid_untaint(obj, ...)`
64+
65+
Marks the given objects as untainted, thereby removing the highlights from the mermaid diagram.
66+

src/rt/core/builtin.cc

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,61 @@ namespace rt::core
5858
return std::nullopt;
5959
});
6060

61+
add_builtin(
62+
"mermaid_show_tainted", [mermaid](auto frame, auto stack, auto args) {
63+
assert(args >= 1);
64+
65+
std::vector<rt::objects::DynObject*> taint;
66+
for (int i = 0; i < args; i++)
67+
{
68+
auto value = stack->back();
69+
mermaid->add_taint(value);
70+
taint.push_back(value);
71+
rt::remove_reference(frame, value);
72+
stack->pop_back();
73+
}
74+
75+
// Mermaid output
76+
std::vector<rt::objects::DynObject*> roots{frame};
77+
mermaid->output(roots, "Builtin: display taint");
78+
79+
for (auto tainted : taint)
80+
{
81+
mermaid->remove_taint(tainted);
82+
}
83+
84+
return std::nullopt;
85+
});
86+
87+
add_builtin("mermaid_taint", [mermaid](auto frame, auto stack, auto args) {
88+
assert(args >= 1);
89+
90+
for (int i = 0; i < args; i++)
91+
{
92+
auto value = stack->back();
93+
mermaid->add_taint(value);
94+
rt::remove_reference(frame, value);
95+
stack->pop_back();
96+
}
97+
98+
return std::nullopt;
99+
});
100+
101+
add_builtin(
102+
"mermaid_untaint", [mermaid](auto frame, auto stack, auto args) {
103+
assert(args >= 1);
104+
105+
for (int i = 0; i < args; i++)
106+
{
107+
auto value = stack->back();
108+
mermaid->remove_taint(value);
109+
rt::remove_reference(frame, value);
110+
stack->pop_back();
111+
}
112+
113+
return std::nullopt;
114+
});
115+
61116
add_builtin("breakpoint", [mermaid](auto, auto, auto args) {
62117
assert(args == 0);
63118

src/rt/ui.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ namespace rt::ui
4848
std::set<objects::DynObject*> unreachable_hide;
4949
/// Nodes that should never be visible.
5050
std::set<objects::DynObject*> always_hide;
51+
/// @brief Nodes that should be tainted, meaning they and all reachable
52+
/// nodes are highlighted.
53+
std::set<rt::objects::DynObject*> taint;
5154

5255
public:
5356
MermaidUI(int step_counter);
@@ -90,6 +93,16 @@ namespace rt::ui
9093
{
9194
always_hide.erase(obj);
9295
}
96+
97+
void add_taint(objects::DynObject* obj)
98+
{
99+
taint.insert(obj);
100+
}
101+
102+
void remove_taint(objects::DynObject* obj)
103+
{
104+
taint.erase(obj);
105+
}
93106
};
94107

95108
[[noreturn]] inline void error(const std::string& msg)

0 commit comments

Comments
 (0)