diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2002-03-14 15:01:52 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2002-03-14 15:01:52 -0300 |
commit | 7ff21273d66541ac19ad817f90e8bcea5790f355 (patch) | |
tree | 9798243bbc84da7f0ea3aa7316ba42b06b947e63 /lparser.h | |
parent | 207dad86065acf4b6168bea1f13e88b7306a7440 (diff) | |
download | lua-7ff21273d66541ac19ad817f90e8bcea5790f355.tar.gz lua-7ff21273d66541ac19ad817f90e8bcea5790f355.tar.bz2 lua-7ff21273d66541ac19ad817f90e8bcea5790f355.zip |
implementation of `global' statement
Diffstat (limited to 'lparser.h')
-rw-r--r-- | lparser.h | 36 |
1 files changed, 18 insertions, 18 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lparser.h,v 1.1 2001/11/29 22:14:34 rieru Exp rieru $ | 2 | ** $Id: lparser.h,v 1.39 2002/02/08 22:42:41 roberto Exp roberto $ |
3 | ** Lua Parser | 3 | ** Lua Parser |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -13,18 +13,6 @@ | |||
13 | #include "lzio.h" | 13 | #include "lzio.h" |
14 | 14 | ||
15 | 15 | ||
16 | |||
17 | /* small implementation of bit arrays */ | ||
18 | |||
19 | #define BPW (CHAR_BIT*sizeof(unsigned int)) /* bits per word */ | ||
20 | |||
21 | #define words2bits(b) (((b)-1)/BPW + 1) | ||
22 | |||
23 | #define setbit(a, b) ((a)[(b)/BPW] |= (1 << (b)%BPW)) | ||
24 | #define resetbit(a, b) ((a)[(b)/BPW] &= ~((1 << (b)%BPW))) | ||
25 | #define testbit(a, b) ((a)[(b)/BPW] & (1 << (b)%BPW)) | ||
26 | |||
27 | |||
28 | /* | 16 | /* |
29 | ** Expression descriptor | 17 | ** Expression descriptor |
30 | */ | 18 | */ |
@@ -37,7 +25,7 @@ typedef enum { | |||
37 | VK, /* info = index of constant in `k' */ | 25 | VK, /* info = index of constant in `k' */ |
38 | VLOCAL, /* info = local register */ | 26 | VLOCAL, /* info = local register */ |
39 | VUPVAL, /* info = index of upvalue in `upvalues' */ | 27 | VUPVAL, /* info = index of upvalue in `upvalues' */ |
40 | VGLOBAL, /* info = index of global name in `k' */ | 28 | VGLOBAL, /* info = index of table; aux = index of global name in `k' */ |
41 | VINDEXED, /* info = table register; aux = index register (or `k') */ | 29 | VINDEXED, /* info = table register; aux = index register (or `k') */ |
42 | VRELOCABLE, /* info = instruction pc */ | 30 | VRELOCABLE, /* info = instruction pc */ |
43 | VNONRELOC, /* info = result register */ | 31 | VNONRELOC, /* info = result register */ |
@@ -53,6 +41,18 @@ typedef struct expdesc { | |||
53 | } expdesc; | 41 | } expdesc; |
54 | 42 | ||
55 | 43 | ||
44 | /* describe declared variables */ | ||
45 | typedef struct vardesc { | ||
46 | int i; /* if local, its index in `locvars'; | ||
47 | if global, its name index in `k' */ | ||
48 | lu_byte k; | ||
49 | lu_byte level; /* if local, stack level; | ||
50 | if global, corresponding local (NO_REG for free globals) */ | ||
51 | } vardesc; | ||
52 | |||
53 | |||
54 | struct BlockCnt; /* defined in lparser.c */ | ||
55 | |||
56 | /* state needed to generate code for a given function */ | 56 | /* state needed to generate code for a given function */ |
57 | typedef struct FuncState { | 57 | typedef struct FuncState { |
58 | Proto *f; /* current function header */ | 58 | Proto *f; /* current function header */ |
@@ -60,21 +60,21 @@ typedef struct FuncState { | |||
60 | struct FuncState *prev; /* enclosing function */ | 60 | struct FuncState *prev; /* enclosing function */ |
61 | struct LexState *ls; /* lexical state */ | 61 | struct LexState *ls; /* lexical state */ |
62 | struct lua_State *L; /* copy of the Lua state */ | 62 | struct lua_State *L; /* copy of the Lua state */ |
63 | struct Breaklabel *bl; /* chain of breakable blocks */ | 63 | struct BlockCnt *bl; /* chain of current blocks */ |
64 | int pc; /* next position to code (equivalent to `ncode') */ | 64 | int pc; /* next position to code (equivalent to `ncode') */ |
65 | int lasttarget; /* `pc' of last `jump target' */ | 65 | int lasttarget; /* `pc' of last `jump target' */ |
66 | int jlt; /* list of jumps to `lasttarget' */ | 66 | int jlt; /* list of jumps to `lasttarget' */ |
67 | int freereg; /* first free register */ | 67 | int freereg; /* first free register */ |
68 | int defaultglob; /* where to look for non-declared globals */ | ||
68 | int nk; /* number of elements in `k' */ | 69 | int nk; /* number of elements in `k' */ |
69 | int np; /* number of elements in `p' */ | 70 | int np; /* number of elements in `p' */ |
70 | int nlineinfo; /* number of elements in `lineinfo' */ | 71 | int nlineinfo; /* number of elements in `lineinfo' */ |
71 | int nlocvars; /* number of elements in `locvars' */ | 72 | int nlocvars; /* number of elements in `locvars' */ |
72 | int nactloc; /* number of active local variables */ | 73 | int nactloc; /* number of active local variables */ |
74 | int nactvar; /* number of elements in array `actvar' */ | ||
73 | int lastline; /* line where last `lineinfo' was generated */ | 75 | int lastline; /* line where last `lineinfo' was generated */ |
74 | expdesc upvalues[MAXUPVALUES]; /* upvalues */ | 76 | expdesc upvalues[MAXUPVALUES]; /* upvalues */ |
75 | int actloc[MAXLOCALS]; /* local-variable stack (indices to locvars) */ | 77 | vardesc actvar[MAXVARS]; /* declared-variable stack */ |
76 | unsigned int wasup[words2bits(MAXLOCALS)]; /* bit array to mark whether a | ||
77 | local variable was used as upvalue at some level */ | ||
78 | } FuncState; | 78 | } FuncState; |
79 | 79 | ||
80 | 80 | ||