Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
4680 | right-hear | 1 | /* |
2 | ** $Id: lparser.h,v 1.65 2010/07/07 16:27:29 roberto Exp $ |
||
3 | ** Lua Parser |
||
4 | ** See Copyright Notice in lua.h |
||
5 | */ |
||
6 | |||
7 | #ifndef lparser_h |
||
8 | #define lparser_h |
||
9 | |||
10 | #include "llimits.h" |
||
11 | #include "lobject.h" |
||
12 | #include "lzio.h" |
||
13 | |||
14 | |||
15 | /* |
||
16 | ** Expression descriptor |
||
17 | */ |
||
18 | |||
19 | typedef enum { |
||
20 | VVOID, /* no value */ |
||
21 | VNIL, |
||
22 | VTRUE, |
||
23 | VFALSE, |
||
24 | VK, /* info = index of constant in `k' */ |
||
25 | VKNUM, /* nval = numerical value */ |
||
26 | VNONRELOC, /* info = result register */ |
||
27 | VLOCAL, /* info = local register */ |
||
28 | VUPVAL, /* info = index of upvalue in 'upvalues' */ |
||
29 | VINDEXED, /* t = table register/upvalue; idx = index R/K */ |
||
30 | VJMP, /* info = instruction pc */ |
||
31 | VRELOCABLE, /* info = instruction pc */ |
||
32 | VCALL, /* info = instruction pc */ |
||
33 | VVARARG /* info = instruction pc */ |
||
34 | } expkind; |
||
35 | |||
36 | |||
37 | #define vkisvar(k) (VLOCAL <= (k) && (k) <= VINDEXED) |
||
38 | #define vkisinreg(k) ((k) == VNONRELOC || (k) == VLOCAL) |
||
39 | |||
40 | typedef struct expdesc { |
||
41 | expkind k; |
||
42 | union { |
||
43 | struct { /* for indexed variables (VINDEXED) */ |
||
44 | short idx; /* index (R/K) */ |
||
45 | lu_byte t; /* table (register or upvalue) */ |
||
46 | lu_byte vt; /* whether 't' is register (VLOCAL) or upvalue (VUPVAL) */ |
||
47 | } ind; |
||
48 | int info; /* for generic use */ |
||
49 | lua_Number nval; /* for VKNUM */ |
||
50 | } u; |
||
51 | int t; /* patch list of `exit when true' */ |
||
52 | int f; /* patch list of `exit when false' */ |
||
53 | } expdesc; |
||
54 | |||
55 | |||
56 | typedef struct vardesc { |
||
57 | unsigned short idx; |
||
58 | } vardesc; |
||
59 | |||
60 | |||
61 | /* list of all active local variables */ |
||
62 | typedef struct Varlist { |
||
63 | vardesc *actvar; |
||
64 | int nactvar; |
||
65 | int actvarsize; |
||
66 | } Varlist; |
||
67 | |||
68 | |||
69 | struct BlockCnt; /* defined in lparser.c */ |
||
70 | |||
71 | |||
72 | /* state needed to generate code for a given function */ |
||
73 | typedef struct FuncState { |
||
74 | Proto *f; /* current function header */ |
||
75 | Table *h; /* table to find (and reuse) elements in `k' */ |
||
76 | struct FuncState *prev; /* enclosing function */ |
||
77 | struct LexState *ls; /* lexical state */ |
||
78 | struct lua_State *L; /* copy of the Lua state */ |
||
79 | struct BlockCnt *bl; /* chain of current blocks */ |
||
80 | int pc; /* next position to code (equivalent to `ncode') */ |
||
81 | int lasttarget; /* `pc' of last `jump target' */ |
||
82 | int jpc; /* list of pending jumps to `pc' */ |
||
83 | int freereg; /* first free register */ |
||
84 | int nk; /* number of elements in `k' */ |
||
85 | int np; /* number of elements in `p' */ |
||
86 | int firstlocal; /* index of first local var of this function */ |
||
87 | short nlocvars; /* number of elements in `locvars' */ |
||
88 | lu_byte nactvar; /* number of active local variables */ |
||
89 | lu_byte nups; /* number of upvalues */ |
||
90 | } FuncState; |
||
91 | |||
92 | |||
93 | LUAI_FUNC Proto *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff, |
||
94 | Varlist *varl, const char *name); |
||
95 | |||
96 | |||
97 | #endif=>=> |