Skip to content

Commit f3f78ee

Browse files
committed
Schedule Diagram show cowns as arrows
1 parent 6421848 commit f3f78ee

File tree

6 files changed

+46
-47
lines changed

6 files changed

+46
-47
lines changed

src/lang/interpreter.cc

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -635,14 +635,16 @@ namespace verona::interpreter
635635
auto cown_info = cowns.find(cown);
636636
if (cown_info != cowns.end())
637637
{
638-
auto pending = cown_info->second;
638+
auto predecessor = cown_info->second;
639639
// If a behavior is pending, set the successor
640-
if (pending->status != rt::core::Behavior::Status::Done)
640+
if (predecessor->status != rt::core::Behavior::Status::Done)
641641
{
642-
if (pending->succ.insert(behavior).second)
642+
if (predecessor->succ.insert(behavior).second)
643643
{
644644
behavior->pred_ctn += 1;
645645
}
646+
// Only needed for Mermaid:
647+
behavior->cown_deps[cown] = predecessor.get();
646648
}
647649
}
648650
// Update pointer to the last pending behavior

src/rt/behavior.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,12 @@ namespace rt::core
9696
objects::Region* local_region;
9797

9898
public:
99+
// This maps the cowns of this behavior to the previous behavior this
100+
// is waiting on. This is used to draw the dependencies, it is not used
101+
// for sceduling.
102+
// Both of these pointers are weak reference.
103+
std::map<objects::DynObject*, Behavior*> cown_deps;
104+
99105
Status status;
100106
// The cowns as they were passed in to the cown. These have to be provided
101107
// to the new Interpreter to populate the frame

src/rt/core.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -361,10 +361,9 @@ namespace rt::core
361361

362362
// TODO: This should really be split into `get_name()` just getting the name
363363
// and `get_info()` or the additional info text like lrc and status
364-
std::string get_name() override
364+
std::optional<std::string> get_additional_info() override
365365
{
366366
std::stringstream ss;
367-
ss << this->name << std::endl;
368367
ss << "status=" << to_string(status);
369368
return ss.str();
370369
}

src/rt/core/behavior.cc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@ namespace rt::core
8585
return rt::try_get_bytecode(this->code).value();
8686
}
8787

88+
// FIXME: Currently both the scheduler and the behavior has a function
89+
// to complete a behavior. All of this should really be in one place. It
90+
// might be better to move all of this into the scheduler.
8891
void Behavior::complete()
8992
{
9093
this->status = Status::Done;
@@ -98,6 +101,14 @@ namespace rt::core
98101
}
99102
this->cowns.clear();
100103

104+
for (auto [cown, waiting_on] : cown_deps)
105+
{
106+
if (waiting_on == this)
107+
{
108+
cown_deps.erase(cown);
109+
}
110+
}
111+
101112
this->s_running_behaviors.erase(this->id);
102113
}
103114
} // namespace rt::core

src/rt/objects/dyn_object.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,12 @@ namespace rt::objects
137137
return name;
138138
}
139139

140+
// TODO make more types use this instead of `get_name()`
141+
virtual std::optional<std::string> get_additional_info()
142+
{
143+
return std::nullopt;
144+
}
145+
140146
/// TODO remove virtual once we have primitive functions.
141147
virtual DynObject* is_primitive()
142148
{

src/rt/ui/mermaid.cc

Lines changed: 17 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -201,15 +201,7 @@ namespace rt::ui
201201

202202
void draw_behavior(core::behavior_ptr behavior)
203203
{
204-
out << "subgraph " << behavior->id_str() << "[\" \"]" << std::endl;
205204
draw_behavior_info(behavior.get());
206-
207-
for (auto [_, c] : behavior->ordered_cown)
208-
{
209-
this->draw_cown(c, behavior);
210-
}
211-
out << "end" << std::endl;
212-
213205
// Set background color
214206
auto background = ERROR_NODE_COLOR;
215207
switch (behavior->status)
@@ -224,31 +216,23 @@ namespace rt::ui
224216
background = BEHAVIOR_PENDING_COLOR;
225217
break;
226218
}
227-
out << "style " << behavior->id_str() << " fill:" << background
228-
<< std::endl;
229-
}
230-
231-
void draw_dependencies(core::behavior_ptr behavior)
232-
{
233-
for (auto [_, cown_obj] : behavior->ordered_cown)
234-
{
235-
assert(cown_obj->get_prototype() == core::cownPrototypeObject());
236-
core::CownObject* cown = reinterpret_cast<core::CownObject*>(cown_obj);
237-
auto cown_id = cown->get_id();
238-
239-
// Draw dependencies
240-
for (auto succ : behavior->succ)
241-
{
242-
if (succ->ordered_cown.contains(cown_id))
243-
{
244-
out << " ";
245-
out << cown_node_id(cown, succ->id);
246-
out << " --> ";
247-
out << cown_node_id(cown, behavior->id);
248-
out << std::endl;
249-
edge_counter += 1;
250-
}
251-
}
219+
out << "style " << this->behavior_node_name(behavior.get())
220+
<< " fill:" << background << std::endl;
221+
222+
for (auto [cown, pred] : behavior->cown_deps)
223+
{
224+
out << " ";
225+
out << this->behavior_node_name(behavior.get());
226+
out << " --> |";
227+
// TODO: This really shouldn't directly access the name. get_name()
228+
// should always just return the name and then there is a
229+
// `more_info()` method that provides additional info like
230+
// the cown status or LRC for regions etc.
231+
out << escape(cown->get_name());
232+
out << "| ";
233+
out << this->behavior_node_name(pred);
234+
out << std::endl;
235+
edge_counter += 1;
252236
}
253237
}
254238

@@ -290,15 +274,6 @@ namespace rt::ui
290274
this->draw_behavior(behavior);
291275
}
292276

293-
for (auto& [bid, behavior] : behaviors)
294-
{
295-
this->draw_dependencies(behavior);
296-
}
297-
298-
// TODO:
299-
// -> Show running behavior?
300-
// -> Cown colors
301-
302277
// Footer
303278
this->draw_footer();
304279
}

0 commit comments

Comments
 (0)