aboutsummaryrefslogtreecommitdiff
path: root/lparser.h
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2000-02-22 11:31:43 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2000-02-22 11:31:43 -0200
commit3bc925138ebcb534f863b3fb32b21eb8d52aa915 (patch)
tree6fcbc3bf92357a5e2e1651bc38c79b9bbea42a51 /lparser.h
parent39e1f079bdf045d64ad6f1b5da1eb48cc79c6c38 (diff)
downloadlua-3bc925138ebcb534f863b3fb32b21eb8d52aa915.tar.gz
lua-3bc925138ebcb534f863b3fb32b21eb8d52aa915.tar.bz2
lua-3bc925138ebcb534f863b3fb32b21eb8d52aa915.zip
first version of code optimizer
Diffstat (limited to 'lparser.h')
-rw-r--r--lparser.h74
1 files changed, 73 insertions, 1 deletions
diff --git a/lparser.h b/lparser.h
index df25c6fa..aa47d0fd 100644
--- a/lparser.h
+++ b/lparser.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lparser.h,v 1.4 1999/08/16 20:52:00 roberto Exp roberto $ 2** $Id: lparser.h,v 1.5 1999/11/22 13:12:07 roberto Exp roberto $
3** LL(1) Parser and code generator for Lua 3** LL(1) Parser and code generator for Lua
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -8,9 +8,81 @@
8#define lparser_h 8#define lparser_h
9 9
10#include "lobject.h" 10#include "lobject.h"
11#include "lopcodes.h"
11#include "lzio.h" 12#include "lzio.h"
12 13
13 14
15/* maximum number of local variables */
16#ifndef MAXLOCALS
17#define MAXLOCALS 200 /* arbitrary limit (<=MAXARG_B) */
18#endif
19
20
21/* maximum number of upvalues */
22#ifndef MAXUPVALUES
23#define MAXUPVALUES 32 /* arbitrary limit (<=MAXARG_B) */
24#endif
25
26
27/* maximum number of variables in the left side of an assignment */
28#ifndef MAXVARSLH
29#define MAXVARSLH 100 /* arbitrary limit (<=MAXARG_B) */
30#endif
31
32
33/* maximum number of parameters in a function */
34#ifndef MAXPARAMS
35#define MAXPARAMS 100 /* arbitrary limit (<=MAXLOCALS) */
36#endif
37
38
39/* maximum stack size in a function */
40#ifndef MAXSTACK
41#define MAXSTACK 256 /* arbitrary limit (<=MAXARG_A) */
42#endif
43
44
45#if MAXLOCALS>MAXARG_U || MAXUPVALUES>MAXARG_B || MAXVARSLH>MAXARG_B || \
46 MAXPARAMS>MAXLOCALS || MAXSTACK>MAXARG_A || LFIELDS_PER_FLUSH>MAXARG_B
47#error invalid limits
48#endif
49
50
51
52/*
53** Variable descriptor:
54** must include an `exp' option because LL(1) cannot distinguish
55** between variables, upvalues and function calls on first sight.
56*/
57typedef enum {
58 VGLOBAL, /* info is constant index of global name */
59 VLOCAL, /* info is stack index */
60 VINDEXED, /* no info (table and index are on the stack) */
61 VEXP /* info is pc index of a call (or 0 if exp is closed) */
62} varkind;
63
64typedef struct vardesc {
65 varkind k;
66 int info;
67} vardesc;
68
69
70/* state needed to generate code for a given function */
71typedef struct FuncState {
72 TProtoFunc *f; /* current function header */
73 struct FuncState *prev; /* enclosing function */
74 int pc; /* next position to code */
75 int last_pc; /* last instruction coded (for optimizations) */
76 int stacksize; /* number of values on activation register */
77 int nlocalvar; /* number of active local variables */
78 int nupvalues; /* number of upvalues */
79 int nvars; /* number of entries in f->locvars (-1 if no debug information) */
80 int lastsetline; /* line where last SETLINE was issued */
81 vardesc upvalues[MAXUPVALUES]; /* upvalues */
82 TaggedString *localvar[MAXLOCALS]; /* store local variable names */
83} FuncState;
84
85
14TProtoFunc *luaY_parser (lua_State *L, ZIO *z); 86TProtoFunc *luaY_parser (lua_State *L, ZIO *z);
15 87
16 88