This site is version 0.0.1. Most of the code on this site is drafted by an agent and needs review. I apologize for the AI-speak, we are working on rewriting it!
viv-lang.org

Notebooks · lib/graphdraw

The whole program as a graph, drawn by Viv

draw_program(g, title) draws a ProgramGraph (lib/proggraph.viv) with the figure records of a diagram: every def that matters to the run as a box, the steps inside it as boxes in the order they run, the loops that hold steps as dashed boxes around them, the calls between defs as arrows from the step that makes each call, and the values steps hand each other as arrows labeled with the variables. A value that reaches the next pass of a loop is a dashed arrow back up.

Which defs are drawn: <main>, every def with steps that the run can reach, and every def on a call path from <main> to one of them. When no def has steps, every def the run reaches (up to MAX_PLAIN_DEFS). The defs these call and that are not drawn are named at the foot of their caller's box.

The layout is lib/graphlayout.viv, twice: inside each box its children, top to bottom; then the boxes of the defs, left to right, callers before callees. Each box's id is its node's id (hf_scf, hf_scf/fock), so a page can find the box of the def or step a reader is at.

draw_view(g, v, title) draws what a GraphView says: which defs are boxes, how many callees each one hides (written +3 at the right of its header, for a page to open) or whether its callees are open (−), how many times each call ran (written on its arrow when more than once), and where the boxes of an earlier drawing were, so a redrawing after a box is opened moves the others as little as it can. draw_program is draw_view with the defs chosen above and nothing hidden, counted or remembered.

Every mark has an id a page can act on: a box is its node's id; an arrow is call:<step or def>-><def>, data:<step>-><step>, next:<step>-><step> (a value for the next pass) or then:<step>-><step> (the order of two steps); the text of a node is <id>#head, #text, #reads, #foot, its marks #more and #less; an arrow's text is <arrow id>#vars or #count. The figure's x label says which way the defs run, across or down, so a page that asks for a redrawing can keep it.

draw_view_mp(g, v, mp, title) also draws a program's multi-paths: a stage with several implementations of one intent, cross-checked against each other. Open, a multi-path is a fork (a diamond named after the stage), one path per implementation, and a join (a diamond with the agreement they are held to); the call into the fork carries the stage's intent, the default's path is solid and the others are dashed. Closed, it is one box, multi-path ×n, with the intent, the contract and how many implementations are independent and were seen agreeing. An implementation that is a drawn function is its own box on its path. The marks: the closed box is mp:<stage>@<host>; open, mp:<stage>@<host>/fork, /join, /m:<name>, and the arrows mp:<stage>@<host>/in, /to:<name>, /from:<name>.

Used with import graphdraw.

Look inside this program

  • Atlas

    The program’s map: every function and which calls which.

  • There’s no recorded run of this program yet.

This program declares a record type (GraphView), and records run only in compiled C for now, so the Run buttons here are off. Open it in the workbench and use its C tab to compile it.

Shift+Enter in a cell runs it and moves to the next. Running a cell runs every cell above it too, as one program.

[1]lines 54–1340