lparser.h 2.0 KB

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