363 |
363 |
364 \end{frame} |
364 \end{frame} |
365 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
365 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
366 |
366 |
367 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
367 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
368 \begin{frame}[t] |
|
369 \frametitle{Compiling Statements} |
|
370 |
|
371 We return a list of instructions and an environment for the |
|
372 variables |
|
373 |
|
374 \begin{center} |
|
375 \bl{\begin{tabular}{@{}l@{\hspace{1mm}}c@{\hspace{1mm}}l@{}} |
|
376 $\text{compile}(\text{skip}, E)$ & $\dn$ & $(\textit{Nil}, E)$\bigskip\\ |
|
377 $\text{compile}(x := a, E)$ & $\dn$\\ |
|
378 \multicolumn{3}{l}{$(\text{compile}(a, E) \;@\;\text{istore}\;index, E(x\mapsto index))$}\\ |
|
379 \end{tabular}} |
|
380 \end{center}\medskip |
|
381 |
|
382 where \bl{$index$} is \bl{$E(x)$} if it is already defined, |
|
383 or if it is not then the largest index not yet seen |
|
384 |
|
385 \end{frame} |
|
386 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
387 |
|
388 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
389 \mode<presentation>{ |
|
390 \begin{frame}[t] |
|
391 \frametitle{\begin{tabular}{c}Compiling AExps\end{tabular}} |
|
392 |
|
393 {\Large\bl{$x := x + 1$}} |
|
394 |
|
395 \begin{center} |
|
396 \bl{\begin{tabular}{l} |
|
397 iload $n_x$\\ |
|
398 ldc 1\\ |
|
399 iadd\\ |
|
400 istore $n_x$\\ |
|
401 \end{tabular}} |
|
402 \end{center} |
|
403 |
|
404 where \bl{$n_x$} is the index corresponding to the variable \bl{$x$} |
|
405 |
|
406 \end{frame}} |
|
407 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
408 |
|
409 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
410 \begin{frame}[c, fragile] |
368 \begin{frame}[c, fragile] |
411 \frametitle{Mathematical Functions} |
369 \frametitle{Mathematical Functions} |
412 |
370 |
413 Compilation of some mathematical functions: |
371 Compilation of some mathematical functions: |
414 |
372 |
424 |
382 |
425 \end{frame} |
383 \end{frame} |
426 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
384 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
427 |
385 |
428 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
386 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
429 \mode<presentation>{ |
387 \begin{frame}[t] |
430 \begin{frame}[t] |
388 \frametitle{Compiling Statements} |
431 \frametitle{\begin{tabular}{c}Compiling Ifs\end{tabular}} |
389 |
|
390 We return a list of instructions and an environment for the |
|
391 variables |
|
392 |
|
393 \begin{center} |
|
394 \bl{\begin{tabular}{@{}l@{\hspace{1mm}}c@{\hspace{1mm}}l@{}} |
|
395 $\text{compile}(\text{skip}, E)$ & $\dn$ & $(\textit{Nil}, E)$\bigskip\\ |
|
396 $\text{compile}(x := a, E)$ & $\dn$\\ |
|
397 \multicolumn{3}{l}{$(\text{compile}(a, E) \;@\;\text{istore}\;index, E(x\mapsto index))$}\\ |
|
398 \end{tabular}} |
|
399 \end{center}\medskip |
|
400 |
|
401 where \bl{$index$} is \bl{$E(x)$} if it is already defined, |
|
402 or if it is not, then the largest index not yet seen |
|
403 |
|
404 \end{frame} |
|
405 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
406 |
|
407 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
408 \begin{frame}[c] |
|
409 \frametitle{Compiling Assignments} |
|
410 |
|
411 {\Large\bl{$x := x + 1$}} |
|
412 |
|
413 \begin{center} |
|
414 \bl{\begin{tabular}{l} |
|
415 iload $n_x$\\ |
|
416 ldc 1\\ |
|
417 iadd\\ |
|
418 istore $n_x$\\ |
|
419 \end{tabular}} |
|
420 \end{center} |
|
421 |
|
422 where \bl{$n_x$} is the index corresponding to the variable~\bl{$x$} |
|
423 |
|
424 \end{frame} |
|
425 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
426 |
|
427 |
|
428 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
429 \begin{frame}[t] |
|
430 \frametitle{Compiling Ifs} |
432 |
431 |
433 {\Large\bl{$\text{if}\;b\;\text{then}\;cs_1\;\text{else}\;cs_2$}}\bigskip\bigskip |
432 {\Large\bl{$\text{if}\;b\;\text{then}\;cs_1\;\text{else}\;cs_2$}}\bigskip\bigskip |
434 |
433 |
435 \onslide<2->{Case }\only<2>{{\bf True}:}\only<3>{{\bf False}:} |
434 \onslide<2->{Case }\only<2>{{\bf True}:}\only<3>{{\bf False}:} |
436 |
435 |
461 \draw (cs2) edge [->,red, line width=1mm] (A4); |
460 \draw (cs2) edge [->,red, line width=1mm] (A4); |
462 \node [below=of cs1] {\raisebox{-5mm}{\small{}conditional jump}};} |
461 \node [below=of cs1] {\raisebox{-5mm}{\small{}conditional jump}};} |
463 \end{tikzpicture} |
462 \end{tikzpicture} |
464 \end{center} |
463 \end{center} |
465 |
464 |
466 |
465 \end{frame} |
467 \end{frame}} |
|
468 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
466 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
469 |
467 |
470 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
468 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
471 \begin{frame}[t] |
469 \begin{frame}[t] |
472 \frametitle{Conditional Jumps} |
470 \frametitle{Conditional Jumps} |
498 \end{textblock} |
496 \end{textblock} |
499 \end{frame} |
497 \end{frame} |
500 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
498 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
501 |
499 |
502 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
500 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
503 \mode<presentation>{ |
501 \begin{frame}[t] |
504 \begin{frame}[t] |
502 \frametitle{Compiling BExps} |
505 \frametitle{\begin{tabular}{c}Compiling BExps\end{tabular}} |
|
506 |
503 |
507 {\Large\bl{$a_1 = a_2$}} |
504 {\Large\bl{$a_1 = a_2$}} |
508 |
505 |
509 \begin{center} |
506 \begin{center} |
510 \bl{\begin{tabular}{lcl} |
507 \bl{\begin{tabular}{lcl} |
511 $\text{compile}(a_1 = a_2, E, lab)$ & $\dn$\\ |
508 $\text{compile}(a_1 = a_2, E, lab)$ & $\dn$\\ |
512 \multicolumn{3}{l}{$\quad\text{compile}(a_1, E) \;@\;\text{compile}(a_2, E)\;@\; \text{if\_icmpne}\;lab$} |
509 \multicolumn{3}{l}{$\quad\text{compile}(a_1, E) \;@\;\text{compile}(a_2, E)\;@\; \text{if\_icmpne}\;lab$} |
513 \end{tabular}} |
510 \end{tabular}} |
514 \end{center} |
511 \end{center} |
515 |
512 |
516 \end{frame}} |
513 \end{frame} |
517 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
514 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
518 |
515 |
519 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
516 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
520 \begin{frame}[c, fragile] |
517 \begin{frame}[c, fragile] |
521 \frametitle{Boolean Expressions} |
518 \frametitle{Boolean Expressions} |
557 \end{frame} |
554 \end{frame} |
558 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
555 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
559 |
556 |
560 |
557 |
561 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
558 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
562 \mode<presentation>{ |
559 \begin{frame}[t] |
563 \begin{frame}[t] |
560 \frametitle{Compiling Ifs} |
564 \frametitle{\begin{tabular}{c}Compiling Ifs\end{tabular}} |
|
565 |
561 |
566 {\Large\bl{if $b$ then $cs_1$ else $cs_2$}} |
562 {\Large\bl{if $b$ then $cs_1$ else $cs_2$}} |
567 |
563 |
568 \begin{center} |
564 \begin{center} |
569 \bl{\begin{tabular}{lcl} |
565 \bl{\begin{tabular}{lcl} |
579 \multicolumn{3}{l}{$\quad\phantom{(}@\;is_2$}\\ |
575 \multicolumn{3}{l}{$\quad\phantom{(}@\;is_2$}\\ |
580 \multicolumn{3}{l}{$\quad\phantom{(}@\;l_{ifend}:, E'')$}\\ |
576 \multicolumn{3}{l}{$\quad\phantom{(}@\;l_{ifend}:, E'')$}\\ |
581 \end{tabular}} |
577 \end{tabular}} |
582 \end{center} |
578 \end{center} |
583 |
579 |
584 \end{frame}} |
580 \end{frame} |
585 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
581 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
586 |
582 |
587 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
583 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
588 \mode<presentation>{ |
584 \mode<presentation>{ |
589 \begin{frame}[t] |
585 \begin{frame}[t] |