Jeremy Siek 3 жил өмнө
parent
commit
9b67d5434b
2 өөрчлөгдсөн 54 нэмэгдсэн , 28 устгасан
  1. 50 26
      book.tex
  2. 4 2
      defs.tex

+ 50 - 26
book.tex

@@ -12626,8 +12626,6 @@ from the set.
 \label{ch:Rfun}
 \index{subject}{function}
 
-\if\edition\racketEd
-
 This chapter studies the compilation of functions similar to those
 found in the C language. This corresponds to a subset of Typed Racket
 in which only top-level function definitions are allowed. This kind of
@@ -12685,11 +12683,27 @@ inside each other.
   \end{array}
 }
 
+\newcommand{\LfunGrammarPython}{
+  \begin{array}{lcl}
+   \Type &::=& \key{Callable}\LS \LS \Type \key{, } \ldots \RS \key{, } \Type \RS \\
+   \Exp &::=& \Exp \LP \Exp \ldots\RP \\
+   \Def &::=& \CDEF{\Var}{\Var \key{:} \Type\key{, } \ldots}{\Type}{\Stmt^{+}} 
+  \end{array}
+}
+\newcommand{\LfunASTPython}{
+  \begin{array}{lcl}
+    \Type &::=& \key{FunctionType}\LP \Type^{*} \key{, } \Type \RP \\
+    \itm{arguments}&::=& 
+   \Def &::=& \FUNDEF{\Var}{\itm{arguments}}{\Type}{}{\Stmt^{+}} 
+  \end{array}
+}
+
 \begin{figure}[tp]
 \centering
 \fbox{
   \begin{minipage}{0.96\textwidth}
     \small
+{\if\edition\racketEd    
 \[
 \begin{array}{l}
   \gray{\LintGrammarRacket{}} \\ \hline
@@ -12699,26 +12713,26 @@ inside each other.
   \gray{\LtupGrammarRacket} \\   \hline
   \LfunGrammarRacket \\  
   \begin{array}{lcl}
-%%   \Type &::=& \gray{ \key{Integer} \MID \key{Boolean}
-%%          \MID (\key{Vector}\;\Type\ldots) \MID \key{Void}  } \MID (\Type \ldots \; \key{->}\; \Type) \\
-%% \itm{cmp} &::= & \gray{  \key{eq?} \MID \key{<} \MID \key{<=} \MID \key{>} \MID \key{>=}  } \\
-%%   \Exp &::=& \gray{ \Int \MID \CREAD{} \MID \CNEG{\Exp} \MID \CADD{\Exp}{\Exp} \MID \CSUB{\Exp}{\Exp} } \\
-%%     &\MID&  \gray{ \Var \MID \CLET{\Var}{\Exp}{\Exp} }\\
-%%     &\MID& \gray{ \key{\#t} \MID \key{\#f} 
-%%     \MID (\key{and}\;\Exp\;\Exp)
-%%     \MID (\key{or}\;\Exp\;\Exp)
-%%     \MID (\key{not}\;\Exp)} \\
-%%    &\MID& \gray{(\itm{cmp}\;\Exp\;\Exp) \MID \CIF{\Exp}{\Exp}{\Exp} } \\
-%%   &\MID& \gray{(\key{vector}\;\Exp\ldots) \MID
-%%     (\key{vector-ref}\;\Exp\;\Int)} \\
-%%   &\MID& \gray{(\key{vector-set!}\;\Exp\;\Int\;\Exp)\MID (\key{void})
-%%       \MID \LP\key{has-type}~\Exp~\Type\RP } \\
-%%   &\MID& \LP\Exp \; \Exp \ldots\RP \\
-%%   \Def &::=& \CDEF{\Var}{\LS\Var \key{:} \Type\RS \ldots}{\Type}{\Exp} \\
   \LangFunM{} &::=& \Def \ldots \; \Exp
   \end{array}
 \end{array}
 \]
+\fi}
+{\if\edition\pythonEd
+\[
+\begin{array}{l}
+  \gray{\LintGrammarPython{}} \\ \hline
+  \gray{\LvarGrammarPython{}} \\ \hline
+  \gray{\LifGrammarPython{}} \\ \hline
+  \gray{\LwhileGrammarPython} \\ \hline
+  \gray{\LtupGrammarPython} \\  \hline
+  \LfunGrammarPython \\
+\begin{array}{rcl}
+  \LangFunM{} &::=& \Def^{*} \Stmt^{*}
+\end{array}
+\end{array}
+\]
+\fi}
 \end{minipage}
 }
 \caption{The concrete syntax of \LangFun{}, extending \LangVec{} (Figure~\ref{fig:Lvec-concrete-syntax}).}
@@ -12730,6 +12744,7 @@ inside each other.
 \fbox{
   \begin{minipage}{0.96\textwidth}
     \small
+{\if\edition\racketEd
 \[
 \begin{array}{l}
   \gray{\LintOpAST} \\ \hline
@@ -12739,17 +12754,26 @@ inside each other.
   \gray{\LtupASTRacket{}} \\ \hline
   \LfunASTRacket \\
   \begin{array}{lcl}
-%% \Exp &::=& \gray{ \INT{\Int} \MID \VAR{\Var} \MID \LET{\Var}{\Exp}{\Exp} } \\
-%%      &\MID& \gray{ \PRIM{\itm{op}}{\Exp\ldots} }\\
-%%      &\MID& \gray{ \BOOL{\itm{bool}} 
-%%       \MID \IF{\Exp}{\Exp}{\Exp} } \\
-%%      &\MID& \gray{ \VOID{} \MID \LP\key{HasType}~\Exp~\Type \RP } 
-%%      \MID \APPLY{\Exp}{\Exp\ldots}\\
-%%  \Def &::=& \FUNDEF{\Var}{\LP[\Var \code{:} \Type]\ldots\RP}{\Type}{\code{'()}}{\Exp}\\
   \LangFunM{} &::=& \PROGRAMDEFSEXP{\code{'()}}{\LP\Def\ldots\RP)}{\Exp}
   \end{array}
 \end{array}
 \]
+\fi}
+{\if\edition\pythonEd
+\[
+\begin{array}{l}
+  \gray{\LintASTPython{}} \\ \hline
+  \gray{\LvarASTPython{}} \\ \hline
+  \gray{\LifASTPython{}} \\ \hline
+  \gray{\LwhileASTPython} \\ \hline
+  \gray{\LtupASTPython} \\  \hline
+  \LfunASTPython \\
+\begin{array}{rcl}
+  \LangFunM{} &::=& ??
+\end{array}
+\end{array}
+\]
+\fi}
 \end{minipage}
 }
 \caption{The abstract syntax of \LangFun{}, extending \LangVec{} (Figure~\ref{fig:Lvec-syntax}).}
@@ -13827,7 +13851,7 @@ mainconclusion:
 
 % Further Reading
 
-\fi % racketEd
+
 
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 \chapter{Lexically Scoped Functions}

+ 4 - 2
defs.tex

@@ -243,7 +243,6 @@
 \newcommand{\APPLY}[2]{\key{(Apply}~#1~#2\code{)}}
 \newcommand{\CALL}[2]{\key{(Call}~#1~#2\code{)}}
 \newcommand{\TAILCALL}[2]{\key{(TailCall}~#1~#2\code{)}}
-\newcommand{\FUNDEF}[5]{\key{(Def}~#1~#2~#3~#4~#5\code{)}}
 \newcommand{\FUNREF}[1]{\key{(FunRef}~#1\code{)}}
 \newcommand{\CFUNREF}[1]{\key{(fun-ref}~#1\code{)}}
 \newcommand{\FUNREFARITY}[2]{\key{(FunRefArity}~#1~#2\code{)}}
@@ -263,6 +262,7 @@
 \newcommand{\IFSTMT}[3]{\key{(IfStmt}\,#1~#2~#3\key{)}}
 \newcommand{\RETURN}[1]{\key{(Return}~#1\key{)}}
 \newcommand{\GOTO}[1]{\key{(Goto}~#1\key{)}}
+\newcommand{\FUNDEF}[5]{\key{(Def}~#1~#2~#3~#4~#5\code{)}}
 \fi
 \if\edition\pythonEd
 \newcommand{\CASSIGN}[2]{#1~\key{=}~#2}
@@ -273,6 +273,7 @@
 \newcommand{\WHILESTMT}[2]{\key{While}\LP #1 \code{, } #2 \code{, []}\RP}
 \newcommand{\RETURN}[1]{\key{Return}\LP #1 \RP}
 \newcommand{\GOTO}[1]{\key{Goto}\LP #1 \RP}
+\newcommand{\FUNDEF}[5]{\key{FunctionDef}\LP#1\key{, }#2\key{, }#3\key{, }#5\RP}
 \fi
 
 \newcommand{\SEQ}[2]{\key{(Seq}~#1~#2\key{)}}
@@ -291,6 +292,7 @@
 \newcommand{\RETQ}{\key{(Retq)}}
 \newcommand{\XPROGRAM}[2]{\LP\code{X86Program}~#1~#2\RP}
 \newcommand{\BYTEREG}[1]{\key{(ByteReg}~#1\key{)}}
+\newcommand{\CDEF}[4]{\LP\key{define}~\LP#1~#2\RP\,\key{:}\,#3~#4\RP}
 \fi
 \if\edition\pythonEd
 \newcommand{\IMM}[1]{\key{Constant}\LP #1\RP}
@@ -307,12 +309,12 @@
 % TODO: change \XPROGRAM to 1 parameter
 \newcommand{\XPROGRAM}[2]{\code{X86Program}\LP #2 \RP}
 \newcommand{\BYTEREG}[1]{\key{ByteReg}\LP #1 \RP}
+\newcommand{\CDEF}[4]{\key{def}~#1\LP #2 \RP ~\key{->}~ #3 \key{:}~#4}
 \fi
 
 
 
 \newcommand{\DEF}[5]{\LP\key{Def}~#1~#2~#3~#4~#5\RP}
-\newcommand{\CDEF}[4]{\LP\key{define}~\LP#1~#2\RP\,\key{:}\,#3~#4\RP}
 \newcommand{\CGDEF}[4]{\LP\key{define}~\LP#1~#2\RP\,#3~#4\RP}
 \newcommand{\DECL}[2]{\LP\key{Decl}~#1~#2\RP}
 \newcommand{\INST}[3]{\LP\key{Inst}~#1~#2~#3\RP}