From d9f40e3f6fb61650240c47d548bee69b24b07859 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Fri, 17 May 2019 11:11:44 -0300 Subject: First implementation for 'const' variables A variable can be declared const, which means it cannot be assigned to, with the syntax 'local name = exp'. --- lparser.h | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'lparser.h') diff --git a/lparser.h b/lparser.h index 3d6bd978..3b5d399f 100644 --- a/lparser.h +++ b/lparser.h @@ -33,8 +33,8 @@ typedef enum { VKINT, /* integer constant; nval = numerical integer value */ VNONRELOC, /* expression has its value in a fixed register; info = result register */ - VLOCAL, /* local variable; info = local register */ - VUPVAL, /* upvalue variable; info = index of upvalue in 'upvalues' */ + VLOCAL, /* local variable; var.idx = local register */ + VUPVAL, /* upvalue variable; var.idx = index of upvalue in 'upvalues' */ VINDEXED, /* indexed variable; ind.t = table register; ind.idx = key's R index */ @@ -58,7 +58,7 @@ typedef enum { #define vkisvar(k) (VLOCAL <= (k) && (k) <= VINDEXSTR) #define vkisindexed(k) (VINDEXED <= (k) && (k) <= VINDEXSTR) -#define vkisinreg(k) ((k) == VNONRELOC || (k) == VLOCAL) + typedef struct expdesc { expkind k; @@ -70,15 +70,20 @@ typedef struct expdesc { short idx; /* index (R or "long" K) */ lu_byte t; /* table (register or upvalue) */ } ind; + struct { /* for local variables and upvalues */ + lu_byte idx; /* index of the variable */ + } var; } u; int t; /* patch list of 'exit when true' */ int f; /* patch list of 'exit when false' */ } expdesc; -/* description of active local variable */ +/* description of an active local variable */ typedef struct Vardesc { + TString *name; short idx; /* index of the variable in the Proto's 'locvars' array */ + lu_byte ro; /* true if variable is 'const' */ } Vardesc; -- cgit v1.2.3-55-g6feb