Skip to main content

Memory model diagrams

This package generates memory model diagrams for Python code in the style of CSC110/111/148 at the University of Toronto. This uses the Rough.js Javascript library to emulate the look of hand-drawn diagrams.

Note: this project is currently experimental, and may undergo significant changes before stabilizing.

Installation

You can install the memory-viz package from GitHub (it is currently not on npm):

$ npm install git+https://github.com/david-yz-liu/memory-viz.git

Example

Here's an example of using this package in a Javascript file executed by NodeJS.

// simple_demo.js
const { draw } = require("memory_viz");

const objects = [
{
type: ".frame",
name: "__main__",
id: null,
value: { lst1: 82, lst2: 84, p: 99, d: 10, t: 11 },
},
{
type: "str",
id: 19,
value: "David is cool!",
style: ["highlight"],
},
{ type: "int", id: 13, value: 7 },
];

const m = draw(objects, true, { width: 1300 });

m.save("simple_demo.svg");

Running $ node simple_demo.js produces the following file:

Diagram generated for simple_demo.js file.