diff options
| -rw-r--r-- | ldo.c | 7 | ||||
| -rw-r--r-- | liolib.c | 3 | ||||
| -rw-r--r-- | lobject.c | 19 | ||||
| -rw-r--r-- | lobject.h | 15 | ||||
| -rw-r--r-- | lua.stx | 101 |
5 files changed, 79 insertions, 66 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ldo.c,v 1.18 1997/12/22 20:57:18 roberto Exp roberto $ | 2 | ** $Id: ldo.c,v 1.19 1997/12/23 12:50:49 roberto Exp roberto $ |
| 3 | ** Stack and Call structure of Lua | 3 | ** Stack and Call structure of Lua |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -96,9 +96,8 @@ void luaD_adjusttop (StkId newtop) | |||
| 96 | */ | 96 | */ |
| 97 | void luaD_openstack (int nelems) | 97 | void luaD_openstack (int nelems) |
| 98 | { | 98 | { |
| 99 | int i; | 99 | luaO_memup(L->stack.top-nelems+1, L->stack.top-nelems, |
| 100 | for (i=0; i<nelems; i++) | 100 | nelems*sizeof(TObject)); |
| 101 | *(L->stack.top-i) = *(L->stack.top-i-1); | ||
| 102 | incr_top; | 101 | incr_top; |
| 103 | } | 102 | } |
| 104 | 103 | ||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: liolib.c,v 1.11 1997/12/18 18:32:39 roberto Exp roberto $ | 2 | ** $Id: liolib.c,v 1.12 1997/12/18 19:11:43 roberto Exp roberto $ |
| 3 | ** Standard I/O (and system) library | 3 | ** Standard I/O (and system) library |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -20,7 +20,6 @@ | |||
| 20 | #ifndef OLD_ANSI | 20 | #ifndef OLD_ANSI |
| 21 | #include <locale.h> | 21 | #include <locale.h> |
| 22 | #else | 22 | #else |
| 23 | #define strcoll(a,b) strcmp(a,b) | ||
| 24 | #define setlocale(a,b) 0 | 23 | #define setlocale(a,b) 0 |
| 25 | #define LC_ALL 0 | 24 | #define LC_ALL 0 |
| 26 | #define LC_COLLATE 0 | 25 | #define LC_COLLATE 0 |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lobject.c,v 1.7 1997/11/19 17:29:23 roberto Exp roberto $ | 2 | ** $Id: lobject.c,v 1.8 1997/12/15 16:17:20 roberto Exp roberto $ |
| 3 | ** Some generic functions over Lua objects | 3 | ** Some generic functions over Lua objects |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -75,3 +75,20 @@ void luaO_insertlist (GCnode *root, GCnode *node) | |||
| 75 | node->marked = 0; | 75 | node->marked = 0; |
| 76 | } | 76 | } |
| 77 | 77 | ||
| 78 | #ifdef OLD_ANSI | ||
| 79 | void luaO_memup (void *dest, void *src, int size) | ||
| 80 | { | ||
| 81 | char *d = dest; | ||
| 82 | char *s = src; | ||
| 83 | while (size--) d[size]=s[size]; | ||
| 84 | } | ||
| 85 | |||
| 86 | void luaO_memdown (void *dest, void *src, int size) | ||
| 87 | { | ||
| 88 | char *d = dest; | ||
| 89 | char *s = src; | ||
| 90 | int i; | ||
| 91 | for (i=0; i<size; i++) d[i]=s[i]; | ||
| 92 | } | ||
| 93 | #endif | ||
| 94 | |||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lobject.h,v 1.11 1997/12/15 16:17:20 roberto Exp roberto $ | 2 | ** $Id: lobject.h,v 1.12 1997/12/23 19:24:19 roberto Exp roberto $ |
| 3 | ** Type definitions for Lua objects | 3 | ** Type definitions for Lua objects |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -8,11 +8,10 @@ | |||
| 8 | #define lobject_h | 8 | #define lobject_h |
| 9 | 9 | ||
| 10 | 10 | ||
| 11 | #include "lua.h" | ||
| 12 | |||
| 13 | |||
| 14 | #include <limits.h> | 11 | #include <limits.h> |
| 15 | 12 | ||
| 13 | #include "lua.h" | ||
| 14 | |||
| 16 | 15 | ||
| 17 | /* | 16 | /* |
| 18 | ** "real" is the type "number" of Lua | 17 | ** "real" is the type "number" of Lua |
| @@ -181,5 +180,13 @@ int luaO_redimension (int oldsize); | |||
| 181 | int luaO_findstring (char *name, char *list[]); | 180 | int luaO_findstring (char *name, char *list[]); |
| 182 | void luaO_insertlist (GCnode *root, GCnode *node); | 181 | void luaO_insertlist (GCnode *root, GCnode *node); |
| 183 | 182 | ||
| 183 | #ifdef OLD_ANSI | ||
| 184 | void luaO_memup (void *dest, void *src, int size); | ||
| 185 | void luaO_memdown (void *dest, void *src, int size); | ||
| 186 | #else | ||
| 187 | #include <string.h> | ||
| 188 | #define luaO_memup(d,s,n) memmove(d,s,n) | ||
| 189 | #define luaO_memdown(d,s,n) memmove(d,s,n) | ||
| 190 | #endif | ||
| 184 | 191 | ||
| 185 | #endif | 192 | #endif |
| @@ -1,6 +1,6 @@ | |||
| 1 | %{ | 1 | %{ |
| 2 | /* | 2 | /* |
| 3 | ** $Id: lua.stx,v 1.25 1997/12/22 20:57:18 roberto Exp roberto $ | 3 | ** $Id: lua.stx,v 1.26 1997/12/23 19:24:19 roberto Exp roberto $ |
| 4 | ** Syntax analizer and code generator | 4 | ** Syntax analizer and code generator |
| 5 | ** See Copyright Notice in lua.h | 5 | ** See Copyright Notice in lua.h |
| 6 | */ | 6 | */ |
| @@ -108,24 +108,10 @@ void luaY_error (char *s) | |||
| 108 | 108 | ||
| 109 | static void check_pc (int n) | 109 | static void check_pc (int n) |
| 110 | { | 110 | { |
| 111 | if (L->currState->pc+n > L->currState->maxcode) | 111 | FuncState *fs = L->currState; |
| 112 | L->currState->maxcode = luaM_growvector(&L->currState->f->code, | 112 | if (fs->pc+n > fs->maxcode) |
| 113 | L->currState->maxcode, Byte, codeEM, MAX_INT); | 113 | fs->maxcode = luaM_growvector(&fs->f->code, fs->maxcode, |
| 114 | } | 114 | Byte, codeEM, MAX_INT); |
| 115 | |||
| 116 | |||
| 117 | static void movecode_up (int d, int s, int n) | ||
| 118 | { | ||
| 119 | while (n--) | ||
| 120 | L->currState->f->code[d+n] = L->currState->f->code[s+n]; | ||
| 121 | } | ||
| 122 | |||
| 123 | |||
| 124 | static void movecode_down (int d, int s, int n) | ||
| 125 | { | ||
| 126 | int i; | ||
| 127 | for (i=0; i<n; i++) | ||
| 128 | L->currState->f->code[d+i] = L->currState->f->code[s+i]; | ||
| 129 | } | 115 | } |
| 130 | 116 | ||
| 131 | 117 | ||
| @@ -138,31 +124,33 @@ static void code_byte (Byte c) | |||
| 138 | 124 | ||
| 139 | static void deltastack (int delta) | 125 | static void deltastack (int delta) |
| 140 | { | 126 | { |
| 141 | L->currState->stacksize += delta; | 127 | FuncState *fs = L->currState; |
| 142 | if (L->currState->stacksize > L->currState->maxstacksize) { | 128 | fs->stacksize += delta; |
| 143 | if (L->currState->stacksize > 255) | 129 | if (fs->stacksize > fs->maxstacksize) { |
| 130 | if (fs->stacksize > 255) | ||
| 144 | luaY_error("function/expression too complex"); | 131 | luaY_error("function/expression too complex"); |
| 145 | L->currState->maxstacksize = L->currState->stacksize; | 132 | fs->maxstacksize = fs->stacksize; |
| 146 | } | 133 | } |
| 147 | } | 134 | } |
| 148 | 135 | ||
| 149 | 136 | ||
| 150 | static int code_oparg_at (int pc, OpCode op, int builtin, int arg, int delta) | 137 | static int code_oparg_at (int pc, OpCode op, int builtin, int arg, int delta) |
| 151 | { | 138 | { |
| 139 | Byte *code = L->currState->f->code; | ||
| 152 | deltastack(delta); | 140 | deltastack(delta); |
| 153 | if (arg < builtin) { | 141 | if (arg < builtin) { |
| 154 | L->currState->f->code[pc] = op+1+arg; | 142 | code[pc] = op+1+arg; |
| 155 | return 1; | 143 | return 1; |
| 156 | } | 144 | } |
| 157 | else if (arg <= 255) { | 145 | else if (arg <= 255) { |
| 158 | L->currState->f->code[pc] = op; | 146 | code[pc] = op; |
| 159 | L->currState->f->code[pc+1] = arg; | 147 | code[pc+1] = arg; |
| 160 | return 2; | 148 | return 2; |
| 161 | } | 149 | } |
| 162 | else if (arg <= MAX_WORD) { | 150 | else if (arg <= MAX_WORD) { |
| 163 | L->currState->f->code[pc] = op+1+builtin; | 151 | code[pc] = op+1+builtin; |
| 164 | L->currState->f->code[pc+1] = arg&0xFF; | 152 | code[pc+1] = arg&0xFF; |
| 165 | L->currState->f->code[pc+2] = arg>>8; | 153 | code[pc+2] = arg>>8; |
| 166 | return 3; | 154 | return 3; |
| 167 | } | 155 | } |
| 168 | else luaY_error("code too long " MES_LIM("64K")); | 156 | else luaY_error("code too long " MES_LIM("64K")); |
| @@ -172,14 +160,15 @@ static int code_oparg_at (int pc, OpCode op, int builtin, int arg, int delta) | |||
| 172 | 160 | ||
| 173 | static int fix_opcode (int pc, OpCode op, int builtin, int arg) | 161 | static int fix_opcode (int pc, OpCode op, int builtin, int arg) |
| 174 | { | 162 | { |
| 163 | FuncState *fs = L->currState; | ||
| 175 | if (arg < builtin) { /* close space */ | 164 | if (arg < builtin) { /* close space */ |
| 176 | movecode_down(pc+1, pc+2, L->currState->pc-(pc+2)); | 165 | luaO_memdown(fs->f->code+pc+1, fs->f->code+pc+2, fs->pc-(pc+2)); |
| 177 | L->currState->pc--; | 166 | fs->pc--; |
| 178 | } | 167 | } |
| 179 | else if (arg > 255) { /* open space */ | 168 | else if (arg > 255) { /* open space */ |
| 180 | check_pc(1); | 169 | check_pc(1); |
| 181 | movecode_up(pc+1, pc, L->currState->pc-pc); | 170 | luaO_memup(fs->f->code+pc+1, fs->f->code+pc, fs->pc-pc); |
| 182 | L->currState->pc++; | 171 | fs->pc++; |
| 183 | } | 172 | } |
| 184 | return code_oparg_at(pc, op, builtin, arg, 0) - 2; | 173 | return code_oparg_at(pc, op, builtin, arg, 0) - 2; |
| 185 | } | 174 | } |
| @@ -301,13 +290,14 @@ static void flush_list (int m, int n) | |||
| 301 | 290 | ||
| 302 | static void luaI_registerlocalvar (TaggedString *varname, int line) | 291 | static void luaI_registerlocalvar (TaggedString *varname, int line) |
| 303 | { | 292 | { |
| 304 | if (L->currState->maxvars != -1) { /* debug information? */ | 293 | FuncState *fs = L->currState; |
| 305 | if (L->currState->nvars >= L->currState->maxvars) | 294 | if (fs->maxvars != -1) { /* debug information? */ |
| 306 | L->currState->maxvars = luaM_growvector(&L->currState->f->locvars, | 295 | if (fs->nvars >= fs->maxvars) |
| 307 | L->currState->maxvars, LocVar, "", MAX_WORD); | 296 | fs->maxvars = luaM_growvector(&fs->f->locvars, fs->maxvars, |
| 308 | L->currState->f->locvars[L->currState->nvars].varname = varname; | 297 | LocVar, "", MAX_WORD); |
| 309 | L->currState->f->locvars[L->currState->nvars].line = line; | 298 | fs->f->locvars[fs->nvars].varname = varname; |
| 310 | L->currState->nvars++; | 299 | fs->f->locvars[fs->nvars].line = line; |
| 300 | fs->nvars++; | ||
| 311 | } | 301 | } |
| 312 | } | 302 | } |
| 313 | 303 | ||
| @@ -569,22 +559,23 @@ static void func_onstack (TProtoFunc *f) | |||
| 569 | static void init_state (TaggedString *filename) | 559 | static void init_state (TaggedString *filename) |
| 570 | { | 560 | { |
| 571 | TProtoFunc *f = luaF_newproto(); | 561 | TProtoFunc *f = luaF_newproto(); |
| 572 | L->currState->stacksize = 0; | 562 | FuncState *fs = L->currState; |
| 573 | L->currState->maxstacksize = 0; | 563 | fs->stacksize = 0; |
| 574 | L->currState->nlocalvar = 0; | 564 | fs->maxstacksize = 0; |
| 575 | L->currState->nupvalues = 0; | 565 | fs->nlocalvar = 0; |
| 576 | L->currState->f = f; | 566 | fs->nupvalues = 0; |
| 567 | fs->f = f; | ||
| 577 | f->fileName = filename; | 568 | f->fileName = filename; |
| 578 | L->currState->pc = 0; | 569 | fs->pc = 0; |
| 579 | L->currState->maxcode = 0; | 570 | fs->maxcode = 0; |
| 580 | f->code = NULL; | 571 | f->code = NULL; |
| 581 | L->currState->maxconsts = 0; | 572 | fs->maxconsts = 0; |
| 582 | if (lua_debug) { | 573 | if (lua_debug) { |
| 583 | L->currState->nvars = 0; | 574 | fs->nvars = 0; |
| 584 | L->currState->maxvars = 0; | 575 | fs->maxvars = 0; |
| 585 | } | 576 | } |
| 586 | else | 577 | else |
| 587 | L->currState->maxvars = -1; /* flag no debug information */ | 578 | fs->maxvars = -1; /* flag no debug information */ |
| 588 | code_byte(0); /* to be filled with stacksize */ | 579 | code_byte(0); /* to be filled with stacksize */ |
| 589 | L->lexstate->lastline = 0; /* invalidate it */ | 580 | L->lexstate->lastline = 0; /* invalidate it */ |
| 590 | } | 581 | } |
| @@ -696,13 +687,13 @@ stat : IF cond THEN block SaveWord elsepart END { codeIf($2, $5); } | |||
| 696 | 687 | ||
| 697 | | WHILE GetPC cond DO block END | 688 | | WHILE GetPC cond DO block END |
| 698 | {{ | 689 | {{ |
| 690 | FuncState *fs = L->currState; | ||
| 699 | int expsize = $3-$2; | 691 | int expsize = $3-$2; |
| 700 | int newpos = $2+JMPSIZE; | 692 | int newpos = $2+JMPSIZE; |
| 701 | check_pc(expsize); | 693 | check_pc(expsize); |
| 702 | memcpy(&L->currState->f->code[L->currState->pc], | 694 | memcpy(fs->f->code+fs->pc, fs->f->code+$2, expsize); |
| 703 | &L->currState->f->code[$2], expsize); | 695 | luaO_memdown(fs->f->code+$2, fs->f->code+$3, fs->pc-$2); |
| 704 | movecode_down($2, $3, L->currState->pc-$2); | 696 | newpos += fix_jump($2, JMP, fs->pc-expsize); |
| 705 | newpos += fix_jump($2, JMP, L->currState->pc-expsize); | ||
| 706 | fix_upjmp(IFTUPJMP, newpos); | 697 | fix_upjmp(IFTUPJMP, newpos); |
| 707 | }} | 698 | }} |
| 708 | 699 | ||
