lparser.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /*
  2. ** $Id: lparser.h,v 1.44 2002/05/14 17:52:22 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 = result register */
  29. } expkind;
  30. typedef struct expdesc {
  31. expkind k;
  32. int info, aux;
  33. int t; /* patch list of `exit when true' */
  34. int f; /* patch list of `exit when false' */
  35. } expdesc;
  36. struct BlockCnt; /* defined in lparser.c */
  37. /* state needed to generate code for a given function */
  38. typedef struct FuncState {
  39. Proto *f; /* current function header */
  40. Table *h; /* table to find (and reuse) elements in `k' */
  41. struct FuncState *prev; /* enclosing function */
  42. struct LexState *ls; /* lexical state */
  43. struct lua_State *L; /* copy of the Lua state */
  44. struct BlockCnt *bl; /* chain of current blocks */
  45. int pc; /* next position to code (equivalent to `ncode') */
  46. int lasttarget; /* `pc' of last `jump target' */
  47. int jpc; /* list of pending jumps to `pc' */
  48. int freereg; /* first free register */
  49. int nk; /* number of elements in `k' */
  50. int np; /* number of elements in `p' */
  51. int nlocvars; /* number of elements in `locvars' */
  52. int nactvar; /* number of active local variables */
  53. expdesc upvalues[MAXUPVALUES]; /* upvalues */
  54. int actvar[MAXVARS]; /* declared-variable stack */
  55. } FuncState;
  56. Proto *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff);
  57. #endif