some details related to OLD_ANSI

This commit is contained in:
Roberto Ierusalimschy 1997-12-26 16:38:16 -02:00
parent fada8efd01
commit da96eb2cce
5 changed files with 79 additions and 66 deletions

7
ldo.c
View File

@ -1,5 +1,5 @@
/* /*
** $Id: ldo.c,v 1.18 1997/12/22 20:57:18 roberto Exp roberto $ ** $Id: ldo.c,v 1.19 1997/12/23 12:50:49 roberto Exp roberto $
** Stack and Call structure of Lua ** Stack and Call structure of Lua
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -96,9 +96,8 @@ void luaD_adjusttop (StkId newtop)
*/ */
void luaD_openstack (int nelems) void luaD_openstack (int nelems)
{ {
int i; luaO_memup(L->stack.top-nelems+1, L->stack.top-nelems,
for (i=0; i<nelems; i++) nelems*sizeof(TObject));
*(L->stack.top-i) = *(L->stack.top-i-1);
incr_top; incr_top;
} }

View File

@ -1,5 +1,5 @@
/* /*
** $Id: liolib.c,v 1.11 1997/12/18 18:32:39 roberto Exp roberto $ ** $Id: liolib.c,v 1.12 1997/12/18 19:11:43 roberto Exp roberto $
** Standard I/O (and system) library ** Standard I/O (and system) library
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -20,7 +20,6 @@
#ifndef OLD_ANSI #ifndef OLD_ANSI
#include <locale.h> #include <locale.h>
#else #else
#define strcoll(a,b) strcmp(a,b)
#define setlocale(a,b) 0 #define setlocale(a,b) 0
#define LC_ALL 0 #define LC_ALL 0
#define LC_COLLATE 0 #define LC_COLLATE 0

View File

@ -1,5 +1,5 @@
/* /*
** $Id: lobject.c,v 1.7 1997/11/19 17:29:23 roberto Exp roberto $ ** $Id: lobject.c,v 1.8 1997/12/15 16:17:20 roberto Exp roberto $
** Some generic functions over Lua objects ** Some generic functions over Lua objects
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -75,3 +75,20 @@ void luaO_insertlist (GCnode *root, GCnode *node)
node->marked = 0; node->marked = 0;
} }
#ifdef OLD_ANSI
void luaO_memup (void *dest, void *src, int size)
{
char *d = dest;
char *s = src;
while (size--) d[size]=s[size];
}
void luaO_memdown (void *dest, void *src, int size)
{
char *d = dest;
char *s = src;
int i;
for (i=0; i<size; i++) d[i]=s[i];
}
#endif

View File

@ -1,5 +1,5 @@
/* /*
** $Id: lobject.h,v 1.11 1997/12/15 16:17:20 roberto Exp roberto $ ** $Id: lobject.h,v 1.12 1997/12/23 19:24:19 roberto Exp roberto $
** Type definitions for Lua objects ** Type definitions for Lua objects
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -8,11 +8,10 @@
#define lobject_h #define lobject_h
#include "lua.h"
#include <limits.h> #include <limits.h>
#include "lua.h"
/* /*
** "real" is the type "number" of Lua ** "real" is the type "number" of Lua
@ -181,5 +180,13 @@ int luaO_redimension (int oldsize);
int luaO_findstring (char *name, char *list[]); int luaO_findstring (char *name, char *list[]);
void luaO_insertlist (GCnode *root, GCnode *node); void luaO_insertlist (GCnode *root, GCnode *node);
#ifdef OLD_ANSI
void luaO_memup (void *dest, void *src, int size);
void luaO_memdown (void *dest, void *src, int size);
#else
#include <string.h>
#define luaO_memup(d,s,n) memmove(d,s,n)
#define luaO_memdown(d,s,n) memmove(d,s,n)
#endif
#endif #endif

101
lua.stx
View File

@ -1,6 +1,6 @@
%{ %{
/* /*
** $Id: lua.stx,v 1.25 1997/12/22 20:57:18 roberto Exp roberto $ ** $Id: lua.stx,v 1.26 1997/12/23 19:24:19 roberto Exp roberto $
** Syntax analizer and code generator ** Syntax analizer and code generator
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -108,24 +108,10 @@ void luaY_error (char *s)
static void check_pc (int n) static void check_pc (int n)
{ {
if (L->currState->pc+n > L->currState->maxcode) FuncState *fs = L->currState;
L->currState->maxcode = luaM_growvector(&L->currState->f->code, if (fs->pc+n > fs->maxcode)
L->currState->maxcode, Byte, codeEM, MAX_INT); fs->maxcode = luaM_growvector(&fs->f->code, fs->maxcode,
} Byte, codeEM, MAX_INT);
static void movecode_up (int d, int s, int n)
{
while (n--)
L->currState->f->code[d+n] = L->currState->f->code[s+n];
}
static void movecode_down (int d, int s, int n)
{
int i;
for (i=0; i<n; i++)
L->currState->f->code[d+i] = L->currState->f->code[s+i];
} }
@ -138,31 +124,33 @@ static void code_byte (Byte c)
static void deltastack (int delta) static void deltastack (int delta)
{ {
L->currState->stacksize += delta; FuncState *fs = L->currState;
if (L->currState->stacksize > L->currState->maxstacksize) { fs->stacksize += delta;
if (L->currState->stacksize > 255) if (fs->stacksize > fs->maxstacksize) {
if (fs->stacksize > 255)
luaY_error("function/expression too complex"); luaY_error("function/expression too complex");
L->currState->maxstacksize = L->currState->stacksize; fs->maxstacksize = fs->stacksize;
} }
} }
static int code_oparg_at (int pc, OpCode op, int builtin, int arg, int delta) static int code_oparg_at (int pc, OpCode op, int builtin, int arg, int delta)
{ {
Byte *code = L->currState->f->code;
deltastack(delta); deltastack(delta);
if (arg < builtin) { if (arg < builtin) {
L->currState->f->code[pc] = op+1+arg; code[pc] = op+1+arg;
return 1; return 1;
} }
else if (arg <= 255) { else if (arg <= 255) {
L->currState->f->code[pc] = op; code[pc] = op;
L->currState->f->code[pc+1] = arg; code[pc+1] = arg;
return 2; return 2;
} }
else if (arg <= MAX_WORD) { else if (arg <= MAX_WORD) {
L->currState->f->code[pc] = op+1+builtin; code[pc] = op+1+builtin;
L->currState->f->code[pc+1] = arg&0xFF; code[pc+1] = arg&0xFF;
L->currState->f->code[pc+2] = arg>>8; code[pc+2] = arg>>8;
return 3; return 3;
} }
else luaY_error("code too long " MES_LIM("64K")); 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)
static int fix_opcode (int pc, OpCode op, int builtin, int arg) static int fix_opcode (int pc, OpCode op, int builtin, int arg)
{ {
FuncState *fs = L->currState;
if (arg < builtin) { /* close space */ if (arg < builtin) { /* close space */
movecode_down(pc+1, pc+2, L->currState->pc-(pc+2)); luaO_memdown(fs->f->code+pc+1, fs->f->code+pc+2, fs->pc-(pc+2));
L->currState->pc--; fs->pc--;
} }
else if (arg > 255) { /* open space */ else if (arg > 255) { /* open space */
check_pc(1); check_pc(1);
movecode_up(pc+1, pc, L->currState->pc-pc); luaO_memup(fs->f->code+pc+1, fs->f->code+pc, fs->pc-pc);
L->currState->pc++; fs->pc++;
} }
return code_oparg_at(pc, op, builtin, arg, 0) - 2; return code_oparg_at(pc, op, builtin, arg, 0) - 2;
} }
@ -301,13 +290,14 @@ static void flush_list (int m, int n)
static void luaI_registerlocalvar (TaggedString *varname, int line) static void luaI_registerlocalvar (TaggedString *varname, int line)
{ {
if (L->currState->maxvars != -1) { /* debug information? */ FuncState *fs = L->currState;
if (L->currState->nvars >= L->currState->maxvars) if (fs->maxvars != -1) { /* debug information? */
L->currState->maxvars = luaM_growvector(&L->currState->f->locvars, if (fs->nvars >= fs->maxvars)
L->currState->maxvars, LocVar, "", MAX_WORD); fs->maxvars = luaM_growvector(&fs->f->locvars, fs->maxvars,
L->currState->f->locvars[L->currState->nvars].varname = varname; LocVar, "", MAX_WORD);
L->currState->f->locvars[L->currState->nvars].line = line; fs->f->locvars[fs->nvars].varname = varname;
L->currState->nvars++; fs->f->locvars[fs->nvars].line = line;
fs->nvars++;
} }
} }
@ -569,22 +559,23 @@ static void func_onstack (TProtoFunc *f)
static void init_state (TaggedString *filename) static void init_state (TaggedString *filename)
{ {
TProtoFunc *f = luaF_newproto(); TProtoFunc *f = luaF_newproto();
L->currState->stacksize = 0; FuncState *fs = L->currState;
L->currState->maxstacksize = 0; fs->stacksize = 0;
L->currState->nlocalvar = 0; fs->maxstacksize = 0;
L->currState->nupvalues = 0; fs->nlocalvar = 0;
L->currState->f = f; fs->nupvalues = 0;
fs->f = f;
f->fileName = filename; f->fileName = filename;
L->currState->pc = 0; fs->pc = 0;
L->currState->maxcode = 0; fs->maxcode = 0;
f->code = NULL; f->code = NULL;
L->currState->maxconsts = 0; fs->maxconsts = 0;
if (lua_debug) { if (lua_debug) {
L->currState->nvars = 0; fs->nvars = 0;
L->currState->maxvars = 0; fs->maxvars = 0;
} }
else else
L->currState->maxvars = -1; /* flag no debug information */ fs->maxvars = -1; /* flag no debug information */
code_byte(0); /* to be filled with stacksize */ code_byte(0); /* to be filled with stacksize */
L->lexstate->lastline = 0; /* invalidate it */ L->lexstate->lastline = 0; /* invalidate it */
} }
@ -696,13 +687,13 @@ stat : IF cond THEN block SaveWord elsepart END { codeIf($2, $5); }
| WHILE GetPC cond DO block END | WHILE GetPC cond DO block END
{{ {{
FuncState *fs = L->currState;
int expsize = $3-$2; int expsize = $3-$2;
int newpos = $2+JMPSIZE; int newpos = $2+JMPSIZE;
check_pc(expsize); check_pc(expsize);
memcpy(&L->currState->f->code[L->currState->pc], memcpy(fs->f->code+fs->pc, fs->f->code+$2, expsize);
&L->currState->f->code[$2], expsize); luaO_memdown(fs->f->code+$2, fs->f->code+$3, fs->pc-$2);
movecode_down($2, $3, L->currState->pc-$2); newpos += fix_jump($2, JMP, fs->pc-expsize);
newpos += fix_jump($2, JMP, L->currState->pc-expsize);
fix_upjmp(IFTUPJMP, newpos); fix_upjmp(IFTUPJMP, newpos);
}} }}