aboutsummaryrefslogtreecommitdiff
path: root/lparser.h
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2019-05-17 11:11:44 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2019-05-17 11:11:44 -0300
commitd9f40e3f6fb61650240c47d548bee69b24b07859 (patch)
treeab01022b3e3bc6bdb800423c97095a9423e0a798 /lparser.h
parent347d6961ac14213264c7176e3d125c9ba8475b01 (diff)
downloadlua-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.h13
1 files changed, 9 insertions, 4 deletions
diff --git a/lparser.h b/lparser.h
index 3d6bd978..3b5d399f 100644
--- a/lparser.h
+++ b/lparser.h
@@ -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
63typedef struct expdesc { 63typedef 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 */
80typedef struct Vardesc { 83typedef 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