Compare commits

...

18 Commits

Author SHA1 Message Date
Roberto Ierusalimschy
dbfe28e199 correction in inheritance code in C 1996-11-18 12:27:42 -02:00
Roberto Ierusalimschy
d59c52753f undump needs file in binary mode 1996-11-18 11:48:44 -02:00
Roberto Ierusalimschy
62e1a4c84d BUG: problems with negative indexes 1996-11-18 11:48:44 -02:00
Luiz Henrique de Figueiredo
81411e8913 headers includes sizeof(Word) not sizeof(int) 1996-11-18 09:18:29 -02:00
Luiz Henrique de Figueiredo
62aa717f7e stdlib.h for exit
blocks are void*
1996-11-16 18:14:23 -02:00
Roberto Ierusalimschy
a5614eae3c spelling corrections. 1996-11-14 15:45:37 -02:00
Luiz Henrique de Figueiredo
536bae5871 corrected version test (0x23 not 23) 1996-11-14 13:00:32 -02:00
Luiz Henrique de Figueiredo
679eddf296 1996-11-14 11:33:15 -02:00
Luiz Henrique de Figueiredo
d991def36c added 3 new bytes to header (sizeof's) 1996-11-14 09:44:34 -02:00
Luiz Henrique de Figueiredo
8b195533d2 new header version 1996-11-14 09:44:34 -02:00
Roberto Ierusalimschy
3ccdd57c26 new version 1996-11-12 14:00:16 -02:00
Roberto Ierusalimschy
a103455dda better format for error messages. 1996-11-08 17:08:30 -02:00
Roberto Ierusalimschy
60242e1930 error message for syntax "1..2";
syntax error function is in "lex.c" (it has the token)
1996-11-08 10:49:35 -02:00
Roberto Ierusalimschy
a0e9bfbb48 syntax error function is in "lex.c" (it has the token) 1996-11-08 10:49:35 -02:00
Roberto Ierusalimschy
2f19e0ba16 SunOS is not ANSI about the return value of "sprintf". 1996-11-07 18:26:19 -02:00
Roberto Ierusalimschy
ab7fdcbbed corrected copyright notice 1996-11-07 18:26:08 -02:00
Luiz Henrique de Figueiredo
48cf1de356 replaced unions by memcpy 1996-11-07 12:13:28 -02:00
Luiz Henrique de Figueiredo
8d50122af0 replaced unions by memcpy 1996-11-07 11:59:51 -02:00
10 changed files with 98 additions and 80 deletions

40
hash.c
View File

@@ -3,7 +3,7 @@
** hash manager for lua ** hash manager for lua
*/ */
char *rcs_hash="$Id: hash.c,v 2.30 1996/05/06 14:30:27 roberto Exp roberto $"; char *rcs_hash="$Id: hash.c,v 2.31 1996/07/12 20:00:26 roberto Exp roberto $";
#include "mem.h" #include "mem.h"
@@ -48,24 +48,26 @@ int luaI_redimension (int nhash)
static int hashindex (Hash *t, Object *ref) /* hash function */ static int hashindex (Hash *t, Object *ref) /* hash function */
{ {
switch (tag(ref)) long int h;
{ switch (tag(ref)) {
case LUA_T_NIL: case LUA_T_NIL:
lua_error ("unexpected type to index table"); lua_error ("unexpected type to index table");
return -1; /* UNREACHEABLE */ h = 0; /* UNREACHEABLE */
case LUA_T_NUMBER: case LUA_T_NUMBER:
return (((int)nvalue(ref))%nhash(t)); h = (long int)nvalue(ref); break;
case LUA_T_STRING: case LUA_T_STRING:
return (int)((tsvalue(ref)->hash)%nhash(t)); /* make it a valid index */ h = tsvalue(ref)->hash; break;
case LUA_T_FUNCTION: case LUA_T_FUNCTION:
return (((IntPoint)ref->value.tf)%nhash(t)); h = (IntPoint)ref->value.tf; break;
case LUA_T_CFUNCTION: case LUA_T_CFUNCTION:
return (((IntPoint)fvalue(ref))%nhash(t)); h = (IntPoint)fvalue(ref); break;
case LUA_T_ARRAY: case LUA_T_ARRAY:
return (((IntPoint)avalue(ref))%nhash(t)); h = (IntPoint)avalue(ref); break;
default: /* user data */ default: /* user data */
return (((IntPoint)uvalue(ref))%nhash(t)); h = (IntPoint)uvalue(ref); break;
} }
if (h < 0) h = -h;
return h%nhash(t); /* make it a valid index */
} }
int lua_equalObj (Object *t1, Object *t2) int lua_equalObj (Object *t1, Object *t2)

28
lex.c
View File

@@ -1,4 +1,4 @@
char *rcs_lex = "$Id: lex.c,v 2.36 1996/09/25 21:52:00 roberto Exp roberto $"; char *rcs_lex = "$Id: lex.c,v 2.38 1996/11/08 12:49:35 roberto Exp roberto $";
#include <ctype.h> #include <ctype.h>
@@ -30,9 +30,15 @@ void lua_setinput (Input fn)
input = fn; input = fn;
} }
char *lua_lasttext (void) void luaI_syntaxerror (char *s)
{ {
return luaI_buffer(1); char msg[256];
char *token = luaI_buffer(1);
if (token[0] == 0)
token = "<eof>";
sprintf (msg,"%s;\n> last token read: \"%s\" at line %d in file %s",
s, token, lua_linenumber, lua_parsedfile);
lua_error (msg);
} }
@@ -74,12 +80,13 @@ void luaI_addReserved (void)
static int inclinenumber (int pragma_allowed) static int inclinenumber (int pragma_allowed)
{ {
++lua_linenumber;
if (pragma_allowed && current == '$') { /* is a pragma? */ if (pragma_allowed && current == '$') { /* is a pragma? */
char buff[MINBUFF]; char *buff = luaI_buffer(MINBUFF+1);
int i = 0; int i = 0;
next(); /* skip $ */ next(); /* skip $ */
while (isalnum(current)) { while (isalnum(current)) {
if (i >= MINBUFF) lua_error("pragma too long"); if (i >= MINBUFF) luaI_syntaxerror("pragma too long");
buff[i++] = current; buff[i++] = current;
next(); next();
} }
@@ -88,9 +95,9 @@ static int inclinenumber (int pragma_allowed)
lua_debug = 1; lua_debug = 1;
else if (strcmp(buff, "nodebug") == 0) else if (strcmp(buff, "nodebug") == 0)
lua_debug = 0; lua_debug = 0;
else lua_error("invalid pragma"); else luaI_syntaxerror("invalid pragma");
} }
return ++lua_linenumber; return lua_linenumber;
} }
static int read_long_string (char *yytext, int buffsize) static int read_long_string (char *yytext, int buffsize)
@@ -285,7 +292,12 @@ int luaY_lex (void)
a=10.0*a+(current-'0'); a=10.0*a+(current-'0');
save_and_next(); save_and_next();
} while (isdigit(current)); } while (isdigit(current));
if (current == '.') save_and_next(); if (current == '.') {
save_and_next();
if (current == '.')
luaI_syntaxerror(
"ambiguous syntax (decimal point x string concatenation)");
}
fraction: fraction:
{ double da=0.1; { double da=0.1;
while (isdigit(current)) while (isdigit(current))

4
lex.h
View File

@@ -1,7 +1,7 @@
/* /*
** lex.h ** lex.h
** TecCGraf - PUC-Rio ** TecCGraf - PUC-Rio
** $Id: lex.h,v 1.1 1996/02/13 17:30:39 roberto Exp roberto $ ** $Id: lex.h,v 1.2 1996/02/14 13:35:51 roberto Exp roberto $
*/ */
#ifndef lex_h #ifndef lex_h
@@ -11,7 +11,7 @@
typedef int (*Input) (void); typedef int (*Input) (void);
void lua_setinput (Input fn); void lua_setinput (Input fn);
char *lua_lasttext (void); void luaI_syntaxerror (char *s);
int luaY_lex (void); int luaY_lex (void);
void luaI_addReserved (void); void luaI_addReserved (void);

6
lua.h
View File

@@ -2,15 +2,15 @@
** LUA - Linguagem para Usuarios de Aplicacao ** LUA - Linguagem para Usuarios de Aplicacao
** Grupo de Tecnologia em Computacao Grafica ** Grupo de Tecnologia em Computacao Grafica
** TeCGraf - PUC-Rio ** TeCGraf - PUC-Rio
** $Id: lua.h,v 3.28 1996/05/06 14:32:59 roberto Exp roberto $ ** $Id: lua.h,v 3.30 1996/11/07 20:26:08 roberto Exp roberto $
*/ */
#ifndef lua_h #ifndef lua_h
#define lua_h #define lua_h
#define LUA_VERSION "Lua 2.5 (beta)" #define LUA_VERSION "Lua 2.5"
#define LUA_COPYRIGHT "Copyright (C) 1994, 1995 TeCGraf" #define LUA_COPYRIGHT "Copyright (C) 1994-1996 TeCGraf"
#define LUA_AUTHORS "W. Celes, R. Ierusalimschy & L. H. de Figueiredo" #define LUA_AUTHORS "W. Celes, R. Ierusalimschy & L. H. de Figueiredo"

10
lua.stx
View File

@@ -1,6 +1,6 @@
%{ %{
char *rcs_luastx = "$Id: lua.stx,v 3.39 1996/09/24 17:29:50 roberto Exp roberto $"; char *rcs_luastx = "$Id: lua.stx,v 3.40 1996/09/25 21:52:00 roberto Exp roberto $";
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
@@ -59,13 +59,7 @@ int lua_debug = 0;
static void yyerror (char *s) static void yyerror (char *s)
{ {
char msg[256]; luaI_syntaxerror(s);
char *token = lua_lasttext();
if (token[0] == 0)
token = "<eof>";
sprintf (msg,"%s; last token read: \"%s\" at line %d in file `%s'",
s, token, lua_linenumber, lua_parsedfile);
lua_error (msg);
} }
static void check_space (int i) static void check_space (int i)

View File

@@ -1,4 +1,4 @@
% $Id: manual.tex,v 1.21 1996/11/01 18:02:53 roberto Exp roberto $ % $Id: manual.tex,v 1.24 1996/11/14 17:45:37 roberto Exp roberto $
\documentstyle[fullpage,11pt,bnf]{article} \documentstyle[fullpage,11pt,bnf]{article}
@@ -15,7 +15,7 @@
\newcommand{\ff}{$\bullet$\ } \newcommand{\ff}{$\bullet$\ }
\newcommand{\Version}{2.5 (beta)} \newcommand{\Version}{2.5}
\makeindex \makeindex
@@ -35,7 +35,7 @@ Waldemar Celes
\tecgraf\ --- Departamento de Inform\'atica --- PUC-Rio \tecgraf\ --- Departamento de Inform\'atica --- PUC-Rio
} }
\date{\small \verb$Date: 1996/11/01 18:02:53 $} \date{\small \verb$Date: 1996/11/14 17:45:37 $}
\maketitle \maketitle
@@ -231,7 +231,7 @@ and do not interpret escape sequences.
\Index{Comments} start anywhere outside a string with a \Index{Comments} start anywhere outside a string with a
double hyphen (\verb'--') and run until the end of the line. double hyphen (\verb'--') and run until the end of the line.
Moreover, if the first line of a chunk file starts with \verb'#', Moreover, if the first line of a chunk file starts with \verb'#',
this line is skiped% this line is skipped%
\footnote{This facility allows the use of Lua as a script interpreter \footnote{This facility allows the use of Lua as a script interpreter
in Unix systems.}. in Unix systems.}.
@@ -678,7 +678,7 @@ called when Lua tries to assign indexed a non table value.
It receives as arguments the non table value, It receives as arguments the non table value,
the index, and the assigned value. the index, and the assigned value.
The default handler issues an error. The default handler issues an error.
\item[``function'':]\index{function falback} \item[``function'':]\index{function fallback}
called when Lua tries to call a non function value. called when Lua tries to call a non function value.
It receives as arguments the non function value and the It receives as arguments the non function value and the
arguments given in the original call. arguments given in the original call.
@@ -1334,7 +1334,7 @@ whereas \verb'q' and \verb's' expect a string.
\subsubsection*{\ff{\tt gsub (s, pat, repl [, n])}}\Deffunc{gsub} \subsubsection*{\ff{\tt gsub (s, pat, repl [, n])}}\Deffunc{gsub}
Returns a copy of \verb-s-, Returns a copy of \verb-s-,
where all ocurrences of the pattern \verb-pat- have been where all occurrences of the pattern \verb-pat- have been
replaced by a replacement string specified by \verb-repl-. replaced by a replacement string specified by \verb-repl-.
This function also returns, as a second value, This function also returns, as a second value,
the total number of substitutions made. the total number of substitutions made.
@@ -1352,10 +1352,10 @@ otherwise, the replacement string is the empty string.
An optional parameter \verb-n- limits An optional parameter \verb-n- limits
the maximum number of substitutions to occur. the maximum number of substitutions to occur.
For instance, when \verb-n- is 1 only the first ocurrence of For instance, when \verb-n- is 1 only the first occurrence of
\verb-pat- is replaced. \verb-pat- is replaced.
As an example, in the following expression each ocurrence of the form As an example, in the following expression each occurrence of the form
\verb-$name$- calls the function \verb|getenv|, \verb-$name$- calls the function \verb|getenv|,
passing \verb|name| as argument passing \verb|name| as argument
(because only this part of the pattern is captured). (because only this part of the pattern is captured).
@@ -1415,7 +1415,7 @@ or a character class followed by \verb'*' or by \verb'?'.
A single character class matches any single character in the class. A single character class matches any single character in the class.
A character class followed by \verb'*' matches 0 or more repetitions A character class followed by \verb'*' matches 0 or more repetitions
of characters in the class. of characters in the class.
A character class followed by \verb'?' matches 0 or one ocurrence A character class followed by \verb'?' matches 0 or one occurrence
of a character in the class. of a character in the class.
A pattern item may also has the form \verb'%n', A pattern item may also has the form \verb'%n',
for \verb-n- between 1 and 9; for \verb-n- between 1 and 9;
@@ -1987,6 +1987,8 @@ void callOldFallback (lua_Object table, lua_Object index)
lua_pushobject(table); lua_pushobject(table);
lua_pushobject(index); lua_pushobject(index);
lua_callfunction(oldIndex); lua_callfunction(oldIndex);
if (lua_getresult(1) != LUA_NOOBJECT)
lua_pushobject(lua_getresult(1)); /* return result */
} }
void Index (void) void Index (void)
@@ -2204,9 +2206,9 @@ This program can be called with any sequence of the following arguments:
\item[{\tt -v}] prints version information. \item[{\tt -v}] prints version information.
\item[{\tt -}] runs interactively, accepting commands from standard input \item[{\tt -}] runs interactively, accepting commands from standard input
until an \verb|EOF|. until an \verb|EOF|.
\item[{\tt -e stat}] executes \verb|stat| as a Lua chunck. \item[{\tt -e stat}] executes \verb|stat| as a Lua chunk.
\item[{\tt var=exp}] executes \verb|var=exp| as a Lua chunck. \item[{\tt var=exp}] executes \verb|var=exp| as a Lua chunk.
\item[{\tt filename}] executes file \verb|filename| as a Lua chunck. \item[{\tt filename}] executes file \verb|filename| as a Lua chunk.
\end{description} \end{description}
All arguments are handle in order. All arguments are handle in order.
For instance, an invocation like For instance, an invocation like

View File

@@ -3,7 +3,7 @@
** TecCGraf - PUC-Rio ** TecCGraf - PUC-Rio
*/ */
char *rcs_opcode="$Id: opcode.c,v 3.75 1996/09/24 17:30:28 roberto Exp roberto $"; char *rcs_opcode="$Id: opcode.c,v 3.76 1996/09/24 21:46:44 roberto Exp roberto $";
#include <setjmp.h> #include <setjmp.h>
#include <stdio.h> #include <stdio.h>
@@ -548,8 +548,10 @@ int lua_dofile (char *filename)
return 2; return 2;
c = fgetc(f); c = fgetc(f);
ungetc(c, f); ungetc(c, f);
if (c == ID_CHUNK) if (c == ID_CHUNK) {
f = freopen(filename, "rb", f); /* set binary mode */
status = luaI_undump(f); status = luaI_undump(f);
}
else { else {
if (c == '#') if (c == '#')
while ((c=fgetc(f)) != '\n') /* skip first line */; while ((c=fgetc(f)) != '\n') /* skip first line */;

View File

@@ -3,7 +3,7 @@
** String library to LUA ** String library to LUA
*/ */
char *rcs_strlib="$Id: strlib.c,v 1.30 1996/10/31 17:26:04 roberto Exp roberto $"; char *rcs_strlib="$Id: strlib.c,v 1.31 1996/10/31 20:18:05 roberto Exp roberto $";
#include <string.h> #include <string.h>
#include <stdio.h> #include <stdio.h>
@@ -493,25 +493,24 @@ static void str_format (void)
switch (*strfrmt++) { switch (*strfrmt++) {
case 'q': case 'q':
luaI_addquoted(lua_check_string(arg++, "format")); luaI_addquoted(lua_check_string(arg++, "format"));
break; continue;
case 's': { case 's': {
char *s = lua_check_string(arg++, "format"); char *s = lua_check_string(arg++, "format");
buff = openspace(strlen(s)); buff = openspace(strlen(s));
lbuffer.size += sprintf(buff, form, s); sprintf(buff, form, s);
break; break;
} }
case 'c': case 'd': case 'i': case 'o': case 'c': case 'd': case 'i': case 'o':
case 'u': case 'x': case 'X': case 'u': case 'x': case 'X':
lbuffer.size += sprintf(buff, form, sprintf(buff, form, (int)lua_check_number(arg++, "format"));
(int)lua_check_number(arg++, "format"));
break; break;
case 'e': case 'E': case 'f': case 'g': case 'e': case 'E': case 'f': case 'g':
lbuffer.size += sprintf(buff, form, sprintf(buff, form, lua_check_number(arg++, "format"));
lua_check_number(arg++, "format"));
break; break;
default: /* also treat cases 'pnLlh' */ default: /* also treat cases 'pnLlh' */
lua_error("invalid format option in function `format'"); lua_error("invalid format option in function `format'");
} }
lbuffer.size += strlen(buff);
} }
} }
lua_pushstring(luaI_addchar(0)); /* push the result */ lua_pushstring(luaI_addchar(0)); /* push the result */

View File

@@ -3,7 +3,7 @@
** load bytecodes from files ** load bytecodes from files
*/ */
char* rcs_undump="$Id: undump.c,v 1.13 1996/03/12 20:00:40 lhf Exp lhf $"; char* rcs_undump="$Id: undump.c,v 1.20 1996/11/16 20:14:23 lhf Exp lhf $";
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
@@ -90,7 +90,7 @@ static void FixCode(Byte* code, Byte* end) /* swap words */
p+=3; p+=3;
break; break;
case PUSHFUNCTION: case PUSHFUNCTION:
p+=5; p+=5; /* TODO: use sizeof(TFunc*) or old? */
break; break;
case PUSHWORD: case PUSHWORD:
case PUSHSELF: case PUSHSELF:
@@ -111,7 +111,7 @@ static void FixCode(Byte* code, Byte* end) /* swap words */
p+=3; p+=3;
break; break;
} }
case PUSHFLOAT: case PUSHFLOAT: /* assumes sizeof(float)==4 */
{ {
Byte t; Byte t;
t=p[1]; p[1]=p[4]; p[4]=t; t=p[1]; p[1]=p[4]; p[4]=t;
@@ -142,13 +142,11 @@ static void Unthread(Byte* code, int i, int v)
{ {
while (i!=0) while (i!=0)
{ {
CodeWord c; Word w;
Byte* p=code+i; Byte* p=code+i;
get_word(c,p); memcpy(&w,p,sizeof(w));
i=c.w; i=w; w=v;
c.w=v; memcpy(p,&w,sizeof(w));
p[-2]=c.m.c1;
p[-1]=c.m.c2;
} }
} }
@@ -174,9 +172,9 @@ static int LoadSize(FILE* D)
return s; return s;
} }
static char* LoadBlock(int size, FILE* D) static void* LoadBlock(int size, FILE* D)
{ {
char* b=luaI_malloc(size); void* b=luaI_malloc(size);
fread(b,size,1,D); fread(b,size,1,D);
return b; return b;
} }
@@ -208,13 +206,9 @@ static void LoadFunction(FILE* D)
} }
else /* fix PUSHFUNCTION */ else /* fix PUSHFUNCTION */
{ {
CodeCode c;
Byte* p;
tf->marked=LoadWord(D); tf->marked=LoadWord(D);
tf->fileName=Main->fileName; tf->fileName=Main->fileName;
p=Main->code+tf->marked; memcpy(Main->code+tf->marked,&tf,sizeof(tf));
c.tf=tf;
*p++=c.m.c1; *p++=c.m.c2; *p++=c.m.c3; *p++=c.m.c4;
lastF=lastF->next=tf; lastF=lastF->next=tf;
} }
tf->code=LoadBlock(tf->size,D); tf->code=LoadBlock(tf->size,D);
@@ -256,8 +250,21 @@ static void LoadHeader(FILE* D) /* TODO: error handling */
{ {
Word w,tw=TEST_WORD; Word w,tw=TEST_WORD;
float f,tf=TEST_FLOAT; float f,tf=TEST_FLOAT;
int version;
LoadSignature(D); LoadSignature(D);
getc(D); /* skip version */ version=getc(D);
if (version>0x23) /* after 2.5 */
{
int oldsizeofW=getc(D);
int oldsizeofF=getc(D);
int oldsizeofP=getc(D);
if (oldsizeofW!=2)
lua_error("cannot load binary file created on machine with sizeof(Word)!=2");
if (oldsizeofF!=4)
lua_error("cannot load binary file created on machine with sizeof(float)!=4. not an IEEE machine?");
if (oldsizeofP!=sizeof(TFunc*)) /* TODO: pack */
lua_error("cannot load binary file: different pointer sizes");
}
fread(&w,sizeof(w),1,D); /* test word */ fread(&w,sizeof(w),1,D); /* test word */
if (w!=tw) if (w!=tw)
{ {

View File

@@ -1,7 +1,7 @@
/* /*
** undump.h ** undump.h
** definitions for lua decompiler ** definitions for lua decompiler
** $Id: undump.h,v 1.1 1996/03/08 21:43:21 lhf Exp lhf $ ** $Id: undump.h,v 1.2 1996/03/11 21:59:41 lhf Exp lhf $
*/ */
#include "func.h" #include "func.h"
@@ -15,7 +15,7 @@
#define ID_VAR 'V' #define ID_VAR 'V'
#define ID_STR 'S' #define ID_STR 'S'
#define SIGNATURE "Lua" #define SIGNATURE "Lua"
#define VERSION 0x23 /* 2.3 */ #define VERSION 0x25 /* 2.5 */
#define TEST_WORD 0x1234 /* a word for testing byte ordering */ #define TEST_WORD 0x1234 /* a word for testing byte ordering */
#define TEST_FLOAT 0.123456789e-23 /* a float for testing representation */ #define TEST_FLOAT 0.123456789e-23 /* a float for testing representation */