// File: Stack.java
// Time-stamp: "2005-01-09 11:23:18 calvanese"
// Purpose: illustrate the evolution of the stack of activation records

/*
This program is used to illustrate the evolution of the stack of activation
records when methods are executed.  To do so, we execute the program in
debugging modality, i.e., one statement at a time.

To execute the program in debugging modality in BlueJ, proceed as follows:

- Set a breakpoint on the first line of the main method.
- Execute the main method.
- A debugging window will be opened.
- Use the "Step Into" button to execute the program one statement at a time.

  In the "Call Sequence" subwindow of the debugging window you can see the
  method calls that are still active.
  In the "Local variables" subwindow you can see the local variables and the
  formal parameters (i.e., the most interesting part of the activation record)
  of the method that is highlighted in the "Call sequence" window.  You can
  click on the different method activations in the "Call sequence" window to
  see how the local variables of the different activations have different
  values.
*/

import javax.swing.JOptionPane;

public class Stack {

  public static int B(int pb) {
    /* b0 */ System.out.println("In B. Parameter pb = " + pb);
    /* b1 */ return pb+1;
  }

  public static int A(int pa) {
    /* a0 */ System.out.println("In A. Parameter pa = " + pa);
    /* a1 */ System.out.println("Call of B(" + (pa * 2) + ").");
    /* a2 */ int va = B(pa * 2);
    /* a3 */ System.out.println("Again in A. va = " + va);
    /* a4 */ return va + pa;
  }

  public static void main(String[] args) {
    /* m0 */ System.out.println("In main.");
    /* m1 */ int vm = 22;
    /* m2 */ System.out.println("Call of A(" + vm + ").");
    /* m3 */ vm = A(vm);
    /* m4 */ System.out.println("Again in main. vm = " + vm);
    /* m5 */ return;
  }
}


/* Produced output:

In main.
Call of A(22).
In A. Parameter pa = 22
Call of B(44).
In B. Parameter pb = 44
Again in A. va = 45
Again in main. vm = 67

*/
