writinnnnnng
This commit is contained in:
51
src/main.tex
51
src/main.tex
@@ -269,24 +269,65 @@ The operational semantics of the \lambdammm is shown in Fig.\ref{fig:semantics}.
|
||||
\section{VM Model and Instruction Set}
|
||||
\label{sec:vm}
|
||||
|
||||
A model for the virtual machine and its instruction set is based on Lua 5.0\cite{ierusalimschy2005}. \textit{upvalue}
|
||||
A model for the virtual machine and its instruction to run \lambdammm set is based on Lua 5.0\cite{ierusalimschy2005}.
|
||||
|
||||
When executing a computational model based on lambda calculus, the problem is how to handle a data structure called a closure that captures the variable environment where the inner function is defined, to refer the outer variables from the inner function context. If the dictionary data of names and values of variables are paired with inner function, implementation of the compiler(intepreter) is simple, but run-time performance is limited.
|
||||
|
||||
On the contrary, a runtime performance can be improved by performing a process called closure transformation (or lambda lifting), which analyses all the names of outer variables referred by the inner function and transforms the inner function by adding argument so that the variables can be referred explicitly, but the compiler implementation of the transformation is relatively complex.
|
||||
|
||||
The Lua VM takes an intermediate approach between these two by adding the VM instructions \textit{GetUpValue/SetUpValue}, which allows the outer variables to be referenced dynamically at runtime. The implementation of compiler and VM using \textit{UpValue} is simpler than closure conversion, while at the same time preventing execution performance degradation, as outer variables can be referenced via the call stack rather than on the heap memory while the closure object is executed in the context of the original function\cite{nystrom2021}.
|
||||
The Lua VM takes an intermediate approach between these two by adding the VM instructions \textit{GetUpValue/SetUpValue}, which allows the outer variables to be referenced dynamically at runtime. The implementation of compiler and VM using \textit{UpValue} is simpler than closure conversion, while at the same time preventing execution performance degradation, as outer variables can be referenced via the call stack rather than on the heap memory unless the closure object escapes from the context of the original function\cite{nystrom2021}.
|
||||
|
||||
|
||||
\subsection{Instruction Set}
|
||||
\label{sec:instruction}
|
||||
|
||||
VM Instructions for \lambdammm differs from Lua VM in the following respects.
|
||||
|
||||
\begin{lstlisting}[label=lst:instruction,caption=Instruction set for VM to run \lambdammm]
|
||||
\begin{enumerate}
|
||||
|
||||
Upvalue
|
||||
\item{Since mimium is a statically typed language unlike Lua, instructions for basic arithmetics are provided for each type.}
|
||||
\item{If statements are realised by a combination of two instructions, \textrm{JMP} and \textrm{JMPIFNEG}, whereas the Lua VM uses a dedicated \textrm{TEST} instruction.}
|
||||
\item{Instructions related to for loop, the \textrm{SELF} instruction used for object-oriented programming and the \textrm{TABLE}-related instructions for metadata references to variables are omitted in mimium as they are not used.}
|
||||
\item{Instructions related to list-related data structures are also omitted in this paper, as the implementation of data structures such as tuples and arrays was omitted in the description of the \lambdammm in this paper.}
|
||||
|
||||
\end{lstlisting}
|
||||
\end{enumerate}
|
||||
|
||||
Instructions in \lambdammm VM are 32bit tagged-union data that has up to 3 operands. Currently, a bit width for tag and each operands are all 8 bit\footnote[1]{Reason for this is easy to implemented on \textrm{enum} data structure on Rust, a host language of the latest mimium compiler.}.
|
||||
|
||||
The VM of \lambdammm is a register machine like the Lua VM(after version 5, although the VM has no real register but the register number simply means the offset index of call stack from the base pointer at the point of execution of the VM). The first operand of most instructions is the register number in which to store the result of the calculation.
|
||||
|
||||
|
||||
The list of instructions is shown in Fig.\ref{fig:instruction} (basic arithmetic operations are partly omitted). The notation for the instruction follows the Lua VM paper \cite[p.13]{ierusalimschy2005}. From left to right, the name of operation, a list of operands, and pseudo-code of the operation. When using each of the three operands as unsigned 8 bits, they are denoted as \texttt{A B C}. When used with a signed integer, prefix \texttt{s} is added, and when the two operand fields are used as one 16 bits, an suffix \texttt{x} is added. For example, when B and C are merged and treated as signed 16 bits, they are denoted as \texttt{sBx}.
|
||||
|
||||
In pseudo-code describing an functionality, \texttt{R(A)} means that data is moved in and out through the register (call stack) according to the numerical value of the operand \texttt{A}. \texttt{K(A)} means that it retrieves the \texttt{A}-th number in the static variable field of the compiled programm. \texttt{U(A)} means that referring \texttt{A}-th Upvalue of the current function.
|
||||
|
||||
|
||||
\begin{figure*}[ht]
|
||||
\tt
|
||||
\small
|
||||
\begin{tabular}{lll}
|
||||
MOVE & A B & R(A) := R(B) \\
|
||||
MOVECONST & A B & R(A) := K(B) \\
|
||||
GETUPVALUE & A B & R(A) := U(B) \\
|
||||
SETUPVALUE & A B & U(B) := R(A) \\
|
||||
GETSTATE & A & R(A) := *SPtr \\
|
||||
SETSTATE & A & *Sptr := R(A) \\
|
||||
SHIFTSTATE & sAx & Sptr += sAx \\
|
||||
JMP & sAx & PC +=sAx \\
|
||||
JMPIFNEG & A sBx & if (R(A)<0) then PC += sBx \\
|
||||
CALL & A B C & \\
|
||||
CALLCLS & A B C & \\
|
||||
RETURN & A B & return R(A), R(A+1)...,R(A+B-2) \\
|
||||
ADDF & A B C & R(A) := R(B) as float + R(C) as float\\
|
||||
SUBF & A B C & R(A) := R(B) as float - R(C) as float\\
|
||||
MULF & A B C & R(A) := R(B) as float * R(C) as float\\
|
||||
DIVF & A B C & R(A) := R(B) as float / R(C) as float\\
|
||||
\multicolumn{3}{l}{
|
||||
\textit{...Other basic arithmetics continues for each primitive types...}
|
||||
}
|
||||
\end{tabular}
|
||||
\caption{\label{fig:instruction}{\it Instruction sets for VM to run $\lambda_{mmm}$.}}
|
||||
\end{figure*}
|
||||
|
||||
|
||||
\section{Discussion}
|
||||
|
||||
Reference in New Issue
Block a user