lparser.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*
  2. ** $Id: lparser.h,v 1.33 2001/08/10 20:53:03 roberto Exp roberto $
  3. ** Lua Parser
  4. ** See Copyright Notice in lua.h
  5. */
  6. #ifndef lparser_h
  7. #define lparser_h
  8. #include "lobject.h"
  9. #include "ltable.h"
  10. #include "lzio.h"
  11. /*
  12. ** Expression descriptor
  13. */
  14. typedef enum {
  15. VVOID, /* no value */
  16. VNIL,
  17. VNUMBER, /* n = value */
  18. VK, /* info = index of constant in `k' */
  19. VGLOBAL, /* info = index of global name in `k' */
  20. VLOCAL, /* info = local register */
  21. VINDEXED, /* info = table register; aux = index register (or `k') */
  22. VRELOCABLE, /* info = instruction pc */
  23. VNONRELOC, /* info = result register */
  24. VJMP, /* info = result register */
  25. VCALL /* info = result register */
  26. } expkind;
  27. typedef struct expdesc {
  28. expkind k;
  29. union {
  30. struct {
  31. int info, aux;
  32. } i;
  33. lua_Number n;
  34. } u;
  35. int t; /* patch list of `exit when true' */
  36. int f; /* patch list of `exit when false' */
  37. } expdesc;
  38. /* state needed to generate code for a given function */
  39. typedef struct FuncState {
  40. Proto *f; /* current function header */
  41. struct FuncState *prev; /* enclosing function */
  42. struct LexState *ls; /* lexical state */
  43. struct lua_State *L; /* copy of the Lua state */
  44. int pc; /* next position to code (equivalent to `ncode') */
  45. int lasttarget; /* `pc' of last `jump target' */
  46. int jlt; /* list of jumps to `lasttarget' */
  47. int freereg; /* first free register */
  48. int nk; /* number of elements in `k' */
  49. Hash *h; /* table to find (and reuse) elements in `k' */
  50. int np; /* number of elements in `p' */
  51. int nlineinfo; /* number of elements in `lineinfo' */
  52. int nlocvars; /* number of elements in `locvars' */
  53. int nactloc; /* number of active local variables */
  54. int lastline; /* line where last `lineinfo' was generated */
  55. struct Breaklabel *bl; /* chain of breakable blocks */
  56. expdesc upvalues[MAXUPVALUES]; /* upvalues */
  57. int actloc[MAXLOCALS]; /* local-variable stack (indices to locvars) */
  58. } FuncState;
  59. Proto *luaY_parser (lua_State *L, ZIO *z);
  60. #endif