lparser.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /*
  2. ** $Id: lparser.h,v 1.34 2001/08/27 15:16:28 roberto Exp $
  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. VNUMBER, /* n = value */
  25. VK, /* info = index of constant in `k' */
  26. VLOCAL, /* info = local register */
  27. VUPVAL, /* info = index of upvalue in `upvalues' */
  28. VGLOBAL, /* info = index of global name in `k' */
  29. VINDEXED, /* info = table register; aux = index register (or `k') */
  30. VRELOCABLE, /* info = instruction pc */
  31. VNONRELOC, /* info = result register */
  32. VJMP, /* info = result register */
  33. VCALL /* info = result register */
  34. } expkind;
  35. typedef struct expdesc {
  36. expkind k;
  37. union {
  38. struct {
  39. int info, aux;
  40. } i;
  41. lua_Number n;
  42. } u;
  43. int t; /* patch list of `exit when true' */
  44. int f; /* patch list of `exit when false' */
  45. } expdesc;
  46. /* state needed to generate code for a given function */
  47. typedef struct FuncState {
  48. Proto *f; /* current function header */
  49. struct FuncState *prev; /* enclosing function */
  50. struct LexState *ls; /* lexical state */
  51. struct lua_State *L; /* copy of the Lua state */
  52. int pc; /* next position to code (equivalent to `ncode') */
  53. int lasttarget; /* `pc' of last `jump target' */
  54. int jlt; /* list of jumps to `lasttarget' */
  55. int freereg; /* first free register */
  56. int nk; /* number of elements in `k' */
  57. Hash *h; /* table to find (and reuse) elements in `k' */
  58. int np; /* number of elements in `p' */
  59. int nlineinfo; /* number of elements in `lineinfo' */
  60. int nlocvars; /* number of elements in `locvars' */
  61. int nactloc; /* number of active local variables */
  62. int lastline; /* line where last `lineinfo' was generated */
  63. struct Breaklabel *bl; /* chain of breakable blocks */
  64. expdesc upvalues[MAXUPVALUES]; /* upvalues */
  65. int actloc[MAXLOCALS]; /* local-variable stack (indices to locvars) */
  66. unsigned int wasup[words2bits(MAXLOCALS)]; /* bit array to mark whether a
  67. local variable was used as upvalue at some level */
  68. } FuncState;
  69. Proto *luaY_parser (lua_State *L, ZIO *z);
  70. #endif