opcode.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. /*
  2. ** TeCGraf - PUC-Rio
  3. ** $Id: opcode.h,v 3.11 1995/04/11 17:56:30 celes Exp $
  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. #ifndef real
  12. #define real float
  13. #endif
  14. #define FIELDS_PER_FLUSH 40
  15. typedef enum
  16. {
  17. PUSHNIL,
  18. PUSH0, PUSH1, PUSH2,
  19. PUSHBYTE,
  20. PUSHWORD,
  21. PUSHFLOAT,
  22. PUSHSTRING,
  23. PUSHFUNCTION,
  24. PUSHLOCAL0, PUSHLOCAL1, PUSHLOCAL2, PUSHLOCAL3, PUSHLOCAL4,
  25. PUSHLOCAL5, PUSHLOCAL6, PUSHLOCAL7, PUSHLOCAL8, PUSHLOCAL9,
  26. PUSHLOCAL,
  27. PUSHGLOBAL,
  28. PUSHINDEXED,
  29. PUSHSELF,
  30. STORELOCAL0, STORELOCAL1, STORELOCAL2, STORELOCAL3, STORELOCAL4,
  31. STORELOCAL5, STORELOCAL6, STORELOCAL7, STORELOCAL8, STORELOCAL9,
  32. STORELOCAL,
  33. STOREGLOBAL,
  34. STOREINDEXED0,
  35. STOREINDEXED,
  36. STORELIST0,
  37. STORELIST,
  38. STORERECORD,
  39. ADJUST0,
  40. ADJUST,
  41. CREATEARRAY,
  42. EQOP,
  43. LTOP,
  44. LEOP,
  45. GTOP,
  46. GEOP,
  47. ADDOP,
  48. SUBOP,
  49. MULTOP,
  50. DIVOP,
  51. POWOP,
  52. CONCOP,
  53. MINUSOP,
  54. NOTOP,
  55. ONTJMP,
  56. ONFJMP,
  57. JMP,
  58. UPJMP,
  59. IFFJMP,
  60. IFFUPJMP,
  61. POP,
  62. CALLFUNC,
  63. RETCODE0,
  64. RETCODE,
  65. SETFUNCTION,
  66. SETLINE,
  67. RESET
  68. } OpCode;
  69. #define MULT_RET 255
  70. typedef void (*Cfunction) (void);
  71. typedef int (*Input) (void);
  72. typedef union
  73. {
  74. Cfunction f;
  75. real n;
  76. TaggedString *ts;
  77. TFunc *tf;
  78. struct Hash *a;
  79. void *u;
  80. } Value;
  81. typedef struct Object
  82. {
  83. lua_Type tag;
  84. Value value;
  85. } Object;
  86. typedef struct
  87. {
  88. Object object;
  89. } Symbol;
  90. /* Macros to access structure members */
  91. #define tag(o) ((o)->tag)
  92. #define nvalue(o) ((o)->value.n)
  93. #define svalue(o) ((o)->value.ts->str)
  94. #define tsvalue(o) ((o)->value.ts)
  95. #define avalue(o) ((o)->value.a)
  96. #define fvalue(o) ((o)->value.f)
  97. #define uvalue(o) ((o)->value.u)
  98. /* Macros to access symbol table */
  99. #define s_object(i) (lua_table[i].object)
  100. #define s_tag(i) (tag(&s_object(i)))
  101. #define s_nvalue(i) (nvalue(&s_object(i)))
  102. #define s_svalue(i) (svalue(&s_object(i)))
  103. #define s_avalue(i) (avalue(&s_object(i)))
  104. #define s_fvalue(i) (fvalue(&s_object(i)))
  105. #define s_uvalue(i) (uvalue(&s_object(i)))
  106. typedef union
  107. {
  108. struct {char c1; char c2;} m;
  109. Word w;
  110. } CodeWord;
  111. #define get_word(code,pc) {code.m.c1 = *pc++; code.m.c2 = *pc++;}
  112. typedef union
  113. {
  114. struct {char c1; char c2; char c3; char c4;} m;
  115. float f;
  116. } CodeFloat;
  117. #define get_float(code,pc) {code.m.c1 = *pc++; code.m.c2 = *pc++;\
  118. code.m.c3 = *pc++; code.m.c4 = *pc++;}
  119. typedef union
  120. {
  121. struct {char c1; char c2; char c3; char c4;} m;
  122. TFunc *tf;
  123. } CodeCode;
  124. #define get_code(code,pc) {code.m.c1 = *pc++; code.m.c2 = *pc++;\
  125. code.m.c3 = *pc++; code.m.c4 = *pc++;}
  126. /* Exported functions */
  127. char *lua_strdup (char *l);
  128. void lua_setinput (Input fn); /* from "lex.c" module */
  129. char *lua_lasttext (void); /* from "lex.c" module */
  130. int yylex (void); /* from "lex.c" module */
  131. void lua_parse (TFunc *tf); /* from "lua.stx" module */
  132. void lua_travstack (void (*fn)(Object *));
  133. Object *luaI_Address (lua_Object o);
  134. void luaI_pushobject (Object *o);
  135. void luaI_gcFB (Object *o);
  136. #endif