lparser.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*
  2. ** $Id: lparser.h,v 1.1 2001/11/29 22:14:34 rieru Exp rieru $
  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. /* small implementation of bit arrays */
  13. #define BPW (CHAR_BIT*sizeof(unsigned int)) /* bits per word */
  14. #define words2bits(b) (((b)-1)/BPW + 1)
  15. #define setbit(a, b) ((a)[(b)/BPW] |= (1 << (b)%BPW))
  16. #define resetbit(a, b) ((a)[(b)/BPW] &= ~((1 << (b)%BPW)))
  17. #define testbit(a, b) ((a)[(b)/BPW] & (1 << (b)%BPW))
  18. /*
  19. ** Expression descriptor
  20. */
  21. typedef enum {
  22. VVOID, /* no value */
  23. VNIL,
  24. VTRUE,
  25. VFALSE,
  26. VK, /* info = index of constant in `k' */
  27. VLOCAL, /* info = local register */
  28. VUPVAL, /* info = index of upvalue in `upvalues' */
  29. VGLOBAL, /* info = index of global name in `k' */
  30. VINDEXED, /* info = table register; aux = index register (or `k') */
  31. VRELOCABLE, /* info = instruction pc */
  32. VNONRELOC, /* info = result register */
  33. VJMP, /* info = result register */
  34. VCALL /* info = result register */
  35. } expkind;
  36. typedef struct expdesc {
  37. expkind k;
  38. int info, aux;
  39. int t; /* patch list of `exit when true' */
  40. int f; /* patch list of `exit when false' */
  41. } expdesc;
  42. /* state needed to generate code for a given function */
  43. typedef struct FuncState {
  44. Proto *f; /* current function header */
  45. struct FuncState *prev; /* enclosing function */
  46. struct LexState *ls; /* lexical state */
  47. struct lua_State *L; /* copy of the Lua state */
  48. int pc; /* next position to code (equivalent to `ncode') */
  49. int lasttarget; /* `pc' of last `jump target' */
  50. int jlt; /* list of jumps to `lasttarget' */
  51. int freereg; /* first free register */
  52. int nk; /* number of elements in `k' */
  53. Table *h; /* table to find (and reuse) elements in `k' */
  54. int np; /* number of elements in `p' */
  55. int nlineinfo; /* number of elements in `lineinfo' */
  56. int nlocvars; /* number of elements in `locvars' */
  57. int nactloc; /* number of active local variables */
  58. int lastline; /* line where last `lineinfo' was generated */
  59. struct Breaklabel *bl; /* chain of breakable blocks */
  60. expdesc upvalues[MAXUPVALUES]; /* upvalues */
  61. int actloc[MAXLOCALS]; /* local-variable stack (indices to locvars) */
  62. unsigned int wasup[words2bits(MAXLOCALS)]; /* bit array to mark whether a
  63. local variable was used as upvalue at some level */
  64. } FuncState;
  65. Proto *luaY_parser (lua_State *L, ZIO *z);
  66. #endif