diff options
| -rw-r--r-- | lbuffer.c | 55 | ||||
| -rw-r--r-- | llex.c | 14 | ||||
| -rw-r--r-- | lstate.c | 4 | ||||
| -rw-r--r-- | lstate.h | 4 |
4 files changed, 32 insertions, 45 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lbuffer.c,v 1.4 1998/06/19 16:14:09 roberto Exp roberto $ | 2 | ** $Id: lbuffer.c,v 1.5 1998/12/28 13:44:54 roberto Exp roberto $ |
| 3 | ** Auxiliary functions for building Lua libraries | 3 | ** Auxiliary functions for building Lua libraries |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -16,70 +16,57 @@ | |||
| 16 | ** Auxiliary buffer | 16 | ** Auxiliary buffer |
| 17 | -------------------------------------------------------*/ | 17 | -------------------------------------------------------*/ |
| 18 | 18 | ||
| 19 | #define BUFF_STEP 32 | ||
| 20 | 19 | ||
| 21 | #define openspace(size) if (L->Mbuffnext+(size) > L->Mbuffsize) Openspace(size) | 20 | #define openspace(size) if (L->Mbuffnext+(size) > L->Mbuffsize) Openspace(size) |
| 22 | 21 | ||
| 23 | static void Openspace (int size) | 22 | static void Openspace (int size) { |
| 24 | { | ||
| 25 | lua_State *l = L; /* to optimize */ | 23 | lua_State *l = L; /* to optimize */ |
| 26 | int base = l->Mbuffbase-l->Mbuffer; | 24 | l->Mbuffsize = l->Mbuffnext+size; |
| 27 | l->Mbuffsize *= 2; | 25 | l->Mbuffer = luaM_growvector(l->Mbuffer, l->Mbuffnext, size, char, |
| 28 | if (l->Mbuffnext+size > l->Mbuffsize) /* still not big enough? */ | 26 | memEM, MAX_INT); |
| 29 | l->Mbuffsize = l->Mbuffnext+size; | ||
| 30 | l->Mbuffer = luaM_realloc(l->Mbuffer, l->Mbuffsize); | ||
| 31 | l->Mbuffbase = l->Mbuffer+base; | ||
| 32 | } | 27 | } |
| 33 | 28 | ||
| 34 | 29 | ||
| 35 | char *luaL_openspace (int size) | 30 | char *luaL_openspace (int size) { |
| 36 | { | ||
| 37 | openspace(size); | 31 | openspace(size); |
| 38 | return L->Mbuffer+L->Mbuffnext; | 32 | return L->Mbuffer+L->Mbuffnext; |
| 39 | } | 33 | } |
| 40 | 34 | ||
| 41 | 35 | ||
| 42 | void luaL_addchar (int c) | 36 | void luaL_addchar (int c) { |
| 43 | { | 37 | openspace(1); |
| 44 | openspace(BUFF_STEP); | ||
| 45 | L->Mbuffer[L->Mbuffnext++] = (char)c; | 38 | L->Mbuffer[L->Mbuffnext++] = (char)c; |
| 46 | } | 39 | } |
| 47 | 40 | ||
| 48 | 41 | ||
| 49 | void luaL_resetbuffer (void) | 42 | void luaL_resetbuffer (void) { |
| 50 | { | 43 | L->Mbuffnext = L->Mbuffbase; |
| 51 | L->Mbuffnext = L->Mbuffbase-L->Mbuffer; | ||
| 52 | } | 44 | } |
| 53 | 45 | ||
| 54 | 46 | ||
| 55 | void luaL_addsize (int n) | 47 | void luaL_addsize (int n) { |
| 56 | { | ||
| 57 | L->Mbuffnext += n; | 48 | L->Mbuffnext += n; |
| 58 | } | 49 | } |
| 59 | 50 | ||
| 60 | int luaL_getsize (void) | 51 | int luaL_getsize (void) { |
| 61 | { | 52 | return L->Mbuffnext-L->Mbuffbase; |
| 62 | return L->Mbuffnext-(L->Mbuffbase-L->Mbuffer); | ||
| 63 | } | 53 | } |
| 64 | 54 | ||
| 65 | int luaL_newbuffer (int size) | 55 | int luaL_newbuffer (int size) { |
| 66 | { | 56 | int old = L->Mbuffbase; |
| 67 | int old = L->Mbuffbase-L->Mbuffer; | ||
| 68 | openspace(size); | 57 | openspace(size); |
| 69 | L->Mbuffbase = L->Mbuffer+L->Mbuffnext; | 58 | L->Mbuffbase = L->Mbuffnext; |
| 70 | return old; | 59 | return old; |
| 71 | } | 60 | } |
| 72 | 61 | ||
| 73 | 62 | ||
| 74 | void luaL_oldbuffer (int old) | 63 | void luaL_oldbuffer (int old) { |
| 75 | { | 64 | L->Mbuffnext = L->Mbuffbase; |
| 76 | L->Mbuffnext = L->Mbuffbase-L->Mbuffer; | 65 | L->Mbuffbase = old; |
| 77 | L->Mbuffbase = L->Mbuffer+old; | ||
| 78 | } | 66 | } |
| 79 | 67 | ||
| 80 | 68 | ||
| 81 | char *luaL_buffer (void) | 69 | char *luaL_buffer (void) { |
| 82 | { | 70 | return L->Mbuffer+L->Mbuffbase; |
| 83 | return L->Mbuffbase; | ||
| 84 | } | 71 | } |
| 85 | 72 | ||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: llex.c,v 1.27 1998/12/28 13:44:54 roberto Exp roberto $ | 2 | ** $Id: llex.c,v 1.28 1999/02/04 17:47:59 roberto Exp roberto $ |
| 3 | ** Lexical Analizer | 3 | ** Lexical Analizer |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -258,8 +258,8 @@ static int read_long_string (LexState *LS) { | |||
| 258 | } | 258 | } |
| 259 | } endloop: | 259 | } endloop: |
| 260 | save_and_next(LS); /* skip the second ']' */ | 260 | save_and_next(LS); /* skip the second ']' */ |
| 261 | LS->seminfo.ts = luaS_newlstr(L->Mbuffbase+2, | 261 | LS->seminfo.ts = luaS_newlstr(L->Mbuffer+(L->Mbuffbase+2), |
| 262 | L->Mbuffnext-(L->Mbuffbase-L->Mbuffer)-4); | 262 | L->Mbuffnext-L->Mbuffbase-4); |
| 263 | return STRING; | 263 | return STRING; |
| 264 | } | 264 | } |
| 265 | 265 | ||
| @@ -358,8 +358,8 @@ int luaX_lex (LexState *LS) { | |||
| 358 | } | 358 | } |
| 359 | } | 359 | } |
| 360 | save_and_next(LS); /* skip delimiter */ | 360 | save_and_next(LS); /* skip delimiter */ |
| 361 | LS->seminfo.ts = luaS_newlstr(L->Mbuffbase+1, | 361 | LS->seminfo.ts = luaS_newlstr(L->Mbuffer+(L->Mbuffbase+1), |
| 362 | L->Mbuffnext-(L->Mbuffbase-L->Mbuffer)-2); | 362 | L->Mbuffnext-L->Mbuffbase-2); |
| 363 | return STRING; | 363 | return STRING; |
| 364 | } | 364 | } |
| 365 | 365 | ||
| @@ -401,7 +401,7 @@ int luaX_lex (LexState *LS) { | |||
| 401 | save_and_next(LS); | 401 | save_and_next(LS); |
| 402 | } | 402 | } |
| 403 | save('\0'); | 403 | save('\0'); |
| 404 | LS->seminfo.r = luaO_str2d(L->Mbuffbase); | 404 | LS->seminfo.r = luaO_str2d(L->Mbuffer+L->Mbuffbase); |
| 405 | if (LS->seminfo.r < 0) | 405 | if (LS->seminfo.r < 0) |
| 406 | luaX_error(LS, "invalid numeric format"); | 406 | luaX_error(LS, "invalid numeric format"); |
| 407 | return NUMBER; | 407 | return NUMBER; |
| @@ -425,7 +425,7 @@ int luaX_lex (LexState *LS) { | |||
| 425 | save_and_next(LS); | 425 | save_and_next(LS); |
| 426 | } while (isalnum(LS->current) || LS->current == '_'); | 426 | } while (isalnum(LS->current) || LS->current == '_'); |
| 427 | save('\0'); | 427 | save('\0'); |
| 428 | ts = luaS_new(L->Mbuffbase); | 428 | ts = luaS_new(L->Mbuffer+L->Mbuffbase); |
| 429 | if (ts->head.marked >= FIRST_RESERVED) | 429 | if (ts->head.marked >= FIRST_RESERVED) |
| 430 | return ts->head.marked; /* reserved word */ | 430 | return ts->head.marked; /* reserved word */ |
| 431 | LS->seminfo.ts = ts; | 431 | LS->seminfo.ts = ts; |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lstate.c,v 1.7 1999/01/15 13:11:22 roberto Exp roberto $ | 2 | ** $Id: lstate.c,v 1.8 1999/02/04 17:47:59 roberto Exp roberto $ |
| 3 | ** Global State | 3 | ** Global State |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -44,7 +44,7 @@ void lua_open (void) | |||
| 44 | L->refSize = 0; | 44 | L->refSize = 0; |
| 45 | L->Mbuffsize = 0; | 45 | L->Mbuffsize = 0; |
| 46 | L->Mbuffnext = 0; | 46 | L->Mbuffnext = 0; |
| 47 | L->Mbuffbase = NULL; | 47 | L->Mbuffbase = 0; |
| 48 | L->Mbuffer = NULL; | 48 | L->Mbuffer = NULL; |
| 49 | L->GCthreshold = GARBAGE_BLOCK; | 49 | L->GCthreshold = GARBAGE_BLOCK; |
| 50 | L->nblocks = 0; | 50 | L->nblocks = 0; |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lstate.h,v 1.13 1998/08/30 18:28:58 roberto Exp roberto $ | 2 | ** $Id: lstate.h,v 1.14 1999/02/04 17:47:59 roberto Exp roberto $ |
| 3 | ** Global State | 3 | ** Global State |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -56,7 +56,7 @@ struct lua_State { | |||
| 56 | struct C_Lua_Stack Cstack; /* C2lua struct */ | 56 | struct C_Lua_Stack Cstack; /* C2lua struct */ |
| 57 | jmp_buf *errorJmp; /* current error recover point */ | 57 | jmp_buf *errorJmp; /* current error recover point */ |
| 58 | char *Mbuffer; /* global buffer */ | 58 | char *Mbuffer; /* global buffer */ |
| 59 | char *Mbuffbase; /* current first position of Mbuffer */ | 59 | int Mbuffbase; /* current first position of Mbuffer */ |
| 60 | int Mbuffsize; /* size of Mbuffer */ | 60 | int Mbuffsize; /* size of Mbuffer */ |
| 61 | int Mbuffnext; /* next position to fill in Mbuffer */ | 61 | int Mbuffnext; /* next position to fill in Mbuffer */ |
| 62 | struct C_Lua_Stack Cblocks[MAX_C_BLOCKS]; | 62 | struct C_Lua_Stack Cblocks[MAX_C_BLOCKS]; |
