From 7419a4d836777b183c97aca08d8596eecc7903c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=BE=E6=B5=A6=20=E7=9F=A5=E4=B9=9F=20Matsuura=20Tomoy?= =?UTF-8?q?a?= Date: Tue, 9 Jul 2024 09:56:30 +0000 Subject: [PATCH] writtttttttttting --- src/main.tex | 14 +- src/vmmodel.svg | 631 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 639 insertions(+), 6 deletions(-) create mode 100644 src/vmmodel.svg diff --git a/src/main.tex b/src/main.tex index 76e63c2..8b32d05 100644 --- a/src/main.tex +++ b/src/main.tex @@ -296,11 +296,11 @@ Instructions in \lambdammm VM are 32bit tagged-union data that has up to 3 opera 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. +In addition to Lua's Upvalue operation, 3 operations related to internal state variables over time, \texttt{GETSTATE}, \texttt{SETSTATE}, \texttt{SHIFTSTATE} are added. \begin{figure*}[ht] \tt @@ -310,13 +310,15 @@ 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 \\ +GETSTATE & A & R(A) := SPtr[SPos] \\ +SETSTATE & A & Sptr[SPos] := R(A) \\ +SHIFTSTATE & sAx & SPos += sAx \\ JMP & sAx & PC +=sAx \\ JMPIFNEG & A sBx & if (R(A)<0) then PC += sBx \\ -CALL & A B C & \\ -CALLCLS & A B C & \\ +CALL & A B C & R(A), ... ,R(A+C-2) := program.functions[R(A)](R(A+1),...,R(A+B-1)) \\ +CALLCLS & A B C & Sptr := vm.closures[R(A)].Sptr; \\ +\ & \ & R(A), ... ,R(A+C-2) := vm.closures[R(A)].fnproto(R(A+1),...,R(A+B-1)); \\ +\ & \ & Sptr := global\_sptr \\ 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\\ diff --git a/src/vmmodel.svg b/src/vmmodel.svg new file mode 100644 index 0000000..2cae5ae --- /dev/null +++ b/src/vmmodel.svg @@ -0,0 +1,631 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Virtual Machine + + + Program Counter + + + + State_Ptr + + + + Audio Driver + + + + Call Stack + + + + + + + + ... + + + + Global States + + + + Closure Storage + + + + Closure Storage + + + + State Position + + + + + + + + + + + + Program + + Function Prototype0 + + Static Variables + + + + + + ... + + + + + + + OP + + + + A + + + + B + + + + C + + + + + + + + + ... + Function Prototype1 + + + + +