lopcodes.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /*
  2. ** $Id: lopcodes.h,v 1.36 1999/12/29 16:31:15 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_n-v_1 f(at c) r_b-r_1 f(v1,...,v_n) */
  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. PUSHSTRCNSTW,/* w - STRCNST[w] */
  26. PUSHSTRCNST,/* b - STRCNST[b] */
  27. PUSHNUMCNSTW,/* w - NUMCNST[w] */
  28. PUSHNUMCNST,/* b - NUMCNST[b] */
  29. PUSHUPVALUE,/* b - Closure[b] */
  30. PUSHLOCAL,/* b - LOC[b] */
  31. GETGLOBALW,/* w - VAR[CNST[w]] */
  32. GETGLOBAL,/* b - VAR[CNST[b]] */
  33. GETTABLE,/* - i t t[i] */
  34. GETDOTTEDW,/* w t t[CNST[w]] */
  35. GETDOTTED,/* b t t[CNST[b]] */
  36. PUSHSELFW,/* w t t t[CNST[w]] */
  37. PUSHSELF,/* b t t t[CNST[b]] */
  38. CREATEARRAYW,/* w - newarray(size = w) */
  39. CREATEARRAY,/* b - newarray(size = b) */
  40. SETLOCAL,/* b x - LOC[b]=x */
  41. SETGLOBALW,/* w x - VAR[CNST[w]]=x */
  42. SETGLOBAL,/* b x - VAR[CNST[b]]=x */
  43. SETTABLEPOP,/* - v i t - t[i]=v */
  44. SETTABLE,/* b v a_b-a_1 i t a_b-a_1 i t t[i]=v */
  45. SETLISTW,/* w c v_c-v_1 t t t[i+w*FPF]=v_i */
  46. SETLIST,/* b c v_c-v_1 t t t[i+b*FPF]=v_i */
  47. SETMAP,/* b v_b k_b - v_0 k_0 t t t[k_i]=v_i */
  48. NEQOP,/* - y x (x~=y)? 1 : nil */
  49. EQOP,/* - y x (x==y)? 1 : nil */
  50. LTOP,/* - y x (x<y)? 1 : nil */
  51. LEOP,/* - y x (x<y)? 1 : nil */
  52. GTOP,/* - y x (x>y)? 1 : nil */
  53. GEOP,/* - y x (x>=y)? 1 : nil */
  54. ADDOP,/* - y x x+y */
  55. SUBOP,/* - y x x-y */
  56. MULTOP,/* - y x x*y */
  57. DIVOP,/* - y x x/y */
  58. POWOP,/* - y x x^y */
  59. CONCOP,/* - y x x..y */
  60. MINUSOP,/* - x -x */
  61. NOTOP,/* - x (x==nil)? 1 : nil */
  62. ONTJMPW,/* w x (x!=nil)? x : - (x!=nil)? PC+=w */
  63. ONTJMP,/* b x (x!=nil)? x : - (x!=nil)? PC+=b */
  64. ONFJMPW,/* w x (x==nil)? x : - (x==nil)? PC+=w */
  65. ONFJMP,/* b x (x==nil)? x : - (x==nil)? PC+=b */
  66. JMPW,/* w - - PC+=w */
  67. JMP,/* b - - PC+=b */
  68. IFFJMPW,/* w x - (x==nil)? PC+=w */
  69. IFFJMP,/* b x - (x==nil)? PC+=b */
  70. IFTUPJMPW,/* w x - (x!=nil)? PC-=w */
  71. IFTUPJMP,/* b x - (x!=nil)? PC-=b */
  72. IFFUPJMPW,/* w x - (x==nil)? PC-=w */
  73. IFFUPJMP,/* b x - (x==nil)? PC-=b */
  74. CLOSUREW,/* w c v_c-v_1 closure(CNST[w], v_c-v_1) */
  75. CLOSURE,/* b c v_c-v_1 closure(CNST[b], v_c-v_1) */
  76. SETLINEW,/* w - - LINE=w */
  77. SETLINE,/* b - - LINE=b */
  78. SETNAMEW,/* w c - - NAME=CNST[w],c */
  79. SETNAME,/* b c - - NAME=CNST[b],c */
  80. LONGARGW,/* w (add w*(1<<16) to arg of next instruction) */
  81. LONGARG /* b (add b*(1<<16) to arg of next instruction) */
  82. } OpCode;
  83. #define RFIELDS_PER_FLUSH 32 /* records (SETMAP) */
  84. #define LFIELDS_PER_FLUSH 64 /* FPF - lists (SETLIST) */
  85. #define ZEROVARARG 128
  86. /* maximum value of an arg of 3 bytes; must fit in an "int" */
  87. #if MAX_INT < (1<<24)
  88. #define MAX_ARG MAX_INT
  89. #else
  90. #define MAX_ARG ((1<<24)-1)
  91. #endif
  92. /* maximum value of a word of 2 bytes; cannot be larger than MAX_ARG */
  93. #if MAX_ARG < (1<<16)
  94. #define MAX_WORD MAX_ARG
  95. #else
  96. #define MAX_WORD ((1<<16)-1)
  97. #endif
  98. /* maximum value of a byte */
  99. #define MAX_BYTE ((1<<8)-1)
  100. #endif