writiiiiing

This commit is contained in:
2024-07-09 06:16:13 +00:00
parent 9672035ba3
commit 1b7f772e1d
2 changed files with 47 additions and 1 deletions

View File

@@ -251,7 +251,7 @@ Additional typing rules to usual simply-typed lambda calculus are shown in Fig.\
In the W-calculus, a starting point of designing \lambdammm, function types can takes tuples of real numbers and return tuples of real numbers. This means that higher-order functions cannot be written. While this restriction is reasonable as a design choice for a language for signal processing since higher-order functions require data structures that require dynamic memory allocation, such as closures, for their implementation, it also lacks the generality of the lambda calculus.
In \lambdammm, the problem of memory allocation for closures is left to the implementation of the runtime, and higher-order functions are allowed. However, the $feed$ abstraction does not allow function types as its input and output. Allowing the return of function types in the $feed$ abstraction means that it is possible to define functions whose processing contents change time-to-time. While this may be interesting theoritically, there are currently no practical cases in real-world signal processing, and it is expected to further complicate implementations.
In \lambdammm, the problem of memory allocation for closures is left to the implementation of the runtime in the Section\ref{sec:vm}, and higher-order functions are allowed. However, the $feed$ abstraction does not allow function types as its input and output. Allowing the return of function types in the $feed$ abstraction means that it is possible to define functions whose processing contents change time-to-time. While this may be interesting theoritically, there are currently no practical cases in real-world signal processing, and it is expected to further complicate implementations.
\input{typing.tex}
@@ -269,10 +269,24 @@ 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}
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}.
\subsection{Instruction Set}
\label{sec:instruction}
\begin{lstlisting}[label=lst:instruction,caption=Instruction set for VM to run \lambdammm]
Upvalue
\end{lstlisting}
\section{Discussion}

View File

@@ -72,3 +72,35 @@
keywords = {Compiler,Dataflow,Functional programming,Real-time,Signal processing},
file = {/Users/tomoya/Zotero/storage/YZVBLW85/Orlarey, Fober, Letz_2004_Syntactical and semantical aspects of Faust.pdf}
}
@article{ierusalimschy2005,
title = {The {{Implementation}} of {{Lua}} 5.0},
author = {Ierusalimschy, Roberto and de Figueiredo, Luiz Henrique and Celes, Waldemar},
year = {2005},
month = jul,
journal = {JUCS - Journal of Universal Computer Science},
volume = {11},
number = {7},
pages = {1159--1176},
publisher = {Journal of Universal Computer Science},
issn = {0948-6968},
doi = {10.3217/jucs-011-07-1159},
urldate = {2024-07-09},
abstract = {We discuss the main novelties of the implementation of Lua 5.0: its register-based virtual machine, the new algorithm for optimizing tables used as arrays, the implementation of closures, and the addition of coroutines.},
copyright = {2005 Roberto Ierusalimschy, Luiz Henrique de Figueiredo, Waldemar Celes},
language = {en},
file = {/Users/tomoya/Zotero/storage/GQRQSVPC/Ierusalimschy et al. - 2005 - The Implementation of Lua 5.0.pdf}
}
@book{nystrom2021,
title = {{Crafting Interpreters}},
author = {Nystrom, Robert},
year = {2021},
month = jul,
publisher = {Genever Benning},
address = {Daryaganj Delhi},
abstract = {Despite using them every day, most software engineers know little about how programming languages are designed and implemented. For many, their only experience with that corner of computer science was a terrifying "compilers" class that they suffered through in undergrad and tried to blot from their memory as soon as they had scribbled their last NFA to DFA conversion on the final exam.That fearsome reputation belies a field that is rich with useful techniques and not so difficult as some of its practitioners might have you believe. A better understanding of how programming languages are built will make you a stronger software engineer and teach you concepts and data structures you'll use the rest of your coding days. You might even have fun.This book teaches you everything you need to know to implement a full-featured, efficient scripting language. You'll learn both high-level concepts around parsing and semantics and gritty details like bytecode representation and garbage collection. Your brain will light up with new ideas, and your hands will get dirty and calloused.Starting from main(), you will build a language that features rich syntax, dynamic typing, garbage collection, lexical scope, first-class functions, closures, classes, and inheritance. All packed into a few thousand lines of clean, fast code that you thoroughly understand because you wrote each one yourself.},
isbn = {978-0-9905829-3-9},
}