Compare commits

...

21 Commits

Author SHA1 Message Date
Roberto Ierusalimschy
42359b8b13 new version 1996-11-20 11:49:32 -02:00
Roberto Ierusalimschy
169870e37d BUG: ISO chars are negative, ISO ints are not. 1996-11-20 11:47:59 -02:00
Roberto Ierusalimschy
78e454d864 BUG: ISO chars are negative, ISO ints are not.
new "balanced" pattern.
1996-11-20 11:47:59 -02:00
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
11 changed files with 130 additions and 87 deletions

40
hash.c
View File

@@ -3,7 +3,7 @@
** 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"
@@ -48,24 +48,26 @@ int luaI_redimension (int nhash)
static int hashindex (Hash *t, Object *ref) /* hash function */
{
switch (tag(ref))
{
case LUA_T_NIL:
lua_error ("unexpected type to index table");
return -1; /* UNREACHEABLE */
case LUA_T_NUMBER:
return (((int)nvalue(ref))%nhash(t));
case LUA_T_STRING:
return (int)((tsvalue(ref)->hash)%nhash(t)); /* make it a valid index */
case LUA_T_FUNCTION:
return (((IntPoint)ref->value.tf)%nhash(t));
case LUA_T_CFUNCTION:
return (((IntPoint)fvalue(ref))%nhash(t));
case LUA_T_ARRAY:
return (((IntPoint)avalue(ref))%nhash(t));
default: /* user data */
return (((IntPoint)uvalue(ref))%nhash(t));
}
long int h;
switch (tag(ref)) {
case LUA_T_NIL:
lua_error ("unexpected type to index table");
h = 0; /* UNREACHEABLE */
case LUA_T_NUMBER:
h = (long int)nvalue(ref); break;
case LUA_T_STRING:
h = tsvalue(ref)->hash; break;
case LUA_T_FUNCTION:
h = (IntPoint)ref->value.tf; break;
case LUA_T_CFUNCTION:
h = (IntPoint)fvalue(ref); break;
case LUA_T_ARRAY:
h = (IntPoint)avalue(ref); break;
default: /* user data */
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)

View File

@@ -122,9 +122,10 @@ static void io_read (void)
}
else {
char *ep = item_end(p); /* get what is next */
int m;
int m; /* match result */
if (c == NEED_OTHER) c = getc(lua_infile);
if ((m = singlematch(c, p)) != 0) {
m = (c == EOF) ? 0 : singlematch((char)c, p);
if (m) {
if (!inskip) luaI_addchar(c);
c = NEED_OTHER;
}

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>
@@ -30,9 +30,15 @@ void lua_setinput (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)
{
++lua_linenumber;
if (pragma_allowed && current == '$') { /* is a pragma? */
char buff[MINBUFF];
char *buff = luaI_buffer(MINBUFF+1);
int i = 0;
next(); /* skip $ */
while (isalnum(current)) {
if (i >= MINBUFF) lua_error("pragma too long");
if (i >= MINBUFF) luaI_syntaxerror("pragma too long");
buff[i++] = current;
next();
}
@@ -88,9 +95,9 @@ static int inclinenumber (int pragma_allowed)
lua_debug = 1;
else if (strcmp(buff, "nodebug") == 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)
@@ -285,7 +292,12 @@ int luaY_lex (void)
a=10.0*a+(current-'0');
save_and_next();
} 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:
{ double da=0.1;
while (isdigit(current))

4
lex.h
View File

@@ -1,7 +1,7 @@
/*
** lex.h
** 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
@@ -11,7 +11,7 @@
typedef int (*Input) (void);
void lua_setinput (Input fn);
char *lua_lasttext (void);
void luaI_syntaxerror (char *s);
int luaY_lex (void);
void luaI_addReserved (void);

6
lua.h
View File

@@ -2,15 +2,15 @@
** LUA - Linguagem para Usuarios de Aplicacao
** Grupo de Tecnologia em Computacao Grafica
** TeCGraf - PUC-Rio
** $Id: lua.h,v 3.28 1996/05/06 14:32:59 roberto Exp roberto $
** $Id: lua.h,v 3.31 1996/11/12 16:00:16 roberto Exp roberto $
*/
#ifndef lua_h
#define lua_h
#define LUA_VERSION "Lua 2.5 (beta)"
#define LUA_COPYRIGHT "Copyright (C) 1994, 1995 TeCGraf"
#define LUA_VERSION "Lua 2.5.1"
#define LUA_COPYRIGHT "Copyright (C) 1994-1996 TeCGraf"
#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 <stdlib.h>
@@ -59,13 +59,7 @@ int lua_debug = 0;
static void yyerror (char *s)
{
char msg[256];
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);
luaI_syntaxerror(s);
}
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}
@@ -15,7 +15,7 @@
\newcommand{\ff}{$\bullet$\ }
\newcommand{\Version}{2.5 (beta)}
\newcommand{\Version}{2.5}
\makeindex
@@ -35,7 +35,7 @@ Waldemar Celes
\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
@@ -231,7 +231,7 @@ and do not interpret escape sequences.
\Index{Comments} start anywhere outside a string with a
double hyphen (\verb'--') and run until the end of the line.
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
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,
the index, and the assigned value.
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.
It receives as arguments the non function value and the
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}
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-.
This function also returns, as a second value,
the total number of substitutions made.
@@ -1352,10 +1352,10 @@ otherwise, the replacement string is the empty string.
An optional parameter \verb-n- limits
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.
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|,
passing \verb|name| as argument
(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 character class followed by \verb'*' matches 0 or more repetitions
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.
A pattern item may also has the form \verb'%n',
for \verb-n- between 1 and 9;
@@ -1987,6 +1987,8 @@ void callOldFallback (lua_Object table, lua_Object index)
lua_pushobject(table);
lua_pushobject(index);
lua_callfunction(oldIndex);
if (lua_getresult(1) != LUA_NOOBJECT)
lua_pushobject(lua_getresult(1)); /* return result */
}
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 -}] runs interactively, accepting commands from standard input
until an \verb|EOF|.
\item[{\tt -e stat}] executes \verb|stat| as a Lua chunck.
\item[{\tt var=exp}] executes \verb|var=exp| as a Lua chunck.
\item[{\tt filename}] executes file \verb|filename| 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 chunk.
\item[{\tt filename}] executes file \verb|filename| as a Lua chunk.
\end{description}
All arguments are handle in order.
For instance, an invocation like

View File

@@ -3,7 +3,7 @@
** 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 <stdio.h>
@@ -548,8 +548,10 @@ int lua_dofile (char *filename)
return 2;
c = fgetc(f);
ungetc(c, f);
if (c == ID_CHUNK)
if (c == ID_CHUNK) {
f = freopen(filename, "rb", f); /* set binary mode */
status = luaI_undump(f);
}
else {
if (c == '#')
while ((c=fgetc(f)) != '\n') /* skip first line */;

View File

@@ -3,7 +3,7 @@
** 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.32 1996/11/07 20:26:19 roberto Exp roberto $";
#include <string.h>
#include <stdio.h>
@@ -238,7 +238,7 @@ static int matchclass (int c, int cl)
int singlematch (int c, char *p)
{
if (c <= 0) return 0; /* \0, EOF or other strange flags */
if (c == 0) return 0;
switch (*p) {
case '.': return 1;
case ESC: return matchclass(c, *(p+1));
@@ -300,6 +300,21 @@ static int capture_to_close (int level)
return 0; /* to avoid warnings */
}
static char *matchbalance (char *s, int b, int e)
{
if (*s != b) return NULL;
else {
int cont = 1;
while (*(++s)) {
if (*s == e) {
if (--cont == 0) return s+1;
}
else if (*s == b) cont++;
}
}
return NULL; /* string ends out of balance */
}
static char *match (char *s, char *p, int level)
{
init: /* using goto's to optimize tail recursion */
@@ -317,16 +332,25 @@ static char *match (char *s, char *p, int level)
capture[l].len = -1; /* undo capture */
return res;
}
case ESC: /* possibly a capture (if followed by a digit) */
if (!isdigit(*(p+1))) goto dflt;
else {
case ESC:
if (isdigit(*(p+1))) { /* capture */
int l = check_cap(*(p+1), level);
if (strncmp(capture[l].init, s, capture[l].len) == 0) {
/* return match(p+2, s+capture[l].len, level); */
p+=2; s+=capture[l].len; goto init;
}
else return NULL;
}
}
else if (*(p+1) == 'b') { /* balanced string */
if (*(p+2) == 0 || *(p+3) == 0)
lua_error("bad balanced pattern specification");
s = matchbalance(s, *(p+2), *(p+3));
if (s == NULL) return NULL;
else { /* return match(p+4, s, level); */
p+=4; goto init;
}
}
else goto dflt;
case '\0': case '$': /* (possibly) end of pattern */
if (*p == 0 || (*(p+1) == 0 && *s == 0)) {
num_captures = level;
@@ -493,25 +517,24 @@ static void str_format (void)
switch (*strfrmt++) {
case 'q':
luaI_addquoted(lua_check_string(arg++, "format"));
break;
continue;
case 's': {
char *s = lua_check_string(arg++, "format");
buff = openspace(strlen(s));
lbuffer.size += sprintf(buff, form, s);
sprintf(buff, form, s);
break;
}
case 'c': case 'd': case 'i': case 'o':
case 'u': case 'x': case 'X':
lbuffer.size += sprintf(buff, form,
(int)lua_check_number(arg++, "format"));
sprintf(buff, form, (int)lua_check_number(arg++, "format"));
break;
case 'e': case 'E': case 'f': case 'g':
lbuffer.size += sprintf(buff, form,
lua_check_number(arg++, "format"));
sprintf(buff, form, lua_check_number(arg++, "format"));
break;
default: /* also treat cases 'pnLlh' */
lua_error("invalid format option in function `format'");
}
lbuffer.size += strlen(buff);
}
}
lua_pushstring(luaI_addchar(0)); /* push the result */

View File

@@ -3,7 +3,7 @@
** 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 <string.h>
@@ -90,7 +90,7 @@ static void FixCode(Byte* code, Byte* end) /* swap words */
p+=3;
break;
case PUSHFUNCTION:
p+=5;
p+=5; /* TODO: use sizeof(TFunc*) or old? */
break;
case PUSHWORD:
case PUSHSELF:
@@ -111,7 +111,7 @@ static void FixCode(Byte* code, Byte* end) /* swap words */
p+=3;
break;
}
case PUSHFLOAT:
case PUSHFLOAT: /* assumes sizeof(float)==4 */
{
Byte 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)
{
CodeWord c;
Word w;
Byte* p=code+i;
get_word(c,p);
i=c.w;
c.w=v;
p[-2]=c.m.c1;
p[-1]=c.m.c2;
memcpy(&w,p,sizeof(w));
i=w; w=v;
memcpy(p,&w,sizeof(w));
}
}
@@ -174,9 +172,9 @@ static int LoadSize(FILE* D)
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);
return b;
}
@@ -208,13 +206,9 @@ static void LoadFunction(FILE* D)
}
else /* fix PUSHFUNCTION */
{
CodeCode c;
Byte* p;
tf->marked=LoadWord(D);
tf->fileName=Main->fileName;
p=Main->code+tf->marked;
c.tf=tf;
*p++=c.m.c1; *p++=c.m.c2; *p++=c.m.c3; *p++=c.m.c4;
memcpy(Main->code+tf->marked,&tf,sizeof(tf));
lastF=lastF->next=tf;
}
tf->code=LoadBlock(tf->size,D);
@@ -256,8 +250,21 @@ static void LoadHeader(FILE* D) /* TODO: error handling */
{
Word w,tw=TEST_WORD;
float f,tf=TEST_FLOAT;
int version;
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 */
if (w!=tw)
{

View File

@@ -1,7 +1,7 @@
/*
** undump.h
** 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"
@@ -15,7 +15,7 @@
#define ID_VAR 'V'
#define ID_STR 'S'
#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_FLOAT 0.123456789e-23 /* a float for testing representation */