1 /* $NetBSD: lparser.h,v 1.3 2015/02/02 14:03:05 lneto Exp $ */
4 ** Id: lparser.h,v 1.74 2014/10/25 11:50:46 roberto Exp
6 ** See Copyright Notice in lua.h
18 ** Expression descriptor
26 VK
, /* info = index of constant in 'k' */
28 VKFLT
, /* nval = numerical float value */
30 VKINT
, /* nval = numerical integer value */
31 VNONRELOC
, /* info = result register */
32 VLOCAL
, /* info = local register */
33 VUPVAL
, /* info = index of upvalue in 'upvalues' */
34 VINDEXED
, /* t = table register/upvalue; idx = index R/K */
35 VJMP
, /* info = instruction pc */
36 VRELOCABLE
, /* info = instruction pc */
37 VCALL
, /* info = instruction pc */
38 VVARARG
/* info = instruction pc */
42 #define vkisvar(k) (VLOCAL <= (k) && (k) <= VINDEXED)
43 #define vkisinreg(k) ((k) == VNONRELOC || (k) == VLOCAL)
45 typedef struct expdesc
{
48 struct { /* for indexed variables (VINDEXED) */
49 short idx
; /* index (R/K) */
50 lu_byte t
; /* table (register or upvalue) */
51 lu_byte vt
; /* whether 't' is register (VLOCAL) or upvalue (VUPVAL) */
53 int info
; /* for generic use */
55 lua_Number nval
; /* for VKFLT */
57 lua_Integer ival
; /* for VKINT */
59 int t
; /* patch list of 'exit when true' */
60 int f
; /* patch list of 'exit when false' */
64 /* description of active local variable */
65 typedef struct Vardesc
{
66 short idx
; /* variable index in stack */
70 /* description of pending goto statements and label statements */
71 typedef struct Labeldesc
{
72 TString
*name
; /* label identifier */
73 int pc
; /* position in code */
74 int line
; /* line where it appeared */
75 lu_byte nactvar
; /* local level where it appears in current block */
79 /* list of labels or gotos */
80 typedef struct Labellist
{
81 Labeldesc
*arr
; /* array */
82 int n
; /* number of entries in use */
83 int size
; /* array size */
87 /* dynamic structures used by the parser */
88 typedef struct Dyndata
{
89 struct { /* list of active local variables */
94 Labellist gt
; /* list of pending gotos */
95 Labellist label
; /* list of active labels */
99 /* control of blocks */
100 struct BlockCnt
; /* defined in lparser.c */
103 /* state needed to generate code for a given function */
104 typedef struct FuncState
{
105 Proto
*f
; /* current function header */
106 struct FuncState
*prev
; /* enclosing function */
107 struct LexState
*ls
; /* lexical state */
108 struct BlockCnt
*bl
; /* chain of current blocks */
109 int pc
; /* next position to code (equivalent to 'ncode') */
110 int lasttarget
; /* 'label' of last 'jump label' */
111 int jpc
; /* list of pending jumps to 'pc' */
112 int nk
; /* number of elements in 'k' */
113 int np
; /* number of elements in 'p' */
114 int firstlocal
; /* index of first local var (in Dyndata array) */
115 short nlocvars
; /* number of elements in 'f->locvars' */
116 lu_byte nactvar
; /* number of active local variables */
117 lu_byte nups
; /* number of upvalues */
118 lu_byte freereg
; /* first free register */
122 LUAI_FUNC LClosure
*luaY_parser (lua_State
*L
, ZIO
*z
, Mbuffer
*buff
,
123 Dyndata
*dyd
, const char *name
, int firstchar
);