lparser.h 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /*
  2. ** $Id: lparser.h,v 1.64 2010/07/02 20:42:40 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. 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. typedef struct vardesc {
  47. unsigned short idx;
  48. } vardesc;
  49. /* list of all active local variables */
  50. typedef struct Varlist {
  51. vardesc *actvar;
  52. int nactvar;
  53. int actvarsize;
  54. } Varlist;
  55. struct BlockCnt; /* defined in lparser.c */
  56. /* state needed to generate code for a given function */
  57. typedef struct FuncState {
  58. Proto *f; /* current function header */
  59. Table *h; /* table to find (and reuse) elements in `k' */
  60. struct FuncState *prev; /* enclosing function */
  61. struct LexState *ls; /* lexical state */
  62. struct lua_State *L; /* copy of the Lua state */
  63. struct BlockCnt *bl; /* chain of current blocks */
  64. int pc; /* next position to code (equivalent to `ncode') */
  65. int lasttarget; /* `pc' of last `jump target' */
  66. int jpc; /* list of pending jumps to `pc' */
  67. int freereg; /* first free register */
  68. int nk; /* number of elements in `k' */
  69. int np; /* number of elements in `p' */
  70. int firstlocal; /* index of first local var of this function */
  71. short nlocvars; /* number of elements in `locvars' */
  72. lu_byte nactvar; /* number of active local variables */
  73. lu_byte nups; /* number of upvalues */
  74. } FuncState;
  75. LUAI_FUNC Proto *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff,
  76. Varlist *varl, const char *name);
  77. #endif