From 54f7b46c1e8a0188e1649046a3a72522f2d769f4 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Tue, 9 Jul 2019 10:43:17 -0300 Subject: New implementation for constants VLOCAL expressions keep a reference to their corresponding 'Vardesc', and 'Upvaldesc' (for upvalues) has a field 'ro' (read-only). So, it is easier to check whether a variable is read-only. The decoupling in VLOCAL between 'vidx' ('Vardesc' index) and 'sidx' (stack index) should also help the forthcoming implementation of compile-time constant propagation. --- lparser.h | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'lparser.h') diff --git a/lparser.h b/lparser.h index b708de25..cc2ec14d 100644 --- a/lparser.h +++ b/lparser.h @@ -33,8 +33,9 @@ typedef enum { VKINT, /* integer constant; nval = numerical integer value */ VNONRELOC, /* expression has its value in a fixed register; info = result register */ - VLOCAL, /* local variable; var.idx = local register */ - VUPVAL, /* upvalue variable; var.idx = index of upvalue in 'upvalues' */ + VLOCAL, /* local variable; var.ridx = local register; + var.vidx = index in 'actvar.arr' */ + VUPVAL, /* upvalue variable; info = index of upvalue in 'upvalues' */ VINDEXED, /* indexed variable; ind.t = table register; ind.idx = key's R index */ @@ -70,8 +71,9 @@ 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 */ + struct { /* for local variables */ + lu_byte sidx; /* index in the stack */ + unsigned short vidx; /* index in 'actvar.arr' */ } var; } u; int t; /* patch list of 'exit when true' */ @@ -81,9 +83,10 @@ typedef struct expdesc { /* description of an active local variable */ typedef struct Vardesc { - TValue val; /* constant value (if variable is 'const') */ - short idx; /* index of the variable in the Proto's 'locvars' array */ + TValuefields; /* constant value (if variable is 'const') */ lu_byte ro; /* true if variable is 'const' */ + lu_byte sidx; /* index of the variable in the stack */ + short pidx; /* index of the variable in the Proto's 'locvars' array */ } Vardesc; @@ -144,7 +147,6 @@ typedef struct FuncState { } FuncState; -LUAI_FUNC Vardesc *luaY_getvardesc (FuncState **fs, const expdesc *e); LUAI_FUNC LClosure *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff, Dyndata *dyd, const char *name, int firstchar); -- cgit v1.2.3-55-g6feb