lparser.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /*
  2. ** $Id: lparser.h,v 1.55 2005/04/25 19:24:10 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. 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. 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 upvaldesc {
  42. lu_byte k;
  43. lu_byte info;
  44. } upvaldesc;
  45. struct BlockCnt; /* defined in lparser.c */
  46. /* state needed to generate code for a given function */
  47. typedef struct FuncState {
  48. Proto *f; /* current function header */
  49. Table *h; /* table to find (and reuse) elements in `k' */
  50. struct FuncState *prev; /* enclosing function */
  51. struct LexState *ls; /* lexical state */
  52. struct lua_State *L; /* copy of the Lua state */
  53. struct BlockCnt *bl; /* chain of current blocks */
  54. int pc; /* next position to code (equivalent to `ncode') */
  55. int lasttarget; /* `pc' of last `jump target' */
  56. int jpc; /* list of pending jumps to `pc' */
  57. int freereg; /* first free register */
  58. int nk; /* number of elements in `k' */
  59. int np; /* number of elements in `p' */
  60. short nlocvars; /* number of elements in `locvars' */
  61. lu_byte nactvar; /* number of active local variables */
  62. upvaldesc upvalues[LUAI_MAXUPVALUES]; /* upvalues */
  63. unsigned short actvar[LUAI_MAXVARS]; /* declared-variable stack */
  64. } FuncState;
  65. LUAI_FUNC Proto *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff,
  66. const char *name);
  67. #endif