The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
lparser.h
Go to the documentation of this file.
1 /*
2 ** Lua Parser
3 ** See Copyright Notice in lua.h
4 */
5 
6 #ifndef lparser_h
7 #define lparser_h
8 
9 #include "llimits.h"
10 #include "lobject.h"
11 #include "lzio.h"
12 
13 
14 /*
15 ** Expression descriptor
16 */
17 
18 typedef enum {
19  VVOID, /* no value */
23  VK, /* info = index of constant in `k' */
24  VKNUM, /* nval = numerical value */
25  VNONRELOC, /* info = result register */
26  VLOCAL, /* info = local register */
27  VUPVAL, /* info = index of upvalue in 'upvalues' */
28  VINDEXED, /* t = table register/upvalue; idx = index R/K */
29  VJMP, /* info = instruction pc */
30  VRELOCABLE, /* info = instruction pc */
31  VCALL, /* info = instruction pc */
32  VVARARG /* info = instruction pc */
33 } expkind;
34 
35 
36 #define vkisvar(k) (VLOCAL <= (k) && (k) <= VINDEXED)
37 #define vkisinreg(k) ((k) == VNONRELOC || (k) == VLOCAL)
38 
39 typedef struct expdesc {
41  union {
42  struct { /* for indexed variables (VINDEXED) */
43  short idx; /* index (R/K) */
44  lu_byte t; /* table (register or upvalue) */
45  lu_byte vt; /* whether 't' is register (VLOCAL) or upvalue (VUPVAL) */
46  } ind;
47  int info; /* for generic use */
48  lua_Number nval; /* for VKNUM */
49  } u;
50  int t; /* patch list of `exit when true' */
51  int f; /* patch list of `exit when false' */
52 } expdesc;
53 
54 
55 /* description of active local variable */
56 typedef struct Vardesc {
57  short idx; /* variable index in stack */
58 } Vardesc;
59 
60 
61 /* description of pending goto statements and label statements */
62 typedef struct Labeldesc {
63  TString *name; /* label identifier */
64  int pc; /* position in code */
65  int line; /* line where it appeared */
66  lu_byte nactvar; /* local level where it appears in current block */
67 } Labeldesc;
68 
69 
70 /* list of labels or gotos */
71 typedef struct Labellist {
72  Labeldesc *arr; /* array */
73  int n; /* number of entries in use */
74  int size; /* array size */
75 } Labellist;
76 
77 
78 /* dynamic structures used by the parser */
79 typedef struct Dyndata {
80  struct { /* list of active local variables */
82  int n;
83  int size;
84  } actvar;
85  Labellist gt; /* list of pending gotos */
86  Labellist label; /* list of active labels */
87 } Dyndata;
88 
89 
90 /* control of blocks */
91 struct BlockCnt; /* defined in lparser.c */
92 
93 
94 /* state needed to generate code for a given function */
95 typedef struct FuncState {
96  Proto *f; /* current function header */
97  Table *h; /* table to find (and reuse) elements in `k' */
98  struct FuncState *prev; /* enclosing function */
99  struct LexState *ls; /* lexical state */
100  struct BlockCnt *bl; /* chain of current blocks */
101  int pc; /* next position to code (equivalent to `ncode') */
102  int lasttarget; /* 'label' of last 'jump label' */
103  int jpc; /* list of pending jumps to `pc' */
104  int nk; /* number of elements in `k' */
105  int np; /* number of elements in `p' */
106  int firstlocal; /* index of first local var (in Dyndata array) */
107  short nlocvars; /* number of elements in 'f->locvars' */
108  lu_byte nactvar; /* number of active local variables */
109  lu_byte nups; /* number of upvalues */
110  lu_byte freereg; /* first free register */
111 } FuncState;
112 
113 
115  Dyndata *dyd, const char *name, int firstchar);
116 
117 
118 #endif
struct LexState * ls
Definition: lparser.h:99
GLdouble GLdouble z
Definition: glew.h:1527
int n
Definition: lparser.h:73
Definition: lobject.h:559
lu_byte t
Definition: lparser.h:44
int pc
Definition: lparser.h:64
Definition: lobject.h:466
#define LUAI_FUNC
Definition: luaconf.h:187
Definition: lparser.h:19
lua_Number nval
Definition: lparser.h:48
int pc
Definition: lparser.h:101
int nk
Definition: lparser.h:104
Labellist gt
Definition: lparser.h:85
int n
Definition: lparser.h:82
Definition: lparser.h:29
int lasttarget
Definition: lparser.h:102
int line
Definition: lparser.h:65
lu_byte nups
Definition: lparser.h:109
int firstlocal
Definition: lparser.h:106
expkind
Definition: lparser.h:18
int info
Definition: lparser.h:47
TString * name
Definition: lparser.h:63
Definition: lparser.h:26
unsigned char lu_byte
Definition: llimits.h:26
Definition: lparser.h:23
Definition: lparser.h:31
Labeldesc * arr
Definition: lparser.h:72
int jpc
Definition: lparser.h:103
short idx
Definition: lparser.h:57
int size
Definition: lparser.h:74
Definition: lparser.h:24
lu_byte vt
Definition: lparser.h:45
struct Labeldesc Labeldesc
struct Dyndata Dyndata
int t
Definition: lparser.h:50
Vardesc * arr
Definition: lparser.h:81
Labellist label
Definition: lparser.h:86
Definition: lparser.h:21
Definition: lzio.h:53
struct Dyndata::@15 actvar
short idx
Definition: lparser.h:43
short nlocvars
Definition: lparser.h:107
lu_byte nactvar
Definition: lparser.h:108
lu_byte freereg
Definition: lparser.h:110
Definition: lparser.h:20
Definition: llex.h:50
lu_byte nactvar
Definition: lparser.h:66
struct expdesc::@13::@14 ind
Table * h
Definition: lparser.h:97
GLuint const GLchar * name
Definition: glew.h:1782
struct Labellist Labellist
int np
Definition: lparser.h:105
struct Vardesc Vardesc
Proto * f
Definition: lparser.h:96
LUAI_FUNC Closure * luaY_parser(lua_State *L, ZIO *z, Mbuffer *buff, Dyndata *dyd, const char *name, int firstchar)
Definition: lparser.cpp:1617
struct expdesc expdesc
union expdesc::@13 u
Definition: lzio.h:22
int f
Definition: lparser.h:51
struct FuncState FuncState
int size
Definition: lparser.h:83
struct BlockCnt * bl
Definition: lparser.h:100
LUA_NUMBER lua_Number
Definition: lua.h:102
Definition: lparser.h:27
Definition: lparser.h:22
struct FuncState * prev
Definition: lparser.h:98
expkind k
Definition: lparser.h:40