writinnnnnng

This commit is contained in:
2024-07-09 08:22:23 +00:00
parent 1b7f772e1d
commit b36ef5eb52
2 changed files with 72 additions and 20 deletions

View File

@@ -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}

View File

@@ -1,11 +1,11 @@
@article{arias2021,
@inproceedings{arias2021,
title = {The {{W-calculus}}: {{A Synchronous Framework}} for the {{Verified Modelling}} of {{Digital Signal Processing Algorithms}}},
author = {Arias, Emilio Jesús Gallego and Jouvelot, Pierre and Ribstein, Sylvain and Desblancs, Dorian},
date = {2021-08-22},
journaltitle = {Proceedings of the 9th ACM SIGPLAN International Workshop on Functional Art, Music, Modelling, and Design},
year= {2021},
booktitle = {Proceedings of the 9th ACM SIGPLAN International Workshop on Functional Art, Music, Modelling, and Design},
volume = {12},
pages = {35--46},
publisher = {ACM},
publisher = {Association for Computing Machinery},
location = {New York, NY, USA},
doi = {10.1145/3471872.3472970},
url = {https://hal-mines-paristech.archives-ouvertes.fr/hal-03322174},
@@ -19,7 +19,7 @@
title = {{{OUTSIDE THE BLOCK SYNDICATE}}: {{TRANSLATING FAUST}}'{{S ALGEBRA OF BLOCKS TO THE ARROWS FRAMEWORK}}},
booktitle = {Proceedings of the 1st {{International Faust Conference}}},
author = {Gaster, Benedict R and Renney, Nathan and Mitchell, Tom},
date = {2018},
year = {2018},
location = {Mainz,Germany},
abstract = {Folklore has it that Faust's algebra of blocks can be represented in Hughes' algebra of Arrows. In this paper we formalise this understanding, showing that blocks can indeed be encoded with Causal Commutative Arrows. Whilst an interesting finding in itself, we believe that this formal translation opens up new avenues of research. For instance, recent work in functional reactive programming on well typed clocks, could provide an alternative to the dependent type approach proposed for multi-rate Faust.},
file = {/Users/tomoya/Zotero/storage/6X7SPZEM/full-text.pdf}
@@ -29,26 +29,37 @@
title = {Term {{Rewriting Extension}} for the {{Faust Programming Language}}},
booktitle = {International {{Linux Audio Conference}}},
author = {Gräf, Albert},
date = {2010},
year = {2010},
url = {https://hal.archives-ouvertes.fr/hal-03162973 https://hal.archives-ouvertes.fr/hal-03162973/document},
abstract = {This paper discusses a term rewriting extension for the functional signal processing language Faust. The extension equips Faust with a hygienic macro processing facility. Faust macros can be used to define complicated, parameterized block diagrams, and perform arbitrary symbolic manipulations of block diagrams. Thus they make it easier to create elaborate signal processor specifications involving many complicated components.},
keywords = {Digital signal processing,Faust,functional programming,macro processing,term rewriting},
file = {/Users/tomoya/Zotero/storage/KXEWFSGX/full-text.pdf}
}
@inproceedings{Matsuura2021,
title = {Mimium: {{A Self-Extensible Programming Language}} for {{Sound}} and {{Music}}},
booktitle = {{{FARM}} 2021 - {{Proceedings}} of the {{ACM SIGPLAN International Workshop}} on {{Functional Art}}, {{Music}}, {{Modeling}}, and {{Design}}},
@inproceedings{matsuura2021a,
title = {Mimium: A Self-Extensible Programming Language for Sound and Music},
shorttitle = {Mimium},
booktitle = {Proceedings of the 9th {{ACM SIGPLAN International Workshop}} on {{Functional Art}}, {{Music}}, {{Modelling}}, and {{Design}}},
author = {Matsuura, Tomoya and Jo, Kazuhiro},
date = {2021},
doi = {10.1145/3471872.3472969}
year = {2021},
month = aug,
series = {{{FARM}} 2021},
pages = {1--12},
publisher = {Association for Computing Machinery},
address = {New York, NY, USA},
doi = {10.1145/3471872.3472969},
urldate = {2024-07-09},
abstract = {We propose a programming language for music named mimium, which combines temporal-discrete control and signal processing in a single language. mimium has an intuitive imperative syntax and can use stateful functions as Unit Generator in the same way as ordinary function definitions and applications. Furthermore, the runtime performance is made equivalent to that of lower-level languages by compiling the code through the LLVM compiler infrastructure. By using the strategy of adding a minimum number of features for sound to the design and implementation of a general-purpose functional language, mimium is expected to lower the learning cost for users, simplify the implementation of compilers, and increase the self-extensibility of the language. In this paper, we present the basic language specification, semantics for simple task scheduling, the semantics for stateful functions, and the compilation process. mimium has certain specifications that have not been achieved in existing languages. Future works suggested include extending the compiler functionality to combine task scheduling with the functional paradigm and introducing multi-stage computation for parametric replication of stateful functions.},
isbn = {978-1-4503-8613-5},
file = {/Users/tomoya/Zotero/storage/TDBLJQTL/Matsuura and Jo - 2021 - mimium a self-extensible programming language for.pdf}
}
@article{norilo2015,
title = {Kronos: {{A Declarative Metaprogramming Language}} for {{Digital Signal Processing}}},
author = {Norilo, Vesa},
date = {2015},
journaltitle = {Computer Music Journal},
year = {2015},
journal = {Computer Music Journal},
volume = {39},
number = {4},
pages = {30--48},
@@ -61,8 +72,8 @@
@article{Orlarey2004,
title = {Syntactical and Semantical Aspects of {{Faust}}},
author = {Orlarey, Y. and Fober, D. and Letz, S.},
date = {2004},
journaltitle = {Soft Computing},
year = {2004},
journal = {Soft Computing},
volume = {8},
number = {9},
pages = {623--632},