# HG changeset patch # User Christian Urban # Date 1476706714 -3600 # Node ID b93f4d2aeee1bcde50dfb329ace128c995e13fac # Parent 4a5876f321aeece97ff23fde5b66a346f4892710 updated diff -r 4a5876f321ae -r b93f4d2aeee1 handouts/ho01.tex --- a/handouts/ho01.tex Sat Oct 15 14:27:01 2016 +0100 +++ b/handouts/ho01.tex Mon Oct 17 13:18:34 2016 +0100 @@ -27,23 +27,6 @@ %% reasons for a new prgramming language %% http://beautifulracket.com -%regher -% We can start off with a couple of observations about the role of -% compilers. First, hardware is getting weirder rather than getting -% clocked faster: almost all processors are multicores and it looks -% like there is increasing asymmetry in resources across -% cores. Processors come with vector units, crypto accelerators, bit -% twiddling instructions, and lots of features to make virtualization -% and concurrency work. We have DSPs, GPUs, big.little, and Xeon -% Phi. This is only scratching the surface. Second, we’re getting -% tired of low-level languages and their associated security -% disasters, we want to write new code, to whatever extent possible, -% in safer, higher-level languages. Compilers are caught right in the -% middle of these opposing trends: one of their main jobs is to help -% bridge the large and growing gap between increasingly high-level -% languages and increasingly wacky platforms. It’s effectively a -% perpetual employment act for solid compiler hackers. - % compiler explorer % https://gcc.godbolt.org diff -r 4a5876f321ae -r b93f4d2aeee1 handouts/ho07.pdf Binary file handouts/ho07.pdf has changed diff -r 4a5876f321ae -r b93f4d2aeee1 handouts/ho07.tex --- a/handouts/ho07.tex Sat Oct 15 14:27:01 2016 +0100 +++ b/handouts/ho07.tex Mon Oct 17 13:18:34 2016 +0100 @@ -17,15 +17,33 @@ the fastest possible code, but code that is fast enough and has the advantage that the virtual machine takes care of things a compiler would normally need to take care of (like -explicit memory management). +explicit memory management). Why study compilers? John Regher +gives this answer in his compiler blog:\footnote{\url{http://blog.regehr.org/archives/1419}} -As a first example we will implement a compiler for the very -simple While-language. It will generate code for the Java -Virtual Machine (JVM). This is a stack-based virtual machine, -a fact which will make it easy to generate code for arithmetic -expressions. For example for generating code for the -expression $1 + 2$ we need to generate the following three -instructions +\begin{quote}\it{}``We can start off with a couple of observations + about the role of compilers. First, hardware is getting weirder + rather than getting clocked faster: almost all processors are + multicores and it looks like there is increasing asymmetry in + resources across cores. Processors come with vector units, crypto + accelerators, bit twiddling instructions, and lots of features to + make virtualization and concurrency work. We have DSPs, GPUs, + big.little, and Xeon Phi. This is only scratching the + surface. Second, we’re getting tired of low-level languages and + their associated security disasters, we want to write new code, to + whatever extent possible, in safer, higher-level + languages. Compilers are caught right in the middle of these + opposing trends: one of their main jobs is to help bridge the large + and growing gap between increasingly high-level languages and + increasingly wacky platforms. It’s effectively a perpetual + employment act for solid compiler hackers.'' +\end{quote} + +As a first example in this module we will implement a compiler for the +very simple While-language. It will generate code for the Java Virtual +Machine (JVM). This is a stack-based virtual machine, a fact which +will make it easy to generate code for arithmetic expressions. For +example for generating code for the expression $1 + 2$ we need to +generate the following three instructions \begin{lstlisting}[numbers=none] ldc 1 diff -r 4a5876f321ae -r b93f4d2aeee1 slides/slides04.pdf Binary file slides/slides04.pdf has changed diff -r 4a5876f321ae -r b93f4d2aeee1 slides/slides04.tex --- a/slides/slides04.tex Sat Oct 15 14:27:01 2016 +0100 +++ b/slides/slides04.tex Mon Oct 17 13:18:34 2016 +0100 @@ -936,13 +936,13 @@ \bl{$(\ZERO \cdot (b \cdot c)) + ((\ZERO \cdot c) + \ONE)$} \end{center} - and answer + and answer how this regular expression matches the empty string \begin{center} \bl{$Right(Right(Empty))$} \end{center}\bigskip - But now we simplify to \bl{$\ONE$} and produce \bl{$Empty$}. + But now we simplify this to \bl{$\ONE$} and would produce \bl{$Empty$}. \end{frame} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%