Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/lua/blob/master/lopcodes.c # lua [Ported from github.com/lua/lua] Cast in 'rl_readline_name' Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `master` Branches Tags History `lua / lopcodes.c` 131 lines ยท 4805 bytes Raw Blame History 1 /* 2 ** $Id: lopcodes.c $ 3 ** Opcodes for Lua virtual machine 4 ** See Copyright Notice in lua.h 5 */ 6 7 #define lopcodes_c 8 #define LUA_CORE 9 10 #include "lprefix.h" 11 12 13 #include "lopcodes.h" 14 15 16 #define opmode(mm,ot,it,t,a,m) \ 17 (((mm) << 7) | ((ot) << 6) | ((it) << 5) | ((t) << 4) | ((a) << 3) | (m)) 18 19 20 /* ORDER OP */ 21 22 LUAI_DDEF const lu_byte luaP_opmodes[NUM_OPCODES] = { 23 /* MM OT IT T A mode opcode */ 24 opmode(0, 0, 0, 0, 1, iABC) /* OP_MOVE */ 25 ,opmode(0, 0, 0, 0, 1, iAsBx) /* OP_LOADI */ 26 ,opmode(0, 0, 0, 0, 1, iAsBx) /* OP_LOADF */ 27 ,opmode(0, 0, 0, 0, 1, iABx) /* OP_LOADK */ 28 ,opmode(0, 0, 0, 0, 1, iABx) /* OP_LOADKX */ 29 ,opmode(0, 0, 0, 0, 1, iABC) /* OP_LOADFALSE */ 30 ,opmode(0, 0, 0, 0, 1, iABC) /* OP_LFALSESKIP */ 31 ,opmode(0, 0, 0, 0, 1, iABC) /* OP_LOADTRUE */ 32 ,opmode(0, 0, 0, 0, 1, iABC) /* OP_LOADNIL */ 33 ,opmode(0, 0, 0, 0, 1, iABC) /* OP_GETUPVAL */ 34 ,opmode(0, 0, 0, 0, 0, iABC) /* OP_SETUPVAL */ 35 ,opmode(0, 0, 0, 0, 1, iABC) /* OP_GETTABUP */ 36 ,opmode(0, 0, 0, 0, 1, iABC) /* OP_GETTABLE */ 37 ,opmode(0, 0, 0, 0, 1, iABC) /* OP_GETI */ 38 ,opmode(0, 0, 0, 0, 1, iABC) /* OP_GETFIELD */ 39 ,opmode(0, 0, 0, 0, 0, iABC) /* OP_SETTABUP */ 40 ,opmode(0, 0, 0, 0, 0, iABC) /* OP_SETTABLE */ 41 ,opmode(0, 0, 0, 0, 0, iABC) /* OP_SETI */ 42 ,opmode(0, 0, 0, 0, 0, iABC) /* OP_SETFIELD */ 43 ,opmode(0, 0, 0, 0, 1, ivABC) /* OP_NEWTABLE */ 44 ,opmode(0, 0, 0, 0, 1, iABC) /* OP_SELF */ 45 ,opmode(0, 0, 0, 0, 1, iABC) /* OP_ADDI */ 46 ,opmode(0, 0, 0, 0, 1, iABC) /* OP_ADDK */ 47 ,opmode(0, 0, 0, 0, 1, iABC) /* OP_SUBK */ 48 ,opmode(0, 0, 0, 0, 1, iABC) /* OP_MULK */ 49 ,opmode(0, 0, 0, 0, 1, iABC) /* OP_MODK */ 50 ,opmode(0, 0, 0, 0, 1, iABC) /* OP_POWK */ 51 ,opmode(0, 0, 0, 0, 1, iABC) /* OP_DIVK */ 52 ,opmode(0, 0, 0, 0, 1, iABC) /* OP_IDIVK */ 53 ,opmode(0, 0, 0, 0, 1, iABC) /* OP_BANDK */ 54 ,opmode(0, 0, 0, 0, 1, iABC) /* OP_BORK */ 55 ,opmode(0, 0, 0, 0, 1, iABC) /* OP_BXORK */ 56 ,opmode(0, 0, 0, 0, 1, iABC) /* OP_SHLI */ 57 ,opmode(0, 0, 0, 0, 1, iABC) /* OP_SHRI */ 58 ,opmode(0, 0, 0, 0, 1, iABC) /* OP_ADD */ 59 ,opmode(0, 0, 0, 0, 1, iABC) /* OP_SUB */ 60 ,opmode(0, 0, 0, 0, 1, iABC) /* OP_MUL */ 61 ,opmode(0, 0, 0, 0, 1, iABC) /* OP_MOD */ 62 ,opmode(0, 0, 0, 0, 1, iABC) /* OP_POW */ 63 ,opmode(0, 0, 0, 0, 1, iABC) /* OP_DIV */ 64 ,opmode(0, 0, 0, 0, 1, iABC) /* OP_IDIV */ 65 ,opmode(0, 0, 0, 0, 1, iABC) /* OP_BAND */ 66 ,opmode(0, 0, 0, 0, 1, iABC) /* OP_BOR */ 67 ,opmode(0, 0, 0, 0, 1, iABC) /* OP_BXOR */ 68 ,opmode(0, 0, 0, 0, 1, iABC) /* OP_SHL */ 69 ,opmode(0, 0, 0, 0, 1, iABC) /* OP_SHR */ 70 ,opmode(1, 0, 0, 0, 0, iABC) /* OP_MMBIN */ 71 ,opmode(1, 0, 0, 0, 0, iABC) /* OP_MMBINI */ 72 ,opmode(1, 0, 0, 0, 0, iABC) /* OP_MMBINK */ 73 ,opmode(0, 0, 0, 0, 1, iABC) /* OP_UNM */ 74 ,opmode(0, 0, 0, 0, 1, iABC) /* OP_BNOT */ 75 ,opmode(0, 0, 0, 0, 1, iABC) /* OP_NOT */ 76 ,opmode(0, 0, 0, 0, 1, iABC) /* OP_LEN */ 77 ,opmode(0, 0, 0, 0, 1, iABC) /* OP_CONCAT */ 78 ,opmode(0, 0, 0, 0, 0, iABC) /* OP_CLOSE */ 79 ,opmode(0, 0, 0, 0, 0, iABC) /* OP_TBC */ 80 ,opmode(0, 0, 0, 0, 0, isJ) /* OP_JMP */ 81 ,opmode(0, 0, 0, 1, 0, iABC) /* OP_EQ */ 82 ,opmode(0, 0, 0, 1, 0, iABC) /* OP_LT */ 83 ,opmode(0, 0, 0, 1, 0, iABC) /* OP_LE */ 84 ,opmode(0, 0, 0, 1, 0, iABC) /* OP_EQK */ 85 ,opmode(0, 0, 0, 1, 0, iABC) /* OP_EQI */ 86 ,opmode(0, 0, 0, 1, 0, iABC) /* OP_LTI */ 87 ,opmode(0, 0, 0, 1, 0, iABC) /* OP_LEI */ 88 ,opmode(0, 0, 0, 1, 0, iABC) /* OP_GTI */ 89 ,opmode(0, 0, 0, 1, 0, iABC) /* OP_GEI */ 90 ,opmode(0, 0, 0, 1, 0, iABC) /* OP_TEST */ 91 ,opmode(0, 0, 0, 1, 1, iABC) /* OP_TESTSET */ 92 ,opmode(0, 1, 1, 0, 1, iABC) /* OP_CALL */ 93 ,opmode(0, 1, 1, 0, 1, iABC) /* OP_TAILCALL */ 94 ,opmode(0, 0, 1, 0, 0, iABC) /* OP_RETURN */ 95 ,opmode(0, 0, 0, 0, 0, iABC) /* OP_RETURN0 */ 96 ,opmode(0, 0, 0, 0, 0, iABC) /* OP_RETURN1 */ 97 ,opmode(0, 0, 0, 0, 1, iABx) /* OP_FORLOOP */ 98 ,opmode(0, 0, 0, 0, 1, iABx) /* OP_FORPREP */ 99 ,opmode(0, 0, 0, 0, 0, iABx) /* OP_TFORPREP */ 100 ,opmode(0, 0, 0, 0, 0, iABC) /* OP_TFORCALL */ 101 ,opmode(0, 0, 0, 0, 1, iABx) /* OP_TFORLOOP */ 102 ,opmode(0, 0, 1, 0, 0, ivABC) /* OP_SETLIST */ 103 ,opmode(0, 0, 0, 0, 1, iABx) /* OP_CLOSURE */ 104 ,opmode(0, 1, 0, 0, 1, iABC) /* OP_VARARG */ 105 ,opmode(0, 0, 0, 0, 1, iABC) /* OP_GETVARG */ 106 ,opmode(0, 0, 0, 0, 0, iABx) /* OP_ERRNNIL */ 107 ,opmode(0, 0, 0, 0, 0, iABC) /* OP_VARARGPREP */ 108 ,opmode(0, 0, 0, 0, 0, iAx) /* OP_EXTRAARG */ 109 }; 110 111 112 #define testITMode(m) (luaP_opmodes[m] & (1 << 5)) 113 114 115 /* 116 ** Check whether instruction uses top. That happens for OP_VARARGPREP 117 ** and for instructions that use multiple values set by the previous 118 ** instruction. 119 */ 120 int luaP_isIT (Instruction i) { 121 OpCode op = GET_OPCODE(i); 122 switch (op) { 123 case OP_SETLIST: 124 return GETARG_vB(i) == 0; 125 case OP_VARARGPREP: 126 return 1; 127 default: 128 return testITMode(GET_OPCODE(i)) && GETARG_B(i) == 0; 129 } 130 } 131