Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

120 строки
3.3 KiB

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