lopcodes.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /*
  2. ** $Id: lopcodes.h,v 1.39 2000/02/11 16:52:54 roberto Exp roberto $
  3. ** Opcodes for Lua virtual machine
  4. ** See Copyright Notice in lua.h
  5. */
  6. #ifndef lopcodes_h
  7. #define lopcodes_h
  8. /*===========================================================================
  9. We assume that instructions are unsigned numbers with 4 bytes.
  10. All instructions have an opcode in the lower byte. Moreover,
  11. an instruction can have 0, 1, or 2 arguments. There are 4 types of
  12. Instructions:
  13. type 0: no arguments
  14. type 1: 1 unsigned argument in the higher 24 bits (called `U')
  15. type 2: 1 signed argument in the higher 24 bits (`S')
  16. type 3: 1st unsigned argument in the higher 16 bits (`A')
  17. 2nd unsigned argument in the middle 8 bits (`B')
  18. The signed argument is represented in excess 2^23; that is, the real value
  19. is 2^23 minus the usigned value.
  20. ===========================================================================*/
  21. /*
  22. ** the following macros help to manipulate instructions
  23. */
  24. #define MAXARG_U ((1<<24)-1)
  25. #define MAXARG_S ((1<<23)-1)
  26. #define MAXARG_A ((1<<16)-1)
  27. #define MAXARG_B ((1<<8)-1)
  28. #define GET_OPCODE(i) ((OpCode)((i)&0xFF))
  29. #define GETARG_U(i) ((int)((i)>>8))
  30. #define GETARG_S(i) ((int)((i)>>8)-(1<<23))
  31. #define GETARG_A(i) ((int)((i)>>16))
  32. #define GETARG_B(i) ((int)(((i)>>8) & 0xFF))
  33. #define SET_OPCODE(i,o) (((i)&0xFFFFFF00u) | (Instruction)(o))
  34. #define SETARG_U(i,u) (((i)&0x000000FFu) | ((Instruction)(u)<<8))
  35. #define SETARG_S(i,s) (((i)&0x000000FFu) | ((Instruction)((s)+(1<<23))<<8))
  36. #define SETARG_A(i,a) (((i)&0x0000FFFFu) | ((Instruction)(a)<<16))
  37. #define SETARG_B(i,b) (((i)&0xFFFF00FFu) | ((Instruction)(b)<<8))
  38. typedef enum {
  39. /* name parm before after side effect
  40. -----------------------------------------------------------------------------*/
  41. ENDCODE,/* - - (return) */
  42. RETCODE,/* U - (return) */
  43. CALL,/* A B v_n-v_1 f(at a) r_b-r_1 f(v1,...,v_n) */
  44. TAILCALL,/* A B v_a-v_1 f (return) f(v1,...,v_a) */
  45. PUSHNIL,/* U - nil_0-nil_u */
  46. POP,/* U a_u-a_1 - */
  47. PUSHINT,/* S - (real)s */
  48. PUSHSTRING,/* U - KSTR[u] */
  49. PUSHNUMBER,/* U - KNUM[u] */
  50. PUSHUPVALUE,/* U - Closure[u] */
  51. PUSHLOCAL,/* U - LOC[u] */
  52. GETGLOBAL,/* U - VAR[CNST[u]] */
  53. GETTABLE,/* - i t t[i] */
  54. GETDOTTED,/* U t t[CNST[u]] */
  55. PUSHSELF,/* U t t t[CNST[u]] */
  56. CREATETABLE,/* U - newarray(size = u) */
  57. SETLOCAL,/* U x - LOC[u]=x */
  58. SETGLOBAL,/* U x - VAR[CNST[u]]=x */
  59. SETTABLEPOP,/* - v i t - t[i]=v */
  60. SETTABLE,/* U v a_u-a_1 i t a_u-a_1 i t t[i]=v */
  61. SETLIST,/* A B v_b-v_0 t t t[i+a*FPF]=v_i */
  62. SETMAP,/* U v_u k_u - v_0 k_0 t t t[k_i]=v_i */
  63. NEQOP,/* - y x (x~=y)? 1 : nil */
  64. EQOP,/* - y x (x==y)? 1 : nil */
  65. LTOP,/* - y x (x<y)? 1 : nil */
  66. LEOP,/* - y x (x<y)? 1 : nil */
  67. GTOP,/* - y x (x>y)? 1 : nil */
  68. GEOP,/* - y x (x>=y)? 1 : nil */
  69. ADDOP,/* - y x x+y */
  70. SUBOP,/* - y x x-y */
  71. MULTOP,/* - y x x*y */
  72. DIVOP,/* - y x x/y */
  73. POWOP,/* - y x x^y */
  74. CONCOP,/* - y x x..y */
  75. MINUSOP,/* - x -x */
  76. NOTOP,/* - x (x==nil)? 1 : nil */
  77. ONTJMP,/* S x (x!=nil)? x : - (x!=nil)? PC+=s */
  78. ONFJMP,/* S x (x==nil)? x : - (x==nil)? PC+=s */
  79. JMP,/* S - - PC+=s */
  80. IFTJMP,/* S x - (x!=nil)? PC+=s */
  81. IFFJMP,/* S x - (x==nil)? PC+=s */
  82. CLOSURE,/* A B v_b-v_1 closure(CNST[a], v_b-v_1) */
  83. SETLINE/* U - - LINE=u */
  84. } OpCode;
  85. #define RFIELDS_PER_FLUSH 32 /* records (SETMAP) */
  86. #define LFIELDS_PER_FLUSH 64 /* FPF - lists (SETLIST) (<MAXARG_B) */
  87. #endif