Skip to content

Commit 7c9f091

Browse files
committed
Merge mermaid diagrams and other cahos
1 parent 5fe108b commit 7c9f091

File tree

8 files changed

+97
-170
lines changed

8 files changed

+97
-170
lines changed

src/lang/interpreter.cc

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -501,14 +501,6 @@ namespace verona::interpreter
501501
rt::core::behavior_ptr behavior_)
502502
: ui(ui_), behavior(behavior_)
503503
{
504-
// FIXME: Oh no, we need to set the local region before running this but
505-
// the interpreter would then need to know about behaviors right?
506-
// Maybe not? What if the scheduler sets the behavior before doing this?
507-
// That could work, I don't like it but it could
508-
//
509-
// Looking at this, I believe it would be better to let the interpreter
510-
// know about behaviors
511-
512504
// There is a question where the active behavior should be set.
513505
//
514506
// Python mixes the runtime and interpreter a bit more. There the runtime
@@ -631,6 +623,21 @@ namespace verona::interpreter
631623
rt::post_run(initial, ui);
632624
}
633625

626+
Scheduler::Scheduler()
627+
{
628+
auto ui = rt::ui::globalUI();
629+
assert(ui->is_mermaid());
630+
reinterpret_cast<rt::ui::MermaidUI*>(ui)->scheduler_ready_list =
631+
&this->ready;
632+
}
633+
634+
Scheduler::~Scheduler()
635+
{
636+
auto ui = rt::ui::globalUI();
637+
assert(ui->is_mermaid());
638+
reinterpret_cast<rt::ui::MermaidUI*>(ui)->scheduler_ready_list = nullptr;
639+
}
640+
634641
void Scheduler::add(rt::core::behavior_ptr behavior)
635642
{
636643
assert(behavior->status == rt::core::Behavior::Status::New);
@@ -751,10 +758,13 @@ namespace verona::interpreter
751758
this->next_schedule_msg.reset();
752759
}
753760

761+
// FIXME: We should really get wrid of the UI* abstraction. There is no way
762+
// that we'll ever change the output at this point and it just makes several
763+
// things harder, like this:
754764
auto ui = rt::ui::globalUI();
755765
assert(ui->is_mermaid());
756766
auto mermaid = reinterpret_cast<rt::ui::MermaidUI*>(ui);
757-
mermaid->draw_schedule(this->ready, message);
767+
mermaid->output(message);
758768
mermaid->close_file();
759769
}
760770

src/lang/interpreter.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,6 @@ namespace rt::objects
1414
class DynObject;
1515
} // namespace rt::objects
1616

17-
namespace rt::ui
18-
{
19-
class ScheduleDiagram;
20-
}
21-
2217
namespace verona::interpreter
2318
{
2419
class Interpreter;
@@ -76,6 +71,9 @@ namespace verona::interpreter
7671
Interpreter* current_int;
7772

7873
public:
74+
Scheduler();
75+
~Scheduler();
76+
7977
void add(rt::core::behavior_ptr behavior);
8078

8179
void start(Bytecode* main);

src/rt/behavior.h

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ namespace rt::objects
2020
namespace rt::ui
2121
{
2222
class MermaidUI;
23-
class ScheduleDiagram;
2423
class ObjectGraphDiagram;
2524
}
2625

@@ -30,7 +29,6 @@ namespace rt::core
3029
class Behavior
3130
{
3231
friend class rt::ui::MermaidUI;
33-
friend class rt::ui::ScheduleDiagram;
3432
friend class rt::ui::ObjectGraphDiagram;
3533

3634
public:
@@ -66,16 +64,6 @@ namespace rt::core
6664
static std::shared_ptr<Behavior> get_active_behavior();
6765

6866
private:
69-
// This map is a collection of all behaviors that have started running and
70-
// therefore also have a local region. This is needed here for the lovely
71-
// mermaid output. This uses an ordered map in the hope that the diagram
72-
// will keep the same layout every iteration.
73-
//
74-
// It uses behavior pointers since it's being updated from inside methods
75-
// where `this` is a pointer and not a `shared_ptr`. This should be fine
76-
// since each behavior should call `complete()` before being freed thereby
77-
// also updating this list.
78-
static std::map<int, Behavior*> s_running_behaviors;
7967
static std::shared_ptr<Behavior> s_active_behavior;
8068

8169
private:

src/rt/core/behavior.cc

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ namespace rt::objects
1414
namespace rt::core
1515
{
1616
int Behavior::s_behavior_counter = 0;
17-
std::map<int, Behavior*> Behavior::s_running_behaviors = {};
1817
std::shared_ptr<Behavior> Behavior::s_active_behavior = nullptr;
1918

2019
void Behavior::set_active_behavior(std::shared_ptr<Behavior> active)
@@ -79,9 +78,6 @@ namespace rt::core
7978

8079
this->local_region = objects::Region::new_local_region();
8180

82-
// Add self to running behaviors to have it also drawn as a local region.
83-
s_running_behaviors[this->id] = this;
84-
8581
return rt::try_get_bytecode(this->code).value();
8682
}
8783

@@ -108,7 +104,5 @@ namespace rt::core
108104
cown_deps.erase(cown);
109105
}
110106
}
111-
112-
this->s_running_behaviors.erase(this->id);
113107
}
114108
} // namespace rt::core

src/rt/rt.cc

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -251,13 +251,8 @@ namespace rt
251251
std::cout << "Final count: " << objects::DynObject::get_count()
252252
<< std::endl;
253253

254-
std::vector<objects::DynObject*> roots;
255-
for (auto obj : objects::DynObject::get_objects())
256-
{
257-
roots.push_back(obj);
258-
}
259254
ui::MermaidUI::highlight_unreachable = true;
260-
ui->output(roots, "Memory leak detected!");
255+
ui->output("Memory leak detected!");
261256

262257
std::exit(1);
263258
}

src/rt/ui.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ namespace rt::core
4141
namespace rt::ui
4242
{
4343
class MermaidDiagram;
44-
class ScheduleDiagram;
4544
class ObjectGraphDiagram;
4645

4746
class MermaidUI : public UI
@@ -50,9 +49,13 @@ namespace rt::ui
5049
static inline bool pragma_draw_regions_nested = true;
5150
static inline bool highlight_unreachable = false;
5251

52+
// This feels really wrong, but is the easiest fix rn. The list should
53+
// probably always be passed in to the `output()` call but that would
54+
// require more refactorings
55+
std::vector<rt::core::behavior_ptr>* scheduler_ready_list;
56+
5357
private:
5458
friend class ObjectGraphDiagram;
55-
friend class ScheduleDiagram;
5659
friend class MermaidDiagram;
5760
friend void core::mermaid_builtins(ui::UI* ui);
5861

@@ -104,9 +107,6 @@ namespace rt::ui
104107
std::vector<objects::DynObject*>& roots, std::string message) override;
105108
void output(std::string message) override;
106109

107-
void draw_schedule(
108-
std::vector<core::behavior_ptr> behaviors, std::string message);
109-
110110
void highlight(
111111
std::string message,
112112
std::vector<objects::DynObject*>& highlight) override;

0 commit comments

Comments
 (0)