6. Translation and Stack Level. Consider the expression e if x > 1 then x else let z = x+y inz+z Compute codey e p sl fo

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

6. Translation and Stack Level. Consider the expression e if x > 1 then x else let z = x+y inz+z Compute codey e p sl fo

Post by answerhappygod »

6 Translation And Stack Level Consider The Expression E If X 1 Then X Else Let Z X Y Inz Z Compute Codey E P Sl Fo 1
6 Translation And Stack Level Consider The Expression E If X 1 Then X Else Let Z X Y Inz Z Compute Codey E P Sl Fo 1 (57.09 KiB) Viewed 61 times
Wilhelm, R., Seidl, H. (2010). Compiler Design:virtual machines. page 99. Questions 6 - 9
6. Translation and Stack Level. Consider the expression e if x > 1 then x else let z = x+y inz+z Compute codey e p sl for an address environment p = {x (L, 1), y → (L, -1)} and stack level s/= 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 codey e p sl for the address environment p = {fac→ (L, 1)} and stack level sl = 5. 8. Addressing of Variables. Introduce a new register SP, 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 SP (the stack pointer when entering the function body). • Compute the address environment p 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.
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply