

% add the PATH to retrieve cls and sty beamer styles files
\makeatletter
\providecommand*{\input@path}{}
\edef\input@path{{../../support/beamer/}\input@path}% prepend
\makeatother

% \documentclass{pharoslides}
% \documentclass[aspectratio=169]{pharoslides} % format 16/9
\documentclass[withvideo]{pharoslides} % format 16/9 + incrustation video

\graphicspath{{./figures/}{../}{../../support/beamer/imgs/}}

%Information to be included in the title page:
\title{Reflection: Stack as an Object}
\subtitle{}
\author{Damien Cassou, Stéphane Ducasse and Luc Fabresse}
\institute{http://stephane.ducasse.free.fr}
\date{}
\slidesid{W7S06}

\begin{document}

\frame[plain]{\titlepage}



\begin{frame}[fragile]

\frametitle{Just to Reveal a Bit of It}

To let you know that it exists

\begin{itemize}
\item On demand the stack can be turned into an object
\item We can walk but also \textbf{modify} it
\end{itemize}
\end{frame}



\begin{frame}[fragile]

\frametitle{Coding in the Debugger}

\begin{itemize}
\item When a method is not found, we may end up with a debugger
\item In the debugger, we can ask for the creation of a method on the fly
\item The system compiles on the spot a special method
\item Then it reexecutes the method
\item It raises a shouldBeImplemented exception 
\item Then you can edit the method in the debugger 
\item Then proceed and the program continues to run
\end{itemize}
\end{frame}



\begin{frame}[fragile]

\frametitle{Operation Supporting Coding in the Debugger}

\begin{itemize}
\item On the fly method definition
\item Stack navigation / manipulation
\end{itemize}
\end{frame}



\begin{frame}[fragile]

\frametitle{Stack Frame as an Object}

\begin{itemize}
\item Execution stack can be turned into a live object
\item By default the stack is not an object 
\begin{itemize}
\item Can be reified on demand
\end{itemize}

\item Support exception definitions from within the language
\item Basis for continuations and web serving
\end{itemize}
\end{frame}



\begin{frame}[fragile]

\frametitle{thisContext}

\begin{itemize}
\item \code{thisContext} is one of the three pseudovariables with \code{self} and \code{super}
\item Returns an object that represents the method activation
\item Can walk and change the stack
\item Put \code{self halt} in the code to see it and walk
\end{itemize}
\end{frame}



\begin{frame}[fragile]

\frametitle{Example: Better Deprecated Message}

We declare deprecation

\begin{listing}{}
A >> foo
   self deprecated: 'Use bar.' on: '31/12/2015' in: 'Pharo50'.
   self bar
\end{listing}

should print: 'Message foo is deprecated in Pharo50. Use bar'
\end{frame}



\begin{frame}[fragile]

\frametitle{Example: Better Deprecated Message}

\begin{listing}{}
deprecated: anExplanationString on: date in: version
	"Warn that the sending method has been deprecated"
	
	(Deprecation
		method: thisContext sender method
		explanation: anExplanationString
		on: date
		in: version) signal
\end{listing}

\code{thisContext sender method} returns compiled method \code{A\textgreater{}\textgreater{}\#foo}
\end{frame}



\begin{frame}[fragile]

\frametitle{Example: Conditional Halt and Test}

\begin{itemize}
\item How to halt a method that is heavily used?
\item How to stop execution only from a given execution flow?
\end{itemize}

\begin{listing}{}
foo 
  ...
  Halt if: #testSetInitialized
  ...
\end{listing}

Only halt if executed from \code{testSetInitialized}
\end{frame}



\begin{frame}[fragile]

\frametitle{ if: Implementation}

\begin{listing}{}
Halt class >> if: condition
  "This is the typical message to use for inserting breakpoints during debugging.
  The argument can be one of the following:
    - a block: if the Block has one arg, the calling object is bound to that.
    - an expression
    - a selector: Halt if found in the call chain"

  condition isSymbol ifTrue: [ ^ self haltIfCallChainContains: condition ].
  condition isBlock ifTrue: [ ^ self haltIfBlockWithCallingObject: condition].
  condition ifTrue: [self signal].
\end{listing}
\end{frame}



\begin{frame}[fragile]

\frametitle{How if: is implemented?}

\begin{listing}{}
Halt class >> haltIfCallChainContains: aSelector
  | cntxt |
  cntxt := thisContext.
  [ cntxt sender isNil ] whileFalse: [
    cntxt := cntxt sender. 
    (cntxt selector = aSelector) ifTrue: [ self signal ] ].
\end{listing}
\end{frame}



\begin{frame}[fragile]

\frametitle{Foundation for Innovation}

\begin{itemize}
\item Continuations
\item Seaside: Powerful dynamic web framework for dynamic web applications
\begin{itemize}
\item http://www.seaside.st
\item http://book.seaside.st
\end{itemize}

\end{itemize}
\end{frame}




% \setlength{\textwidth}{\originaltextwidth}
\setbeamertemplate{background canvas}{\insertBorderForHandout}

\begin{frame}[plain]

\begin{minipage}{\originaltextwidth}
\centering
\large


\vspace{2em}

A course by

\vspace{1em}

\hspace{-20px}\includegraphics[height=32px]{inriaLogo}\hspace{3em}\raisebox{7px}{and}\hspace{3em}\raisebox{-6px}{\includegraphics[height=30px]{logoutop}}

\vspace{2em}

in collaboration with

\vspace{1em}

\includegraphics[height=40px]{unisciellogo}\hskip 1.5em%
\raisebox{5px}{\includegraphics[height=30px]{unitlogo}}\hskip 2em%
\raisebox{8px}{\includegraphics[height=24px]{univLilleLogo}}\hskip 2em%
\raisebox{3px}{\includegraphics[height=29px]{logo-IMT}}\hskip 2em%
\raisebox{1px}{\includegraphics[height=32px]{minesDouaiLogo}}

\vspace{2.5em}

\includegraphics[width=50px]{by-nc-nd} \tiny \hskip 0.5em \raisebox{5px}{Inria 2016}

\medskip

\tiny
Except where otherwise noted, this work is licensed under CC BY-NC-ND 3.0 France

\url{https://creativecommons.org/licenses/by-nc-nd/3.0/fr/} 

\end{minipage}
\end{frame}

\end{document}

%%% Local Variables:
%%% mode: latex
%%% TeX-master: t
%%% End:
