aboutsummaryrefslogtreecommitdiff
path: root/lopcodes.h
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2021-03-29 11:47:12 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2021-03-29 11:47:12 -0300
commitbef250eb8d44ba58fa04f82df7550a79b068d2d0 (patch)
tree62c7ca754b529b907c701e93a1e8f364904a7907 /lopcodes.h
parentba81adaad9a72530d1ac81149a1fdd154b010b06 (diff)
downloadlua-bef250eb8d44ba58fa04f82df7550a79b068d2d0.tar.gz
lua-bef250eb8d44ba58fa04f82df7550a79b068d2d0.tar.bz2
lua-bef250eb8d44ba58fa04f82df7550a79b068d2d0.zip
Details
Comments and small improvements in the manual.
Diffstat (limited to 'lopcodes.h')
-rw-r--r--lopcodes.h21
1 files changed, 17 insertions, 4 deletions
diff --git a/lopcodes.h b/lopcodes.h
index d6a47e5a..7c274515 100644
--- a/lopcodes.h
+++ b/lopcodes.h
@@ -190,7 +190,8 @@ enum OpMode {iABC, iABx, iAsBx, iAx, isJ}; /* basic instruction formats */
190 190
191 191
192/* 192/*
193** grep "ORDER OP" if you change these enums 193** Grep "ORDER OP" if you change these enums. Opcodes marked with a (*)
194** has extra descriptions in the notes after the enumeration.
194*/ 195*/
195 196
196typedef enum { 197typedef enum {
@@ -203,7 +204,7 @@ OP_LOADF,/* A sBx R[A] := (lua_Number)sBx */
203OP_LOADK,/* A Bx R[A] := K[Bx] */ 204OP_LOADK,/* A Bx R[A] := K[Bx] */
204OP_LOADKX,/* A R[A] := K[extra arg] */ 205OP_LOADKX,/* A R[A] := K[extra arg] */
205OP_LOADFALSE,/* A R[A] := false */ 206OP_LOADFALSE,/* A R[A] := false */
206OP_LFALSESKIP,/*A R[A] := false; pc++ */ 207OP_LFALSESKIP,/*A R[A] := false; pc++ (*) */
207OP_LOADTRUE,/* A R[A] := true */ 208OP_LOADTRUE,/* A R[A] := true */
208OP_LOADNIL,/* A B R[A], R[A+1], ..., R[A+B] := nil */ 209OP_LOADNIL,/* A B R[A], R[A+1], ..., R[A+B] := nil */
209OP_GETUPVAL,/* A B R[A] := UpValue[B] */ 210OP_GETUPVAL,/* A B R[A] := UpValue[B] */
@@ -254,7 +255,7 @@ OP_BXOR,/* A B C R[A] := R[B] ~ R[C] */
254OP_SHL,/* A B C R[A] := R[B] << R[C] */ 255OP_SHL,/* A B C R[A] := R[B] << R[C] */
255OP_SHR,/* A B C R[A] := R[B] >> R[C] */ 256OP_SHR,/* A B C R[A] := R[B] >> R[C] */
256 257
257OP_MMBIN,/* A B C call C metamethod over R[A] and R[B] */ 258OP_MMBIN,/* A B C call C metamethod over R[A] and R[B] (*) */
258OP_MMBINI,/* A sB C k call C metamethod over R[A] and sB */ 259OP_MMBINI,/* A sB C k call C metamethod over R[A] and sB */
259OP_MMBINK,/* A B C k call C metamethod over R[A] and K[B] */ 260OP_MMBINK,/* A B C k call C metamethod over R[A] and K[B] */
260 261
@@ -280,7 +281,7 @@ OP_GTI,/* A sB k if ((R[A] > sB) ~= k) then pc++ */
280OP_GEI,/* A sB k if ((R[A] >= sB) ~= k) then pc++ */ 281OP_GEI,/* A sB k if ((R[A] >= sB) ~= k) then pc++ */
281 282
282OP_TEST,/* A k if (not R[A] == k) then pc++ */ 283OP_TEST,/* A k if (not R[A] == k) then pc++ */
283OP_TESTSET,/* A B k if (not R[B] == k) then pc++ else R[A] := R[B] */ 284OP_TESTSET,/* A B k if (not R[B] == k) then pc++ else R[A] := R[B] (*) */
284 285
285OP_CALL,/* A B C R[A], ... ,R[A+C-2] := R[A](R[A+1], ... ,R[A+B-1]) */ 286OP_CALL,/* A B C R[A], ... ,R[A+C-2] := R[A](R[A+1], ... ,R[A+B-1]) */
286OP_TAILCALL,/* A B C k return R[A](R[A+1], ... ,R[A+B-1]) */ 287OP_TAILCALL,/* A B C k return R[A](R[A+1], ... ,R[A+B-1]) */
@@ -315,6 +316,18 @@ OP_EXTRAARG/* Ax extra (larger) argument for previous opcode */
315 316
316/*=========================================================================== 317/*===========================================================================
317 Notes: 318 Notes:
319
320 (*) Opcode OP_LFALSESKIP is used to convert a condition to a boolean
321 value, in a code equivalent to (not cond ? false : true). (It
322 produces false and skips the next instruction producing true.)
323
324 (*) Opcodes OP_MMBIN and variants follow each arithmetic and
325 bitwise opcode. If the operation succeeds, it skips this next
326 opcode. Otherwise, this opcode calls the corresponding metamethod.
327
328 (*) Opcode OP_TESTSET is used in short-circuit expressions that need
329 both to jump and to produce a value, such as (a = b or c).
330
318 (*) In OP_CALL, if (B == 0) then B = top - A. If (C == 0), then 331 (*) In OP_CALL, if (B == 0) then B = top - A. If (C == 0), then
319 'top' is set to last_result+1, so next open instruction (OP_CALL, 332 'top' is set to last_result+1, so next open instruction (OP_CALL,
320 OP_RETURN*, OP_SETLIST) may use 'top'. 333 OP_RETURN*, OP_SETLIST) may use 'top'.