lopcodes.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /*
  2. ** $Id: lopcodes.h,v 1.32 1999/03/10 14:09:45 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. ** NOTICE: variants of the same opcode must be consecutive: First, those
  10. ** with word parameter, then with byte parameter.
  11. */
  12. typedef enum {
  13. /* name parm before after side effect
  14. -----------------------------------------------------------------------------*/
  15. ENDCODE,/* - - (return) */
  16. RETCODE,/* b - (return) */
  17. CALL,/* b c v_c...v_1 f r_b...r_1 f(v1,...,v_c) */
  18. TAILCALL,/* b c v_c...v_1 f (return) f(v1,...,v_c) */
  19. PUSHNIL,/* b - nil_0...nil_b */
  20. POP,/* b a_b...a_1 - */
  21. PUSHNUMBERW,/* w - (float)w */
  22. PUSHNUMBER,/* b - (float)b */
  23. PUSHNUMBERNEGW,/* w - (float)-w */
  24. PUSHNUMBERNEG,/* b - (float)-b */
  25. PUSHCONSTANTW,/*w - CNST[w] */
  26. PUSHCONSTANT,/* b - CNST[b] */
  27. PUSHUPVALUE,/* b - Closure[b] */
  28. PUSHLOCAL,/* b - LOC[b] */
  29. GETGLOBALW,/* w - VAR[CNST[w]] */
  30. GETGLOBAL,/* b - VAR[CNST[b]] */
  31. GETTABLE,/* - i t t[i] */
  32. GETDOTTEDW,/* w t t[CNST[w]] */
  33. GETDOTTED,/* b t t[CNST[b]] */
  34. PUSHSELFW,/* w t t t[CNST[w]] */
  35. PUSHSELF,/* b t t t[CNST[b]] */
  36. CREATEARRAYW,/* w - newarray(size = w) */
  37. CREATEARRAY,/* b - newarray(size = b) */
  38. SETLOCAL,/* b x - LOC[b]=x */
  39. SETGLOBALW,/* w x - VAR[CNST[w]]=x */
  40. SETGLOBAL,/* b x - VAR[CNST[b]]=x */
  41. SETTABLEPOP,/* - v i t - t[i]=v */
  42. SETTABLE,/* b v a_b...a_1 i t a_b...a_1 i t t[i]=v */
  43. SETLISTW,/* w c v_c...v_1 t t t[i+w*FPF]=v_i */
  44. SETLIST,/* b c v_c...v_1 t t t[i+b*FPF]=v_i */
  45. SETMAP,/* b v_b k_b ...v_0 k_0 t t t[k_i]=v_i */
  46. NEQOP,/* - y x (x~=y)? 1 : nil */
  47. EQOP,/* - y x (x==y)? 1 : nil */
  48. LTOP,/* - y x (x<y)? 1 : nil */
  49. LEOP,/* - y x (x<y)? 1 : nil */
  50. GTOP,/* - y x (x>y)? 1 : nil */
  51. GEOP,/* - y x (x>=y)? 1 : nil */
  52. ADDOP,/* - y x x+y */
  53. SUBOP,/* - y x x-y */
  54. MULTOP,/* - y x x*y */
  55. DIVOP,/* - y x x/y */
  56. POWOP,/* - y x x^y */
  57. CONCOP,/* - y x x..y */
  58. MINUSOP,/* - x -x */
  59. NOTOP,/* - x (x==nil)? 1 : nil */
  60. ONTJMPW,/* w x (x!=nil)? x : - (x!=nil)? PC+=w */
  61. ONTJMP,/* b x (x!=nil)? x : - (x!=nil)? PC+=b */
  62. ONFJMPW,/* w x (x==nil)? x : - (x==nil)? PC+=w */
  63. ONFJMP,/* b x (x==nil)? x : - (x==nil)? PC+=b */
  64. JMPW,/* w - - PC+=w */
  65. JMP,/* b - - PC+=b */
  66. IFFJMPW,/* w x - (x==nil)? PC+=w */
  67. IFFJMP,/* b x - (x==nil)? PC+=b */
  68. IFTUPJMPW,/* w x - (x!=nil)? PC-=w */
  69. IFTUPJMP,/* b x - (x!=nil)? PC-=b */
  70. IFFUPJMPW,/* w x - (x==nil)? PC-=w */
  71. IFFUPJMP,/* b x - (x==nil)? PC-=b */
  72. CLOSUREW,/* w c v_c...v_1 closure(CNST[w], v_c...v_1) */
  73. CLOSURE,/* b c v_c...v_1 closure(CNST[b], v_c...v_1) */
  74. SETLINEW,/* w - - LINE=w */
  75. SETLINE,/* b - - LINE=b */
  76. LONGARGW,/* w (add w*(1<<16) to arg of next instruction) */
  77. LONGARG,/* b (add b*(1<<16) to arg of next instruction) */
  78. CHECKSTACK /* b (assert #temporaries == b; only for internal debuging!) */
  79. } OpCode;
  80. #define RFIELDS_PER_FLUSH 32 /* records (SETMAP) */
  81. #define LFIELDS_PER_FLUSH 64 /* FPF - lists (SETLIST) */
  82. #define ZEROVARARG 128
  83. /* maximum value of an arg of 3 bytes; must fit in an "int" */
  84. #if MAX_INT < (1<<24)
  85. #define MAX_ARG MAX_INT
  86. #else
  87. #define MAX_ARG ((1<<24)-1)
  88. #endif
  89. /* maximum value of a word of 2 bytes; cannot be bigger than MAX_ARG */
  90. #if MAX_ARG < (1<<16)
  91. #define MAX_WORD MAX_ARG
  92. #else
  93. #define MAX_WORD ((1<<16)-1)
  94. #endif
  95. /* maximum value of a byte */
  96. #define MAX_BYTE ((1<<8)-1)
  97. #endif