lparser.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*
  2. ** $Id: lparser.h,v 1.8 2000/03/03 14:58:26 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. /* maximum number of local variables */
  11. #ifndef MAXLOCALS
  12. #define MAXLOCALS 200 /* arbitrary limit (<=MAXARG_B) */
  13. #endif
  14. /* maximum number of upvalues */
  15. #ifndef MAXUPVALUES
  16. #define MAXUPVALUES 32 /* arbitrary limit (<=MAXARG_B) */
  17. #endif
  18. /* maximum number of variables in the left side of an assignment */
  19. #ifndef MAXVARSLH
  20. #define MAXVARSLH 100 /* arbitrary limit (<=MAXARG_B) */
  21. #endif
  22. /* maximum number of parameters in a function */
  23. #ifndef MAXPARAMS
  24. #define MAXPARAMS 100 /* arbitrary limit (<=MAXLOCALS) */
  25. #endif
  26. /* maximum stack size in a function */
  27. #ifndef MAXSTACK
  28. #define MAXSTACK 256 /* arbitrary limit (<=MAXARG_A) */
  29. #endif
  30. /*
  31. ** Expression descriptor
  32. */
  33. #define NOJUMPS 0
  34. typedef enum {
  35. VGLOBAL, /* info is constant index of global name */
  36. VLOCAL, /* info is stack index */
  37. VINDEXED, /* info is info of the index expression */
  38. VEXP /* info is NOJUMPS if exp has no internal jumps */
  39. } expkind;
  40. typedef struct expdesc {
  41. expkind k;
  42. int info;
  43. } expdesc;
  44. /*
  45. ** Expression List descriptor:
  46. ** tells number of expressions in the list,
  47. ** and gives the `info' of last expression.
  48. */
  49. typedef struct listdesc {
  50. int n;
  51. int info; /* 0 if last expression has no internal jumps */
  52. } listdesc;
  53. /* state needed to generate code for a given function */
  54. typedef struct FuncState {
  55. TProtoFunc *f; /* current function header */
  56. struct FuncState *prev; /* enclosing function */
  57. int pc; /* next position to code */
  58. int stacksize; /* number of values on activation register */
  59. int nlocalvar; /* number of active local variables */
  60. int nupvalues; /* number of upvalues */
  61. int nvars; /* number of entries in f->locvars (-1 if no debug information) */
  62. int lastsetline; /* line where last SETLINE was issued */
  63. expdesc upvalues[MAXUPVALUES]; /* upvalues */
  64. TaggedString *localvar[MAXLOCALS]; /* store local variable names */
  65. } FuncState;
  66. TProtoFunc *luaY_parser (lua_State *L, ZIO *z);
  67. #endif