00001 /* 00002 ** $Id: lparser.h,v 1.2 2004/03/23 05:09:14 jbj Exp $ 00003 ** Lua Parser 00004 ** See Copyright Notice in lua.h 00005 */ 00006 00007 #ifndef lparser_h 00008 #define lparser_h 00009 00010 #include "llimits.h" 00011 #include "lobject.h" 00012 #include "ltable.h" 00013 #include "lzio.h" 00014 00015 00016 /* 00017 ** Expression descriptor 00018 */ 00019 00020 typedef enum { 00021 VVOID, /* no value */ 00022 VNIL, 00023 VTRUE, 00024 VFALSE, 00025 VK, /* info = index of constant in `k' */ 00026 VLOCAL, /* info = local register */ 00027 VUPVAL, /* info = index of upvalue in `upvalues' */ 00028 VGLOBAL, /* info = index of table; aux = index of global name in `k' */ 00029 VINDEXED, /* info = table register; aux = index register (or `k') */ 00030 VJMP, /* info = instruction pc */ 00031 VRELOCABLE, /* info = instruction pc */ 00032 VNONRELOC, /* info = result register */ 00033 VCALL /* info = result register */ 00034 } expkind; 00035 00036 typedef struct expdesc { 00037 expkind k; 00038 int info, aux; 00039 int t; /* patch list of `exit when true' */ 00040 int f; /* patch list of `exit when false' */ 00041 } expdesc; 00042 00043 00044 struct BlockCnt; /* defined in lparser.c */ 00045 00046 00047 /* state needed to generate code for a given function */ 00048 typedef struct FuncState { 00049 /*@null@*/ 00050 Proto *f; /* current function header */ 00051 /*@null@*/ 00052 Table *h; /* table to find (and reuse) elements in `k' */ 00053 /*@null@*/ 00054 struct FuncState *prev; /* enclosing function */ 00055 struct LexState *ls; /* lexical state */ 00056 struct lua_State *L; /* copy of the Lua state */ 00057 /*@null@*/ 00058 struct BlockCnt *bl; /* chain of current blocks */ 00059 int pc; /* next position to code (equivalent to `ncode') */ 00060 int lasttarget; /* `pc' of last `jump target' */ 00061 int jpc; /* list of pending jumps to `pc' */ 00062 int freereg; /* first free register */ 00063 int nk; /* number of elements in `k' */ 00064 int np; /* number of elements in `p' */ 00065 int nlocvars; /* number of elements in `locvars' */ 00066 int nactvar; /* number of active local variables */ 00067 expdesc upvalues[MAXUPVALUES]; /* upvalues */ 00068 int actvar[MAXVARS]; /* declared-variable stack */ 00069 } FuncState; 00070 00071 00072 Proto *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff) 00073 /*@modifies L, z @*/; 00074 00075 00076 #endif