diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2021-03-29 11:47:12 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2021-03-29 11:47:12 -0300 |
commit | bef250eb8d44ba58fa04f82df7550a79b068d2d0 (patch) | |
tree | 62c7ca754b529b907c701e93a1e8f364904a7907 /lopcodes.h | |
parent | ba81adaad9a72530d1ac81149a1fdd154b010b06 (diff) | |
download | lua-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.h | 21 |
1 files changed, 17 insertions, 4 deletions
@@ -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 | ||
196 | typedef enum { | 197 | typedef enum { |
@@ -203,7 +204,7 @@ OP_LOADF,/* A sBx R[A] := (lua_Number)sBx */ | |||
203 | OP_LOADK,/* A Bx R[A] := K[Bx] */ | 204 | OP_LOADK,/* A Bx R[A] := K[Bx] */ |
204 | OP_LOADKX,/* A R[A] := K[extra arg] */ | 205 | OP_LOADKX,/* A R[A] := K[extra arg] */ |
205 | OP_LOADFALSE,/* A R[A] := false */ | 206 | OP_LOADFALSE,/* A R[A] := false */ |
206 | OP_LFALSESKIP,/*A R[A] := false; pc++ */ | 207 | OP_LFALSESKIP,/*A R[A] := false; pc++ (*) */ |
207 | OP_LOADTRUE,/* A R[A] := true */ | 208 | OP_LOADTRUE,/* A R[A] := true */ |
208 | OP_LOADNIL,/* A B R[A], R[A+1], ..., R[A+B] := nil */ | 209 | OP_LOADNIL,/* A B R[A], R[A+1], ..., R[A+B] := nil */ |
209 | OP_GETUPVAL,/* A B R[A] := UpValue[B] */ | 210 | OP_GETUPVAL,/* A B R[A] := UpValue[B] */ |
@@ -254,7 +255,7 @@ OP_BXOR,/* A B C R[A] := R[B] ~ R[C] */ | |||
254 | OP_SHL,/* A B C R[A] := R[B] << R[C] */ | 255 | OP_SHL,/* A B C R[A] := R[B] << R[C] */ |
255 | OP_SHR,/* A B C R[A] := R[B] >> R[C] */ | 256 | OP_SHR,/* A B C R[A] := R[B] >> R[C] */ |
256 | 257 | ||
257 | OP_MMBIN,/* A B C call C metamethod over R[A] and R[B] */ | 258 | OP_MMBIN,/* A B C call C metamethod over R[A] and R[B] (*) */ |
258 | OP_MMBINI,/* A sB C k call C metamethod over R[A] and sB */ | 259 | OP_MMBINI,/* A sB C k call C metamethod over R[A] and sB */ |
259 | OP_MMBINK,/* A B C k call C metamethod over R[A] and K[B] */ | 260 | OP_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++ */ | |||
280 | OP_GEI,/* A sB k if ((R[A] >= sB) ~= k) then pc++ */ | 281 | OP_GEI,/* A sB k if ((R[A] >= sB) ~= k) then pc++ */ |
281 | 282 | ||
282 | OP_TEST,/* A k if (not R[A] == k) then pc++ */ | 283 | OP_TEST,/* A k if (not R[A] == k) then pc++ */ |
283 | OP_TESTSET,/* A B k if (not R[B] == k) then pc++ else R[A] := R[B] */ | 284 | OP_TESTSET,/* A B k if (not R[B] == k) then pc++ else R[A] := R[B] (*) */ |
284 | 285 | ||
285 | OP_CALL,/* A B C R[A], ... ,R[A+C-2] := R[A](R[A+1], ... ,R[A+B-1]) */ | 286 | OP_CALL,/* A B C R[A], ... ,R[A+C-2] := R[A](R[A+1], ... ,R[A+B-1]) */ |
286 | OP_TAILCALL,/* A B C k return R[A](R[A+1], ... ,R[A+B-1]) */ | 287 | OP_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'. |