Skip to content
Robbie Gleichman edited this page Jan 25, 2018 · 2 revisions

The page provides a brief overview of the current code architecture of Glance, and provides some suggestions of where to start looking around in the code.

Architecture

Currently the Glance executable produces a 2D SVG image when given a textual Haskell source file.

The high level pipeline is that the Haskell source file is parsed by a library (haskell-src-exts) which returns a syntax tree for each function. The syntax tree is then translated into a syntax graph, and the syntax graph is then rendered into an image.

The syntax graph is a graphical representation of the Haskell syntax. The nodes of the syntax graph are the basic elements of Haskell syntax such as function composition, case expressions (pattern matching), and guards (if and else if). The edges in the syntax graph represent variables and expression results. For example, If two things are connected by edges in the syntax graph, then when the function is called, those two things will have the same value.

Once the syntax graph for a function is created, the syntax graph is rendered into a 2d image. First, a visual icon is drawn for each node in the syntax graph. The syntax graph is then given to GraphViz (a graph layout library), which returns an X,Y position for each node. The icons are then placed at the positions determined by GraphViz, and then rotated to optimize where the edges will connect. Once the icons have been rotated, the edges of the syntax graph are drawn as lines between the icons.

This process is done for all of the functions in a file, and the images for all of the functions are combined into one image.

Files

/app/Translate.hs translates the syntax tree into the syntax graph.
app/TranslateCore.hs has helper functions for Translate.hs
app/Rendering.hs renders the syntax graph into an image

The main types are defined in app/Types.hs:
The you can think of the types SyntaxNode and Icon as the nodes in the syntax graph. The type Edge is used for the edges in the syntax graph.

Clone this wiki locally