lparser.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*
  2. ** $Id: lparser.h,v 1.60 2009/09/30 15:38:37 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. VLOCAL, /* info = local register; aux = read only */
  22. VUPVAL, /* info = index of upvalue in 'upvalues'; aux = read only */
  23. VGLOBAL, /* info = index of table; aux = index of global name in `k' */
  24. VINDEXED, /* info = table register; aux = index register (or `k') */
  25. VJMP, /* info = instruction pc */
  26. VRELOCABLE, /* info = instruction pc */
  27. VNONRELOC, /* info = result register */
  28. VCALL, /* info = instruction pc */
  29. VVARARG /* info = instruction pc */
  30. } expkind;
  31. typedef struct expdesc {
  32. expkind k;
  33. union {
  34. struct { int info, aux; } s;
  35. lua_Number nval;
  36. } u;
  37. int t; /* patch list of `exit when true' */
  38. int f; /* patch list of `exit when false' */
  39. } expdesc;
  40. typedef struct vardesc {
  41. unsigned short idx;
  42. } vardesc;
  43. /* list of all active local variables */
  44. typedef struct Varlist {
  45. vardesc *actvar;
  46. int nactvar;
  47. int actvarsize;
  48. } Varlist;
  49. struct BlockCnt; /* defined in lparser.c */
  50. /* state needed to generate code for a given function */
  51. typedef struct FuncState {
  52. Proto *f; /* current function header */
  53. Table *h; /* table to find (and reuse) elements in `k' */
  54. struct FuncState *prev; /* enclosing function */
  55. struct LexState *ls; /* lexical state */
  56. struct lua_State *L; /* copy of the Lua state */
  57. struct BlockCnt *bl; /* chain of current blocks */
  58. int pc; /* next position to code (equivalent to `ncode') */
  59. int lasttarget; /* `pc' of last `jump target' */
  60. int jpc; /* list of pending jumps to `pc' */
  61. int freereg; /* first free register */
  62. int nk; /* number of elements in `k' */
  63. int np; /* number of elements in `p' */
  64. int firstlocal; /* index of first local var of this function */
  65. short nlocvars; /* number of elements in `locvars' */
  66. lu_byte nactvar; /* number of active local variables */
  67. lu_byte nups; /* number of upvalues */
  68. lu_byte envreg; /* register holding current lexical environment */
  69. } FuncState;
  70. LUAI_FUNC Proto *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff,
  71. Varlist *varl, const char *name);
  72. #endif