From 1d3069762b4908606be7f15107e8835c1464bf35 Mon Sep 17 00:00:00 2001 From: xFrednet Date: Fri, 1 Nov 2024 14:07:42 +0100 Subject: [PATCH] Mermaid: Mark immutable nodes by color and hide the immutable region --- docs/builtin.md | 14 +++++++++++--- src/rt/core/builtin.cc | 13 +++++++++++++ src/rt/objects/region.cc | 1 - src/rt/ui.h | 1 + src/rt/ui/mermaid.cc | 27 ++++++++++++++++++++++----- 5 files changed, 47 insertions(+), 9 deletions(-) diff --git a/docs/builtin.md b/docs/builtin.md index 2dfdce6..03395c5 100644 --- a/docs/builtin.md +++ b/docs/builtin.md @@ -12,7 +12,7 @@ Aborts the interpreter process. It's intended to indicate that an execution bran ## Constructors -#### `region()` +#### `Region()` Creates a new region object. @@ -74,7 +74,15 @@ This explicitly shows the "Cown region" in the generated diagrams. #### `mermaid_hide_cown_region()` -This hides the "Cown region" and cown prototype in diagram. (This is the default) +This hides the "Cown region" and cown prototype in diagram. (Default) + +#### `mermaid_show_immutable_region()` + +This explicitly shows the "Immutable region" in the generated diagrams + +#### `mermaid_hide_immutable_region()` + +This hides the "Immutable region" in diagram. (Default) #### `mermaid_show_functions()` @@ -82,4 +90,4 @@ Shows user defined functions in the diagram. #### `mermaid_hide_functions()` -Hides user defined functions in the diagram. (This is the default) +Hides user defined functions in the diagram. (Default) diff --git a/src/rt/core/builtin.cc b/src/rt/core/builtin.cc index 3656029..af0e478 100644 --- a/src/rt/core/builtin.cc +++ b/src/rt/core/builtin.cc @@ -124,6 +124,19 @@ namespace rt::core return std::nullopt; }); + add_builtin( + "mermaid_show_immutable_region", [mermaid](auto, auto, auto args) { + assert(args == 0); + mermaid->draw_immutable_region = true; + return std::nullopt; + }); + add_builtin( + "mermaid_hide_immutable_region", [mermaid](auto, auto, auto args) { + assert(args == 0); + mermaid->draw_immutable_region = false; + return std::nullopt; + }); + add_builtin("mermaid_show_functions", [mermaid](auto, auto, auto args) { assert(args == 0); mermaid->show_functions(); diff --git a/src/rt/objects/region.cc b/src/rt/objects/region.cc index 459f0ca..68bee31 100644 --- a/src/rt/objects/region.cc +++ b/src/rt/objects/region.cc @@ -266,5 +266,4 @@ namespace rt::objects } } } - } diff --git a/src/rt/ui.h b/src/rt/ui.h index 816e02e..7e86a91 100644 --- a/src/rt/ui.h +++ b/src/rt/ui.h @@ -57,6 +57,7 @@ namespace rt::ui std::set taint; /// Indicates if the cown region show be explicitly drawn bool draw_cown_region; + bool draw_immutable_region; /// Indicates if local functions should be visible bool draw_funcs; diff --git a/src/rt/ui/mermaid.cc b/src/rt/ui/mermaid.cc index 459b1f0..aedd914 100644 --- a/src/rt/ui/mermaid.cc +++ b/src/rt/ui/mermaid.cc @@ -17,7 +17,8 @@ namespace rt::ui const char* UNREACHABLE_NODE_COLOR = "red"; const char* ERROR_NODE_COLOR = "red"; - const char* IMMUTABLE_REGION_COLOR = "#32445d"; + const char* IMMUTABLE_NODE_COLOR = "#243042"; + const char* IMMUTABLE_REGION_COLOR = "#485464"; const char* IMMUTABLE_EDGE_COLOR = "#94f7ff"; const char* LOCAL_REGION_ID = "LocalReg"; @@ -96,6 +97,7 @@ namespace rt::ui out << "%%{init: {'themeVariables': { 'fontSize': '" << FONT_SIZE << "' }}}%%"; out << "graph TD" << std::endl; + out << " id0(None):::immutable" << std::endl; draw_nodes(roots); draw_regions(); @@ -103,13 +105,12 @@ namespace rt::ui draw_error(); draw_info(); - out << "style " << IMM_REGION_ID << " fill:" << IMMUTABLE_REGION_COLOR - << std::endl; out << "classDef unreachable stroke-width:2px,stroke:" << UNREACHABLE_NODE_COLOR << std::endl; out << "classDef error stroke-width:4px,stroke:" << ERROR_NODE_COLOR << std::endl; out << "classDef tainted fill:" << TAINT_NODE_COLOR << std::endl; + out << "classDef immutable fill:" << IMMUTABLE_NODE_COLOR << std::endl; // Footer (end of mermaid graph) out << "```" << std::endl; } @@ -127,6 +128,12 @@ namespace rt::ui return {"[\\", "/]"}; } + if (obj->is_immutable()) + { + // Make sure to also update the None node, when editing these + return {"(", ")"}; + } + return {"[", "]"}; } @@ -181,6 +188,7 @@ namespace rt::ui // Footer out << markers.second; out << (reachable ? "" : ":::unreachable"); + out << (dst->is_immutable() ? ":::immutable" : ""); out << std::endl; result = node; @@ -266,7 +274,10 @@ namespace rt::ui // Output all the region membership information for (auto [region, objects] : region_strings) { - if ((!info->draw_cown_region) && region == objects::cown_region) + if ( + ((!info->draw_cown_region) && region == objects::cown_region) || + ((!info->draw_immutable_region) && + region == objects::immutable_region)) { continue; } @@ -280,7 +291,7 @@ namespace rt::ui else if (region == objects::immutable_region) { out << IMM_REGION_ID << "[\"Immutable region\"]" << std::endl; - out << " id0[nullptr]" << std::endl; + out << " id0" << std::endl; } else if (region == objects::cown_region) { @@ -299,6 +310,12 @@ namespace rt::ui } out << "end" << std::endl; } + + if (info->draw_immutable_region) + { + out << "style " << IMM_REGION_ID << " fill:" << IMMUTABLE_REGION_COLOR + << std::endl; + } } void draw_taint()