瀏覽代碼

more stuff about arity and closures

Jeremy Siek 4 年之前
父節點
當前提交
915b472e44
共有 2 個文件被更改,包括 37 次插入4 次删除
  1. 29 0
      book.tex
  2. 8 4
      defs.tex

+ 29 - 0
book.tex

@@ -8679,6 +8679,35 @@ your previously created test programs.
 
 \clearpage
 
+
+\section{Expose Allocation}
+\label{sec:expose-allocation-r5}
+
+Compile the $\CLOSURE{\itm{arity}}{\LP\Exp\ldots\RP}$ form into code
+that allocates and initializes a vector, similar to the translation of
+the \code{vector} operator in Section~\ref{sec:expose-allocation}.
+The only difference is replacing the use of
+\ALLOC{\itm{len}}{\itm{type}} with
+\ALLOCCLOS{\itm{len}}{\itm{type}}{\itm{arity}}.
+
+
+\section{Select Instructions}
+\label{sec:select-instructions-R5}
+
+Compile the \ALLOCCLOS{\itm{len}}{\itm{type}}{\itm{arity}} form
+similar to the \ALLOC{\itm{len}}{\itm{type}} form
+(Section~\ref{sec:select-instructions-gc}). The only difference is
+that you should place the \itm{arity} in the tag that is stored at
+position $0$ of the vector. Recall that in
+Section~\ref{sec:select-instructions-gc} we used the first $56$ bits
+of the 64-bit tag, but that the rest were unused. So the arity goes
+into the tag in bit positions $57$ through $63$.
+
+Compile the \code{procedure-arity} operator into a sequence of
+instructions that access the tag from position $0$ of the vector and
+shift it by $57$ bits to the right.
+
+
 \section{Challenge: Optimize Closures}
 \label{sec:optimize-closures}
 

+ 8 - 4
defs.tex

@@ -56,10 +56,14 @@
 \newcommand{\VAR}[1]{\key{(Var}\;#1\key{)}}
 \newcommand{\LET}[3]{\key{(Let}~#1~#2~#3\key{)}}
 \newcommand{\IF}[3]{\key{(If}\,#1\;#2\;#3\key{)}}
-\newcommand{\VECTOR}[1]{\key{(Prim}\;\code{'vector}\;\code{(list}\;#1^{*}\code{))}}
-\newcommand{\VECREF}[2]{\key{(Prim}\;\code{'vector-ref}\;\code{(list}\;#1\;#2\code{))}}
-\newcommand{\VECSET}[3]{\key{(Prim}\;\code{'vector-set!}\;\code{(list}\;#1\;#2\;#3\code{))}}
-\newcommand{\VECLEN}[1]{\key{(Prim}\;\code{'vector-length}\;\code{(list}\;#1\code{))}}
+\newcommand{\VECTOR}[1]{\LP\key{Prim}\;\code{'vector}\;\LP\key{list}\;#1\RP\RP}
+\newcommand{\VECREF}[2]{\LP\key{Prim}\;\code{'vector-ref}\;\LP\key{list}\;#1\;#2\RP\RP}
+\newcommand{\VECSET}[3]{\LP\key{Prim}\;\code{'vector-set!}\;\LP\key{list}\;#1\;#2\;#3\RP\RP}
+\newcommand{\VECLEN}[1]{\LP\key{Prim}\;\code{'vector-length}\;\LP\key{list}\;#1\RP\RP}
+\newcommand{\CLOSURE}[2]{\LP\key{Closure}~#1~#2\RP}
+\newcommand{\ALLOC}[2]{\LP\key{Allocate}~#1~#2\RP}
+\newcommand{\ALLOCCLOS}[3]{\LP\key{Allocate}~#1~#2~#3\RP}
+
 \newcommand{\VOID}[1]{\key{(Void)}}
 \newcommand{\APPLY}[2]{\key{(Apply}\;#1\;#2\code{)}}
 \newcommand{\CALL}[2]{\key{(Call}\;#1\;#2\code{)}}