Posted on January 6, 2018

Compiler Construction Example Sheet II

  1. What is the difference between a register machine and a stack machine as used in programming language runtimes. In your discussion include at least, code density, performance, memory allocation, and implementation complexity.

  2. How is environment implemented in Slang interpreters 0 and 2. Pay special attention to handling of functions.

  3. What is the main difference between interpreter 0 and interpreter 2? What are the purposes of this change? What are the additions to interpreter 2 in the version 3 and how do they improve the compiler?

  4. As you know Java virtual machine is a bytecode interpreter. Here are the instructions of a function f. What is the high-level code that produces these instructions? Annotate fragments of the code. This will require you to lookup what these instructions do online. Please do not use a decompiler.

    public static int f(int);
       0: iload_0
       1: ifne          6
       4: iconst_1
       5: ireturn
       6: iload_0
       7: iload_0
       8: iconst_1
       9: isub
      10: invokestatic  #4     // Method f
      13: imul
      14: ireturn
  5. 2011/3/5

  6. 2014/3/4