Skip to content

Commit

Permalink
Mermaid: Make mermaid aware of cowns
Browse files Browse the repository at this point in the history
  • Loading branch information
xFrednet committed Oct 19, 2024
1 parent b69a27f commit e7b2d80
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 25 deletions.
13 changes: 7 additions & 6 deletions src/rt/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -198,12 +198,8 @@ namespace rt::core
//
// FIXME: Also check that the region has a LRC == 1, with 1
// being the reference passed into this constructor
this->set("region", region);
}

bool is_aquired()
{
return aquired;
auto old = this->set("region", region);
assert(old == nullptr);
}

std::string get_name()
Expand All @@ -220,6 +216,11 @@ namespace rt::core
{
return true;
}

bool is_cown_aquired() override
{
return aquired;
}
};

inline std::set<objects::DynObject*>* globals()
Expand Down
8 changes: 8 additions & 0 deletions src/rt/objects/dyn_object.h
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,14 @@ namespace rt::objects
{
return false;
}
virtual bool is_cown_aquired()
{
assert(false && "should only be called on cowns");
}
bool is_opaque()
{
return this->is_cown() && !this->is_cown_aquired();
}

[[nodiscard]] DynObject* get(std::string name)
{
Expand Down
21 changes: 6 additions & 15 deletions src/rt/rt.cc
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,9 @@ namespace rt

objects::DynObject* get(objects::DynObject* obj, std::string key)
{
if (obj->get_prototype() == core::cownPrototypeObject())
if (obj->is_opaque())
{
core::CownObject* cown = reinterpret_cast<core::CownObject*>(obj);
if (!cown->is_aquired())
{
ui::error(
"the cown needs to be aquired, before its data can be accessed");
}
ui::error("opaque objects can't be accessed");
}
return obj->get(key);
}
Expand All @@ -88,15 +83,11 @@ namespace rt
objects::DynObject*
set(objects::DynObject* obj, std::string key, objects::DynObject* value)
{
if (obj->get_prototype() == core::cownPrototypeObject())
if (obj->is_opaque())
{
core::CownObject* cown = reinterpret_cast<core::CownObject*>(obj);
if (!cown->is_aquired())
{
// Overwriting data can change the RC and then call destructors of the
// type this action therefore requires the cown to be aquired
ui::error("the cown needs to be aquired, before its data can modified");
}
// Overwriting data can change the RC and then call destructors of the
// type this action therefore requires the cown to be aquired
ui::error("opaque objects can't be modified");
}

return obj->set(key, value);
Expand Down
22 changes: 18 additions & 4 deletions src/rt/ui/mermaid.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@
namespace rt::ui
{

struct MermaidDecoration
{
const char* start;
const char* end;
const char* out;
};
const inline auto NORMAL = MermaidDecoration{"[", "]", "-->"};
const inline auto COWN = MermaidDecoration{"[[", "]]", "-.->"};

void replace(std::string& text, std::string from, std::string replace)
{
size_t pos = 0;
Expand Down Expand Up @@ -64,9 +73,13 @@ namespace rt::ui
{
return false;
}
auto src_deco = ((src && src->is_cown()) ? &COWN : &NORMAL);
auto dst_deco = ((dst && dst->is_cown()) ? &COWN : &NORMAL);

if (src != nullptr)
{
out << " id" << visited[src] << " -->|" << escape(key) << "| ";
out << " id" << visited[src] << " " << src_deco->out << "|"
<< escape(key) << "| ";
}
if (visited.find(dst) != visited.end())
{
Expand All @@ -75,11 +88,12 @@ namespace rt::ui
}
auto curr_id = id++;
visited[dst] = curr_id;
out << "id" << curr_id << "[ ";
out << "id" << curr_id << dst_deco->start << " ";
out << escape(dst->get_name());
out << "<br/>rc=" << dst->rc;

out << " ]" << (unreachable ? ":::unreachable" : "") << std::endl;
out << " " << dst_deco->end << (unreachable ? ":::unreachable" : "")
<< std::endl;

auto region = objects::DynObject::get_region(dst);
if (region != nullptr)
Expand Down Expand Up @@ -169,7 +183,7 @@ namespace rt::ui
out << "class id" << visited[dst] << " tainted;" << std::endl;
tainted.insert(dst);

return true;
return dst->is_opaque();
};

for (auto root : *taint)
Expand Down

0 comments on commit e7b2d80

Please sign in to comment.