Difference between revisions of "Environment diagram"

From CS 61A Wiki
Jump to: navigation, search
[checked revision][checked revision]
m ({{Sufficient-class}})
(Added environment navbox)
 
(6 intermediate revisions by 4 users not shown)
Line 1: Line 1:
 
{{Sufficient-class}}
 
{{Sufficient-class}}
An '''environment diagram''' is a visualization of the [[frame]]s of a program and all the existing bindings.
+
An '''environment diagram''' is a tool to show the state of a program after the execution of a certain number of lines. More precisely, it is a visualization of the [[frame]]s created by running a program, along with the bindings of each frame.
 +
 
 +
== Structure ==
 +
Environment diagrams are divided into two columns: on the left side is the ''stack frame'' (where all frames are) and on the right side, the ''heap'' (where all objects are).
 +
 
 +
=== Stack ===
 +
The stack frame is a group of frames. When a function is called, a new frame is created and placed on top of all the other frames. When that function terminates, the frame is removed.
 +
 
 +
Every local frame (i.e., not global) should have a frame number, a parent label, and a return value that will be filled out when the function terminates. Then, within the frame, names go on the left hand side, and the associated values go on the right hand side. Values can be primitives or object references (arrows pointing to an object in the heap).
 +
 
 +
=== Heap ===
 +
The heap holds objects. Most commonly, these will be function objects, [[tuple]]s, and [[list]]s.
 +
* function objects are labeled as <code>func name(params) [parent=f]</code>, where <code>f</code> is the parent frame
 +
* tuples and lists are drawn as boxes for each element, labeled by its index
  
 
== Rules ==
 
== Rules ==
* [http://inst.eecs.berkeley.edu/~cs61a/sp14/pdfs/environment-diagrams.pdf Official guide]
+
* [http://www.ocf.berkeley.edu/~shidi/cs61a/guerrilla/env.txt Official rules]
 +
* [http://inst.eecs.berkeley.edu/~cs61a/sp14/pdfs/environment-diagrams.pdf Step-by-step guide]
 
* [http://albertwu.org/cs61a/notes/environments Albert's guide]
 
* [http://albertwu.org/cs61a/notes/environments Albert's guide]
 
* [http://markmiyashita.com/cs61a/environment_diagrams/rules_of_environment_diagrams/ Mark's guide]
 
* [http://markmiyashita.com/cs61a/environment_diagrams/rules_of_environment_diagrams/ Mark's guide]
 
* [http://www.michellerubyhwang.com/handouts/sp14/EnvDiagramSp14.pdf Michelle's guide]
 
* [http://www.michellerubyhwang.com/handouts/sp14/EnvDiagramSp14.pdf Michelle's guide]
* [http://inst.eecs.berkeley.edu/~cs61a-tz/guerrilla/env.txt Andrew's guide]
 
  
 
== Sources ==
 
== Sources ==
Line 13: Line 26:
  
 
== External links ==
 
== External links ==
* [http://pythontutor.com/visualize.html#mode=edit Python Tutor]
+
* [http://pythontutor.com/composingprograms.html#mode=edit Python Tutor] (environment diagram drawer)
 +
 
 +
{{Environment}}

Latest revision as of 11:33, 9 July 2014

An environment diagram is a tool to show the state of a program after the execution of a certain number of lines. More precisely, it is a visualization of the frames created by running a program, along with the bindings of each frame.

Structure

Environment diagrams are divided into two columns: on the left side is the stack frame (where all frames are) and on the right side, the heap (where all objects are).

Stack

The stack frame is a group of frames. When a function is called, a new frame is created and placed on top of all the other frames. When that function terminates, the frame is removed.

Every local frame (i.e., not global) should have a frame number, a parent label, and a return value that will be filled out when the function terminates. Then, within the frame, names go on the left hand side, and the associated values go on the right hand side. Values can be primitives or object references (arrows pointing to an object in the heap).

Heap

The heap holds objects. Most commonly, these will be function objects, tuples, and lists.

  • function objects are labeled as func name(params) [parent=f], where f is the parent frame
  • tuples and lists are drawn as boxes for each element, labeled by its index

Rules

Sources

External links