xref: /minix/external/mit/lua/dist/src/lparser.h (revision ebfedea0)
1 /*	$NetBSD: lparser.h,v 1.1.1.2 2012/03/15 00:08:10 alnsn Exp $	*/
2 
3 /*
4 ** $Id: lparser.h,v 1.1.1.2 2012/03/15 00:08:10 alnsn Exp $
5 ** Lua Parser
6 ** See Copyright Notice in lua.h
7 */
8 
9 #ifndef lparser_h
10 #define lparser_h
11 
12 #include "llimits.h"
13 #include "lobject.h"
14 #include "lzio.h"
15 
16 
17 /*
18 ** Expression descriptor
19 */
20 
21 typedef enum {
22   VVOID,	/* no value */
23   VNIL,
24   VTRUE,
25   VFALSE,
26   VK,		/* info = index of constant in `k' */
27   VKNUM,	/* nval = numerical value */
28   VLOCAL,	/* info = local register */
29   VUPVAL,       /* info = index of upvalue in `upvalues' */
30   VGLOBAL,	/* info = index of table; aux = index of global name in `k' */
31   VINDEXED,	/* info = table register; aux = index register (or `k') */
32   VJMP,		/* info = instruction pc */
33   VRELOCABLE,	/* info = instruction pc */
34   VNONRELOC,	/* info = result register */
35   VCALL,	/* info = instruction pc */
36   VVARARG	/* info = instruction pc */
37 } expkind;
38 
39 typedef struct expdesc {
40   expkind k;
41   union {
42     struct { int info, aux; } s;
43     lua_Number nval;
44   } u;
45   int t;  /* patch list of `exit when true' */
46   int f;  /* patch list of `exit when false' */
47 } expdesc;
48 
49 
50 typedef struct upvaldesc {
51   lu_byte k;
52   lu_byte info;
53 } upvaldesc;
54 
55 
56 struct BlockCnt;  /* defined in lparser.c */
57 
58 
59 /* state needed to generate code for a given function */
60 typedef struct FuncState {
61   Proto *f;  /* current function header */
62   Table *h;  /* table to find (and reuse) elements in `k' */
63   struct FuncState *prev;  /* enclosing function */
64   struct LexState *ls;  /* lexical state */
65   struct lua_State *L;  /* copy of the Lua state */
66   struct BlockCnt *bl;  /* chain of current blocks */
67   int pc;  /* next position to code (equivalent to `ncode') */
68   int lasttarget;   /* `pc' of last `jump target' */
69   int jpc;  /* list of pending jumps to `pc' */
70   int freereg;  /* first free register */
71   int nk;  /* number of elements in `k' */
72   int np;  /* number of elements in `p' */
73   short nlocvars;  /* number of elements in `locvars' */
74   lu_byte nactvar;  /* number of active local variables */
75   upvaldesc upvalues[LUAI_MAXUPVALUES];  /* upvalues */
76   unsigned short actvar[LUAI_MAXVARS];  /* declared-variable stack */
77 } FuncState;
78 
79 
80 LUAI_FUNC Proto *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff,
81                                             const char *name);
82 
83 
84 #endif
85