2 ** $Id: lparser.h,v 1.70 2012/05/08 13:53:33 roberto Exp $
4 ** See Copyright Notice in lua.h
16 ** Expression descriptor
24 VK
, /* info = index of constant in `k' */
25 VKNUM
, /* nval = numerical value */
26 VNONRELOC
, /* info = result register */
27 VLOCAL
, /* info = local register */
28 VUPVAL
, /* info = index of upvalue in 'upvalues' */
29 VINDEXED
, /* t = table register/upvalue; idx = index R/K */
30 VJMP
, /* info = instruction pc */
31 VRELOCABLE
, /* info = instruction pc */
32 VCALL
, /* info = instruction pc */
33 VVARARG
/* info = instruction pc */
37 #define vkisvar(k) (VLOCAL <= (k) && (k) <= VINDEXED)
38 #define vkisinreg(k) ((k) == VNONRELOC || (k) == VLOCAL)
40 typedef struct expdesc
{
43 struct { /* for indexed variables (VINDEXED) */
44 short idx
; /* index (R/K) */
45 lu_byte t
; /* table (register or upvalue) */
46 lu_byte vt
; /* whether 't' is register (VLOCAL) or upvalue (VUPVAL) */
48 int info
; /* for generic use */
49 lua_Number nval
; /* for VKNUM */
51 int t
; /* patch list of `exit when true' */
52 int f
; /* patch list of `exit when false' */
56 /* description of active local variable */
57 typedef struct Vardesc
{
58 short idx
; /* variable index in stack */
62 /* description of pending goto statements and label statements */
63 typedef struct Labeldesc
{
64 TString
*name
; /* label identifier */
65 int pc
; /* position in code */
66 int line
; /* line where it appeared */
67 lu_byte nactvar
; /* local level where it appears in current block */
71 /* list of labels or gotos */
72 typedef struct Labellist
{
73 Labeldesc
*arr
; /* array */
74 int n
; /* number of entries in use */
75 int size
; /* array size */
79 /* dynamic structures used by the parser */
80 typedef struct Dyndata
{
81 struct { /* list of active local variables */
86 Labellist gt
; /* list of pending gotos */
87 Labellist label
; /* list of active labels */
91 /* control of blocks */
92 struct BlockCnt
; /* defined in lparser.c */
95 /* state needed to generate code for a given function */
96 typedef struct FuncState
{
97 Proto
*f
; /* current function header */
98 Table
*h
; /* table to find (and reuse) elements in `k' */
99 struct FuncState
*prev
; /* enclosing function */
100 struct LexState
*ls
; /* lexical state */
101 struct BlockCnt
*bl
; /* chain of current blocks */
102 int pc
; /* next position to code (equivalent to `ncode') */
103 int lasttarget
; /* 'label' of last 'jump label' */
104 int jpc
; /* list of pending jumps to `pc' */
105 int nk
; /* number of elements in `k' */
106 int np
; /* number of elements in `p' */
107 int firstlocal
; /* index of first local var (in Dyndata array) */
108 short nlocvars
; /* number of elements in 'f->locvars' */
109 lu_byte nactvar
; /* number of active local variables */
110 lu_byte nups
; /* number of upvalues */
111 lu_byte freereg
; /* first free register */
115 LUAI_FUNC Closure
*luaY_parser(lua_State
*L
, ZIO
*z
, Mbuffer
*buff
,
116 Dyndata
*dyd
, const char *name
, int firstchar
);