Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/freebsd-src
Path: blob/main/sys/contrib/openzfs/module/lua/lparser.h
48383 views
1
// SPDX-License-Identifier: MIT
2
/*
3
** $Id: lparser.h,v 1.70.1.1 2013/04/12 18:48:47 roberto Exp $
4
** Lua Parser
5
** See Copyright Notice in lua.h
6
*/
7
8
#ifndef lparser_h
9
#define lparser_h
10
11
#include "llimits.h"
12
#include "lobject.h"
13
#include "lzio.h"
14
15
16
/*
17
** Expression descriptor
18
*/
19
20
typedef enum {
21
VVOID, /* no value */
22
VNIL,
23
VTRUE,
24
VFALSE,
25
VK, /* info = index of constant in `k' */
26
VKNUM, /* nval = numerical value */
27
VNONRELOC, /* info = result register */
28
VLOCAL, /* info = local register */
29
VUPVAL, /* info = index of upvalue in 'upvalues' */
30
VINDEXED, /* t = table register/upvalue; idx = index R/K */
31
VJMP, /* info = instruction pc */
32
VRELOCABLE, /* info = instruction pc */
33
VCALL, /* info = instruction pc */
34
VVARARG /* info = instruction pc */
35
} expkind;
36
37
38
#define vkisvar(k) (VLOCAL <= (k) && (k) <= VINDEXED)
39
#define vkisinreg(k) ((k) == VNONRELOC || (k) == VLOCAL)
40
41
typedef struct expdesc {
42
expkind k;
43
union {
44
struct { /* for indexed variables (VINDEXED) */
45
short idx; /* index (R/K) */
46
lu_byte t; /* table (register or upvalue) */
47
lu_byte vt; /* whether 't' is register (VLOCAL) or upvalue (VUPVAL) */
48
} ind;
49
int info; /* for generic use */
50
lua_Number nval; /* for VKNUM */
51
} u;
52
int t; /* patch list of `exit when true' */
53
int f; /* patch list of `exit when false' */
54
} expdesc;
55
56
57
/* description of active local variable */
58
typedef struct Vardesc {
59
short idx; /* variable index in stack */
60
} Vardesc;
61
62
63
/* description of pending goto statements and label statements */
64
typedef struct Labeldesc {
65
TString *name; /* label identifier */
66
int pc; /* position in code */
67
int line; /* line where it appeared */
68
lu_byte nactvar; /* local level where it appears in current block */
69
} Labeldesc;
70
71
72
/* list of labels or gotos */
73
typedef struct Labellist {
74
Labeldesc *arr; /* array */
75
int n; /* number of entries in use */
76
int size; /* array size */
77
} Labellist;
78
79
80
/* dynamic structures used by the parser */
81
typedef struct Dyndata {
82
struct { /* list of active local variables */
83
Vardesc *arr;
84
int n;
85
int size;
86
} actvar;
87
Labellist gt; /* list of pending gotos */
88
Labellist label; /* list of active labels */
89
} Dyndata;
90
91
92
/* control of blocks */
93
struct BlockCnt; /* defined in lparser.c */
94
95
96
/* state needed to generate code for a given function */
97
typedef struct FuncState {
98
Proto *f; /* current function header */
99
Table *h; /* table to find (and reuse) elements in `k' */
100
struct FuncState *prev; /* enclosing function */
101
struct LexState *ls; /* lexical state */
102
struct BlockCnt *bl; /* chain of current blocks */
103
int pc; /* next position to code (equivalent to `ncode') */
104
int lasttarget; /* 'label' of last 'jump label' */
105
int jpc; /* list of pending jumps to `pc' */
106
int nk; /* number of elements in `k' */
107
int np; /* number of elements in `p' */
108
int firstlocal; /* index of first local var (in Dyndata array) */
109
short nlocvars; /* number of elements in 'f->locvars' */
110
lu_byte nactvar; /* number of active local variables */
111
lu_byte nups; /* number of upvalues */
112
lu_byte freereg; /* first free register */
113
} FuncState;
114
115
116
LUAI_FUNC Closure *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff,
117
Dyndata *dyd, const char *name, int firstchar);
118
119
120
#endif
121
122