lparser.h 1.9 KB

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