|
@@ -18368,8 +18368,8 @@ class Tagged(Value):
|
|
\racket{The tags are \code{Integer}, \BOOLTY{}, \code{Void},
|
|
\racket{The tags are \code{Integer}, \BOOLTY{}, \code{Void},
|
|
\code{Vector}, and \code{Procedure}.}
|
|
\code{Vector}, and \code{Procedure}.}
|
|
%
|
|
%
|
|
-\python{The tags are \code{'int'}, \code{'bool'}, \code{'none'},
|
|
|
|
- \code{'tuple'}, and \code{'function'}.}
|
|
|
|
|
|
+\python{The tags are \skey{int}, \skey{bool}, \skey{none},
|
|
|
|
+ \skey{tuple}, and \skey{function}.}
|
|
%
|
|
%
|
|
Tags are closely related to types but do not always capture all the
|
|
Tags are closely related to types but do not always capture all the
|
|
information that a type does.
|
|
information that a type does.
|
|
@@ -18379,9 +18379,9 @@ information that a type does.
|
|
Any)} is tagged with \code{Procedure}.}
|
|
Any)} is tagged with \code{Procedure}.}
|
|
%
|
|
%
|
|
\python{For example, a tuple of type \code{TupleType([AnyType(),AnyType()])}
|
|
\python{For example, a tuple of type \code{TupleType([AnyType(),AnyType()])}
|
|
- is tagged with \code{'tuple'} and a function of type
|
|
|
|
|
|
+ is tagged with \skey{tuple} and a function of type
|
|
\code{FunctionType([AnyType(), AnyType()], AnyType())}
|
|
\code{FunctionType([AnyType(), AnyType()], AnyType())}
|
|
- is tagged with \code{'function'}.}
|
|
|
|
|
|
+ is tagged with \skey{function}.}
|
|
|
|
|
|
Next consider the match case for accessing the element of a tuple.
|
|
Next consider the match case for accessing the element of a tuple.
|
|
The \racket{\code{check-tag}}\python{\code{untag}} auxiliary function
|
|
The \racket{\code{check-tag}}\python{\code{untag}} auxiliary function
|
|
@@ -18460,7 +18460,7 @@ length of the vector.
|
|
\end{lstlisting}
|
|
\end{lstlisting}
|
|
\fi}
|
|
\fi}
|
|
{\if\edition\pythonEd\pythonColor
|
|
{\if\edition\pythonEd\pythonColor
|
|
-\begin{lstlisting}[basicstyle=\ttfamily\footnotesize]
|
|
|
|
|
|
+\begin{lstlisting}[basicstyle=\ttfamily\scriptsize]
|
|
class InterpLdyn(InterpLlambda):
|
|
class InterpLdyn(InterpLlambda):
|
|
def interp_exp(self, e, env):
|
|
def interp_exp(self, e, env):
|
|
match e:
|
|
match e:
|
|
@@ -18739,15 +18739,15 @@ section~\ref{sec:compile-r7}; in the next section we describe the
|
|
\MID \key{TupleType}\LS\key{AnyType()}^+\RS \\
|
|
\MID \key{TupleType}\LS\key{AnyType()}^+\RS \\
|
|
&\MID& \key{FunctionType}\LP \key{AnyType()}^{*}\key{, }\key{AnyType()}\RP \\
|
|
&\MID& \key{FunctionType}\LP \key{AnyType()}^{*}\key{, }\key{AnyType()}\RP \\
|
|
\Exp & ::= & \INJECT{\Exp}{\FType} \MID \PROJECT{\Exp}{\FType} \\
|
|
\Exp & ::= & \INJECT{\Exp}{\FType} \MID \PROJECT{\Exp}{\FType} \\
|
|
- &\MID& \CALL{\VAR{\key{'any\_tuple\_load'}}}{\LS\Exp\key{, }\Exp\RS}\\
|
|
|
|
- &\MID& \CALL{\VAR{\key{'any\_len'}}}{\LS\Exp\RS} \\
|
|
|
|
- &\MID& \CALL{\VAR{\key{'arity'}}}{\LS\Exp\RS} \\
|
|
|
|
- &\MID& \CALL{\VAR{\key{'make\_any'}}}{\LS\Exp\key{, }\INT{\Int}\RS}
|
|
|
|
- %% &\MID& \CALL{\VAR{\key{'is\_int'}}}{\Exp}
|
|
|
|
- %% \MID \CALL{\VAR{\key{'is\_bool'}}}{\Exp} \\
|
|
|
|
- %% &\MID& \CALL{\VAR{\key{'is\_none'}}}{\Exp}
|
|
|
|
- %% \MID \CALL{\VAR{\key{'is\_tuple'}}}{\Exp} \\
|
|
|
|
- %% &\MID& \CALL{\VAR{\key{'is\_function'}}}{\Exp}
|
|
|
|
|
|
+ &\MID& \CALL{\VAR{\skey{any\_tuple\_load}}}{\LS\Exp\key{, }\Exp\RS}\\
|
|
|
|
+ &\MID& \CALL{\VAR{\skey{any\_len}}}{\LS\Exp\RS} \\
|
|
|
|
+ &\MID& \CALL{\VAR{\skey{arity}}}{\LS\Exp\RS} \\
|
|
|
|
+ &\MID& \CALL{\VAR{\skey{make\_any}}}{\LS\Exp\key{, }\INT{\Int}\RS}
|
|
|
|
+ %% &\MID& \CALL{\VAR{\skey{is\_int}}}{\Exp}
|
|
|
|
+ %% \MID \CALL{\VAR{\skey{is\_bool}}}{\Exp} \\
|
|
|
|
+ %% &\MID& \CALL{\VAR{\skey{is\_none}}}{\Exp}
|
|
|
|
+ %% \MID \CALL{\VAR{\skey{is\_tuple}}}{\Exp} \\
|
|
|
|
+ %% &\MID& \CALL{\VAR{\skey{is\_function}}}{\Exp}
|
|
\end{array}
|
|
\end{array}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -19443,7 +19443,7 @@ To perform these actions we need two new AST classes: \code{TagOf} and
|
|
\code{ValueOf}. The \code{TagOf} operation retrieves the type tag from a
|
|
\code{ValueOf}. The \code{TagOf} operation retrieves the type tag from a
|
|
tagged value of type \ANYTY{}. The \code{ValueOf} operation retrieves
|
|
tagged value of type \ANYTY{}. The \code{ValueOf} operation retrieves
|
|
the underlying value from a tagged value. The \code{ValueOf}
|
|
the underlying value from a tagged value. The \code{ValueOf}
|
|
-operation includes the type for the underlying value which is used by
|
|
|
|
|
|
+operation includes the type for the underlying value that is used by
|
|
the type checker.
|
|
the type checker.
|
|
%
|
|
%
|
|
\fi}
|
|
\fi}
|
|
@@ -19511,8 +19511,8 @@ bidirectional type checking because we no longer have an expected type
|
|
to use for type checking the expression $e'$. Thus, we run into
|
|
to use for type checking the expression $e'$. Thus, we run into
|
|
difficulty if $e'$ is a \code{Lambda} expression. We recommend
|
|
difficulty if $e'$ is a \code{Lambda} expression. We recommend
|
|
translating \code{Lambda} to a new AST class \code{AnnLambda} (for
|
|
translating \code{Lambda} to a new AST class \code{AnnLambda} (for
|
|
-annotated lambda) whose parameters have type annotations and that
|
|
|
|
-records the return type.
|
|
|
|
|
|
+annotated lambda), that contains its return type and the types of its
|
|
|
|
+parameters.
|
|
%
|
|
%
|
|
\fi}
|
|
\fi}
|
|
|
|
|
|
@@ -19551,7 +19551,7 @@ translated in a similar way:
|
|
The \code{any\_tuple\_load} operation combines the projection action
|
|
The \code{any\_tuple\_load} operation combines the projection action
|
|
with the load operation. Also, the load operation allows arbitrary
|
|
with the load operation. Also, the load operation allows arbitrary
|
|
expressions for the index so the type checker for \LangAny{}
|
|
expressions for the index so the type checker for \LangAny{}
|
|
-(figure~\ref{fig:type-check-Lany}) cannot guarantee that the index is
|
|
|
|
|
|
+(figure~\ref{fig:type-check-Lany}) cannot guarantee that the index, is
|
|
within bounds. Thus, we insert code to perform bounds checking at
|
|
within bounds. Thus, we insert code to perform bounds checking at
|
|
runtime. The translation for \code{any\_tuple\_load} is as follows.
|
|
runtime. The translation for \code{any\_tuple\_load} is as follows.
|
|
|
|
|
|
@@ -19605,21 +19605,19 @@ whose syntax definition is shown in figure~\ref{fig:c5-syntax}.
|
|
\code{vector-set!} is an $\Atm$, instead of an integer as it was in
|
|
\code{vector-set!} is an $\Atm$, instead of an integer as it was in
|
|
\LangCVec{} (figure~\ref{fig:c2-syntax}).}
|
|
\LangCVec{} (figure~\ref{fig:c2-syntax}).}
|
|
%
|
|
%
|
|
-\python{
|
|
|
|
- Update the auxiliary functions \code{explicate\_tail}, \code{explicate\_effect},
|
|
|
|
- and \code{explicate\_pred} as appropriately to handle the new expressions
|
|
|
|
- in \LangCAny{}.
|
|
|
|
-}
|
|
|
|
|
|
+\python{Update the auxiliary functions \code{explicate\_tail},
|
|
|
|
+ \code{explicate\_effect}, and \code{explicate\_pred} as
|
|
|
|
+ appropriate to handle the new expressions in \LangCAny{}. }
|
|
|
|
|
|
|
|
|
|
\newcommand{\CanyASTPython}{
|
|
\newcommand{\CanyASTPython}{
|
|
\begin{array}{lcl}
|
|
\begin{array}{lcl}
|
|
-\Exp &::=& \CALL{\VAR{\key{'make\_any'}}}{\LS \Atm,\Atm \RS}\\
|
|
|
|
|
|
+\Exp &::=& \CALL{\VAR{\skey{make\_any}}}{\LS \Atm,\Atm \RS}\\
|
|
&\MID& \key{TagOf}\LP \Atm \RP
|
|
&\MID& \key{TagOf}\LP \Atm \RP
|
|
\MID \key{ValueOf}\LP \Atm , \FType \RP \\
|
|
\MID \key{ValueOf}\LP \Atm , \FType \RP \\
|
|
- &\MID& \CALL{\VAR{\key{'any\_tuple\_load\_unsafe'}}}{\LS \Atm,\Atm \RS}\\
|
|
|
|
- &\MID& \CALL{\VAR{\key{'any\_len'}}}{\LS \Atm \RS} \\
|
|
|
|
- &\MID& \CALL{\VAR{\key{'exit'}}}{\LS\RS}
|
|
|
|
|
|
+ &\MID& \CALL{\VAR{\skey{any\_tuple\_load\_unsafe}}}{\LS \Atm,\Atm \RS}\\
|
|
|
|
+ &\MID& \CALL{\VAR{\skey{any\_len}}}{\LS \Atm \RS} \\
|
|
|
|
+ &\MID& \CALL{\VAR{\skey{exit}}}{\LS\RS}
|
|
\end{array}
|
|
\end{array}
|
|
}
|
|
}
|
|
|
|
|