A No-Frills Introduction to Lua 5.1 VM Instructions

Extrait du cours A No-Frills Introduction to Lua 5.1 VM Instructions

The iterator function is located in register 0, and is named (for generator) for debugging purposes. The state is in register 1, and has the name (for state). The enumeration index, (for control), is contained in register 2. These correspond to locals R(A), R(A+1) and R(A+2) in the TFORLOOP description. Results from the iterator function call is placed into register 3 and 4, which are locals i and v, respectively. On line [9], the operand C of TFORLOOP is 2, corresponding to two iterator variables (i and v).
Line [1]–[3] prepares the iterator state. Note that the call to the pairs standard library function has 1 parameter and 3 results. After the call in line [3], register 0 is the iterator function, register 1 is the loop state, register 2 is the initial value of the enumeration index. The iterator variables i and v are both invalid at the moment, because we have not entered the loop yet.
Line [4] is a JMP to TFORLOOP on line [9]. With the initial (or zeroth) iterator state, TFORLOOP calls the iterator function, generating the first set of enumeration results in locals i, v. If i is not nil, the internal enumeration index (register 2) is set and the JMP on the next line is immediately executed, starting the first iteration of the loop body (lines [5]–[8]).
The body of the generic for loop executes (print(i,v)) and then TFORLOOP is encountered again, calling the iterator function to get the next iteration state. Finally, when the first result is a nil, the loop ends, and execution continues on line [11].

……..

Si le lien ne fonctionne pas correctement, veuillez nous contacter (mentionner le lien dans votre message)
A No-Frills Introduction to Lua 5.1 VM Instructions (220 KO) (Cours PDF)

Télécharger aussi :

Laisser un commentaire

Votre adresse e-mail ne sera pas publiée. Les champs obligatoires sont indiqués avec *