lparser.h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*
  2. ** $Id: lparser.h,v 1.40 2002/03/14 18:01:52 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. VRELOCABLE, /* info = instruction pc */
  26. VNONRELOC, /* info = result register */
  27. VJMP, /* 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. /* describe declared variables */
  37. typedef struct vardesc {
  38. int i; /* if local, its index in `locvars';
  39. if global, its name index in `k' */
  40. lu_byte k;
  41. lu_byte level; /* if local, stack level;
  42. if global, corresponding local (NO_REG for free globals) */
  43. } vardesc;
  44. struct BlockCnt; /* defined in lparser.c */
  45. /* state needed to generate code for a given function */
  46. typedef struct FuncState {
  47. Proto *f; /* current function header */
  48. Table *h; /* table to find (and reuse) elements in `k' */
  49. struct FuncState *prev; /* enclosing function */
  50. struct LexState *ls; /* lexical state */
  51. struct lua_State *L; /* copy of the Lua state */
  52. struct BlockCnt *bl; /* chain of current blocks */
  53. int pc; /* next position to code (equivalent to `ncode') */
  54. int lasttarget; /* `pc' of last `jump target' */
  55. int jlt; /* list of jumps to `lasttarget' */
  56. int freereg; /* first free register */
  57. int defaultglob; /* where to look for non-declared globals */
  58. int nk; /* number of elements in `k' */
  59. int np; /* number of elements in `p' */
  60. int nlocvars; /* number of elements in `locvars' */
  61. int nactloc; /* number of active local variables */
  62. int nactvar; /* number of elements in array `actvar' */
  63. expdesc upvalues[MAXUPVALUES]; /* upvalues */
  64. vardesc actvar[MAXVARS]; /* declared-variable stack */
  65. } FuncState;
  66. Proto *luaY_parser (lua_State *L, ZIO *z);
  67. #endif