diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2000-03-03 15:53:17 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2000-03-03 15:53:17 -0300 |
| commit | d1ea38580ae35a3a34e7122c41682af7f9901030 (patch) | |
| tree | ce7fa1568be9eb757805966b77ea1eac2bc604f6 /lparser.h | |
| parent | 3c9d999424520c809e05bee11d81788b488434f6 (diff) | |
| download | lua-d1ea38580ae35a3a34e7122c41682af7f9901030.tar.gz lua-d1ea38580ae35a3a34e7122c41682af7f9901030.tar.bz2 lua-d1ea38580ae35a3a34e7122c41682af7f9901030.zip | |
change of code generation design (independent functions for each opcode)
Diffstat (limited to 'lparser.h')
| -rw-r--r-- | lparser.h | 28 |
1 files changed, 17 insertions, 11 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lparser.h,v 1.7 2000/03/03 12:33:59 roberto Exp roberto $ | 2 | ** $Id: lparser.h,v 1.8 2000/03/03 14:58:26 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,7 +8,6 @@ | |||
| 8 | #define lparser_h | 8 | #define lparser_h |
| 9 | 9 | ||
| 10 | #include "lobject.h" | 10 | #include "lobject.h" |
| 11 | #include "lopcodes.h" | ||
| 12 | #include "lzio.h" | 11 | #include "lzio.h" |
| 13 | 12 | ||
| 14 | 13 | ||
| @@ -42,21 +41,18 @@ | |||
| 42 | #endif | 41 | #endif |
| 43 | 42 | ||
| 44 | 43 | ||
| 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 | 44 | ||
| 52 | /* | 45 | /* |
| 53 | ** Expression descriptor | 46 | ** Expression descriptor |
| 54 | */ | 47 | */ |
| 48 | |||
| 49 | #define NOJUMPS 0 | ||
| 50 | |||
| 55 | typedef enum { | 51 | typedef enum { |
| 56 | VGLOBAL, /* info is constant index of global name */ | 52 | VGLOBAL, /* info is constant index of global name */ |
| 57 | VLOCAL, /* info is stack index */ | 53 | VLOCAL, /* info is stack index */ |
| 58 | VINDEXED, /* no info (table and index are on the stack) */ | 54 | VINDEXED, /* info is info of the index expression */ |
| 59 | VEXP /* info is pc index of exp main operator */ | 55 | VEXP /* info is NOJUMPS if exp has no internal jumps */ |
| 60 | } expkind; | 56 | } expkind; |
| 61 | 57 | ||
| 62 | typedef struct expdesc { | 58 | typedef struct expdesc { |
| @@ -65,12 +61,22 @@ typedef struct expdesc { | |||
| 65 | } expdesc; | 61 | } expdesc; |
| 66 | 62 | ||
| 67 | 63 | ||
| 64 | /* | ||
| 65 | ** Expression List descriptor: | ||
| 66 | ** tells number of expressions in the list, | ||
| 67 | ** and gives the `info' of last expression. | ||
| 68 | */ | ||
| 69 | typedef struct listdesc { | ||
| 70 | int n; | ||
| 71 | int info; /* 0 if last expression has no internal jumps */ | ||
| 72 | } listdesc; | ||
| 73 | |||
| 74 | |||
| 68 | /* state needed to generate code for a given function */ | 75 | /* state needed to generate code for a given function */ |
| 69 | typedef struct FuncState { | 76 | typedef struct FuncState { |
| 70 | TProtoFunc *f; /* current function header */ | 77 | TProtoFunc *f; /* current function header */ |
| 71 | struct FuncState *prev; /* enclosing function */ | 78 | struct FuncState *prev; /* enclosing function */ |
| 72 | int pc; /* next position to code */ | 79 | int pc; /* next position to code */ |
| 73 | int last_pc; /* last instruction coded (for optimizations) */ | ||
| 74 | int stacksize; /* number of values on activation register */ | 80 | int stacksize; /* number of values on activation register */ |
| 75 | int nlocalvar; /* number of active local variables */ | 81 | int nlocalvar; /* number of active local variables */ |
| 76 | int nupvalues; /* number of upvalues */ | 82 | int nupvalues; /* number of upvalues */ |
