lua/lparser.h

Go to the documentation of this file.
00001 /*
00002 ** $Id: lparser.h,v 1.69 2011/07/27 18:09:01 roberto 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 "lzio.h"
00013 
00014 
00015 /*
00016 ** Expression descriptor
00017 */
00018 
00019 typedef enum {
00020   VVOID,    /* no value */
00021   VNIL,
00022   VTRUE,
00023   VFALSE,
00024   VK,       /* info = index of constant in `k' */
00025   VKNUM,    /* nval = numerical value */
00026   VNONRELOC,    /* info = result register */
00027   VLOCAL,   /* info = local register */
00028   VUPVAL,       /* info = index of upvalue in 'upvalues' */
00029   VINDEXED, /* t = table register/upvalue; idx = index R/K */
00030   VJMP,     /* info = instruction pc */
00031   VRELOCABLE,   /* info = instruction pc */
00032   VCALL,    /* info = instruction pc */
00033   VVARARG   /* info = instruction pc */
00034 } expkind;
00035 
00036 
00037 #define vkisvar(k)  (VLOCAL <= (k) && (k) <= VINDEXED)
00038 #define vkisinreg(k)    ((k) == VNONRELOC || (k) == VLOCAL)
00039 
00040 typedef struct expdesc {
00041   expkind k;
00042   union {
00043     struct {  /* for indexed variables (VINDEXED) */
00044       short idx;  /* index (R/K) */
00045       lu_byte t;  /* table (register or upvalue) */
00046       lu_byte vt;  /* whether 't' is register (VLOCAL) or upvalue (VUPVAL) */
00047     } ind;
00048     int info;  /* for generic use */
00049     lua_Number nval;  /* for VKNUM */
00050   } u;
00051   int t;  /* patch list of `exit when true' */
00052   int f;  /* patch list of `exit when false' */
00053 } expdesc;
00054 
00055 
00056 /* description of active local variable */
00057 typedef struct Vardesc {
00058   short idx;  /* variable index in stack */
00059 } Vardesc;
00060 
00061 
00062 /* description of pending goto statements and label statements */
00063 typedef struct Labeldesc {
00064   TString *name;  /* label identifier */
00065   int pc;  /* position in code */
00066   int line;  /* line where it appeared */
00067   lu_byte nactvar;  /* local level where it appears in current block */
00068 } Labeldesc;
00069 
00070 
00071 /* list of labels or gotos */
00072 typedef struct Labellist {
00073   Labeldesc *arr;  /* array */
00074   int n;  /* number of entries in use */
00075   int size;  /* array size */
00076 } Labellist;
00077 
00078 
00079 /* dynamic structures used by the parser */
00080 typedef struct Dyndata {
00081   struct {  /* list of active local variables */
00082     Vardesc *arr;
00083     int n;
00084     int size;
00085   } actvar;
00086   Labellist gt;  /* list of pending gotos */
00087   Labellist label;   /* list of active labels */
00088 } Dyndata;
00089 
00090 
00091 /* control of blocks */
00092 struct BlockCnt;  /* defined in lparser.c */
00093 
00094 
00095 /* state needed to generate code for a given function */
00096 typedef struct FuncState {
00097   Proto *f;  /* current function header */
00098   Table *h;  /* table to find (and reuse) elements in `k' */
00099   struct FuncState *prev;  /* enclosing function */
00100   struct LexState *ls;  /* lexical state */
00101   struct BlockCnt *bl;  /* chain of current blocks */
00102   int pc;  /* next position to code (equivalent to `ncode') */
00103   int lasttarget;   /* 'label' of last 'jump label' */
00104   int jpc;  /* list of pending jumps to `pc' */
00105   int nk;  /* number of elements in `k' */
00106   int np;  /* number of elements in `p' */
00107   int firstlocal;  /* index of first local var (in Dyndata array) */
00108   short nlocvars;  /* number of elements in 'f->locvars' */
00109   lu_byte nactvar;  /* number of active local variables */
00110   lu_byte nups;  /* number of upvalues */
00111   lu_byte freereg;  /* first free register */
00112 } FuncState;
00113 
00114 
00115 LUAI_FUNC Proto *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff,
00116                               Dyndata *dyd, const char *name, int firstchar);
00117 
00118 
00119 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated by doxygen 1.7.1 on Fri May 25 2012 01:03:04 for The Battle for Wesnoth
Gna! | Forum | Wiki | CIA | devdocs