opcode.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. /*
  2. ** TeCGraf - PUC-Rio
  3. ** $Id: opcode.h,v 3.26 1997/02/20 15:51:14 roberto Exp roberto $
  4. */
  5. #ifndef opcode_h
  6. #define opcode_h
  7. #include "lua.h"
  8. #include "types.h"
  9. #include "tree.h"
  10. #include "func.h"
  11. #define FIELDS_PER_FLUSH 40
  12. typedef enum
  13. {
  14. LUA_T_NIL = -1,
  15. LUA_T_NUMBER = -2,
  16. LUA_T_STRING = -3,
  17. LUA_T_ARRAY = -4, /* array==table */
  18. LUA_T_FUNCTION = -5,
  19. LUA_T_CFUNCTION= -6,
  20. LUA_T_MARK = -7,
  21. LUA_T_CMARK = -8,
  22. LUA_T_LINE = -9,
  23. LUA_T_USERDATA = 0
  24. } lua_Type;
  25. typedef enum {
  26. /* name parm before after side effect
  27. -----------------------------------------------------------------------------*/
  28. PUSHNIL,/* - nil */
  29. PUSH0,/* - 0.0 */
  30. PUSH1,/* - 1.0 */
  31. PUSH2,/* - 2.0 */
  32. PUSHBYTE,/* b - (float)b */
  33. PUSHWORD,/* w - (float)w */
  34. PUSHFLOAT,/* f - f */
  35. PUSHSTRING,/* w - STR[w] */
  36. PUSHFUNCTION,/* p - FUN(p) */
  37. PUSHLOCAL0,/* - LOC[0] */
  38. PUSHLOCAL1,/* - LOC[1] */
  39. PUSHLOCAL2,/* - LOC[2] */
  40. PUSHLOCAL3,/* - LOC[3] */
  41. PUSHLOCAL4,/* - LOC[4] */
  42. PUSHLOCAL5,/* - LOC[5] */
  43. PUSHLOCAL6,/* - LOC[6] */
  44. PUSHLOCAL7,/* - LOC[7] */
  45. PUSHLOCAL8,/* - LOC[8] */
  46. PUSHLOCAL9,/* - LOC[9] */
  47. PUSHLOCAL,/* w - LOC[w] */
  48. PUSHGLOBAL,/* w - VAR[w] */
  49. PUSHINDEXED,/* i t t[i] */
  50. PUSHSELF,/* w t t t[STR[w]] */
  51. STORELOCAL0,/* x - LOC[0]=x */
  52. STORELOCAL1,/* x - LOC[1]=x */
  53. STORELOCAL2,/* x - LOC[2]=x */
  54. STORELOCAL3,/* x - LOC[3]=x */
  55. STORELOCAL4,/* x - LOC[4]=x */
  56. STORELOCAL5,/* x - LOC[5]=x */
  57. STORELOCAL6,/* x - LOC[6]=x */
  58. STORELOCAL7,/* x - LOC[7]=x */
  59. STORELOCAL8,/* x - LOC[8]=x */
  60. STORELOCAL9,/* x - LOC[9]=x */
  61. STORELOCAL,/* w x - LOC[w]=x */
  62. STOREGLOBAL,/* w x - VAR[w]=x */
  63. STOREINDEXED0,/* v i t - t[i]=v */
  64. STOREINDEXED,/* b v a_b...a_1 i t a_b...a_1 i t t[i]=v */
  65. STORELIST0,/* w v_w...v_1 t - t[i]=v_i */
  66. STORELIST,/* w n v_w...v_1 t - t[i+n*FPF]=v_i */
  67. STORERECORD,/* n
  68. w_n...w_1 v_n...v_1 t - t[STR[w_i]]=v_i */
  69. ADJUST0,/* - - TOP=BASE */
  70. ADJUST,/* b - - TOP=BASE+b */
  71. CREATEARRAY,/* w - newarray(size = w) */
  72. EQOP,/* y x (x==y)? 1 : nil */
  73. LTOP,/* y x (x<y)? 1 : nil */
  74. LEOP,/* y x (x<y)? 1 : nil */
  75. GTOP,/* y x (x>y)? 1 : nil */
  76. GEOP,/* y x (x>=y)? 1 : nil */
  77. ADDOP,/* y x x+y */
  78. SUBOP,/* y x x-y */
  79. MULTOP,/* y x x*y */
  80. DIVOP,/* y x x/y */
  81. POWOP,/* y x x^y */
  82. CONCOP,/* y x x..y */
  83. MINUSOP,/* x -x */
  84. NOTOP,/* x (x==nil)? 1 : nil */
  85. ONTJMP,/* w x - (x!=nil)? PC+=w */
  86. ONFJMP,/* w x - (x==nil)? PC+=w */
  87. JMP,/* w - - PC+=w */
  88. UPJMP,/* w - - PC-=w */
  89. IFFJMP,/* w x - (x==nil)? PC+=w */
  90. IFFUPJMP,/* w x - (x==nil)? PC-=w */
  91. POP,/* x - */
  92. CALLFUNC,/* n m v_n...v_1 f r_m...r_1 f(v1,...,v_n) */
  93. RETCODE0,
  94. RETCODE,/* b - - */
  95. SETLINE,/* w - - LINE=w */
  96. VARARGS,/* b v_n...v_1 {v_1...v_n;n=n} */
  97. STOREMAP/* n v_n k_n ...v_1 k_1 t - t[k_i]=v_i */
  98. } OpCode;
  99. #define MULT_RET 255
  100. typedef union
  101. {
  102. lua_CFunction f;
  103. real n;
  104. TaggedString *ts;
  105. TFunc *tf;
  106. struct Hash *a;
  107. int i;
  108. } Value;
  109. typedef struct Object
  110. {
  111. lua_Type tag;
  112. Value value;
  113. } Object;
  114. /* Macros to access structure members */
  115. #define tag(o) ((o)->tag)
  116. #define nvalue(o) ((o)->value.n)
  117. #define svalue(o) ((o)->value.ts->str)
  118. #define tsvalue(o) ((o)->value.ts)
  119. #define avalue(o) ((o)->value.a)
  120. #define fvalue(o) ((o)->value.f)
  121. /* Macros to access symbol table */
  122. #define s_object(i) (lua_table[i].object)
  123. #define s_tag(i) (tag(&s_object(i)))
  124. #define s_nvalue(i) (nvalue(&s_object(i)))
  125. #define s_svalue(i) (svalue(&s_object(i)))
  126. #define s_tsvalue(i) (tsvalue(&s_object(i)))
  127. #define s_avalue(i) (avalue(&s_object(i)))
  128. #define s_fvalue(i) (fvalue(&s_object(i)))
  129. #define s_uvalue(i) (uvalue(&s_object(i)))
  130. #define get_word(code,pc) {memcpy(&code, pc, sizeof(Word)); pc+=sizeof(Word);}
  131. #define get_float(code,pc){memcpy(&code, pc, sizeof(real)); pc+=sizeof(real);}
  132. #define get_code(code,pc) {memcpy(&code, pc, sizeof(TFunc *)); \
  133. pc+=sizeof(TFunc *);}
  134. /* Exported functions */
  135. void lua_parse (TFunc *tf); /* from "lua.stx" module */
  136. void luaI_codedebugline (int line); /* from "lua.stx" module */
  137. void lua_travstack (int (*fn)(Object *));
  138. Object *luaI_Address (lua_Object o);
  139. void luaI_pushobject (Object *o);
  140. void luaI_gcFB (Object *o);
  141. int luaI_dorun (TFunc *tf);
  142. #endif