
\documentstyle[12pt]{article}
\input mssymb                                 
\input /jj/kt/tex/fixqmsfonts
\input /jj/kt/tex/laktex
\input /jj/kt/tex/illustrations
\input /var/arvind/idcompiler/macros/prelude


\pagestyle{empty}

\begin{document}


\blank
\noindent
{\large
$\begin{array}{ll}
{\tt TE}[\![X]\!] = X \;\; & \;\;
\end{array}$\\
}

\blank
\noindent
{\large
$\begin{array}{ll}
{\tt TE}[\![C]\!] = C 
\end{array}$ \\
}



\blank
\noindent
{\large
$\begin{array}{ll}
{\tt TE}[\![{\sf Negate} \; (X) ]\!] = {\sf Negate} \; (X)  
\end{array}$ 
}\\


\blank
\noindent
{\large
$\begin{array}{lll}
{\tt TE}[\![ {\sf +}\; (X, \; Y) ]\!]  & = & {\sf +} \; (X, \; Y)
\end{array}$\\
}

\blank
\noindent
{\large
$\begin{array}{lll}
{\tt TE}[\![ {\sf WLoop_m}\; (P, \; B, \; \mv{X_m}, \; X_b) ]\!]  & = & {\sf WLoop_m}\; (P, \; B, \; \mv{X_m}, \; X_b)
\end{array}$\\
}


\blank
\noindent
{\large
$\begin{array}{lll}
{\tt TE}[\![ {\sf Bool\_case_m} \; (X, \;  E_1, \; E_2 ) ]\!] & = &
\{_{\sf m}\; \begin{array}[t]{lll}
 t & = & BooltoInt \; (X); \\
 \mv{t_m} & = & {\sf Dispatch_{2,m}} \; (t,\; E_1, \; E_2);\\ 
\multicolumn{3}{l}{ \;\; {\sf In} \; \mv{t_m} \}}
\end{array}
\end{array}$
}\\



\blank
\noindent
{\large
$\begin{array}{lll}
{\tt TE}[\![ \{_{\sf m} \; X_1 = E_1;\; \cdots \; X_n = E_n;\;
                S_1;\; \cdots \; S_m \;  {\sf In} \;\mv{Y_m} \; \}]\!] & = &
\{_{\sf m} \; \begin{array}[t]{lll}
X_1 & = & {\tt TE}[\![E_1]\!];\\
\multicolumn{3}{l}{ \;\;\;\vdots}\\
X_n & = &  {\tt TE}[\![E_n]\!];\\
\multicolumn{3}{l}{ \;\; {\tt TS}[\![S_1]\!]; }\\
\multicolumn{3}{l}{ \;\;\;\vdots}\\
\multicolumn{3}{l}{ \;\; {\tt TS}[\![ S_m ]\!]; }\\
\multicolumn{3}{l}{ \;\;{\sf In}\;\;\mv{Y_m} \;  \} }
\end{array}
\end{array}$ \\
}

\newpage


\illustration{tuple}{1.5in}

\blank
\noindent
{\large
$\begin{array}{lll}
{\tt TE}[\![ {\sf Make\_tuple_n} \; (\mv{X_n}) ]\!] &  = &
\begin{array}[t]{l}
\{ t = {\sf Allocate} \; (\underline{n+1});\\
\; \; {\sf P\_store} \;  (t, \; {\sf Type}, \; ``n\_tuple"); \\
\; \; {\sf P\_store} \; ( t, \; 1 ,\; X_1); \\
\;\;\; \vdots \\
\;\; {\sf P\_store} \; (t, \; \underline{n}, \; X_n); \\
\;\;\;\; {\sf In} \;  t \}
\end{array}
\end{array}$
}


\blank
\noindent
{\large
$\begin{array}{lll}
{\tt TE}[\![ {\sf Detuple_m} \; (X) ]\!]  & = & \{_{\sf m}
\begin{array}[t]{lll}
t_1 & = &  {\sf P\_select} \; ( X , 1) ;\\
\multicolumn{3}{l}{\;\;\;\; \vdots }\\
t_m & = & {\sf P\_select} \; (X, \underline{m}) ;\\
\multicolumn{3}{l}{ \;\; {\sf In} \; \mv{t_m} \}}
\end{array}
\end{array}$ 
}

\pagebreak


\illustration{array}{2.5in}



\blank
\noindent
{\large
$\begin{array}{ll}
{\tt TE}[\![{\sf nD\_Bounds} \; (X) ]\!] = {\sf P\_select} \; (X,\;{\sf Bounds})   
\end{array}$ \\
}



\blank
\noindent
{\large
$\begin{array}{lll}
{\tt TE} [\![  {\sf I\_array} \; (X) ]\!] & = &
\{ \begin{array}[t]{lll}
l & = & {\sf P\_select} \; ( X, \; {\sf Lower}); \\
u & = & {\sf P\_select} \; (X, \; {\sf Upper}); \\
s & = & {\sf -} \;(u,\;  l);\\
size & = & {\sf +}\;( s,\;  3); \\
t & = & {\sf Allocate} \; (size); \\
\multicolumn{3}{l}{ {\sf P\_store } \; (t, \; {\sf Type}, \; ``Array"); }\\
\multicolumn{3}{l}{ {\sf P\_store } \; (t, \; {\sf Bounds}, \; X); } \\
\multicolumn{3}{l}{ \;\;\; {\sf In} \; t   \} }
\end{array}
\end{array}$\\
}


\blank
\noindent
{\large
$\begin{array}{lll}
{\tt TE}[\![ {\sf P\_1D\_select}  \;(X_1, \; X_2 ) ]\!] &  = &
\{ \begin{array}[t]{lll}
t_b & = & {\sf P\_select}  \;(X_1, \; {\sf Bounds} );\\
l & = & {\sf P\_select}  \;(t_b, \; {\sf Lower} );\\
t_1 & = & {\sf -} \;(X_2,\;l);\\
t_2 & = & {\sf +} \;(t_1,\;{\sf Headersize});\\
t & = & {\sf P\_select}  \;(X_1, \; t_2 )\\
\multicolumn{3}{l}{\;\;\; {\sf In} \;  t \}}
\end{array}
\end{array}$\\
}


\blank
\noindent
{\large
$\begin{array}{lll}
{\tt TE}[\![ {\sf P\_1D\_store}  \;(X_1, \; X_2,\;X_3 ) ]\!] &  = &
\{ \begin{array}[t]{lll}
t_b & = & {\sf P\_select}  \;(X_1, \; {\sf Bounds} );\\
l & = & {\sf P\_select}  \;(t_b, \; {\sf Lower} );\\
t_1 & = & {\sf -} \;(X_2,\;l);\\
t_2 & = & {\sf +} \;(t_1,\;{\sf Headersize});\\
t & = & {\sf P\_store}  \;(X_1, \; t_2,\;X_3 ) \\ 
\multicolumn{3}{l}{\;\;\; {\sf In} \;  t \} }
\end{array}
\end{array}$\\
}

\newpage



\blank
\noindent
\[ \begin{array}{llllll}
{\sf First\_dim} & = & 1 & {\sf Second\_dim} & = & 2 \\
{\sf First\_index} & = & 1 & {\sf Second\_index} & = & 2 
\end{array} \]

\blank
\noindent
{\large
$\begin{array}{lll}
{\tt TE} [\![  {\sf I\_2D\_array} \; (X) ]\!] & = &
\{ \begin{array}[t]{lll}
d_1 & = & {\sf P\_select} \; ( X, \; {\sf First\_dim}); \\
d_2 & = & {\sf P\_select} \; ( X, \; {\sf Second\_dim}); \\
l_1 & = & {\sf P\_select} \; ( d_1, \; {\sf Lower}); \\
u_1 & = & {\sf P\_select} \; (d_1, \; {\sf Upper}); \\
l_2 & = & {\sf P\_select} \; ( d_2, \; {\sf Lower}); \\
u_2 & = & {\sf P\_select} \; (d_2, \; {\sf Upper}); \\
s_1 & = & {\sf -} \;( u_1,\;  l_1);\\
s_2 & = &  {\sf -} \;(u_2,\;  l_2);\\
s_1' & = & {\sf +}\;(s_1,\;  1);\\
s_2' & = &  {\sf +} \;(s_2, \;  1);\\
s & = &  {\sf *}\;(s_1',\;  s_2'); \\
size & = &  {\sf +}\;(s,\;  {\sf Headersize}); \\
t & = & {\sf Allocate} \; (size); \\
\multicolumn{3}{l}{ {\sf P\_store } \; (t, \; {\sf Type}, \; ``Array"); }\\
\multicolumn{3}{l}{ {\sf P\_store } \; (t, \; {\sf Bounds}, \; X); } \\
\multicolumn{3}{l}{ \;\;\; {\sf In} \; t   \} }
\end{array}
\end{array}$\\
}

\newpage

\blank
\noindent
{\large
$\begin{array}{lll}
{\tt TE}[\![ {\sf P\_2D\_select}  \;(X_1, \; X_2 ) ]\!] &  = &
\{ \begin{array}[t]{lll}
b & = & {\sf P\_select}\;(X_1,\;{\sf Bounds});\\
d_1 & = & {\sf P\_select}\;(b,\;{\sf First\_dim});\\
d_2 & = & {\sf P\_select}\;(b,\;{\sf Second\_dim});\\
l_1 & = & {\sf P\_select}\;(d_1,\;{\sf Lower});\\
u_1 & = & {\sf P\_select}\;(d_1,\;{\sf Upper});\\
l_2 & = & {\sf P\_select}\;(d_2,\;{\sf Lower});\\
u_2 & = & {\sf P\_select}\;(d_2,\;{\sf Upper});\\
r & = & {\sf - }\;(u_2,\;l_2);\\
r' & = & {\sf + }\;( r, \; 1);\\
i & = & {\sf P\_select}\;(X_2,\;{\sf First\_index});\\
j & = & {\sf P\_select}\;(X_2,\;{\sf Second\_index});\\
i' & = & {\sf -} \; (i,\;l_1);\\
j' & = & {\sf -} \; (j,\;l_2);\\
o & = & {\sf *} \; (i',\;r');\\
o' & = & {\sf +} \; (o,\;{\sf 1});\\
ad & = & {\sf +} \; (o,\;j');\\
ad' & = & {\sf +} \; (ad,\;{\sf Headersize});\\
t & = & {\sf P\_select}  \;(X_1, \;ad' )\\
\multicolumn{3}{l}{\;\;\; {\sf In} \;  t \} }
\end{array}
\end{array}$\\
}

\newpage

\subsection*{Lists} 

\illustration{list}{3in}


\blank
\noindent
{\large
$ {\tt TE}[\![ {\sf Nil}  ]\!] = \begin{array}[t]{l}
\{  t = {\sf Allocate} \; ({\sf Nilsize});\\
 \;\; {\sf P\_store} \;  (t, \; {\sf Type}, \; ``List"); \\
 \; \; {\sf P\_store} \; (t,  \; {\sf Tag}, \; {\sf Nil\_Tag}); \\
\;\;\;\; {\sf In} \;  t \}
\end{array}$
}\\

\blank
\noindent
{\large
$\begin{array}{lll}
{\tt TE}[\![ {\sf Open\_cons}  \;() ]\!] &  = &
\{ \begin{array}[t]{l}
t  =  {\sf Allocate} \; ({\sf Cons\_size});\\
{\sf P\_store} \;  (t, \; {\sf Type}, \; ``List"); \\
{\sf P\_store} \;  (t, \; {\sf Tag}, \; {\sf Cons\_Tag}); \\
\;\;\; {\sf In} \;  t \}
\end{array}
\end{array}$\\
}

\blank
\noindent
{\large
$\begin{array}{lll}
{\tt TE}[\![ {\sf Cons\_1} \; (X) ]\!] &  = &
 {\sf P\_select} \; (X,\;{\sf Hd})
\end{array}$\\
}

\blank
\noindent
{\large
$\begin{array}{lll}
{\tt TE}[\![ {\sf Cons\_2} \; (X) ]\!] &  = &
{\sf P\_select} \; (X,\;{\sf Tl})
\end{array}$\\
}


\blank
\noindent
{\large
$\begin{array}{lll}
{\tt TE}[\![ {\sf Cons} \; (X_1, X_2) ]\!] &  = &
\{ \begin{array}[t]{l}
t  =  {\sf Allocate} \; ({\sf Cons\_size});\\
{\sf P\_store} \;  (t, \; {\sf Type}, \; ``List"); \\
{\sf P\_store} \;  (t, \; {\sf Tag}, \; {\sf Cons\_Tag}); \\
{\sf P\_store} \; (t, \; {\sf Hd}, \; X_1); \\
{\sf P\_store} \; (t, \; {\sf Tl}, \; X_2); \\
\;\;\; {\sf In} \;  t \}
\end{array}
\end{array}$\\
}

\blank
\noindent
{\large
$\begin{array}{lll}
{\tt TS}[\![ {\sf Cons\_store\_1} \; (X_1 , X_2)  ]\!]  & = & 
\begin{array}[t]{l}
 {\sf P\_store} \; ( X_1 , {\sf Hd}, X_2)   ;\\
\end{array}
\end{array}$\\
}

\blank
\noindent
{\large
$\begin{array}{lll}
{\tt TS}[\![ {\sf Cons\_store\_2} \; (X_1 , X_2)  ]\!]  & = & 
\begin{array}[t]{l}
 {\sf P\_store} \; ( X_1 , {\sf Tl}, X_2)   ;\\
\end{array}
\end{array}$\\
}


\blank
\noindent
{\large
$\begin{array}{lll}
{\tt TE}[\![ {\sf List\_case_m} \; (X, \;  E_1, \; E_2 ) ]\!] & = &
\{_{\sf m} \begin{array}[t]{lll}
 t & = & {\sf P\_select} \;(X, \; {\sf Tag});\\
 \mv{t_m} & = & {\sf Dispatch_{2,m}} \; (t,\; E_1, \; E_2);\\ 
\multicolumn{3}{l}{ \;\; {\sf In} \; \mv{t_m} \}}
\end{array}
\end{array}$
}\\

\newpage



\illustration{closure}{2in}


\blank
\noindent
{\large
${\sf Make\_closure} = \underline{{\sf \lambda}} \; (cl, X)  \;\;  . \;\;
(\{ \begin{array}[t]{lll}
f & = & {\sf P\_select} \; (cl, \; {\sf Funcname}); \\
f_{fc} & = & {\sf P\_select} \; (cl, \; {\sf Fastcallname}); \\
n & = & {\sf P\_select} \; (cl, \; {\sf Arity}); \\
ch & = & {\sf P\_select} \; (cl, \; {\sf Chain}); \\
cl' & = & {\sf Allocate} \; ({\sf Closure\_size});\\
\multicolumn{3}{l}{ {\sf P\_store} \; (cl', \; {\sf Type}, \; ``Closure"); } \\
\multicolumn{3}{l}{{\sf P\_store} \; (cl', \; {\sf Functionname}, \; f); } \\
\multicolumn{3}{l}{ {\sf P\_store} \; (cl', \; {\sf Fastcallname},\;f_{fc});} \\
\multicolumn{3}{l}{ {\sf P\_store} \; (cl', \; {\sf Arity}, \; n');} \\
\multicolumn{3}{l}{ {\sf P\_store} \; (cl', \; {\sf Chain}, \; ch');} \\
n' & = & {\sf -}\;(n,\;1); \\ 
ch' & = & {\sf Ap_2} \;({\sf Arg\_chain} , \; X,\;ch);\\
\multicolumn{3}{l}{ \;\;\;{\sf In} \; cl' \} \; ) } 
\end{array}$\\
}

\blank
\noindent
{\large
$\begin{array}{lll}
{\sf Arg\_chain} = \underline{ {\sf \lambda} }\; ( X, Xs)  &  . &
(\; \begin{array}[t]{l}
\{ xs' = {\sf Allocate} \;(2);\\
\; \; {\sf P\_store} \; (xs', {\sf Arg}, X);\\
\; \; {\sf P\_store} \; (xs', {\sf Rest}, Xs);\\
\;\;\;{\sf In} \; xs' \} \;)
\end{array}
\end{array}$\\
}


\blank
\noindent
{\large
${\sf Args_n} = \underline{ {\sf \lambda} } \; (X)  \;\; . \;\;
(\{_{\sf n} \;  \begin{array}[t]{lll}
t_1 & = & {\sf P\_select} \; (X, \; Chain);\\ 
\;a_n & = & {\sf P\_select} \; (t_1, \; {\sf Arg});\\ 
\;t_2 & = & {\sf P\_select} \; (t_1, \; {\sf Rest});\\ 
\;a_{n-1} & = & {\sf P\_select} \; (t_2, \; {\sf Arg});\\ 
\;t_3 & = & {\sf P\_select} \; (t_2, \; {\sf Rest});\\ 
\multicolumn{3}{l}{ \;\;\;\; \vdots} \\
\;a_1 & = & {\sf P\_select} \; (t_{n-1}, \; {\sf Arg});\\
\multicolumn{3}{l}{ \;\;\;\; {\sf In} \;  \mv{a_n}  \} \; ) }  
\end{array}$ \\
}


\blank
\noindent
{\large
$\begin{array}{lll}
{\tt TE}[\![ {\sf Apply} \; (F, \; X) ]\!]  & = & \{ \begin{array}[t]{lll}
n & = & {\sf P\_select} \; (F, \;  {\sf Arity});\\
fire_b & = & {\sf Equal?} \; (n,\;  1);\\
fire_i & = & BooltoInt(fire_b); \\
res & = & {\sf Dispatch_{2,2}} \; (fire_i, \\
& & \;\;\;\;\{\begin{array}[t]{lll}
fun & = & {\sf P\_select}\; (F ,  \;{\sf Functioname});\\
as & = & {\sf P\_select} \;(F,  \;{\sf Chain});\\
as' & = & {\sf Ap_2} \; ({\sf Arg\_chain}, \; X, \;as);\\
res' & = & {\sf Ap} \; (fun, \; as');\\
\multicolumn{3}{l}{ \;\;\; {\sf In} \; res'   \}, }
\end{array}\\
&  &\;\;\;\; {\sf Ap_2} \; ({\sf Make\_closure}, \; F,\; X))\\
\multicolumn{3}{l}{ \;\;\; {\sf In} \; res   \} }
\end{array}
\end{array}$\\
}


\blank
\noindent
{\large
$\begin{array}{lll}
{\tt TE}[\![ {\sf Ap_{n,m}} \; (F, \; \mv{X}) ]\!]  & = &\{_{\sf m} \; \begin{array}[t]{lll}
f' & = & {\sf P\_select} \; (F,  {\sf Fastcallname});\\
\mv{t_m} & = & {\sf Ap_{n,m}} \;(f',\mv{X} );\\
\multicolumn{3}{l}{ \;\;\; {\sf In} \; \mv{t_m} \; \}}
\end{array}
\end{array}$\\
}


\blank
\noindent
{\large
$\begin{array}{lll}
{\tt TE}[\![ {\sf \lambda_{n}}\;  (\mv{X_n}) \; . \; (E) ]\!]  & = &
\begin{array}[t]{l}
\{ cl = {\sf Allocate} \; ({\sf Closure\_size}); \\
 \;\; {\sf P\_store} \; (cl, \; {\sf Type}, \; ``Closure");\\
 \;\; {\sf P\_store} \; (cl, \; {\sf Functioname}, \; `T_c);\\
 \;\; {\sf P\_store} \; (cl, \; {\sf Fastcallname}, \; `T_{fc});\\
 \;\; {\sf P\_store} \; (cl, \; {\sf Arity}, \; \underline{n});\\
 \;\; {\sf P\_store} \; (cl, \; {\sf Chain}, \; ``End");\\
 \;\;\;\; {\sf In} \; cl \}
\end{array} 
\end{array}$\\
}


\begin{center}
{\large
$\begin{array}{l}
 T_c =  {\sf \lambda_{1}} \;  (Xs) \;\; .\;\; 
\{ \begin{array}[t]{lll}
\mv{X_n} & = & {\sf Ap_{1,n}} \; ({\sf Args_n},\;  Xs);\\
\;\; t & = & {\tt TE}[\![E]\!]; \\
\multicolumn{3}{l}{\;\;\; {\sf In} \;  t  \} } 
\end{array}\\
T_{fc} = {\sf \lambda_{n}} \; (\mv{X_n}) \;\;  . \;\;  {\tt TE}[\![ E ]\!]
\end{array}$}
\end{center}


\end{document}
