2
0

lparser.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /*
  2. ** $Id: lparser.h,v 1.73 2014/06/19 18:27:20 roberto Exp roberto $
  3. ** Lua Parser
  4. ** See Copyright Notice in lua.h
  5. */
  6. #ifndef lparser_h
  7. #define lparser_h
  8. #include "llimits.h"
  9. #include "lobject.h"
  10. #include "lzio.h"
  11. /*
  12. ** Expression descriptor
  13. */
  14. typedef enum {
  15. VVOID, /* no value */
  16. VNIL,
  17. VTRUE,
  18. VFALSE,
  19. VK, /* info = index of constant in 'k' */
  20. VKFLT, /* nval = numerical float value */
  21. VKINT, /* nval = numerical integer value */
  22. VNONRELOC, /* info = result register */
  23. VLOCAL, /* info = local register */
  24. VUPVAL, /* info = index of upvalue in 'upvalues' */
  25. VINDEXED, /* t = table register/upvalue; idx = index R/K */
  26. VJMP, /* info = instruction pc */
  27. VRELOCABLE, /* info = instruction pc */
  28. VCALL, /* info = instruction pc */
  29. VVARARG /* info = instruction pc */
  30. } expkind;
  31. #define vkisvar(k) (VLOCAL <= (k) && (k) <= VINDEXED)
  32. #define vkisinreg(k) ((k) == VNONRELOC || (k) == VLOCAL)
  33. typedef struct expdesc {
  34. expkind k;
  35. union {
  36. struct { /* for indexed variables (VINDEXED) */
  37. short idx; /* index (R/K) */
  38. lu_byte t; /* table (register or upvalue) */
  39. lu_byte vt; /* whether 't' is register (VLOCAL) or upvalue (VUPVAL) */
  40. } ind;
  41. int info; /* for generic use */
  42. lua_Number nval; /* for VKFLT */
  43. lua_Integer ival; /* for VKINT */
  44. } u;
  45. int t; /* patch list of 'exit when true' */
  46. int f; /* patch list of 'exit when false' */
  47. } expdesc;
  48. /* description of active local variable */
  49. typedef struct Vardesc {
  50. short idx; /* variable index in stack */
  51. } Vardesc;
  52. /* description of pending goto statements and label statements */
  53. typedef struct Labeldesc {
  54. TString *name; /* label identifier */
  55. int pc; /* position in code */
  56. int line; /* line where it appeared */
  57. lu_byte nactvar; /* local level where it appears in current block */
  58. } Labeldesc;
  59. /* list of labels or gotos */
  60. typedef struct Labellist {
  61. Labeldesc *arr; /* array */
  62. int n; /* number of entries in use */
  63. int size; /* array size */
  64. } Labellist;
  65. /* dynamic structures used by the parser */
  66. typedef struct Dyndata {
  67. struct { /* list of active local variables */
  68. Vardesc *arr;
  69. int n;
  70. int size;
  71. } actvar;
  72. Labellist gt; /* list of pending gotos */
  73. Labellist label; /* list of active labels */
  74. } Dyndata;
  75. /* control of blocks */
  76. struct BlockCnt; /* defined in lparser.c */
  77. /* state needed to generate code for a given function */
  78. typedef struct FuncState {
  79. Proto *f; /* current function header */
  80. struct FuncState *prev; /* enclosing function */
  81. struct LexState *ls; /* lexical state */
  82. struct BlockCnt *bl; /* chain of current blocks */
  83. int pc; /* next position to code (equivalent to 'ncode') */
  84. int lasttarget; /* 'label' of last 'jump label' */
  85. int jpc; /* list of pending jumps to 'pc' */
  86. int nk; /* number of elements in 'k' */
  87. int np; /* number of elements in 'p' */
  88. int firstlocal; /* index of first local var (in Dyndata array) */
  89. short nlocvars; /* number of elements in 'f->locvars' */
  90. lu_byte nactvar; /* number of active local variables */
  91. lu_byte nups; /* number of upvalues */
  92. lu_byte freereg; /* first free register */
  93. } FuncState;
  94. LUAI_FUNC LClosure *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff,
  95. Dyndata *dyd, const char *name, int firstchar);
  96. #endif