Skip to content

Commit

Permalink
Add basic state graph rendering support
Browse files Browse the repository at this point in the history
  • Loading branch information
uhbif19 committed Apr 18, 2024
1 parent 8cca2ea commit ad2da00
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 0 deletions.
1 change: 1 addition & 0 deletions cem-script.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ library
hs-source-dirs: src/
exposed-modules:
Cardano.CEM
Cardano.CEM.Documentaiton
Cardano.CEM.Examples.Auction
Cardano.CEM.Examples.Compilation
Cardano.CEM.Examples.Voting
Expand Down
32 changes: 32 additions & 0 deletions docs/catalyst_milestone_reports.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Milestone 3

## Summary

Changes:

* Running in emulated environment by CLB
* Rendering CEMScript state graphs

## State graph examples

```graphviz
digraph Creator {
rankdir=LR;
node [shape="dot",fontsize=14,fixedsize=true,width=1.5];
edge [fontsize=11];"Void In" [color="orange"];"Void Out" [color="orange"];"Void In" -> NotStarted [label="Create (stage Open)"];
NotStarted -> CurrentBid [label="Start (stage Open)"];
CurrentBid -> CurrentBid [label="MakeBid (stage Open)"];
CurrentBid -> Winner [label="Close (stage Closed)"];
Winner -> "Void Out" [label="Buyout (stage Closed)"];
}
```

```graphviz
digraph Creator {
rankdir=LR;
node [shape="dot",fontsize=14,fixedsize=true,width=1.5];
edge [fontsize=11];"Void In" [color="orange"];"Void Out" [color="orange"];"Void In" -> Spawning [label="Create (stage Always)"];
Spawning -> Spawning [label="Spawn (stage Always)"];
Spawning -> "Void Out" [label="Finalize (stage Always)"];
}
```
44 changes: 44 additions & 0 deletions src/Cardano/CEM/Documentation.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
module Cardano.CEM.Documentation where

import Prelude

import Data.Map qualified as Map
import Data.Proxy

import Cardano.CEM
import Data.List (stripPrefix)

dotStyling =
"rankdir=LR;\n"
<> "node [shape=\"dot\",fontsize=14,fixedsize=true,width=1.5];\n"
<> "edge [fontsize=11];"
<> "\"Void In\" [color=\"orange\"];"
<> "\"Void Out\" [color=\"orange\"];"

cemDotGraphString :: (CEMScript script) => String -> Proxy script -> String
cemDotGraphString name proxy =
"digraph "
<> name
<> " {\n"
<> dotStyling
<> edges
<> "}"
where
showSpine :: (Show s) => s -> String
showSpine = stripSpineSuffix . show
stripSpineSuffix = reverse . drop 5 . reverse
edges =
foldMap id $
[ ( maybe "\"Void In\"" showSpine from
<> " -> "
<> (maybe "\"Void Out\"" showSpine to)
<> " [label=\""
<> showSpine transition
<> " (stage "
<> show stage
<> ")"
<> "\"]; \n"
)
| (transition, (stage, from, to)) <-
Map.assocs $ transitionStage proxy
]

0 comments on commit ad2da00

Please sign in to comment.