slides/slides08.tex
author Christian Urban <christian.urban@kcl.ac.uk>
Fri, 29 Nov 2024 18:58:18 +0000
changeset 975 ae5c03560d4d
parent 974 0cb4bf2469d1
permissions -rw-r--r--
update
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
697
370508e4d7f6 updated
Christian Urban <urbanc@in.tum.de>
parents: 608
diff changeset
     1
% !TEX program = xelatex
744
99c5916d9a8f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 728
diff changeset
     2
\documentclass[dvipsnames,14pt,t,xelatex,aspectratio=169,xcolor={table}]{beamer}
99c5916d9a8f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 728
diff changeset
     3
%%\usepackage{xcolor}
306
fecffce112fa updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 215
diff changeset
     4
\usepackage{../slides}
215
828303e8e4af updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 197
diff changeset
     5
\usepackage{../langs}
828303e8e4af updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 197
diff changeset
     6
\usepackage{../data}
871
94b84d880c2b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 817
diff changeset
     7
\usepackage{../graphicss}
600
d488a3e7b0ec updated
Christian Urban <urbanc@in.tum.de>
parents: 598
diff changeset
     8
\usepackage{../grammar}
196
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
     9
608
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
    10
\usepackage[most]{tcolorbox}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
    11
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
    12
\newtcbox{\hl}[1][]{%
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
    13
     size=fbox,
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
    14
    tcbox raise base, nobeforeafter, 
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
    15
    enhanced, colframe=gray,
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
    16
    colback=gray!30, boxrule=1pt,
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
    17
    fontupper=\ttfamily,
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
    18
    #1}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
    19
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
    20
\lstset{morekeywords={def,if,then,else,write,read},keywordstyle=\color{codepurple}\bfseries}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
    21
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
    22
% beamer stuff
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
    23
\renewcommand{\slidecaption}{CFL 09, King's College London}
65
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    24
\newcommand{\bl}[1]{\textcolor{blue}{#1}}       
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    25
608
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
    26
65
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    27
\begin{document}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    28
899
569a3adb6e01 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 871
diff changeset
    29
569a3adb6e01 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 871
diff changeset
    30
65
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    31
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
306
fecffce112fa updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 215
diff changeset
    32
\begin{frame}[t]
65
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    33
\frametitle{%
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    34
  \begin{tabular}{@ {}c@ {}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    35
  \\[-3mm]
459
780486571e38 updated
Christian Urban <urbanc@in.tum.de>
parents: 387
diff changeset
    36
  \LARGE Compilers and \\[-2mm] 
899
569a3adb6e01 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 871
diff changeset
    37
  \LARGE Formal Languages\\[-3mm] 
65
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    38
  \end{tabular}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    39
899
569a3adb6e01 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 871
diff changeset
    40
   \normalsize
65
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    41
  \begin{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    42
  \begin{tabular}{ll}
940
46eee459a999 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 899
diff changeset
    43
    Email:  & christian.urban at kcl.ac.uk\\
974
0cb4bf2469d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 956
diff changeset
    44
    Office Hour: & Fridays 12 -- 14\\
899
569a3adb6e01 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 871
diff changeset
    45
  Location: & N7.07 (North Wing, Bush House)\\
569a3adb6e01 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 871
diff changeset
    46
  Slides \& Progs: & KEATS\\
569a3adb6e01 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 871
diff changeset
    47
  Pollev: & \texttt{\alert{https://pollev.com/cfltutoratki576}}\\  
65
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    48
  \end{tabular}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    49
  \end{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    50
744
99c5916d9a8f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 728
diff changeset
    51
  \begin{center}
99c5916d9a8f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 728
diff changeset
    52
    \begin{tikzpicture}
99c5916d9a8f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 728
diff changeset
    53
      \node[drop shadow,fill=white,inner sep=0pt] 
99c5916d9a8f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 728
diff changeset
    54
      {\footnotesize\rowcolors{1}{capri!10}{white}
99c5916d9a8f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 728
diff changeset
    55
        \begin{tabular}{|p{4.8cm}|p{4.8cm}|}\hline
99c5916d9a8f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 728
diff changeset
    56
          1 Introduction, Languages          & 6 While-Language \\
99c5916d9a8f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 728
diff changeset
    57
          2 Regular Expressions, Derivatives & 7 Compilation, JVM \\
99c5916d9a8f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 728
diff changeset
    58
          3 Automata, Regular Languages      & \cellcolor{blue!50} 8 Compiling Functional Languages \\
99c5916d9a8f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 728
diff changeset
    59
          4 Lexing, Tokenising               & 9 Optimisations \\
99c5916d9a8f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 728
diff changeset
    60
          5 Grammars, Parsing                & 10 LLVM \\ \hline
99c5916d9a8f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 728
diff changeset
    61
        \end{tabular}%
99c5916d9a8f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 728
diff changeset
    62
      };
99c5916d9a8f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 728
diff changeset
    63
    \end{tikzpicture}
99c5916d9a8f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 728
diff changeset
    64
  \end{center}
306
fecffce112fa updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 215
diff changeset
    65
\end{frame}
608
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
    66
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
66
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
    67
899
569a3adb6e01 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 871
diff changeset
    68
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
569a3adb6e01 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 871
diff changeset
    69
\begin{frame}[t,fragile]
956
ae9782e62bdd updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
    70
\mbox{}\\[-20mm]\mbox{}
ae9782e62bdd updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
    71
  
ae9782e62bdd updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
    72
\footnotesize
ae9782e62bdd updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
    73
\begin{textblock}{13}(-0.5,0.2)
ae9782e62bdd updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
    74
\begin{lstlisting}[language=JVMIS2,numbers=none]
ae9782e62bdd updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
    75
.method public static main([Ljava/lang/String;)V
ae9782e62bdd updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
    76
   .limit locals 200
ae9782e62bdd updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
    77
   .limit stack 200
ae9782e62bdd updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
    78
   invokestatic foo/foo/read()I
ae9782e62bdd updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
    79
   istore 0             
ae9782e62bdd updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
    80
   ldc 1
ae9782e62bdd updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
    81
   istore 1             
ae9782e62bdd updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
    82
Loop_begin_4:
ae9782e62bdd updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
    83
   iload 0              
ae9782e62bdd updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
    84
   ldc 0
ae9782e62bdd updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
    85
   if_icmple Loop_end_5
ae9782e62bdd updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
    86
   iload 0              
ae9782e62bdd updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
    87
   iload 1              
ae9782e62bdd updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
    88
   imul
ae9782e62bdd updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
    89
   istore 1             
ae9782e62bdd updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
    90
   iload 0              
ae9782e62bdd updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
    91
   ldc 1
ae9782e62bdd updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
    92
   isub
ae9782e62bdd updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
    93
   istore 0             
ae9782e62bdd updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
    94
   goto Loop_begin_4
ae9782e62bdd updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
    95
\end{lstlisting}
ae9782e62bdd updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
    96
\end{textblock}
ae9782e62bdd updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
    97
ae9782e62bdd updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
    98
\begin{textblock}{13}(7,8)
ae9782e62bdd updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
    99
\begin{lstlisting}[language=JVMIS2,numbers=none]
ae9782e62bdd updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   100
Loop_end_5:
ae9782e62bdd updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   101
   iload 1              
ae9782e62bdd updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   102
   invokestatic foo/foo/write(I)V
ae9782e62bdd updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   103
   return
ae9782e62bdd updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   104
.end method   
ae9782e62bdd updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   105
\end{lstlisting}
ae9782e62bdd updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   106
\end{textblock}
ae9782e62bdd updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   107
ae9782e62bdd updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   108
\end{frame}
ae9782e62bdd updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   109
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
ae9782e62bdd updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   110
ae9782e62bdd updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   111
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
ae9782e62bdd updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   112
\begin{frame}[t,fragile]
ae9782e62bdd updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   113
\mbox{}\\[-20mm]\mbox{}
ae9782e62bdd updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   114
  
ae9782e62bdd updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   115
\footnotesize
ae9782e62bdd updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   116
\begin{textblock}{13}(-0.5,0.2)
ae9782e62bdd updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   117
\begin{lstlisting}[language=JVMIS2,numbers=none]
ae9782e62bdd updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   118
.method public static main([Ljava/lang/String;)V
ae9782e62bdd updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   119
   .limit locals 200
ae9782e62bdd updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   120
   .limit stack 200
ae9782e62bdd updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   121
   invokestatic foo/foo/read()I
ae9782e62bdd updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   122
   istore 0             ; n
ae9782e62bdd updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   123
   ldc 1
ae9782e62bdd updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   124
   istore 1             ; res
ae9782e62bdd updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   125
Loop_begin_4:
ae9782e62bdd updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   126
   iload 0              ; n
ae9782e62bdd updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   127
   ldc 0
ae9782e62bdd updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   128
   if_icmple Loop_end_5
ae9782e62bdd updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   129
   iload 0              ; n
ae9782e62bdd updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   130
   iload 1              ; res
ae9782e62bdd updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   131
   imul
ae9782e62bdd updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   132
   istore 1             ; res
ae9782e62bdd updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   133
   iload 0              ; n
ae9782e62bdd updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   134
   ldc 1
ae9782e62bdd updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   135
   isub
ae9782e62bdd updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   136
   istore 0             ; n
ae9782e62bdd updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   137
   goto Loop_begin_4
ae9782e62bdd updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   138
\end{lstlisting}
ae9782e62bdd updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   139
\end{textblock}
ae9782e62bdd updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   140
ae9782e62bdd updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   141
\begin{textblock}{13}(7,8)
ae9782e62bdd updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   142
\begin{lstlisting}[language=JVMIS2,numbers=none]
ae9782e62bdd updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   143
Loop_end_5:
ae9782e62bdd updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   144
   iload 1              ; res
ae9782e62bdd updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   145
   invokestatic foo/foo/write(I)V
ae9782e62bdd updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   146
   return
ae9782e62bdd updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   147
.end method   
ae9782e62bdd updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   148
\end{lstlisting}
ae9782e62bdd updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   149
\end{textblock}
ae9782e62bdd updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   150
ae9782e62bdd updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   151
\end{frame}
ae9782e62bdd updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   152
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
ae9782e62bdd updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   153
ae9782e62bdd updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   154
ae9782e62bdd updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   155
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
ae9782e62bdd updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   156
\begin{frame}[t,fragile]
899
569a3adb6e01 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 871
diff changeset
   157
569a3adb6e01 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 871
diff changeset
   158
\small
569a3adb6e01 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 871
diff changeset
   159
\begin{textblock}{13}(-0.5,1)
569a3adb6e01 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 871
diff changeset
   160
\begin{lstlisting}[numbers=none]
569a3adb6e01 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 871
diff changeset
   161
def mkeps(r: Rexp) : Val = r match {
569a3adb6e01 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 871
diff changeset
   162
  ...
569a3adb6e01 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 871
diff changeset
   163
  case PLUS(r) => Stars(List(mkeps(r))) 
569a3adb6e01 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 871
diff changeset
   164
  case OPTIONAL(r) => Stars(Nil)
569a3adb6e01 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 871
diff changeset
   165
  case NTIMES(r, n) => Stars(List.fill(n)(mkeps(r)))
569a3adb6e01 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 871
diff changeset
   166
}
569a3adb6e01 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 871
diff changeset
   167
569a3adb6e01 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 871
diff changeset
   168
def inj(r: Rexp, c: Char, v: Val) : Val = (r, v) match {
569a3adb6e01 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 871
diff changeset
   169
  ...
569a3adb6e01 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 871
diff changeset
   170
  case (RANGE(_), Empty) => Chr(c)
569a3adb6e01 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 871
diff changeset
   171
  case (PLUS(r), Sequ(v1, Stars(vs))) => Stars(inj(r, c, v1)::vs)
569a3adb6e01 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 871
diff changeset
   172
  case (OPTIONAL(r), v) => Stars(inj(r, c, v)::Nil)
569a3adb6e01 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 871
diff changeset
   173
  case (NTIMES(r, n), Sequ(v1, Stars(vs))) => Stars(inj(r, c, v1)::vs)
569a3adb6e01 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 871
diff changeset
   174
}
569a3adb6e01 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 871
diff changeset
   175
\end{lstlisting}
569a3adb6e01 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 871
diff changeset
   176
\end{textblock}
569a3adb6e01 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 871
diff changeset
   177
569a3adb6e01 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 871
diff changeset
   178
569a3adb6e01 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 871
diff changeset
   179
\begin{textblock}{5}(3,13.5)
569a3adb6e01 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 871
diff changeset
   180
\bl{$r^? \dn r^{\{0..1\}}$}
569a3adb6e01 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 871
diff changeset
   181
\end{textblock}
569a3adb6e01 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 871
diff changeset
   182
569a3adb6e01 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 871
diff changeset
   183
\end{frame}
569a3adb6e01 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 871
diff changeset
   184
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
569a3adb6e01 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 871
diff changeset
   185
569a3adb6e01 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 871
diff changeset
   186
569a3adb6e01 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 871
diff changeset
   187
813
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   188
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   189
% \begin{frame}[c]
66
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   190
813
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   191
% \begin{center}
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   192
% \bl{\begin{tabular}{@{}lcl@{}}
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   193
% \meta{Stmt} & $::=$ &  $\texttt{skip}$\\
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   194
%               & $|$ & \textit{Id}\;\texttt{:=}\;\meta{AExp}\\
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   195
%               & $|$ & \texttt{if}\; \meta{BExp} \;\texttt{then}\; \meta{Block} \;\texttt{else}\; \meta{Block}\\
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   196
%               & $|$ & \texttt{while}\; \meta{BExp} \;\texttt{do}\; \meta{Block}\\
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   197
%               & $|$ & \texttt{read}\;\textit{Id}\\
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   198
%               & $|$ & \texttt{write}\;\textit{Id}\\
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   199
%               & $|$ & \texttt{write}\;\textit{String}\medskip\\
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   200
% \meta{Stmts} & $::=$ &  \meta{Stmt} \;\texttt{;}\; \meta{Stmts}\\
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   201
%               & $|$ & \meta{Stmt}\medskip\\
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   202
% \meta{Block} & $::=$ &  \texttt{\{}\,\meta{Stmts}\,\texttt{\}}\\
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   203
%                 & $|$ & \meta{Stmt}\medskip\\
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   204
% \meta{AExp} & $::=$ & \ldots\\
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   205
% \meta{BExp} & $::=$ & \ldots\\
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   206
% \end{tabular}}
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   207
% \end{center}
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   208
% \end{frame}
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   209
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
69
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   210
813
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   211
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   212
% \begin{frame}[t,fragile]
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   213
% \frametitle{Compiling AExps}
196
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   214
813
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   215
% For example \bl{$1 + ((2 * 3) + (4 - 3))$}:\medskip
608
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   216
813
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   217
% \begin{columns}[T]
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   218
% \begin{column}{.3\textwidth}
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   219
% \begin{center}
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   220
% \bl{\begin{tikzpicture}
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   221
% \tikzset{level distance=12mm,sibling distance=4mm}
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   222
% \tikzset{edge from parent/.style={draw,very thick}}
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   223
% \Tree [.$+$ [.$1$ ] [.$+$ [.$*$ $2$ $3$ ] [.$-$ $4$ $3$ ]]]
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   224
% \end{tikzpicture}}
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   225
% \end{center}
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   226
% \end{column}
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   227
% \begin{column}{.3\textwidth}
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   228
% \begin{lstlisting}[language=JVMIS,numbers=none]
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   229
% ldc 1 
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   230
% ldc 2 
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   231
% ldc 3 
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   232
% imul 
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   233
% ldc 4 
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   234
% ldc 3 
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   235
% isub 
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   236
% iadd 
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   237
% iadd
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   238
% \end{lstlisting}
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   239
% \end{column}
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   240
% \end{columns}\bigskip
535
095be64c03c1 updated
Christian Urban <urbanc@in.tum.de>
parents: 534
diff changeset
   241
813
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   242
% \small
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   243
% Traverse tree in post-order \bl{$\Rightarrow$} code for 
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   244
% stack-machine
535
095be64c03c1 updated
Christian Urban <urbanc@in.tum.de>
parents: 534
diff changeset
   245
813
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   246
% \end{frame}
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   247
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
196
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   248
813
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   249
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   250
% \begin{frame}[c,fragile]
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   251
% \frametitle{Compiling AExps}
196
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   252
813
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   253
% \bl{
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   254
% \begin{center}
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   255
% \begin{tabular}{lcl}
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   256
% $\textit{compile}(n, E)$ & $\dn$ & $\pcode{ldc}\;n$\smallskip\\
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   257
% $\textit{compile}(a_1 + a_2, E)$ & $\dn$ \\
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   258
% \multicolumn{3}{c}{$\qquad\textit{compile}(a_1, E) \;@\;\textit{compile}(a_2, E)\;@\; \pcode{iadd}$}\smallskip\\
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   259
% $\textit{compile}(a_1 - a_2, E)$ & $\dn$ \\
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   260
% \multicolumn{3}{c}{$\qquad\textit{compile}(a_1, E) \;@\; \textit{compile}(a_2, E)\;@\; \pcode{isub}$}\smallskip\\
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   261
% $\textit{compile}(a_1 * a_2, E)$ & $\dn$ \\
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   262
% \multicolumn{3}{c}{$\qquad\textit{compile}(a_1, E) \;@\; \textit{compile}(a_2, E)\;@\; \pcode{imul}$}\smallskip\\
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   263
% $\textit{compile}(a_1 \backslash a_2, E)$ & $\dn$\\ 
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   264
% \multicolumn{3}{c}{$\qquad\textit{compile}(a_1, E) \;@\; \textit{compile}(a_2, E)\;@\; \pcode{idiv}$}\smallskip\\
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   265
% $\textit{compile}(x, E)$ & $\dn$ & $\pcode{iload}\;E(x)$\\
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   266
% \end{tabular}
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   267
% \end{center}}
196
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   268
813
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   269
% \end{frame}
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   270
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
196
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   271
813
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   272
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   273
% \begin{frame}[c,fragile]
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   274
% \frametitle{Compiling Ifs}
534
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   275
813
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   276
% For example
534
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   277
813
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   278
% \begin{lstlisting}[mathescape,numbers=none,language=While]
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   279
% if 1 = 1 then x := 2 else y := 3
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   280
% \end{lstlisting}
534
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   281
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   282
813
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   283
% \begin{center}
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   284
% \begin{lstlisting}[mathescape,language=JVMIS,numbers=none]
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   285
%    ldc 1
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   286
%    ldc 1
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   287
%    if_icmpne L_ifelse $\quad\tikz[remember picture] \node (C) {\mbox{}};$
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   288
%    ldc 2
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   289
%    istore 0
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   290
%    goto L_ifend $\quad\tikz[remember picture] \node (A) {\mbox{}};$
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   291
% L_ifelse: $\quad\tikz[remember picture] \node[] (D) {\mbox{}};$
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   292
%    ldc 3
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   293
%    istore 1
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   294
% L_ifend: $\quad\tikz[remember picture] \node[] (B) {\mbox{}};$
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   295
% \end{lstlisting}
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   296
% \end{center}
534
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   297
813
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   298
% \begin{tikzpicture}[remember picture,overlay]
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   299
%   \draw[->,very thick] (A) edge [->,to path={-- ++(10mm,0mm) 
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   300
%            -- ++(0mm,-17.3mm) |- (\tikztotarget)},line width=1mm] (B.east);
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   301
%   \draw[->,very thick] (C) edge [->,to path={-- ++(10mm,0mm) 
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   302
%            -- ++(0mm,-17.3mm) |- (\tikztotarget)},line width=1mm] (D.east);
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   303
% \end{tikzpicture}
196
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   304
813
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   305
% \end{frame}
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   306
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
196
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   307
813
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   308
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   309
% \begin{frame}[c,fragile]
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   310
% \frametitle{Compiling Whiles}
534
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   311
813
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   312
% For example
196
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   313
813
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   314
% \begin{lstlisting}[mathescape,numbers=none,language=While]
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   315
% while x <= 10 do x := x + 1
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   316
% \end{lstlisting}
534
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   317
196
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   318
813
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   319
% \begin{center}
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   320
% \begin{lstlisting}[mathescape,language=JVMIS,numbers=none]
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   321
% L_wbegin: $\quad\tikz[remember picture] \node[] (LB) {\mbox{}};$
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   322
%    iload 0
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   323
%    ldc 10
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   324
%    if_icmpgt L_wend $\quad\tikz[remember picture] \node (LC) {\mbox{}};$
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   325
%    iload 0
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   326
%    ldc 1
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   327
%    iadd
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   328
%    istore 0
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   329
%    goto L_wbegin $\quad\tikz[remember picture] \node (LA) {\mbox{}};$
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   330
% L_wend: $\quad\tikz[remember picture] \node[] (LD) {\mbox{}};$
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   331
% \end{lstlisting}
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   332
% \end{center}
196
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   333
813
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   334
% \begin{tikzpicture}[remember picture,overlay]
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   335
%   \draw[->,very thick] (LA) edge [->,to path={-- ++(12mm,0mm) 
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   336
%            -- ++(0mm,17.3mm) |- (\tikztotarget)},line width=1mm] (LB.east);
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   337
%   \draw[->,very thick] (LC) edge [->,to path={-- ++(12mm,0mm) 
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   338
%            -- ++(0mm,-17.3mm) |- (\tikztotarget)},line width=1mm] (LD.east);
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   339
% \end{tikzpicture}
534
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   340
813
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   341
% \end{frame}
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   342
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
196
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   343
813
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   344
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   345
% \begin{frame}[c,fragile]
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   346
% \frametitle{Compiling Writes}
534
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   347
813
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   348
% \small
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   349
% \begin{lstlisting}[language=JVMIS,mathescape,
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   350
%                    numbers=none,xleftmargin=-6mm]
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   351
% .method public static write(I)V 
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   352
%   .limit locals 1 
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   353
%   .limit stack 2 
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   354
%   getstatic java/lang/System/out 
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   355
%                             Ljava/io/PrintStream; 
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   356
%   iload 0
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   357
%   invokevirtual java/io/PrintStream/println(I)V 
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   358
%   return 
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   359
% .end method
534
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   360
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   361
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   362
813
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   363
% iload $E(x)$ 
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   364
% invokestatic XXX/XXX/write(I)V
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   365
% \end{lstlisting}
534
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   366
813
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   367
% \end{frame}
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   368
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
534
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   369
813
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   370
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   371
% \begin{frame}[c,fragile]
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   372
% \frametitle{Compiling Main}
534
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   373
813
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   374
% \footnotesize
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   375
% \begin{lstlisting}[language=JVMIS,mathescape,
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   376
%                    numbers=none,xleftmargin=-6mm]
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   377
% .class public XXX.XXX
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   378
% .super java/lang/Object
534
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   379
813
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   380
% .method public <init>()V
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   381
%     aload_0
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   382
%     invokenonvirtual java/lang/Object/<init>()V
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   383
%     return
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   384
% .end method
534
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   385
813
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   386
% .method public static main([Ljava/lang/String;)V
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   387
%     .limit locals 200
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   388
%     .limit stack 200
534
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   389
813
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   390
%       $\textit{\ldots{}here comes the compiled code\ldots}$
534
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   391
813
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   392
%     return
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   393
% .end method
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   394
% \end{lstlisting}
534
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   395
813
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   396
% \end{frame}
059f970287d1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   397
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
534
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   398
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   399
196
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   400
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
608
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   401
\begin{frame}[c,fragile]
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   402
\frametitle{Functional Programming}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   403
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   404
\footnotesize
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   405
\begin{textblock}{13}(0.9,3)
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   406
\begin{lstlisting}[]numbers=none]
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   407
def fib(n) = if n == 0 then 0 
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   408
             else if n == 1 then 1 
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   409
             else fib(n - 1) + fib(n - 2);
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   410
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   411
def fact(n) = if n == 0 then 1 else n * fact(n - 1);
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   412
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   413
def ack(m, n) = if m == 0 then n + 1
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   414
                else if n == 0 then ack(m - 1, 1)
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   415
                else ack(m - 1, ack(m, n - 1));
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   416
                
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   417
def gcd(a, b) = if b == 0 then a else gcd(b, a % b);                
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   418
\end{lstlisting}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   419
\end{textblock}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   420
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   421
\end{frame}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   422
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
196
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   423
608
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   424
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   425
\begin{frame}[c]
697
370508e4d7f6 updated
Christian Urban <urbanc@in.tum.de>
parents: 608
diff changeset
   426
\frametitle{Fun-Grammar}
608
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   427
\bl{
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   428
\begin{plstx}[rhs style=]
697
370508e4d7f6 updated
Christian Urban <urbanc@in.tum.de>
parents: 608
diff changeset
   429
: \meta{Exp} ::= \meta{Var} | \meta{Num}{\hspace{4cm}}
608
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   430
             |   \meta{Exp} + \meta{Exp} | ... | (\meta{Exp})
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   431
             |   \code{if} \meta{BExp} \code{then} \meta{Exp} \code{else} \meta{Exp}
697
370508e4d7f6 updated
Christian Urban <urbanc@in.tum.de>
parents: 608
diff changeset
   432
             |   \code{write} \meta{Exp} {\hspace{5cm}}
608
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   433
             |   \meta{Exp} ; \meta{Exp}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   434
             |   \textit{FunName} (\meta{Exp}, ... , \meta{Exp})\\
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   435
: \meta{BExp} ::= ...\\
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   436
: \meta{Def} ::= \code{def} \textit{FunName} ($\hspace{0.4mm}x_1$, ... , $x_n$) = \meta{Exp}\\               
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   437
: \meta{Prog} ::= \meta{Def} ; \meta{Prog}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   438
               | \meta{Exp} ; \meta{Prog}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   439
               | \meta{Exp}\\
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   440
\end{plstx}}
196
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   441
608
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   442
% Almost what is implemented - Exp ; Exp is left-recursive
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   443
%
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   444
\end{frame}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   445
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
196
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   446
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   447
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
608
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   448
\begin{frame}[c, fragile]
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   449
\frametitle{Abstract Syntax Trees}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   450
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   451
\footnotesize
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   452
\begin{lstlisting}[language=Scala, numbers=none, xleftmargin=-1mm]
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   453
abstract class Exp
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   454
abstract class BExp 
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   455
abstract class Decl
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   456
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   457
case class Var(s: String) extends Exp
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   458
case class Num(i: Int) extends Exp
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   459
case class Aop(o: String, a1: Exp, a2: Exp) extends Exp
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   460
case class If(a: BExp, e1: Exp, e2: Exp) extends Exp
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   461
case class Write(e: Exp) extends Exp
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   462
case class Sequ(e1: Exp, e2: Exp) extends Exp
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   463
case class Call(name: String, args: List[Exp]) extends Exp
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   464
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   465
case class Bop(o: String, a1: Exp, a2: Exp) extends BExp
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   466
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   467
case class Def(name: String, 
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   468
               args: List[String], 
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   469
               body: Exp) extends Decl
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   470
case class Main(e: Exp) extends Decl
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   471
\end{lstlisting}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   472
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   473
\end{frame}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   474
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   475
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   476
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   477
\begin{frame}[c, fragile]
697
370508e4d7f6 updated
Christian Urban <urbanc@in.tum.de>
parents: 608
diff changeset
   478
\frametitle{Ideas}
608
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   479
697
370508e4d7f6 updated
Christian Urban <urbanc@in.tum.de>
parents: 608
diff changeset
   480
Use separate JVM methods for each Fun-function.\bigskip
370508e4d7f6 updated
Christian Urban <urbanc@in.tum.de>
parents: 608
diff changeset
   481
370508e4d7f6 updated
Christian Urban <urbanc@in.tum.de>
parents: 608
diff changeset
   482
Compile \bl{\texttt{exp}}s such that the result of the expression
608
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   483
is on top of the stack.\bigskip
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   484
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   485
\begin{itemize}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   486
\item \texttt{\color{codepurple}{write}}\texttt{(1 + 2)}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   487
\item \texttt{1 + 2; 3 + 4} 
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   488
\end{itemize}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   489
  
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   490
\end{frame}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   491
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
196
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   492
608
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   493
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   494
\begin{frame}[c, fragile]
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   495
\frametitle{Sequences}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   496
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   497
Compiling \texttt{exp1 ; exp2}:\bigskip
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   498
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   499
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   500
\begin{lstlisting}[mathescape,language=JVMIS, numbers=none]
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   501
$\textit{compile}$(exp1)
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   502
pop
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   503
$\textit{compile}$(exp2)
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   504
\end{lstlisting}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   505
  
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   506
\end{frame}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   507
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   508
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   509
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   510
\begin{frame}[t, fragile]
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   511
\frametitle{Write}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   512
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   513
Compiling call to \texttt{write(1+2)}:\bigskip
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   514
196
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   515
608
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   516
\begin{lstlisting}[mathescape,language=JVMIS, numbers=none]
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   517
$\textit{compile}$(1+2)
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   518
dup
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   519
invokestatic XXX/XXX/write(I)V
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   520
\end{lstlisting}\bigskip
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   521
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   522
\small
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   523
needs the helper method
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   524
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   525
\footnotesize
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   526
\begin{lstlisting}[language=JVMIS, 
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   527
                   xleftmargin=2mm, 
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   528
                   numbers=none]
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   529
.method public static write(I)V 
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   530
   .limit locals 1
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   531
   .limit stack 2
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   532
   getstatic java/lang/System/out Ljava/io/PrintStream; 
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   533
   iload 0 
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   534
   invokevirtual java/io/PrintStream/println(I)V 
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   535
   return 
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   536
.end method
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   537
\end{lstlisting}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   538
\end{frame}
196
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   539
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   540
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   541
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   542
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   543
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
608
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   544
\begin{frame}[t, fragile]
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   545
\frametitle{Function Definitions}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   546
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   547
\footnotesize
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   548
\begin{lstlisting}[language=JVMIS, 
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   549
                   xleftmargin=2mm, 
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   550
                   numbers=none]
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   551
.method public static write(I)V 
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   552
   .limit locals 1
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   553
   .limit stack 2
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   554
   getstatic java/lang/System/out Ljava/io/PrintStream; 
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   555
   iload 0 
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   556
   invokevirtual java/io/PrintStream/println(I)V 
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   557
   return 
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   558
.end method
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   559
\end{lstlisting}\bigskip
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   560
697
370508e4d7f6 updated
Christian Urban <urbanc@in.tum.de>
parents: 608
diff changeset
   561
\small We will need methods for definitions like\footnotesize\medskip
608
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   562
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   563
\begin{lstlisting}[language=JVMIS, 
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   564
                   xleftmargin=2mm, 
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   565
                   numbers=none]
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   566
def fname (x1, ... , xn) = ...                   
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   567
                   
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   568
.method public static fname (I...I)I
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   569
  .limit locals ??
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   570
  .limit stack ?? 
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   571
  ??
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   572
.end method
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   573
\end{lstlisting}
196
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   574
608
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   575
\end{frame}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   576
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   577
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   578
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   579
\begin{frame}[c, fragile]
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   580
\frametitle{Stack Estimation}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   581
\small
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   582
\mbox{}\\[-15mm]
196
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   583
608
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   584
\bl{\begin{center}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   585
\begin{tabular}{@{\hspace{-4mm}}l@{\hspace{2mm}}c@{\hspace{2mm}}l@{}}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   586
$\textit{estimate}(n)$ & $\dn$ & $1$\\
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   587
$\textit{estimate}(x)$ & $\dn$ & $1$\\
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   588
$\textit{estimate}(a_1\;aop\;a_2)$ & $\dn$ &
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   589
$\textit{estimate}(a_1) + \textit{estimate}(a_2)$\\
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   590
$\textit{estimate}(\pcode{if}\;b\;\pcode{then}\;e_1\;\pcode{else}\;e_2)$ & $\dn$ & 
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   591
$\textit{estimate}(b) +$\\ 
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   592
& & $\quad max(\textit{estimate}(e_1), \textit{estimate}(e_2))$\\
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   593
$\textit{estimate}(\pcode{write}(e))$ & $\dn$ & 
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   594
$\textit{estimate}(e) + 1$\\
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   595
$\textit{estimate}(e_1 ; e_2)$ & $\dn$ & 
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   596
$max(\textit{estimate}(e_1), \textit{estimate}(e_2))$\\
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   597
$\textit{estimate}(f(e_1, ..., e_n))$ & $\dn$ & 
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   598
$\sum_{i = 1..n}\;estimate(e_i)$\medskip\\
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   599
$\textit{estimate}(a_1\;bop\;a_2)$ & $\dn$ &
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   600
$\textit{estimate}(a_1) + \textit{estimate}(a_2)$\\
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   601
\end{tabular}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   602
\end{center}}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   603
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   604
\end{frame}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   605
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
196
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   606
197
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 196
diff changeset
   607
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
608
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   608
\begin{frame}[fragile]
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   609
\frametitle{Successor Function}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   610
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   611
\begin{textblock}{7}(1,2.5)\footnotesize
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   612
\begin{minipage}{6cm}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   613
\begin{lstlisting}[language=JVMIS,basicstyle=\ttfamily, numbers=none]
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   614
.method public static suc(I)I 
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   615
.limit locals 1
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   616
.limit stack 2
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   617
  iload 0
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   618
  ldc 1
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   619
  iadd
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   620
  ireturn
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   621
.end method 
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   622
\end{lstlisting}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   623
\end{minipage}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   624
\end{textblock}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   625
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   626
\begin{textblock}{7}(6,8)
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   627
\begin{bubble}[5cm]\small
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   628
\begin{lstlisting}[language=Lisp,
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   629
                   basicstyle=\ttfamily, 
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   630
                   numbers=none,
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   631
                   xleftmargin=1mm,linebackgroundcolor=\color{cream}]
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   632
def suc(x) = x + 1;
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   633
\end{lstlisting}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   634
\end{bubble}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   635
\end{textblock}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   636
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   637
\end{frame}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   638
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   639
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   640
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   641
\begin{frame}[fragile]
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   642
\frametitle{Addition Function}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   643
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   644
\begin{textblock}{7}(1,1.9)\footnotesize
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   645
\begin{minipage}{6cm}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   646
\begin{lstlisting}[language=JVMIS,basicstyle=\ttfamily, numbers=none]
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   647
.method public static add(II)I 
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   648
.limit locals 2
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   649
.limit stack 5
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   650
  iload 0
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   651
  ldc 0
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   652
  if_icmpne If_else
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   653
  iload 1
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   654
  goto If_end
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   655
If_else:
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   656
  iload 0
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   657
  ldc 1
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   658
  isub
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   659
  iload 1
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   660
  invokestatic XXX/XXX/add(II)I
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   661
  invokestatic XXX/XXX/suc(I)I
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   662
If_end:
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   663
  ireturn
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   664
.end method
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   665
\end{lstlisting}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   666
\end{minipage}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   667
\end{textblock}
196
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   668
608
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   669
\begin{textblock}{7}(6,6.6)
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   670
\begin{bubble}[7cm]\small
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   671
\begin{lstlisting}[language=Lisp,
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   672
                   basicstyle=\ttfamily, 
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   673
                   numbers=none,
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   674
                   xleftmargin=1mm,linebackgroundcolor=\color{cream}]
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   675
def add(x, y) = 
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   676
    if x == 0 then y 
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   677
    else suc(add(x - 1, y));
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   678
\end{lstlisting}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   679
\end{bubble}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   680
\end{textblock}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   681
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   682
\end{frame}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   683
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   684
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   685
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   686
\begin{frame}[c,fragile]
814
1fbaa5f05516 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 813
diff changeset
   687
\frametitle{\mbox{}\hspace{5cm}Factorial}
197
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 196
diff changeset
   688
814
1fbaa5f05516 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 813
diff changeset
   689
\begin{textblock}{7}(0,1.0)\footnotesize
608
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   690
\begin{minipage}{6cm}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   691
\begin{lstlisting}[language=JVMIS,basicstyle=\ttfamily, numbers=none]
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   692
.method public static facT(II)I 
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   693
.limit locals 2
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   694
.limit stack 6
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   695
  iload 0
701
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 697
diff changeset
   696
  ldc 0
608
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   697
  if_icmpne If_else_2
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   698
  iload 1
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   699
  goto If_end_3
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   700
If_else_2:
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   701
  iload 0
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   702
  ldc 1
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   703
  isub
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   704
  iload 0
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   705
  iload 1
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   706
  imul
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   707
  invokestatic fact/fact/facT(II)I
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   708
If_end_3:
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   709
  ireturn
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   710
.end method 
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   711
\end{lstlisting}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   712
\end{minipage}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   713
\end{textblock}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   714
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   715
\begin{textblock}{7}(6,7)
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   716
\begin{bubble}[7cm]\small
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   717
\begin{lstlisting}[language=Lisp,
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   718
                   basicstyle=\ttfamily, 
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   719
                   numbers=none,
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   720
                   xleftmargin=1mm,linebackgroundcolor=\color{cream}]
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   721
def facT(n, acc) = 
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   722
  if n == 0 then acc 
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   723
  else facT(n - 1, n * acc);
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   724
\end{lstlisting}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   725
\end{bubble}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   726
\end{textblock}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   727
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   728
\end{frame}
197
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 196
diff changeset
   729
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
196
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   730
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   731
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
608
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   732
\begin{frame}[fragile]
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   733
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   734
\begin{textblock}{7}(1,-0.2)\footnotesize
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   735
\begin{minipage}{6cm}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   736
\begin{lstlisting}[language=JVMIS,basicstyle=\ttfamily, numbers=none, escapeinside={(*@}{@*)}]
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   737
.method public static facT(II)I 
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   738
.limit locals 2
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   739
.limit stack 6
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   740
(*@\hl{facT\_Start:} @*)
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   741
  iload 0
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   742
  ldc 0
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   743
  if_icmpne If_else_2
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   744
  iload 1
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   745
  goto If_end_3
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   746
If_else_2:
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   747
  iload 0
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   748
  ldc 1
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   749
  isub
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   750
  iload 0
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   751
  iload 1
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   752
  imul
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   753
  (*@\hl{istore 1} @*)
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   754
  (*@\hl{istore 0} @*)
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   755
  (*@\hl{goto facT\_Start} @*)
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   756
If_end_3:
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   757
  ireturn
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   758
.end method 
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   759
\end{lstlisting}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   760
\end{minipage}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   761
\end{textblock}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   762
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   763
\begin{textblock}{7}(6,7)
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   764
\begin{bubble}[7cm]\small
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   765
\begin{lstlisting}[language=Lisp,
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   766
                   basicstyle=\ttfamily, 
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   767
                   numbers=none,
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   768
                   xleftmargin=1mm,linebackgroundcolor=\color{cream}]
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   769
def facT(n, acc) = 
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   770
  if n == 0 then acc 
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   771
  else facT(n - 1, n * acc);
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   772
\end{lstlisting}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   773
\end{bubble}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   774
\end{textblock}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   775
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   776
\end{frame}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   777
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   778
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   779
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   780
\begin{frame}[t, fragile]
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   781
\frametitle{Tail Recursion}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   782
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   783
A call to \texttt{f(args)} is usually compiled as\medskip
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   784
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   785
{\small\begin{lstlisting}[basicstyle=\ttfamily, numbers=none]
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   786
  args onto stack
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   787
  invokestatic  .../f 
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   788
\end{lstlisting}}\pause
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   789
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   790
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   791
A call is in tail position provided:\medskip
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   792
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   793
{\small\begin{itemize}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   794
\item \texttt{if Bexp then \hl{Exp} else \hl{Exp}}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   795
\item \texttt{Exp ; \hl{Exp}}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   796
\item \texttt{Exp  op Exp}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   797
\end{itemize}}\medskip
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   798
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   799
then a call \texttt{f(args)} can be compiled as\medskip\small
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   800
697
370508e4d7f6 updated
Christian Urban <urbanc@in.tum.de>
parents: 608
diff changeset
   801
\begin{lstlisting}[numbers=none]
608
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   802
  prepare environment
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   803
  jump to start of function
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   804
\end{lstlisting}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   805
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   806
\end{frame}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   807
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   808
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   809
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   810
\begin{frame}[c, fragile]
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   811
\frametitle{Tail Recursive Call}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   812
\footnotesize
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   813
697
370508e4d7f6 updated
Christian Urban <urbanc@in.tum.de>
parents: 608
diff changeset
   814
\begin{textblock}{13}(-0.3,3)
370508e4d7f6 updated
Christian Urban <urbanc@in.tum.de>
parents: 608
diff changeset
   815
\begin{lstlisting}[language=Scala, numbers=none]
608
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   816
def compile_expT(a: Exp, env: Mem, name: String): Instrs = 
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   817
  ...
697
370508e4d7f6 updated
Christian Urban <urbanc@in.tum.de>
parents: 608
diff changeset
   818
  case Call(n, args) => if (name == n)
608
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   819
  {
697
370508e4d7f6 updated
Christian Urban <urbanc@in.tum.de>
parents: 608
diff changeset
   820
    val stores =
370508e4d7f6 updated
Christian Urban <urbanc@in.tum.de>
parents: 608
diff changeset
   821
      args.zipWithIndex.map { case (x, y) => i"istore $y" } 
370508e4d7f6 updated
Christian Urban <urbanc@in.tum.de>
parents: 608
diff changeset
   822
370508e4d7f6 updated
Christian Urban <urbanc@in.tum.de>
parents: 608
diff changeset
   823
    args.map(a => compile_expT(a, env, "")).mkString ++
370508e4d7f6 updated
Christian Urban <urbanc@in.tum.de>
parents: 608
diff changeset
   824
    stores.reverse.mkString ++ 
370508e4d7f6 updated
Christian Urban <urbanc@in.tum.de>
parents: 608
diff changeset
   825
    i"goto ${n}_Start" 
370508e4d7f6 updated
Christian Urban <urbanc@in.tum.de>
parents: 608
diff changeset
   826
  } else {
608
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   827
    val is = "I" * args.length
697
370508e4d7f6 updated
Christian Urban <urbanc@in.tum.de>
parents: 608
diff changeset
   828
    args.map(a => compile_expT(a, env, "")).mkString ++
370508e4d7f6 updated
Christian Urban <urbanc@in.tum.de>
parents: 608
diff changeset
   829
    i"invokestatic XXX/XXX/${n}(${is})I"
608
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   830
  }
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   831
\end{lstlisting}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   832
\end{textblock}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   833
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   834
\end{frame}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   835
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   836
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   837
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   838
  \begin{frame}[c]
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   839
  \frametitle{Dijkstra on Testing}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   840
  
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   841
  \begin{bubble}[10cm]
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   842
  ``Program testing can be a very effective way to show the
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   843
  presence of bugs, but it is hopelessly inadequate for showing
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   844
  their absence.''
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   845
  \end{bubble}\bigskip
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   846
  
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   847
  \small
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   848
  What is good about compilers: the either seem to work,
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   849
  or go horribly wrong (most of the time).
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   850
  
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   851
  \end{frame}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   852
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   853
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   854
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   855
\begin{frame}[c]
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   856
\frametitle{\Large Proving Programs to be Correct}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   857
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   858
\begin{bubble}[10cm]
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   859
\small
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   860
{\bf Theorem:} There are infinitely many prime 
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   861
numbers.\medskip\\
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   862
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   863
{\bf Proof} \ldots\\
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   864
\end{bubble}\bigskip
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   865
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   866
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   867
similarly\bigskip
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   868
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   869
\begin{bubble}[10cm]
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   870
\small
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   871
{\bf Theorem:} The program is doing what 
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   872
it is supposed to be doing.\medskip
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   873
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   874
{\bf Long, long proof} \ldots\\
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   875
\end{bubble}\bigskip\medskip
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   876
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   877
\small This can be a gigantic proof. The only hope is to have
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   878
help from the computer. `Program' is here to be understood to be
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   879
quite general (compiler, OS, \ldots).
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   880
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   881
\end{frame}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   882
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   883
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   884
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   885
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%     
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   886
\begin{frame}[c]
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   887
\frametitle{Can This Be Done?}
196
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   888
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   889
\begin{itemize}
608
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   890
\item in 2008, verification of a small C-compiler
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   891
\begin{itemize}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   892
\item ``if my input program has a certain behaviour, then the compiled machine code has the same behaviour''
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   893
\item is as good as \texttt{gcc -O1}, but much, much less buggy 
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   894
\end{itemize}
196
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   895
\end{itemize}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   896
608
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   897
\begin{center}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   898
  \includegraphics[scale=0.12]{../pics/compcert.png}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   899
\end{center}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   900
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   901
\end{frame}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   902
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%     
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   903
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   904
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%     
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   905
\begin{frame}[c]
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   906
\frametitle{Fuzzy Testing C-Compilers}
196
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   907
608
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   908
\begin{itemize}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   909
\item tested GCC, LLVM and others by randomly generating 
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   910
C-programs
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   911
\item found more than 300 bugs in GCC and also
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   912
many in LLVM (some of them highest-level critical)\bigskip
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   913
\item about CompCert:
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   914
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   915
\begin{bubble}[10cm]\small ``The striking thing about our CompCert
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   916
results is that the middle-end bugs we found in all other
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   917
compilers are absent. As of early 2011, the under-development
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   918
version of CompCert is the only compiler we have tested for
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   919
which Csmith cannot find wrong-code errors. This is not for
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   920
lack of trying: we have devoted about six CPU-years to the
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   921
task.'' 
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   922
\end{bubble} 
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   923
\end{itemize}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   924
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   925
\end{frame}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   926
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%     
196
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   927
697
370508e4d7f6 updated
Christian Urban <urbanc@in.tum.de>
parents: 608
diff changeset
   928
817
89f9c68fc417 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 814
diff changeset
   929
\begin{frame}<1-13>
89f9c68fc417 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 814
diff changeset
   930
\end{frame}  
697
370508e4d7f6 updated
Christian Urban <urbanc@in.tum.de>
parents: 608
diff changeset
   931
65
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   932
\end{document}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   933
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   934
%%% Local Variables:  
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   935
%%% mode: latex
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   936
%%% TeX-master: t
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   937
%%% End: 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   938