handouts/ho07.tex
author Christian Urban <christian dot urban at kcl dot ac dot uk>
Sun, 15 Nov 2015 21:31:31 +0000
changeset 369 43c0ed473720
parent 327 9470cd124667
child 370 a65767fe5d71
permissions -rw-r--r--
updated
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
327
9470cd124667 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     1
\documentclass{article}
9470cd124667 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     2
\usepackage{../style}
9470cd124667 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     3
\usepackage{../langs}
9470cd124667 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     4
9470cd124667 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     5
9470cd124667 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     6
\begin{document}
9470cd124667 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     7
369
43c0ed473720 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 327
diff changeset
     8
\section*{Handout 7 (Compilation)}
327
9470cd124667 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     9
369
43c0ed473720 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 327
diff changeset
    10
The purpose of a compiler is to transform a program, a human
43c0ed473720 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 327
diff changeset
    11
can write, into code the machine can run as fast as possible.
43c0ed473720 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 327
diff changeset
    12
The fastest code would be machine code the CPU can run
43c0ed473720 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 327
diff changeset
    13
directly, but it is often enough to improve the speed of a
43c0ed473720 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 327
diff changeset
    14
program by just targeting a virtual machine. This produces not
43c0ed473720 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 327
diff changeset
    15
the fastest possible code, but code that is fast enough and
43c0ed473720 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 327
diff changeset
    16
has the advantage that the virtual machine care of things a
43c0ed473720 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 327
diff changeset
    17
compiler would normally need to take care of (like explicit
43c0ed473720 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 327
diff changeset
    18
memory management).
327
9470cd124667 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    19
369
43c0ed473720 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 327
diff changeset
    20
We will be generating code for the Java Virtual Machine. This
43c0ed473720 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 327
diff changeset
    21
is a stack-based virtual machine which will make it easy to
43c0ed473720 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 327
diff changeset
    22
generate code for arithmetic expressions. Recall
43c0ed473720 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 327
diff changeset
    23
that our
327
9470cd124667 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    24
9470cd124667 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    25
\end{document}
9470cd124667 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    26
9470cd124667 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    27
%%% Local Variables: 
9470cd124667 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    28
%%% mode: latex  
9470cd124667 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    29
%%% TeX-master: t
9470cd124667 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    30
%%% End: