|
@@ -5444,21 +5444,21 @@ for the compilation of $R_3$.
|
|
|
\chapter{Functions}
|
|
|
\label{ch:functions}
|
|
|
|
|
|
-This chapter studies the compilation of functions (aka. procedures) at
|
|
|
-the level of abstraction of the C language. This corresponds to a
|
|
|
-subset of Typed Racket in which only top-level function definitions
|
|
|
-are allowed. This abstraction level is an important stepping stone to
|
|
|
-implementing lexically-scoped functions in the form of \key{lambda}
|
|
|
-abstractions (Chapter~\ref{ch:lambdas}).
|
|
|
+This chapter studies the compilation of functions at the level of
|
|
|
+abstraction of the C language. This corresponds to a subset of Typed
|
|
|
+Racket in which only top-level function definitions are allowed. These
|
|
|
+kind of functions are an important stepping stone to implementing
|
|
|
+lexically-scoped functions in the form of \key{lambda} abstractions,
|
|
|
+which is the topic of Chapter~\ref{ch:lambdas}.
|
|
|
|
|
|
\section{The $R_4$ Language}
|
|
|
|
|
|
-The syntax for function definitions and function application
|
|
|
-(aka. function call) is shown in Figure~\ref{fig:r4-syntax}, where we
|
|
|
-define the $R_4$ language. Programs in $R_4$ start with zero or more
|
|
|
-function definitions. The function names from these definitions are
|
|
|
-in-scope for the entire program, including all other function
|
|
|
-definitions (so the ordering of function definitions does not matter).
|
|
|
+The syntax for function definitions and function application is shown
|
|
|
+in Figure~\ref{fig:r4-syntax}, where we define the $R_4$ language.
|
|
|
+Programs in $R_4$ start with zero or more function definitions. The
|
|
|
+function names from these definitions are in-scope for the entire
|
|
|
+program, including all other function definitions (so the ordering of
|
|
|
+function definitions does not matter).
|
|
|
|
|
|
Functions are first-class in the sense that a function pointer is data
|
|
|
and can be stored in memory or passed as a parameter to another
|
|
@@ -5472,7 +5472,7 @@ these functions (with respect to Racket functions) is that they are
|
|
|
not lexically scoped. That is, the only external entities that can be
|
|
|
referenced from inside a function body are other globally-defined
|
|
|
functions. The syntax of $R_4$ prevents functions from being nested
|
|
|
-inside each other; they can only be defined at the top level.
|
|
|
+inside each other.
|
|
|
|
|
|
\begin{figure}[tp]
|
|
|
\centering
|
|
@@ -5493,7 +5493,7 @@ inside each other; they can only be defined at the top level.
|
|
|
&\mid& \gray{(\key{vector-set!}\;\Exp\;\Int\;\Exp)\mid (\key{void})} \\
|
|
|
&\mid& (\Exp \; \Exp^{*}) \\
|
|
|
\Def &::=& (\key{define}\; (\Var \; [\Var \key{:} \Type]^{*}) \key{:} \Type \; \Exp) \\
|
|
|
- R_4 &::=& (\key{program} \; \Def^{*} \; \Exp)
|
|
|
+ R_4 &::=& (\key{program} \;\itm{info}\; \Def^{*} \; \Exp)
|
|
|
\end{array}
|
|
|
\]
|
|
|
\end{minipage}
|
|
@@ -5513,7 +5513,7 @@ that does what its name suggests. The program then applies
|
|
|
|
|
|
\begin{figure}[tbp]
|
|
|
\begin{lstlisting}
|
|
|
-(program
|
|
|
+(program ()
|
|
|
(define (map-vec [f : (Integer -> Integer)]
|
|
|
[v : (Vector Integer Integer)])
|
|
|
: (Vector Integer Integer)
|
|
@@ -5528,7 +5528,11 @@ that does what its name suggests. The program then applies
|
|
|
\end{figure}
|
|
|
|
|
|
The definitional interpreter for $R_4$ is in
|
|
|
-Figure~\ref{fig:interp-R4}.
|
|
|
+Figure~\ref{fig:interp-R4}. The case for the
|
|
|
+\code{program} form
|
|
|
+
|
|
|
+UNDER CONSTRUCTION
|
|
|
+
|
|
|
|
|
|
\begin{figure}[tp]
|
|
|
\begin{lstlisting}
|