Question: 2. This question is about code generation. The first two parts make reference to the following program fragment in a Java-like language: class MyInt {

2. This question is about code generation. The first two parts make reference to the following program fragment in a Java-like language: class MyInt { private int n; public MyInt (int j) { n=j; } public int f (int x) { n=n+1; return n*x; } public MyInt g (int x) { int j = x+n; MyInt r = new MyInt(i); return r; } } (a) Consider an invocation of the form a.g(z) for variables a (of type My Int) and z (of type int). Describe the locations in memory of the variables x, j, n, and r making reference to the stack, activation frame, symbol table, or heap as appropriate), and explain the reason for your answer. i. Briefly describe the location of the variable x, and the reason for this. [4 marks) ii. Describe the location of the variable j. Does it have any simple relationship to the location of x? Briefly explain your answer. [8 marks] iii. Describe the location of the variable n. Does it have any simple relationship to the location of x or j? Briefly explain your answer. [8 marks] iv. Describe the location of the object r. Does it have any simple relationship to the location of x, j, or n? Briefly explain your answer. [8 marks)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
