opcode.h 2.9 KB

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