xref: /minix3/external/mit/lua/dist/src/lparser.h (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1 /*	$NetBSD: lparser.h,v 1.3 2015/02/02 14:03:05 lneto Exp $	*/
2 
3 /*
4 ** Id: lparser.h,v 1.74 2014/10/25 11:50:46 roberto Exp
5 ** Lua Parser
6 ** See Copyright Notice in lua.h
7 */
8 
9 #ifndef lparser_h
10 #define lparser_h
11 
12 #include "llimits.h"
13 #include "lobject.h"
14 #include "lzio.h"
15 
16 
17 /*
18 ** Expression descriptor
19 */
20 
21 typedef enum {
22   VVOID,	/* no value */
23   VNIL,
24   VTRUE,
25   VFALSE,
26   VK,		/* info = index of constant in 'k' */
27 #ifndef _KERNEL
28   VKFLT,	/* nval = numerical float value */
29 #endif
30   VKINT,	/* nval = numerical integer value */
31   VNONRELOC,	/* info = result register */
32   VLOCAL,	/* info = local register */
33   VUPVAL,       /* info = index of upvalue in 'upvalues' */
34   VINDEXED,	/* t = table register/upvalue; idx = index R/K */
35   VJMP,		/* info = instruction pc */
36   VRELOCABLE,	/* info = instruction pc */
37   VCALL,	/* info = instruction pc */
38   VVARARG	/* info = instruction pc */
39 } expkind;
40 
41 
42 #define vkisvar(k)	(VLOCAL <= (k) && (k) <= VINDEXED)
43 #define vkisinreg(k)	((k) == VNONRELOC || (k) == VLOCAL)
44 
45 typedef struct expdesc {
46   expkind k;
47   union {
48     struct {  /* for indexed variables (VINDEXED) */
49       short idx;  /* index (R/K) */
50       lu_byte t;  /* table (register or upvalue) */
51       lu_byte vt;  /* whether 't' is register (VLOCAL) or upvalue (VUPVAL) */
52     } ind;
53     int info;  /* for generic use */
54 #ifndef _KERNEL
55     lua_Number nval;  /* for VKFLT */
56 #endif
57     lua_Integer ival;    /* for VKINT */
58   } u;
59   int t;  /* patch list of 'exit when true' */
60   int f;  /* patch list of 'exit when false' */
61 } expdesc;
62 
63 
64 /* description of active local variable */
65 typedef struct Vardesc {
66   short idx;  /* variable index in stack */
67 } Vardesc;
68 
69 
70 /* description of pending goto statements and label statements */
71 typedef struct Labeldesc {
72   TString *name;  /* label identifier */
73   int pc;  /* position in code */
74   int line;  /* line where it appeared */
75   lu_byte nactvar;  /* local level where it appears in current block */
76 } Labeldesc;
77 
78 
79 /* list of labels or gotos */
80 typedef struct Labellist {
81   Labeldesc *arr;  /* array */
82   int n;  /* number of entries in use */
83   int size;  /* array size */
84 } Labellist;
85 
86 
87 /* dynamic structures used by the parser */
88 typedef struct Dyndata {
89   struct {  /* list of active local variables */
90     Vardesc *arr;
91     int n;
92     int size;
93   } actvar;
94   Labellist gt;  /* list of pending gotos */
95   Labellist label;   /* list of active labels */
96 } Dyndata;
97 
98 
99 /* control of blocks */
100 struct BlockCnt;  /* defined in lparser.c */
101 
102 
103 /* state needed to generate code for a given function */
104 typedef struct FuncState {
105   Proto *f;  /* current function header */
106   struct FuncState *prev;  /* enclosing function */
107   struct LexState *ls;  /* lexical state */
108   struct BlockCnt *bl;  /* chain of current blocks */
109   int pc;  /* next position to code (equivalent to 'ncode') */
110   int lasttarget;   /* 'label' of last 'jump label' */
111   int jpc;  /* list of pending jumps to 'pc' */
112   int nk;  /* number of elements in 'k' */
113   int np;  /* number of elements in 'p' */
114   int firstlocal;  /* index of first local var (in Dyndata array) */
115   short nlocvars;  /* number of elements in 'f->locvars' */
116   lu_byte nactvar;  /* number of active local variables */
117   lu_byte nups;  /* number of upvalues */
118   lu_byte freereg;  /* first free register */
119 } FuncState;
120 
121 
122 LUAI_FUNC LClosure *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff,
123                                  Dyndata *dyd, const char *name, int firstchar);
124 
125 
126 #endif
127