opcode.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. /*
  2. ** TeCGraf - PUC-Rio
  3. ** $Id: opcode.h,v 2.3 1994/08/05 19:31:09 celes Exp celes $
  4. */
  5. #ifndef opcode_h
  6. #define opcode_h
  7. #ifndef STACKGAP
  8. #define STACKGAP 128
  9. #endif
  10. #ifndef real
  11. #define real float
  12. #endif
  13. #define FIELDS_PER_FLUSH 40
  14. typedef unsigned char Byte;
  15. typedef unsigned short Word;
  16. typedef signed long Long;
  17. typedef union
  18. {
  19. struct {char c1; char c2;} m;
  20. Word w;
  21. } CodeWord;
  22. typedef union
  23. {
  24. struct {char c1; char c2; char c3; char c4;} m;
  25. float f;
  26. } CodeFloat;
  27. typedef union
  28. {
  29. struct {char c1; char c2; char c3; char c4;} m;
  30. Byte *b;
  31. } CodeCode;
  32. typedef enum
  33. {
  34. PUSHNIL,
  35. PUSH0, PUSH1, PUSH2,
  36. PUSHBYTE,
  37. PUSHWORD,
  38. PUSHFLOAT,
  39. PUSHSTRING,
  40. PUSHFUNCTION,
  41. PUSHLOCAL0, PUSHLOCAL1, PUSHLOCAL2, PUSHLOCAL3, PUSHLOCAL4,
  42. PUSHLOCAL5, PUSHLOCAL6, PUSHLOCAL7, PUSHLOCAL8, PUSHLOCAL9,
  43. PUSHLOCAL,
  44. PUSHGLOBAL,
  45. PUSHINDEXED,
  46. PUSHMARK,
  47. PUSHMARKMET,
  48. STORELOCAL0, STORELOCAL1, STORELOCAL2, STORELOCAL3, STORELOCAL4,
  49. STORELOCAL5, STORELOCAL6, STORELOCAL7, STORELOCAL8, STORELOCAL9,
  50. STORELOCAL,
  51. STOREGLOBAL,
  52. STOREINDEXED0,
  53. STOREINDEXED,
  54. STORELIST0,
  55. STORELIST,
  56. STORERECORD,
  57. ADJUST,
  58. CREATEARRAY,
  59. EQOP,
  60. LTOP,
  61. LEOP,
  62. ADDOP,
  63. SUBOP,
  64. MULTOP,
  65. DIVOP,
  66. POWOP,
  67. CONCOP,
  68. MINUSOP,
  69. NOTOP,
  70. ONTJMP,
  71. ONFJMP,
  72. JMP,
  73. UPJMP,
  74. IFFJMP,
  75. IFFUPJMP,
  76. POP,
  77. CALLFUNC,
  78. RETCODE,
  79. HALT,
  80. SETFUNCTION,
  81. SETLINE,
  82. RESET
  83. } OpCode;
  84. typedef enum
  85. {
  86. T_MARK,
  87. T_NIL,
  88. T_NUMBER,
  89. T_STRING,
  90. T_ARRAY,
  91. T_FUNCTION,
  92. T_CFUNCTION,
  93. T_USERDATA
  94. } Type;
  95. typedef void (*Cfunction) (void);
  96. typedef int (*Input) (void);
  97. typedef union
  98. {
  99. Cfunction f;
  100. real n;
  101. char *s;
  102. Byte *b;
  103. struct Hash *a;
  104. void *u;
  105. } Value;
  106. typedef struct Object
  107. {
  108. Type tag;
  109. Value value;
  110. } Object;
  111. typedef struct
  112. {
  113. Object object;
  114. } Symbol;
  115. /* Macros to access structure members */
  116. #define tag(o) ((o)->tag)
  117. #define nvalue(o) ((o)->value.n)
  118. #define svalue(o) ((o)->value.s)
  119. #define bvalue(o) ((o)->value.b)
  120. #define avalue(o) ((o)->value.a)
  121. #define fvalue(o) ((o)->value.f)
  122. #define uvalue(o) ((o)->value.u)
  123. /* Macros to access symbol table */
  124. #define s_object(i) (lua_table[i].object)
  125. #define s_tag(i) (tag(&s_object(i)))
  126. #define s_nvalue(i) (nvalue(&s_object(i)))
  127. #define s_svalue(i) (svalue(&s_object(i)))
  128. #define s_bvalue(i) (bvalue(&s_object(i)))
  129. #define s_avalue(i) (avalue(&s_object(i)))
  130. #define s_fvalue(i) (fvalue(&s_object(i)))
  131. #define s_uvalue(i) (uvalue(&s_object(i)))
  132. #define get_word(code,pc) {code.m.c1 = *pc++; code.m.c2 = *pc++;}
  133. #define get_float(code,pc) {code.m.c1 = *pc++; code.m.c2 = *pc++;\
  134. code.m.c3 = *pc++; code.m.c4 = *pc++;}
  135. #define get_code(code,pc) {code.m.c1 = *pc++; code.m.c2 = *pc++;\
  136. code.m.c3 = *pc++; code.m.c4 = *pc++;}
  137. /* Exported functions */
  138. int lua_execute (Byte *pc);
  139. void lua_markstack (void);
  140. char *lua_strdup (char *l);
  141. void lua_setinput (Input fn); /* from "lex.c" module */
  142. char *lua_lasttext (void); /* from "lex.c" module */
  143. int lua_parse (void); /* from "lua.stx" module */
  144. void lua_type (void);
  145. void lua_obj2number (void);
  146. void lua_print (void);
  147. void lua_internaldofile (void);
  148. void lua_internaldostring (void);
  149. void lua_travstack (void (*fn)(Object *));
  150. #endif