lparser.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. ** $Id: lparser.h,v 1.57.1.1 2007/12/27 13:02:25 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. {
  16. VVOID, /* no value */
  17. VNIL,
  18. VTRUE,
  19. VFALSE,
  20. VK, /* info = index of constant in `k' */
  21. VKNUM, /* nval = numerical value */
  22. VLOCAL, /* info = local register */
  23. VUPVAL, /* info = index of upvalue in `upvalues' */
  24. VGLOBAL, /* info = index of table; aux = index of global name in `k' */
  25. VINDEXED, /* info = table register; aux = index register (or `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. {
  34. expkind k;
  35. union
  36. {
  37. struct
  38. {
  39. int info, aux;
  40. } s;
  41. lua_Number nval;
  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 upvaldesc
  47. {
  48. lu_byte k;
  49. lu_byte info;
  50. } upvaldesc;
  51. struct BlockCnt; /* defined in lparser.c */
  52. /* state needed to generate code for a given function */
  53. typedef struct FuncState
  54. {
  55. Proto *f; /* current function header */
  56. Table *h; /* table to find (and reuse) elements in `k' */
  57. struct FuncState *prev; /* enclosing function */
  58. struct LexState *ls; /* lexical state */
  59. struct lua_State *L; /* copy of the Lua state */
  60. struct BlockCnt *bl; /* chain of current blocks */
  61. int pc; /* next position to code (equivalent to `ncode') */
  62. int lasttarget; /* `pc' of last `jump target' */
  63. int jpc; /* list of pending jumps to `pc' */
  64. int freereg; /* first free register */
  65. int nk; /* number of elements in `k' */
  66. int np; /* number of elements in `p' */
  67. short nlocvars; /* number of elements in `locvars' */
  68. lu_byte nactvar; /* number of active local variables */
  69. upvaldesc upvalues[LUAI_MAXUPVALUES]; /* upvalues */
  70. unsigned short actvar[LUAI_MAXVARS]; /* declared-variable stack */
  71. } FuncState;
  72. LUAI_FUNC Proto *luaY_parser(lua_State *L, ZIO *z, Mbuffer *buff,
  73. const char *name);
  74. #endif