diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2019-05-17 11:11:44 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2019-05-17 11:11:44 -0300 |
| commit | d9f40e3f6fb61650240c47d548bee69b24b07859 (patch) | |
| tree | ab01022b3e3bc6bdb800423c97095a9423e0a798 /lparser.h | |
| parent | 347d6961ac14213264c7176e3d125c9ba8475b01 (diff) | |
| download | lua-d9f40e3f6fb61650240c47d548bee69b24b07859.tar.gz lua-d9f40e3f6fb61650240c47d548bee69b24b07859.tar.bz2 lua-d9f40e3f6fb61650240c47d548bee69b24b07859.zip | |
First implementation for 'const' variables
A variable can be declared const, which means it cannot be assigned to,
with the syntax 'local <const> name = exp'.
Diffstat (limited to 'lparser.h')
| -rw-r--r-- | lparser.h | 13 |
1 files changed, 9 insertions, 4 deletions
| @@ -33,8 +33,8 @@ typedef enum { | |||
| 33 | VKINT, /* integer constant; nval = numerical integer value */ | 33 | VKINT, /* integer constant; nval = numerical integer value */ |
| 34 | VNONRELOC, /* expression has its value in a fixed register; | 34 | VNONRELOC, /* expression has its value in a fixed register; |
| 35 | info = result register */ | 35 | info = result register */ |
| 36 | VLOCAL, /* local variable; info = local register */ | 36 | VLOCAL, /* local variable; var.idx = local register */ |
| 37 | VUPVAL, /* upvalue variable; info = index of upvalue in 'upvalues' */ | 37 | VUPVAL, /* upvalue variable; var.idx = index of upvalue in 'upvalues' */ |
| 38 | VINDEXED, /* indexed variable; | 38 | VINDEXED, /* indexed variable; |
| 39 | ind.t = table register; | 39 | ind.t = table register; |
| 40 | ind.idx = key's R index */ | 40 | ind.idx = key's R index */ |
| @@ -58,7 +58,7 @@ typedef enum { | |||
| 58 | 58 | ||
| 59 | #define vkisvar(k) (VLOCAL <= (k) && (k) <= VINDEXSTR) | 59 | #define vkisvar(k) (VLOCAL <= (k) && (k) <= VINDEXSTR) |
| 60 | #define vkisindexed(k) (VINDEXED <= (k) && (k) <= VINDEXSTR) | 60 | #define vkisindexed(k) (VINDEXED <= (k) && (k) <= VINDEXSTR) |
| 61 | #define vkisinreg(k) ((k) == VNONRELOC || (k) == VLOCAL) | 61 | |
| 62 | 62 | ||
| 63 | typedef struct expdesc { | 63 | typedef struct expdesc { |
| 64 | expkind k; | 64 | expkind k; |
| @@ -70,15 +70,20 @@ typedef struct expdesc { | |||
| 70 | short idx; /* index (R or "long" K) */ | 70 | short idx; /* index (R or "long" K) */ |
| 71 | lu_byte t; /* table (register or upvalue) */ | 71 | lu_byte t; /* table (register or upvalue) */ |
| 72 | } ind; | 72 | } ind; |
| 73 | struct { /* for local variables and upvalues */ | ||
| 74 | lu_byte idx; /* index of the variable */ | ||
| 75 | } var; | ||
| 73 | } u; | 76 | } u; |
| 74 | int t; /* patch list of 'exit when true' */ | 77 | int t; /* patch list of 'exit when true' */ |
| 75 | int f; /* patch list of 'exit when false' */ | 78 | int f; /* patch list of 'exit when false' */ |
| 76 | } expdesc; | 79 | } expdesc; |
| 77 | 80 | ||
| 78 | 81 | ||
| 79 | /* description of active local variable */ | 82 | /* description of an active local variable */ |
| 80 | typedef struct Vardesc { | 83 | typedef struct Vardesc { |
| 84 | TString *name; | ||
| 81 | short idx; /* index of the variable in the Proto's 'locvars' array */ | 85 | short idx; /* index of the variable in the Proto's 'locvars' array */ |
| 86 | lu_byte ro; /* true if variable is 'const' */ | ||
| 82 | } Vardesc; | 87 | } Vardesc; |
| 83 | 88 | ||
| 84 | 89 | ||
