lparser.h 2.4 KB

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