|
@@ -16735,8 +16735,6 @@ class InterpLdyn(InterpLlambda):
|
|
|
|
|
|
\section{Representation of Tagged Values}
|
|
|
|
|
|
-\python{UNDER CONSTRUCTION}
|
|
|
-
|
|
|
The interpreter for \LangDyn{} introduced a new kind of value, a tagged
|
|
|
value. To compile \LangDyn{} to x86 we must decide how to represent tagged
|
|
|
values at the bit level. Because almost every operation in \LangDyn{}
|
|
@@ -16746,6 +16744,7 @@ the 3 right-most bits to encode the tag. We use $001$ to identify
|
|
|
integers, $100$ for Booleans, $010$ for vectors, $011$ for procedures,
|
|
|
and $101$ for the void value. We define the following auxiliary
|
|
|
function for mapping types to tag codes.
|
|
|
+{\if\edition\racketEd
|
|
|
\begin{align*}
|
|
|
\itm{tagof}(\key{Integer}) &= 001 \\
|
|
|
\itm{tagof}(\key{Boolean}) &= 100 \\
|
|
@@ -16753,6 +16752,16 @@ function for mapping types to tag codes.
|
|
|
\itm{tagof}((\ldots \key{->} \ldots)) &= 011 \\
|
|
|
\itm{tagof}(\key{Void}) &= 101
|
|
|
\end{align*}
|
|
|
+\fi}
|
|
|
+{\if\edition\pythonEd
|
|
|
+\begin{align*}
|
|
|
+\itm{tagof}(\key{IntType()}) &= 001 \\
|
|
|
+\itm{tagof}(\key{BoolType()}) &= 100 \\
|
|
|
+\itm{tagof}(\key{TupleType(ts)}) &= 010 \\
|
|
|
+\itm{tagof}(\key{FunctionType(ps, rt)}) &= 011 \\
|
|
|
+\itm{tagof}(\key{type(None)}) &= 101
|
|
|
+\end{align*}
|
|
|
+\fi}
|
|
|
This stealing of 3 bits comes at some price: our integers are reduced
|
|
|
to ranging from $-2^{60}$ to $2^{60}$. The stealing does not adversely
|
|
|
affect vectors and procedures because those values are addresses, and
|
|
@@ -16762,15 +16771,18 @@ the rightmost 3 bits with the tag and we can simply zero-out the tag
|
|
|
to recover the original address.
|
|
|
|
|
|
To make tagged values into first-class entities, we can give them a
|
|
|
-type, called \code{Any}, and define operations such as \code{Inject}
|
|
|
-and \code{Project} for creating and using them, yielding the \LangAny{}
|
|
|
-intermediate language. We describe how to compile \LangDyn{} to \LangAny{} in
|
|
|
-Section~\ref{sec:compile-r7} but first we describe the \LangAny{} language
|
|
|
-in greater detail.
|
|
|
+type, called \racket{\code{Any}}\python{AnyType}, and define operations
|
|
|
+such as \code{Inject} and \code{Project} for creating and using them,
|
|
|
+yielding the \LangAny{} intermediate language. We describe how to
|
|
|
+compile \LangDyn{} to \LangAny{} in Section~\ref{sec:compile-r7}
|
|
|
+but first we describe the \LangAny{} language in greater detail.
|
|
|
|
|
|
\section{The \LangAny{} Language}
|
|
|
\label{sec:Rany-lang}
|
|
|
|
|
|
+\python{UNDER CONSTRUCTION}
|
|
|
+
|
|
|
+
|
|
|
\newcommand{\LAnyAST}{
|
|
|
\begin{array}{lcl}
|
|
|
\Type &::= & \key{Any} \\
|