Question: 6. Translation and Stack Level. Consider the expression e if x > 1 then x else let z = x + y in z +

6. Translation and Stack Level. Consider the expression e if x > 1 then x else let z = x + y in z + z Compute codeV e sl for an address environment = {x (L, 1), y (L,1)} and stack level sl = 3. Determine, similarly as in the examples in the text, the current stack level for each instruction.

7. Translation of Functions. Consider the expression: e fun x y if x = 1 then y else fac (x 1) (x y) Compute codeV e sl for the address environment = {fac (L, 1)} and stack level sl = 5.

8. Addressing of Variables. Introduce a new register SP0 relative to which local variables can be addressed. For this, introduce a new instruction for accessing local variables and modify the MAMA code generation so that this new register is managed correctly.

9. Functions With Local Variables. Consider the function definition: fun x, y, z let x = 1 in let a = 3 in let b = 4 in (a + (b + (x + (y + z))))

Compute the addresses of the variables a, b, x, y, and z relative to SP0 (the stack pointer when entering the function body). Compute the address environment that is used for the code generation of (a + (b + (x + (y + z)))). Generate call-by-value code for the function definition. Give the current stack level for each instruction. The starting stack level is assumed to be sl = 3.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!