lparser.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. ** $Id: lparser.h,v 1.54 2005/03/09 16:28:07 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 "ltable.h"
  11. #include "lzio.h"
  12. /*
  13. ** Expression descriptor
  14. */
  15. typedef enum {
  16. VVOID, /* no value */
  17. VNIL,
  18. VTRUE,
  19. VFALSE,
  20. VK, /* info = index of constant in `k' */
  21. VLOCAL, /* info = local register */
  22. VUPVAL, /* info = index of upvalue in `upvalues' */
  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. int info, aux;
  34. int t; /* patch list of `exit when true' */
  35. int f; /* patch list of `exit when false' */
  36. } expdesc;
  37. typedef struct upvaldesc {
  38. lu_byte k;
  39. lu_byte info;
  40. } upvaldesc;
  41. struct BlockCnt; /* defined in lparser.c */
  42. /* state needed to generate code for a given function */
  43. typedef struct FuncState {
  44. Proto *f; /* current function header */
  45. Table *h; /* table to find (and reuse) elements in `k' */
  46. struct FuncState *prev; /* enclosing function */
  47. struct LexState *ls; /* lexical state */
  48. struct lua_State *L; /* copy of the Lua state */
  49. struct BlockCnt *bl; /* chain of current blocks */
  50. int pc; /* next position to code (equivalent to `ncode') */
  51. int lasttarget; /* `pc' of last `jump target' */
  52. int jpc; /* list of pending jumps to `pc' */
  53. int freereg; /* first free register */
  54. int nk; /* number of elements in `k' */
  55. int np; /* number of elements in `p' */
  56. short nlocvars; /* number of elements in `locvars' */
  57. lu_byte nactvar; /* number of active local variables */
  58. upvaldesc upvalues[LUAI_MAXUPVALUES]; /* upvalues */
  59. unsigned short actvar[LUAI_MAXVARS]; /* declared-variable stack */
  60. } FuncState;
  61. LUAI_FUNC Proto *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff,
  62. const char *name);
  63. #endif