aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThe Lua team <lua@tecgraf.puc-rio.br>2003-10-09 23:44:30 -0300
committerThe Lua team <lua@tecgraf.puc-rio.br>2003-10-09 23:44:30 -0300
commitb9dde086db57ee6664ec1aedbec04c54857f9250 (patch)
treef2f23a63f14744c612f4cf2e52497352a3d8ef53
parentcd05d9c5cb69020c069f037ba7f243f705d0a48a (diff)
downloadlua-1.0.tar.gz
lua-1.0.tar.bz2
lua-1.0.zip
This is Lua 1.0. It was never publicly released. This code is a snapshot ofv1.0
the status of Lua on 28 Jul 1993. It is distributed for historical curiosity to celebrate 10 years of Lua and is hereby placed in the public domain. There is no documentation, except the test programs. The manual for Lua 1.1 probably works for this version as well. The source files for the lexer and parser have been lost: all that is left is the output of lex and yacc. A grammar can be found inside y_tab.c in yyreds. The code compiles and runs in RedHat 5.2 with gcc 2.7.2.3. It may not run in newer systems, because it assumes that stdin and stdout are constants, though ANSI C does not promise they are. If make fails, try using the fixed modules provided in the "fixed" directory. To see the differences (which are really quite minor), do "make diff". To see Lua 1.0 in action, do "make test". (The last test raises an error on purpose.) Enjoy! -- The Lua team, lua@tecgraf.puc-rio.br
-rw-r--r--Makefile29
-rw-r--r--README22
-rw-r--r--array.lua15
-rw-r--r--fixed/iolib.c402
-rw-r--r--fixed/lex_yy.c923
-rw-r--r--fixed/lua.c55
-rw-r--r--floatingpoint.h1
-rw-r--r--globals.lua5
-rw-r--r--save.lua47
-rw-r--r--sort.lua56
-rw-r--r--test.lua15
-rw-r--r--type.lua35
12 files changed, 1605 insertions, 0 deletions
diff --git a/Makefile b/Makefile
new file mode 100644
index 00000000..8ed18bb5
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,29 @@
1OBJS= hash.o inout.o lex_yy.o opcode.o table.o y_tab.o lua.o iolib.o mathlib.o strlib.o
2
3CFLAGS= -O2 -I.
4
5T= lua
6
7all: $T
8
9$T: $(OBJS)
10 $(CC) -o $@ $(OBJS) -lm
11
12A=--------------------------------------------------------------------------
13test: $T
14 @echo "$A"
15 ./$T sort.lua main
16 @echo "$A"
17 ./$T globals.lua | sort | column
18 @echo "$A"
19 ./$T array.lua
20 @echo "$A"
21 ./$T save.lua
22 @echo "$A"
23 ./$T test.lua retorno_multiplo norma
24
25clean:
26 rm -f $T $(OBJS) core core.*
27
28diff:
29 diff . fixed | grep -v ^Only
diff --git a/README b/README
new file mode 100644
index 00000000..29ad01d5
--- /dev/null
+++ b/README
@@ -0,0 +1,22 @@
1This is Lua 1.0. It was never publicly released. This code is a snapshot of
2the status of Lua on 28 Jul 1993. It is distributed for historical curiosity
3to celebrate 10 years of Lua and is hereby placed in the public domain.
4
5There is no documentation, except the test programs. The manual for Lua 1.1
6probably works for this version as well.
7
8The source files for the lexer and parser have been lost: all that is left is
9the output of lex and yacc. A grammar can be found inside y_tab.c in yyreds.
10
11The code compiles and runs in RedHat 5.2 with gcc 2.7.2.3. It may not run in
12newer systems, because it assumes that stdin and stdout are constants, though
13ANSI C does not promise they are. If make fails, try using the fixed modules
14provided in the "fixed" directory. To see the differences (which are really
15quite minor), do "make diff".
16
17To see Lua 1.0 in action, do "make test". (The last test raises an error on
18purpose.)
19
20Enjoy!
21
22-- The Lua team, lua@tecgraf.puc-rio.br
diff --git a/array.lua b/array.lua
new file mode 100644
index 00000000..349fb818
--- /dev/null
+++ b/array.lua
@@ -0,0 +1,15 @@
1$debug
2
3a = @()
4
5i=0
6while i<10 do
7 a[i] = i*i
8 i=i+1
9end
10
11r,v = next(a,nil)
12while r ~= nil do
13 print ("array["..r.."] = "..v)
14 r,v = next(a,r)
15end
diff --git a/fixed/iolib.c b/fixed/iolib.c
new file mode 100644
index 00000000..dce91f9d
--- /dev/null
+++ b/fixed/iolib.c
@@ -0,0 +1,402 @@
1/*
2** iolib.c
3** Input/output library to LUA
4**
5** Waldemar Celes Filho
6** TeCGraf - PUC-Rio
7** 19 May 93
8*/
9
10#include <stdlib.h>
11#include <string.h>
12#include <stdio.h>
13#include <ctype.h>
14#ifdef __GNUC__
15#include <floatingpoint.h>
16#endif
17
18#include "lua.h"
19
20static FILE *in=NULL, *out=NULL;
21
22/*
23** Open a file to read.
24** LUA interface:
25** status = readfrom (filename)
26** where:
27** status = 1 -> success
28** status = 0 -> error
29*/
30static void io_readfrom (void)
31{
32 lua_Object o = lua_getparam (1);
33 if (o == NULL) /* restore standart input */
34 {
35 if (in != stdin)
36 {
37 fclose (in);
38 in = stdin;
39 }
40 lua_pushnumber (1);
41 }
42 else
43 {
44 if (!lua_isstring (o))
45 {
46 lua_error ("incorrect argument to function 'readfrom`");
47 lua_pushnumber (0);
48 }
49 else
50 {
51 FILE *fp = fopen (lua_getstring(o),"r");
52 if (fp == NULL)
53 {
54 lua_pushnumber (0);
55 }
56 else
57 {
58 if (in != stdin) fclose (in);
59 in = fp;
60 lua_pushnumber (1);
61 }
62 }
63 }
64}
65
66
67/*
68** Open a file to write.
69** LUA interface:
70** status = writeto (filename)
71** where:
72** status = 1 -> success
73** status = 0 -> error
74*/
75static void io_writeto (void)
76{
77 lua_Object o = lua_getparam (1);
78 if (o == NULL) /* restore standart output */
79 {
80 if (out != stdout)
81 {
82 fclose (out);
83 out = stdout;
84 }
85 lua_pushnumber (1);
86 }
87 else
88 {
89 if (!lua_isstring (o))
90 {
91 lua_error ("incorrect argument to function 'writeto`");
92 lua_pushnumber (0);
93 }
94 else
95 {
96 FILE *fp = fopen (lua_getstring(o),"w");
97 if (fp == NULL)
98 {
99 lua_pushnumber (0);
100 }
101 else
102 {
103 if (out != stdout) fclose (out);
104 out = fp;
105 lua_pushnumber (1);
106 }
107 }
108 }
109}
110
111
112/*
113** Read a variable. On error put nil on stack.
114** LUA interface:
115** variable = read ([format])
116**
117** O formato pode ter um dos seguintes especificadores:
118**
119** s ou S -> para string
120** f ou F, g ou G, e ou E -> para reais
121** i ou I -> para inteiros
122**
123** Estes especificadores podem vir seguidos de numero que representa
124** o numero de campos a serem lidos.
125*/
126static void io_read (void)
127{
128 lua_Object o = lua_getparam (1);
129 if (o == NULL) /* free format */
130 {
131 int c;
132 char s[256];
133 while (isspace(c=fgetc(in)))
134 ;
135 if (c == '\"')
136 {
137 if (fscanf (in, "%[^\"]\"", s) != 1)
138 {
139 lua_pushnil ();
140 return;
141 }
142 }
143 else if (c == '\'')
144 {
145 if (fscanf (in, "%[^\']\'", s) != 1)
146 {
147 lua_pushnil ();
148 return;
149 }
150 }
151 else
152 {
153 char *ptr;
154 double d;
155 ungetc (c, in);
156 if (fscanf (in, "%s", s) != 1)
157 {
158 lua_pushnil ();
159 return;
160 }
161 d = strtod (s, &ptr);
162 if (!(*ptr))
163 {
164 lua_pushnumber (d);
165 return;
166 }
167 }
168 lua_pushstring (s);
169 return;
170 }
171 else /* formatted */
172 {
173 char *e = lua_getstring(o);
174 char t;
175 int m=0;
176 while (isspace(*e)) e++;
177 t = *e++;
178 while (isdigit(*e))
179 m = m*10 + (*e++ - '0');
180
181 if (m > 0)
182 {
183 char f[80];
184 char s[256];
185 sprintf (f, "%%%ds", m);
186 fscanf (in, f, s);
187 switch (tolower(t))
188 {
189 case 'i':
190 {
191 long int l;
192 sscanf (s, "%ld", &l);
193 lua_pushnumber(l);
194 }
195 break;
196 case 'f': case 'g': case 'e':
197 {
198 float f;
199 sscanf (s, "%f", &f);
200 lua_pushnumber(f);
201 }
202 break;
203 default:
204 lua_pushstring(s);
205 break;
206 }
207 }
208 else
209 {
210 switch (tolower(t))
211 {
212 case 'i':
213 {
214 long int l;
215 fscanf (in, "%ld", &l);
216 lua_pushnumber(l);
217 }
218 break;
219 case 'f': case 'g': case 'e':
220 {
221 float f;
222 fscanf (in, "%f", &f);
223 lua_pushnumber(f);
224 }
225 break;
226 default:
227 {
228 char s[256];
229 fscanf (in, "%s", s);
230 lua_pushstring(s);
231 }
232 break;
233 }
234 }
235 }
236}
237
238
239/*
240** Write a variable. On error put 0 on stack, otherwise put 1.
241** LUA interface:
242** status = write (variable [,format])
243**
244** O formato pode ter um dos seguintes especificadores:
245**
246** s ou S -> para string
247** f ou F, g ou G, e ou E -> para reais
248** i ou I -> para inteiros
249**
250** Estes especificadores podem vir seguidos de:
251**
252** [?][m][.n]
253**
254** onde:
255** ? -> indica justificacao
256** < = esquerda
257** | = centro
258** > = direita (default)
259** m -> numero maximo de campos (se exceder estoura)
260** n -> indica precisao para
261** reais -> numero de casas decimais
262** inteiros -> numero minimo de digitos
263** string -> nao se aplica
264*/
265static char *buildformat (char *e, lua_Object o)
266{
267 static char buffer[512];
268 static char f[80];
269 char *string = &buffer[255];
270 char t, j='r';
271 int m=0, n=0, l;
272 while (isspace(*e)) e++;
273 t = *e++;
274 if (*e == '<' || *e == '|' || *e == '>') j = *e++;
275 while (isdigit(*e))
276 m = m*10 + (*e++ - '0');
277 e++; /* skip point */
278 while (isdigit(*e))
279 n = n*10 + (*e++ - '0');
280
281 sprintf(f,"%%");
282 if (j == '<' || j == '|') sprintf(strchr(f,0),"-");
283 if (m != 0) sprintf(strchr(f,0),"%d", m);
284 if (n != 0) sprintf(strchr(f,0),".%d", n);
285 sprintf(strchr(f,0), "%c", t);
286 switch (tolower(t))
287 {
288 case 'i': t = 'i';
289 sprintf (string, f, (long int)lua_getnumber(o));
290 break;
291 case 'f': case 'g': case 'e': t = 'f';
292 sprintf (string, f, (float)lua_getnumber(o));
293 break;
294 case 's': t = 's';
295 sprintf (string, f, lua_getstring(o));
296 break;
297 default: return "";
298 }
299 l = strlen(string);
300 if (m!=0 && l>m)
301 {
302 int i;
303 for (i=0; i<m; i++)
304 string[i] = '*';
305 string[i] = 0;
306 }
307 else if (m!=0 && j=='|')
308 {
309 int i=l-1;
310 while (isspace(string[i])) i--;
311 string -= (m-i) / 2;
312 i=0;
313 while (string[i]==0) string[i++] = ' ';
314 string[l] = 0;
315 }
316 return string;
317}
318static void io_write (void)
319{
320 lua_Object o1 = lua_getparam (1);
321 lua_Object o2 = lua_getparam (2);
322 if (o1 == NULL) /* new line */
323 {
324 fprintf (out, "\n");
325 lua_pushnumber(1);
326 }
327 else if (o2 == NULL) /* free format */
328 {
329 int status=0;
330 if (lua_isnumber(o1))
331 status = fprintf (out, "%g", lua_getnumber(o1));
332 else if (lua_isstring(o1))
333 status = fprintf (out, "%s", lua_getstring(o1));
334 lua_pushnumber(status);
335 }
336 else /* formated */
337 {
338 if (!lua_isstring(o2))
339 {
340 lua_error ("incorrect format to function `write'");
341 lua_pushnumber(0);
342 return;
343 }
344 lua_pushnumber(fprintf (out, "%s", buildformat(lua_getstring(o2),o1)));
345 }
346}
347
348/*
349** Execute a executable program using "sustem".
350** On error put 0 on stack, otherwise put 1.
351*/
352void io_execute (void)
353{
354 lua_Object o = lua_getparam (1);
355 if (o == NULL || !lua_isstring (o))
356 {
357 lua_error ("incorrect argument to function 'execute`");
358 lua_pushnumber (0);
359 }
360 else
361 {
362 system(lua_getstring(o));
363 lua_pushnumber (1);
364 }
365 return;
366}
367
368/*
369** Remove a file.
370** On error put 0 on stack, otherwise put 1.
371*/
372void io_remove (void)
373{
374 lua_Object o = lua_getparam (1);
375 if (o == NULL || !lua_isstring (o))
376 {
377 lua_error ("incorrect argument to function 'execute`");
378 lua_pushnumber (0);
379 }
380 else
381 {
382 if (remove(lua_getstring(o)) == 0)
383 lua_pushnumber (1);
384 else
385 lua_pushnumber (0);
386 }
387 return;
388}
389
390/*
391** Open io library
392*/
393void iolib_open (void)
394{
395 in=stdin; out=stdout;
396 lua_register ("readfrom", io_readfrom);
397 lua_register ("writeto", io_writeto);
398 lua_register ("read", io_read);
399 lua_register ("write", io_write);
400 lua_register ("execute", io_execute);
401 lua_register ("remove", io_remove);
402}
diff --git a/fixed/lex_yy.c b/fixed/lex_yy.c
new file mode 100644
index 00000000..ab73ea6c
--- /dev/null
+++ b/fixed/lex_yy.c
@@ -0,0 +1,923 @@
1# include "stdio.h"
2# define U(x) x
3# define NLSTATE yyprevious=YYNEWLINE
4# define BEGIN yybgin = yysvec + 1 +
5# define INITIAL 0
6# define YYLERR yysvec
7# define YYSTATE (yyestate-yysvec-1)
8# define YYOPTIM 1
9# define YYLMAX BUFSIZ
10# define output(c) putc(c,yyout)
11# define input() (((yytchar=yysptr>yysbuf?U(*--yysptr):getc(yyin))==10?(yylineno++,yytchar):yytchar)==EOF?0:yytchar)
12# define unput(c) {yytchar= (c);if(yytchar=='\n')yylineno--;*yysptr++=yytchar;}
13# define yymore() (yymorfg=1)
14# define ECHO fprintf(yyout, "%s",yytext)
15# define REJECT { nstr = yyreject(); goto yyfussy;}
16int yyleng; extern char yytext[];
17int yymorfg;
18extern char *yysptr, yysbuf[];
19int yytchar;
20FILE *yyin = {NULL}, *yyout = {NULL};
21extern int yylineno;
22struct yysvf {
23 struct yywork *yystoff;
24 struct yysvf *yyother;
25 int *yystops;};
26struct yysvf *yyestate;
27extern struct yysvf yysvec[], *yybgin;
28#include <stdlib.h>
29#include <string.h>
30
31#include "opcode.h"
32#include "hash.h"
33#include "inout.h"
34#include "table.h"
35#include "y_tab.h"
36
37#undef input
38#undef unput
39
40static Input input;
41static Unput unput;
42
43void lua_setinput (Input fn)
44{
45 input = fn;
46}
47
48void lua_setunput (Unput fn)
49{
50 unput = fn;
51}
52
53char *lua_lasttext (void)
54{
55 return yytext;
56}
57
58# define YYNEWLINE 10
59yylex(){
60int nstr; extern int yyprevious;
61while((nstr = yylook()) >= 0)
62yyfussy: switch(nstr){
63case 0:
64if(yywrap()) return(0); break;
65case 1:
66 ;
67break;
68case 2:
69 {yylval.vInt = 1; return DEBUG;}
70break;
71case 3:
72 {yylval.vInt = 0; return DEBUG;}
73break;
74case 4:
75 lua_linenumber++;
76break;
77case 5:
78 ;
79break;
80case 6:
81 return LOCAL;
82break;
83case 7:
84 return IF;
85break;
86case 8:
87 return THEN;
88break;
89case 9:
90 return ELSE;
91break;
92case 10:
93 return ELSEIF;
94break;
95case 11:
96 return WHILE;
97break;
98case 12:
99 return DO;
100break;
101case 13:
102 return REPEAT;
103break;
104case 14:
105 return UNTIL;
106break;
107case 15:
108 {
109 yylval.vWord = lua_nfile-1;
110 return FUNCTION;
111 }
112break;
113case 16:
114 return END;
115break;
116case 17:
117 return RETURN;
118break;
119case 18:
120 return LOCAL;
121break;
122case 19:
123 return NIL;
124break;
125case 20:
126 return AND;
127break;
128case 21:
129 return OR;
130break;
131case 22:
132 return NOT;
133break;
134case 23:
135 return NE;
136break;
137case 24:
138 return LE;
139break;
140case 25:
141 return GE;
142break;
143case 26:
144 return CONC;
145break;
146case 27:
147 case 28:
148 {
149 yylval.vWord = lua_findenclosedconstant (yytext);
150 return STRING;
151 }
152break;
153case 29:
154case 30:
155case 31:
156case 32:
157{
158 yylval.vFloat = atof(yytext);
159 return NUMBER;
160 }
161break;
162case 33:
163 {
164 yylval.vWord = lua_findsymbol (yytext);
165 return NAME;
166 }
167break;
168case 34:
169 return *yytext;
170break;
171case -1:
172break;
173default:
174fprintf(yyout,"bad switch yylook %d",nstr);
175} return(0); }
176/* end of yylex */
177int yyvstop[] = {
1780,
179
1801,
1810,
182
1831,
1840,
185
18634,
1870,
188
1891,
19034,
1910,
192
1934,
1940,
195
19634,
1970,
198
19934,
2000,
201
20234,
2030,
204
20534,
2060,
207
20829,
20934,
2100,
211
21234,
2130,
214
21534,
2160,
217
21833,
21934,
2200,
221
22233,
22334,
2240,
225
22633,
22734,
2280,
229
23033,
23134,
2320,
233
23433,
23534,
2360,
237
23833,
23934,
2400,
241
24233,
24334,
2440,
245
24633,
24734,
2480,
249
25033,
25134,
2520,
253
25433,
25534,
2560,
257
25833,
25934,
2600,
261
26233,
26334,
2640,
265
26633,
26734,
2680,
269
27034,
2710,
272
27334,
2740,
275
2761,
2770,
278
27927,
2800,
281
28228,
2830,
284
2855,
2860,
287
28826,
2890,
290
29130,
2920,
293
29429,
2950,
296
29729,
2980,
299
30024,
3010,
302
30325,
3040,
305
30633,
3070,
308
30933,
3100,
311
31212,
31333,
3140,
315
31633,
3170,
318
31933,
3200,
321
32233,
3230,
324
3257,
32633,
3270,
328
32933,
3300,
331
33233,
3330,
334
33533,
3360,
337
33821,
33933,
3400,
341
34233,
3430,
344
34533,
3460,
347
34833,
3490,
350
35133,
3520,
353
35423,
3550,
356
35729,
35830,
3590,
360
36131,
3620,
363
36420,
36533,
3660,
367
36833,
3690,
370
37116,
37233,
3730,
374
37533,
3760,
377
37833,
3790,
380
38119,
38233,
3830,
384
38522,
38633,
3870,
388
38933,
3900,
391
39233,
3930,
394
39533,
3960,
397
39833,
3990,
400
40133,
4020,
403
40432,
4050,
406
4079,
40833,
4090,
410
41133,
4120,
413
41433,
4150,
416
41733,
4180,
419
42033,
4210,
422
4238,
42433,
4250,
426
42733,
4280,
429
43033,
4310,
432
43331,
43432,
4350,
436
43733,
4380,
439
44033,
4410,
442
4436,
44418,
44533,
4460,
447
44833,
4490,
450
45133,
4520,
453
45414,
45533,
4560,
457
45811,
45933,
4600,
461
46210,
46333,
4640,
465
46633,
4670,
468
46913,
47033,
4710,
472
47317,
47433,
4750,
476
4772,
4780,
479
48033,
4810,
482
48315,
48433,
4850,
486
4873,
4880,
4890};
490# define YYTYPE char
491struct yywork { YYTYPE verify, advance; } yycrank[] = {
4920,0, 0,0, 1,3, 0,0,
4930,0, 0,0, 0,0, 0,0,
4940,0, 0,0, 1,4, 1,5,
4956,29, 4,28, 0,0, 0,0,
4960,0, 0,0, 7,31, 0,0,
4976,29, 6,29, 0,0, 0,0,
4980,0, 0,0, 7,31, 7,31,
4990,0, 0,0, 0,0, 0,0,
5000,0, 0,0, 0,0, 1,6,
5014,28, 0,0, 0,0, 0,0,
5021,7, 0,0, 0,0, 0,0,
5031,3, 6,30, 1,8, 1,9,
5040,0, 1,10, 6,29, 7,31,
5058,33, 0,0, 6,29, 0,0,
5067,32, 0,0, 0,0, 6,29,
5077,31, 1,11, 0,0, 1,12,
5082,27, 7,31, 1,13, 11,39,
50912,40, 1,13, 26,56, 0,0,
5100,0, 2,8, 2,9, 0,0,
5116,29, 0,0, 0,0, 6,29,
5120,0, 0,0, 7,31, 0,0,
5130,0, 7,31, 0,0, 0,0,
5142,11, 0,0, 2,12, 0,0,
5150,0, 0,0, 0,0, 0,0,
5160,0, 0,0, 1,14, 0,0,
5170,0, 1,15, 1,16, 1,17,
5180,0, 22,52, 1,18, 18,47,
51923,53, 1,19, 42,63, 1,20,
5201,21, 25,55, 14,42, 1,22,
52115,43, 1,23, 1,24, 16,44,
5221,25, 16,45, 17,46, 19,48,
52321,51, 2,14, 20,49, 1,26,
5242,15, 2,16, 2,17, 24,54,
52520,50, 2,18, 44,64, 45,65,
5262,19, 46,66, 2,20, 2,21,
52727,57, 48,67, 2,22, 49,68,
5282,23, 2,24, 50,69, 2,25,
52952,70, 53,72, 27,58, 54,73,
53052,71, 9,34, 2,26, 9,35,
5319,35, 9,35, 9,35, 9,35,
5329,35, 9,35, 9,35, 9,35,
5339,35, 10,36, 55,74, 10,37,
53410,37, 10,37, 10,37, 10,37,
53510,37, 10,37, 10,37, 10,37,
53610,37, 57,75, 58,76, 64,80,
53766,81, 67,82, 70,83, 71,84,
53872,85, 73,86, 74,87, 10,38,
53910,38, 38,61, 10,38, 38,61,
54075,88, 76,89, 38,62, 38,62,
54138,62, 38,62, 38,62, 38,62,
54238,62, 38,62, 38,62, 38,62,
54380,92, 81,93, 13,41, 13,41,
54413,41, 13,41, 13,41, 13,41,
54513,41, 13,41, 13,41, 13,41,
54682,94, 83,95, 84,96, 10,38,
54710,38, 86,97, 10,38, 13,41,
54813,41, 13,41, 13,41, 13,41,
54913,41, 13,41, 13,41, 13,41,
55013,41, 13,41, 13,41, 13,41,
55113,41, 13,41, 13,41, 13,41,
55213,41, 13,41, 13,41, 13,41,
55313,41, 13,41, 13,41, 13,41,
55413,41, 87,98, 88,99, 60,79,
55560,79, 13,41, 60,79, 13,41,
55613,41, 13,41, 13,41, 13,41,
55713,41, 13,41, 13,41, 13,41,
55813,41, 13,41, 13,41, 13,41,
55913,41, 13,41, 13,41, 13,41,
56013,41, 13,41, 13,41, 13,41,
56113,41, 13,41, 13,41, 13,41,
56213,41, 33,33, 89,100, 60,79,
56360,79, 92,101, 60,79, 93,102,
56495,103, 33,33, 33,0, 96,104,
56599,105, 100,106, 102,107, 106,108,
566107,109, 35,35, 35,35, 35,35,
56735,35, 35,35, 35,35, 35,35,
56835,35, 35,35, 35,35, 108,110,
5690,0, 0,0, 0,0, 0,0,
5700,0, 0,0, 33,33, 0,0,
5710,0, 35,59, 35,59, 33,33,
57235,59, 0,0, 0,0, 33,33,
5730,0, 0,0, 0,0, 0,0,
57433,33, 0,0, 0,0, 0,0,
5750,0, 36,60, 36,60, 36,60,
57636,60, 36,60, 36,60, 36,60,
57736,60, 36,60, 36,60, 0,0,
5780,0, 33,33, 0,0, 0,0,
57933,33, 35,59, 35,59, 0,0,
58035,59, 36,38, 36,38, 59,77,
58136,38, 59,77, 0,0, 0,0,
58259,78, 59,78, 59,78, 59,78,
58359,78, 59,78, 59,78, 59,78,
58459,78, 59,78, 61,62, 61,62,
58561,62, 61,62, 61,62, 61,62,
58661,62, 61,62, 61,62, 61,62,
5870,0, 0,0, 0,0, 0,0,
5880,0, 36,38, 36,38, 0,0,
58936,38, 77,78, 77,78, 77,78,
59077,78, 77,78, 77,78, 77,78,
59177,78, 77,78, 77,78, 79,90,
5920,0, 79,90, 0,0, 0,0,
59379,91, 79,91, 79,91, 79,91,
59479,91, 79,91, 79,91, 79,91,
59579,91, 79,91, 90,91, 90,91,
59690,91, 90,91, 90,91, 90,91,
59790,91, 90,91, 90,91, 90,91,
5980,0};
599struct yysvf yysvec[] = {
6000, 0, 0,
601yycrank+-1, 0, yyvstop+1,
602yycrank+-28, yysvec+1, yyvstop+3,
603yycrank+0, 0, yyvstop+5,
604yycrank+4, 0, yyvstop+7,
605yycrank+0, 0, yyvstop+10,
606yycrank+-11, 0, yyvstop+12,
607yycrank+-17, 0, yyvstop+14,
608yycrank+7, 0, yyvstop+16,
609yycrank+107, 0, yyvstop+18,
610yycrank+119, 0, yyvstop+20,
611yycrank+6, 0, yyvstop+23,
612yycrank+7, 0, yyvstop+25,
613yycrank+158, 0, yyvstop+27,
614yycrank+4, yysvec+13, yyvstop+30,
615yycrank+5, yysvec+13, yyvstop+33,
616yycrank+11, yysvec+13, yyvstop+36,
617yycrank+5, yysvec+13, yyvstop+39,
618yycrank+5, yysvec+13, yyvstop+42,
619yycrank+12, yysvec+13, yyvstop+45,
620yycrank+21, yysvec+13, yyvstop+48,
621yycrank+10, yysvec+13, yyvstop+51,
622yycrank+4, yysvec+13, yyvstop+54,
623yycrank+4, yysvec+13, yyvstop+57,
624yycrank+21, yysvec+13, yyvstop+60,
625yycrank+9, yysvec+13, yyvstop+63,
626yycrank+9, 0, yyvstop+66,
627yycrank+40, 0, yyvstop+68,
628yycrank+0, yysvec+4, yyvstop+70,
629yycrank+0, yysvec+6, 0,
630yycrank+0, 0, yyvstop+72,
631yycrank+0, yysvec+7, 0,
632yycrank+0, 0, yyvstop+74,
633yycrank+-280, 0, yyvstop+76,
634yycrank+0, 0, yyvstop+78,
635yycrank+249, 0, yyvstop+80,
636yycrank+285, 0, yyvstop+82,
637yycrank+0, yysvec+10, yyvstop+84,
638yycrank+146, 0, 0,
639yycrank+0, 0, yyvstop+86,
640yycrank+0, 0, yyvstop+88,
641yycrank+0, yysvec+13, yyvstop+90,
642yycrank+10, yysvec+13, yyvstop+92,
643yycrank+0, yysvec+13, yyvstop+94,
644yycrank+19, yysvec+13, yyvstop+97,
645yycrank+35, yysvec+13, yyvstop+99,
646yycrank+27, yysvec+13, yyvstop+101,
647yycrank+0, yysvec+13, yyvstop+103,
648yycrank+42, yysvec+13, yyvstop+106,
649yycrank+35, yysvec+13, yyvstop+108,
650yycrank+30, yysvec+13, yyvstop+110,
651yycrank+0, yysvec+13, yyvstop+112,
652yycrank+36, yysvec+13, yyvstop+115,
653yycrank+48, yysvec+13, yyvstop+117,
654yycrank+35, yysvec+13, yyvstop+119,
655yycrank+61, yysvec+13, yyvstop+121,
656yycrank+0, 0, yyvstop+123,
657yycrank+76, 0, 0,
658yycrank+67, 0, 0,
659yycrank+312, 0, 0,
660yycrank+183, yysvec+36, yyvstop+125,
661yycrank+322, 0, 0,
662yycrank+0, yysvec+61, yyvstop+128,
663yycrank+0, yysvec+13, yyvstop+130,
664yycrank+78, yysvec+13, yyvstop+133,
665yycrank+0, yysvec+13, yyvstop+135,
666yycrank+81, yysvec+13, yyvstop+138,
667yycrank+84, yysvec+13, yyvstop+140,
668yycrank+0, yysvec+13, yyvstop+142,
669yycrank+0, yysvec+13, yyvstop+145,
670yycrank+81, yysvec+13, yyvstop+148,
671yycrank+66, yysvec+13, yyvstop+150,
672yycrank+74, yysvec+13, yyvstop+152,
673yycrank+80, yysvec+13, yyvstop+154,
674yycrank+78, yysvec+13, yyvstop+156,
675yycrank+94, 0, 0,
676yycrank+93, 0, 0,
677yycrank+341, 0, 0,
678yycrank+0, yysvec+77, yyvstop+158,
679yycrank+356, 0, 0,
680yycrank+99, yysvec+13, yyvstop+160,
681yycrank+89, yysvec+13, yyvstop+163,
682yycrank+108, yysvec+13, yyvstop+165,
683yycrank+120, yysvec+13, yyvstop+167,
684yycrank+104, yysvec+13, yyvstop+169,
685yycrank+0, yysvec+13, yyvstop+171,
686yycrank+113, yysvec+13, yyvstop+174,
687yycrank+148, yysvec+13, yyvstop+176,
688yycrank+133, 0, 0,
689yycrank+181, 0, 0,
690yycrank+366, 0, 0,
691yycrank+0, yysvec+90, yyvstop+178,
692yycrank+183, yysvec+13, yyvstop+181,
693yycrank+182, yysvec+13, yyvstop+183,
694yycrank+0, yysvec+13, yyvstop+185,
695yycrank+172, yysvec+13, yyvstop+189,
696yycrank+181, yysvec+13, yyvstop+191,
697yycrank+0, yysvec+13, yyvstop+193,
698yycrank+0, yysvec+13, yyvstop+196,
699yycrank+189, 0, 0,
700yycrank+195, 0, 0,
701yycrank+0, yysvec+13, yyvstop+199,
702yycrank+183, yysvec+13, yyvstop+202,
703yycrank+0, yysvec+13, yyvstop+204,
704yycrank+0, yysvec+13, yyvstop+207,
705yycrank+0, 0, yyvstop+210,
706yycrank+178, 0, 0,
707yycrank+186, yysvec+13, yyvstop+212,
708yycrank+204, 0, 0,
709yycrank+0, yysvec+13, yyvstop+214,
710yycrank+0, 0, yyvstop+217,
7110, 0, 0};
712struct yywork *yytop = yycrank+423;
713struct yysvf *yybgin = yysvec+1;
714char yymatch[] = {
71500 ,01 ,01 ,01 ,01 ,01 ,01 ,01 ,
71601 ,011 ,012 ,01 ,01 ,01 ,01 ,01 ,
71701 ,01 ,01 ,01 ,01 ,01 ,01 ,01 ,
71801 ,01 ,01 ,01 ,01 ,01 ,01 ,01 ,
719011 ,01 ,'"' ,01 ,01 ,01 ,01 ,047 ,
72001 ,01 ,01 ,'+' ,01 ,'+' ,01 ,01 ,
721'0' ,'0' ,'0' ,'0' ,'0' ,'0' ,'0' ,'0' ,
722'0' ,'0' ,01 ,01 ,01 ,01 ,01 ,01 ,
72301 ,'A' ,'A' ,'A' ,'D' ,'D' ,'A' ,'D' ,
724'A' ,'A' ,'A' ,'A' ,'A' ,'A' ,'A' ,'A' ,
725'A' ,'A' ,'A' ,'A' ,'A' ,'A' ,'A' ,'A' ,
726'A' ,'A' ,'A' ,01 ,01 ,01 ,01 ,'A' ,
72701 ,'A' ,'A' ,'A' ,'D' ,'D' ,'A' ,'D' ,
728'A' ,'A' ,'A' ,'A' ,'A' ,'A' ,'A' ,'A' ,
729'A' ,'A' ,'A' ,'A' ,'A' ,'A' ,'A' ,'A' ,
730'A' ,'A' ,'A' ,01 ,01 ,01 ,01 ,01 ,
7310};
732char yyextra[] = {
7330,0,0,0,0,0,0,0,
7340,0,0,0,0,0,0,0,
7350,0,0,0,0,0,0,0,
7360,0,0,0,0,0,0,0,
7370,0,0,0,0,0,0,0,
7380};
739#ifndef lint
740static char ncform_sccsid[] = "@(#)ncform 1.6 88/02/08 SMI"; /* from S5R2 1.2 */
741#endif
742
743int yylineno =1;
744# define YYU(x) x
745# define NLSTATE yyprevious=YYNEWLINE
746char yytext[YYLMAX];
747struct yysvf *yylstate [YYLMAX], **yylsp, **yyolsp;
748char yysbuf[YYLMAX];
749char *yysptr = yysbuf;
750int *yyfnd;
751extern struct yysvf *yyestate;
752int yyprevious = YYNEWLINE;
753yylook(){
754 register struct yysvf *yystate, **lsp;
755 register struct yywork *yyt;
756 struct yysvf *yyz;
757 int yych, yyfirst;
758 struct yywork *yyr;
759# ifdef LEXDEBUG
760 int debug;
761# endif
762 char *yylastch;
763 /* start off machines */
764# ifdef LEXDEBUG
765 debug = 0;
766# endif
767 yyfirst=1;
768 if (!yymorfg)
769 yylastch = yytext;
770 else {
771 yymorfg=0;
772 yylastch = yytext+yyleng;
773 }
774 for(;;){
775 lsp = yylstate;
776 yyestate = yystate = yybgin;
777 if (yyprevious==YYNEWLINE) yystate++;
778 for (;;){
779# ifdef LEXDEBUG
780 if(debug)fprintf(yyout,"state %d\n",yystate-yysvec-1);
781# endif
782 yyt = yystate->yystoff;
783 if(yyt == yycrank && !yyfirst){ /* may not be any transitions */
784 yyz = yystate->yyother;
785 if(yyz == 0)break;
786 if(yyz->yystoff == yycrank)break;
787 }
788 *yylastch++ = yych = input();
789 yyfirst=0;
790 tryagain:
791# ifdef LEXDEBUG
792 if(debug){
793 fprintf(yyout,"char ");
794 allprint(yych);
795 putchar('\n');
796 }
797# endif
798 yyr = yyt;
799 if ( (int)yyt > (int)yycrank){
800 yyt = yyr + yych;
801 if (yyt <= yytop && yyt->verify+yysvec == yystate){
802 if(yyt->advance+yysvec == YYLERR) /* error transitions */
803 {unput(*--yylastch);break;}
804 *lsp++ = yystate = yyt->advance+yysvec;
805 goto contin;
806 }
807 }
808# ifdef YYOPTIM
809 else if((int)yyt < (int)yycrank) { /* r < yycrank */
810 yyt = yyr = yycrank+(yycrank-yyt);
811# ifdef LEXDEBUG
812 if(debug)fprintf(yyout,"compressed state\n");
813# endif
814 yyt = yyt + yych;
815 if(yyt <= yytop && yyt->verify+yysvec == yystate){
816 if(yyt->advance+yysvec == YYLERR) /* error transitions */
817 {unput(*--yylastch);break;}
818 *lsp++ = yystate = yyt->advance+yysvec;
819 goto contin;
820 }
821 yyt = yyr + YYU(yymatch[yych]);
822# ifdef LEXDEBUG
823 if(debug){
824 fprintf(yyout,"try fall back character ");
825 allprint(YYU(yymatch[yych]));
826 putchar('\n');
827 }
828# endif
829 if(yyt <= yytop && yyt->verify+yysvec == yystate){
830 if(yyt->advance+yysvec == YYLERR) /* error transition */
831 {unput(*--yylastch);break;}
832 *lsp++ = yystate = yyt->advance+yysvec;
833 goto contin;
834 }
835 }
836 if ((yystate = yystate->yyother) && (yyt= yystate->yystoff) != yycrank){
837# ifdef LEXDEBUG
838 if(debug)fprintf(yyout,"fall back to state %d\n",yystate-yysvec-1);
839# endif
840 goto tryagain;
841 }
842# endif
843 else
844 {unput(*--yylastch);break;}
845 contin:
846# ifdef LEXDEBUG
847 if(debug){
848 fprintf(yyout,"state %d char ",yystate-yysvec-1);
849 allprint(yych);
850 putchar('\n');
851 }
852# endif
853 ;
854 }
855# ifdef LEXDEBUG
856 if(debug){
857 fprintf(yyout,"stopped at %d with ",*(lsp-1)-yysvec-1);
858 allprint(yych);
859 putchar('\n');
860 }
861# endif
862 while (lsp-- > yylstate){
863 *yylastch-- = 0;
864 if (*lsp != 0 && (yyfnd= (*lsp)->yystops) && *yyfnd > 0){
865 yyolsp = lsp;
866 if(yyextra[*yyfnd]){ /* must backup */
867 while(yyback((*lsp)->yystops,-*yyfnd) != 1 && lsp > yylstate){
868 lsp--;
869 unput(*yylastch--);
870 }
871 }
872 yyprevious = YYU(*yylastch);
873 yylsp = lsp;
874 yyleng = yylastch-yytext+1;
875 yytext[yyleng] = 0;
876# ifdef LEXDEBUG
877 if(debug){
878 fprintf(yyout,"\nmatch ");
879 sprint(yytext);
880 fprintf(yyout," action %d\n",*yyfnd);
881 }
882# endif
883 return(*yyfnd++);
884 }
885 unput(*yylastch);
886 }
887 if (yytext[0] == 0 /* && feof(yyin) */)
888 {
889 yysptr=yysbuf;
890 return(0);
891 }
892 yyprevious = yytext[0] = input();
893 if (yyprevious>0)
894 output(yyprevious);
895 yylastch=yytext;
896# ifdef LEXDEBUG
897 if(debug)putchar('\n');
898# endif
899 }
900 }
901yyback(p, m)
902 int *p;
903{
904if (p==0) return(0);
905while (*p)
906 {
907 if (*p++ == m)
908 return(1);
909 }
910return(0);
911}
912 /* the following are only used in the lex library */
913yyinput(){
914 return(input());
915 }
916yyoutput(c)
917 int c; {
918 output(c);
919 }
920yyunput(c)
921 int c; {
922 unput(c);
923 }
diff --git a/fixed/lua.c b/fixed/lua.c
new file mode 100644
index 00000000..f2cfc0b6
--- /dev/null
+++ b/fixed/lua.c
@@ -0,0 +1,55 @@
1/*
2** lua.c
3** Linguagem para Usuarios de Aplicacao
4** TeCGraf - PUC-Rio
5** 28 Apr 93
6*/
7
8#include <stdio.h>
9
10#include "lua.h"
11#include "lualib.h"
12
13
14void test (void)
15{
16 lua_pushobject(lua_getparam(1));
17 lua_call ("c", 1);
18}
19
20
21static void callfunc (void)
22{
23 lua_Object obj = lua_getparam (1);
24 if (lua_isstring(obj)) lua_call(lua_getstring(obj),0);
25}
26
27static void execstr (void)
28{
29 lua_Object obj = lua_getparam (1);
30 if (lua_isstring(obj)) lua_dostring(lua_getstring(obj));
31}
32
33int main (int argc, char *argv[])
34{
35 int i;
36 if (argc < 2)
37 {
38 puts ("usage: lua filename [functionnames]");
39 return;
40 }
41 lua_register ("callfunc", callfunc);
42 lua_register ("execstr", execstr);
43 lua_register ("test", test);
44 iolib_open ();
45 strlib_open ();
46 mathlib_open ();
47 lua_dofile (argv[1]);
48 for (i=2; i<argc; i++)
49 {
50 lua_call (argv[i],0);
51 }
52 return 0;
53}
54
55
diff --git a/floatingpoint.h b/floatingpoint.h
new file mode 100644
index 00000000..347d2047
--- /dev/null
+++ b/floatingpoint.h
@@ -0,0 +1 @@
/* empty file to please silly code in iolib.c and opcode.c */
diff --git a/globals.lua b/globals.lua
new file mode 100644
index 00000000..f204a9d5
--- /dev/null
+++ b/globals.lua
@@ -0,0 +1,5 @@
1k,v=nextvar(k)
2while k do
3 print(k)
4 k,v=nextvar(k)
5end
diff --git a/save.lua b/save.lua
new file mode 100644
index 00000000..1a4ba04d
--- /dev/null
+++ b/save.lua
@@ -0,0 +1,47 @@
1$debug
2
3
4function savevar (n,v)
5 if v = nil then return end;
6 if type(v) = "number" then print(n.."="..v) return end
7 if type(v) = "string" then print(n.."='"..v.."'") return end
8 if type(v) = "table" then
9 if v.__visited__ ~= nil then
10 print(n .. "=" .. v.__visited__);
11 else
12 print(n.."=@()")
13 v.__visited__ = n;
14 local r,f;
15 r,f = next(v,nil);
16 while r ~= nil do
17 if r ~= "__visited__" then
18 if type(r) = 'string' then
19 savevar(n.."['"..r.."']",f)
20 else
21 savevar(n.."["..r.."]",f)
22 end
23 end
24 r,f = next(v,r)
25 end
26 end
27 end
28end
29
30function save ()
31local n,v
32 n,v = nextvar(nil)
33 while n ~= nil do
34 savevar(n,v);
35 n,v = nextvar(n)
36 end
37end
38
39a = 3
40x = @{a = 4, b = "name", l=@[4,5,67]}
41
42b = @{t=5}
43x.next = b
44
45
46save()
47
diff --git a/sort.lua b/sort.lua
new file mode 100644
index 00000000..f749c122
--- /dev/null
+++ b/sort.lua
@@ -0,0 +1,56 @@
1$debug
2
3function quicksort(r,s)
4 if s<=r then return end -- caso basico da recursao
5 local v=x[r]
6 local i=r
7 local j=s+1
8 i=i+1; while x[i]<v do i=i+1 end
9 j=j-1; while x[j]>v do j=j-1 end
10 x[i],x[j]=x[j],x[i]
11 while j>i do -- separacao
12 i=i+1; while x[i]<v do i=i+1 end
13 j=j-1; while x[j]>v do j=j-1 end
14 x[i],x[j]=x[j],x[i]
15 end
16 x[i],x[j]=x[j],x[i] -- undo last swap
17 x[j],x[r]=x[r],x[j]
18 quicksort(r,j-1) -- recursao
19 quicksort(j+1,s)
20end
21
22function sort(a,n) -- selection sort
23 local i=1
24 while i<=n do
25 local m=i
26 local j=i+1
27 while j<=n do
28 if a[j]<a[m] then m=j end
29 j=j+1
30 end
31 a[i],a[m]=a[m],a[i] -- swap a[i] and a[m]
32 i=i+1
33 end
34end
35
36function main()
37 x=@()
38 n=-1
39 n=n+1; x[n]="a"
40 n=n+1; x[n]="waldemar"
41 n=n+1; x[n]="luiz"
42 n=n+1; x[n]="lula"
43 n=n+1; x[n]="peter"
44 n=n+1; x[n]="raquel"
45 n=n+1; x[n]="camilo"
46 n=n+1; x[n]="andre"
47 n=n+1; x[n]="marcelo"
48 n=n+1; x[n]="sedrez"
49 n=n+1; x[n]="z"
50-- quicksort(1,n-1)
51 print(x[0]..","..x[1]..","..x[2]..","..x[3]..","..x[4]..","..x[5]..","..x[6]..","..x[7]..","..x[8]..","..x[9]..","..x[10])
52 sort (x, n-1)
53 print(x[0]..","..x[1]..","..x[2]..","..x[3]..","..x[4]..","..x[5]..","..x[6]..","..x[7]..","..x[8]..","..x[9]..","..x[10])
54end
55
56
diff --git a/test.lua b/test.lua
new file mode 100644
index 00000000..c0a2eb42
--- /dev/null
+++ b/test.lua
@@ -0,0 +1,15 @@
1$debug
2
3
4function somaP (x1,y1,x2,y2)
5 return x1+x2, y1+y2
6end
7
8function norma (x,y)
9 return x*x+y*y
10end
11
12function retorno_multiplo ()
13 print (norma(somaP(2,3,4,5)))
14end
15
diff --git a/type.lua b/type.lua
new file mode 100644
index 00000000..26dc162f
--- /dev/null
+++ b/type.lua
@@ -0,0 +1,35 @@
1$debug
2
3function check (object, class)
4 local v = next(object,nil);
5 while v ~= nil do
6 if class[v] = nil then print("unknown field: " .. v)
7 elseif type(object[v]) ~= class[v].type
8 then print("wrong type for field " .. v)
9 end
10 v = next(object,v);
11 end
12 v = next(class,nil);
13 while v ~= nil do
14 if object[v] = nil then
15 if class[v].default ~= nil then
16 object[v] = class[v].default
17 else print("field "..v.." not initialized")
18 end
19 end
20 v = next(class,v);
21 end
22end
23
24typetrilha = @{x = @{default = 0, type = "number"},
25 y = @{default = 0, type = "number"},
26 name = @{type = "string"}
27 }
28
29function trilha (t) check(t,typetrilha) end
30
31t1 = @trilha{ x = 4, name = "3"}
32
33a = "na".."me"
34
35 \ No newline at end of file