History

Lua 5.1.2-rc1

Lua Team committed 19 years ago

Commit ce51ee41 parent 954596315 files · +362 −206Browse files

Showing the changes to src (8 of 15 files). Show all

Unified · Split

8 files
  1. src/lbaselib.c +5 −5
  2. src/lcode.c +30 −14
  3. src/ldebug.c +6 −4
  4. src/loslib.c +17 −6
  5. src/lparser.c +2 −2
  6. src/lstrlib.c +2 −2
  7. src/lua.h +4 −4
  8. src/print.c +2 −1
src/lbaselib.c+5−5
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lbaselib.c,v 1.191 2006/06/02 15:34:00 roberto Exp $
2+** $Id: lbaselib.c,v 1.191a 2006/06/02 15:34:00 roberto Exp $
33 ** Basic library
44 ** See Copyright Notice in lua.h
55 */
@@ -114,11 +114,11 @@ static int luaB_setmetatable (lua_State *L) { · 108 unmodified lines
114114 }
115115
116116
117−static void getfunc (lua_State *L) {
117+static void getfunc (lua_State *L, int opt) {
118118 if (lua_isfunction(L, 1)) lua_pushvalue(L, 1);
119119 else {
120120 lua_Debug ar;
121− int level = luaL_optint(L, 1, 1);
121+ int level = opt ? luaL_optint(L, 1, 1) : luaL_checkint(L, 1);
122122 luaL_argcheck(L, level >= 0, 1, "level must be non-negative");
123123 if (lua_getstack(L, level, &ar) == 0)
124124 luaL_argerror(L, 1, "invalid level");
@@ -131,7 +131,7 @@ static void getfunc (lua_State *L) { · 6 unmodified lines
131131
132132
133133 static int luaB_getfenv (lua_State *L) {
134− getfunc(L);
134+ getfunc(L, 1);
135135 if (lua_iscfunction(L, -1)) /* is a C function? */
136136 lua_pushvalue(L, LUA_GLOBALSINDEX); /* return the thread's global env. */
137137 else
@@ -142,7 +142,7 @@ static int luaB_getfenv (lua_State *L) { · 4 unmodified lines
142142
143143 static int luaB_setfenv (lua_State *L) {
144144 luaL_checktype(L, 2, LUA_TTABLE);
145− getfunc(L);
145+ getfunc(L, 0);
146146 lua_pushvalue(L, 2);
147147 if (lua_isnumber(L, 1) && lua_tonumber(L, 1) == 0) {
148148 /* change environment of current thread */
src/lcode.c+30−14
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lcode.c,v 2.25 2006/03/21 19:28:49 roberto Exp $
2+** $Id: lcode.c,v 2.25a 2006/03/21 19:28:49 roberto Exp $
33 ** Code generator for Lua
44 ** See Copyright Notice in lua.h
55 */
@@ -35,15 +35,20 @@ static int isnumeral(expdesc *e) { · 29 unmodified lines
3535 void luaK_nil (FuncState *fs, int from, int n) {
3636 Instruction *previous;
3737 if (fs->pc > fs->lasttarget) { /* no jumps to current position? */
38− if (fs->pc == 0) /* function start? */
39− return; /* positions are already clean */
40− if (GET_OPCODE(*(previous = &fs->f->code[fs->pc-1])) == OP_LOADNIL) {
41− int pfrom = GETARG_A(*previous);
42− int pto = GETARG_B(*previous);
43− if (pfrom <= from && from <= pto+1) { /* can connect both? */
44− if (from+n-1 > pto)
45− SETARG_B(*previous, from+n-1);
46− return;
38+ if (fs->pc == 0) { /* function start? */
39+ if (from >= fs->nactvar)
40+ return; /* positions are already clean */
41+ }
42+ else {
43+ previous = &fs->f->code[fs->pc-1];
44+ if (GET_OPCODE(*previous) == OP_LOADNIL) {
45+ int pfrom = GETARG_A(*previous);
46+ int pto = GETARG_B(*previous);
47+ if (pfrom <= from && from <= pto+1) { /* can connect both? */
48+ if (from+n-1 > pto)
49+ SETARG_B(*previous, from+n-1);
50+ return;
51+ }
4752 }
4853 }
4954 }
@@ -657,10 +662,16 @@ static void codearith (FuncState *fs, OpCode op, expdesc *e1, expdesc *e2) { · 607 unmodified lines
657662 if (constfolding(op, e1, e2))
658663 return;
659664 else {
660− int o1 = luaK_exp2RK(fs, e1);
661665 int o2 = (op != OP_UNM && op != OP_LEN) ? luaK_exp2RK(fs, e2) : 0;
662− freeexp(fs, e2);
663− freeexp(fs, e1);
666+ int o1 = luaK_exp2RK(fs, e1);
667+ if (o1 > o2) {
668+ freeexp(fs, e1);
669+ freeexp(fs, e2);
670+ }
671+ else {
672+ freeexp(fs, e2);
673+ freeexp(fs, e1);
674+ }
664675 e1->u.s.info = luaK_codeABC(fs, op, 0, o1, o2);
665676 e1->k = VRELOCABLE;
666677 }
@@ -718,10 +729,15 @@ void luaK_infix (FuncState *fs, BinOpr op, expdesc *v) { · 51 unmodified lines
718729 luaK_exp2nextreg(fs, v); /* operand must be on the `stack' */
719730 break;
720731 }
721− default: {
732+ case OPR_ADD: case OPR_SUB: case OPR_MUL: case OPR_DIV:
733+ case OPR_MOD: case OPR_POW: {
722734 if (!isnumeral(v)) luaK_exp2RK(fs, v);
723735 break;
724736 }
737+ default: {
738+ luaK_exp2RK(fs, v);
739+ break;
740+ }
725741 }
726742 }
727743
src/ldebug.c+6−4
@@ -1,5 +1,5 @@
11 /*
2−** $Id: ldebug.c,v 2.29 2005/12/22 16:19:56 roberto Exp $
2+** $Id: ldebug.c,v 2.29a 2005/12/22 16:19:56 roberto Exp $
33 ** Debug Interface
44 ** See Copyright Notice in lua.h
55 */
@@ -432,14 +432,16 @@ static Instruction symbexec (const Proto *pt, int lastpc, int reg) { · 426 unmodified lines
432432 break;
433433 }
434434 case OP_CLOSURE: {
435− int nup;
435+ int nup, j;
436436 check(b < pt->sizep);
437437 nup = pt->p[b]->nups;
438438 check(pc + nup < pt->sizecode);
439− for (; nup>0; nup--) {
440− OpCode op1 = GET_OPCODE(pt->code[pc+nup]);
439+ for (j = 1; j <= nup; j++) {
440+ OpCode op1 = GET_OPCODE(pt->code[pc + j]);
441441 check(op1 == OP_GETUPVAL || op1 == OP_MOVE);
442442 }
443+ if (reg != NO_REG) /* tracing? */
444+ pc += nup; /* do not 'execute' these pseudo-instructions */
443445 break;
444446 }
445447 case OP_VARARG: {
src/loslib.c+17−6
@@ -1,5 +1,5 @@
11 /*
2−** $Id: loslib.c,v 1.19 2006/04/26 18:19:49 roberto Exp $
2+** $Id: loslib.c,v 1.20 2006/09/19 13:57:08 roberto Exp $
33 ** Standard Operating System library
44 ** See Copyright Notice in lua.h
55 */
@@ -146,11 +146,22 @@ static int os_date (lua_State *L) { · 140 unmodified lines
146146 setboolfield(L, "isdst", stm->tm_isdst);
147147 }
148148 else {
149− char b[256];
150− if (strftime(b, sizeof(b), s, stm))
151− lua_pushstring(L, b);
152− else
153− return luaL_error(L, LUA_QL("date") " format too long");
149+ char cc[3];
150+ luaL_Buffer b;
151+ cc[0] = '%'; cc[2] = '\0';
152+ luaL_buffinit(L, &b);
153+ for (; *s; s++) {
154+ if (*s != '%' || *(s + 1) == '\0') /* no conversion specifier? */
155+ luaL_addchar(&b, *s);
156+ else {
157+ size_t reslen;
158+ char buff[200]; /* should be big enough for any conversion result */
159+ cc[1] = *(++s);
160+ reslen = strftime(buff, sizeof(buff), cc, stm);
161+ luaL_addlstring(&b, buff, reslen);
162+ }
163+ }
164+ luaL_pushresult(&b);
154165 }
155166 return 1;
156167 }
src/lparser.c+2−2
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lparser.c,v 2.42 2006/06/05 15:57:59 roberto Exp $
2+** $Id: lparser.c,v 2.42a 2006/06/05 15:57:59 roberto Exp $
33 ** Lua Parser
44 ** See Copyright Notice in lua.h
55 */
@@ -489,7 +489,7 @@ static void lastlistfield (FuncState *fs, struct ConsControl *cc) { · 483 unmodified lines
489489
490490 static void listfield (LexState *ls, struct ConsControl *cc) {
491491 expr(ls, &cc->v);
492− luaY_checklimit(ls->fs, cc->na, MAXARG_Bx, "items in a constructor");
492+ luaY_checklimit(ls->fs, cc->na, MAX_INT, "items in a constructor");
493493 cc->na++;
494494 cc->tostore++;
495495 }
src/lstrlib.c+2−2
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lstrlib.c,v 1.132 2006/04/26 20:41:19 roberto Exp $
2+** $Id: lstrlib.c,v 1.132a 2006/04/26 20:41:19 roberto Exp $
33 ** Standard library for string operations and pattern-matching
44 ** See Copyright Notice in lua.h
55 */
@@ -723,7 +723,7 @@ static void addquoted (lua_State *L, luaL_Buffer *b, int arg) { · 717 unmodified lines
723723
724724 static const char *scanformat (lua_State *L, const char *strfrmt, char *form) {
725725 const char *p = strfrmt;
726− while (strchr(FLAGS, *p)) p++; /* skip flags */
726+ while (*p != '\0' && strchr(FLAGS, *p) != NULL) p++; /* skip flags */
727727 if ((size_t)(p - strfrmt) >= sizeof(FLAGS))
728728 luaL_error(L, "invalid format (repeated flags)");
729729 if (isdigit(uchar(*p))) p++; /* skip width */
src/lua.h+4−4
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lua.h,v 1.218 2006/06/02 15:34:00 roberto Exp $
2+** $Id: lua.h,v 1.218a 2006/06/02 15:34:00 roberto Exp $
33 ** Lua - An Extensible Extension Language
44 ** Lua.org, PUC-Rio, Brazil (http://www.lua.org)
55 ** See Copyright Notice at the end of this file
@@ -17,9 +17,9 @@ · 11 unmodified lines
1717
1818
1919 #define LUA_VERSION "Lua 5.1"
20−#define LUA_RELEASE "Lua 5.1.1"
20+#define LUA_RELEASE "Lua 5.1.2"
2121 #define LUA_VERSION_NUM 501
22−#define LUA_COPYRIGHT "Copyright (C) 1994-2006 Lua.org, PUC-Rio"
22+#define LUA_COPYRIGHT "Copyright (C) 1994-2007 Lua.org, PUC-Rio"
2323 #define LUA_AUTHORS "R. Ierusalimschy, L. H. de Figueiredo & W. Celes"
2424
2525
@@ -359,7 +359,7 @@ struct lua_Debug { · 333 unmodified lines
359359
360360
361361 /******************************************************************************
362−* Copyright (C) 1994-2006 Lua.org, PUC-Rio. All rights reserved.
362+* Copyright (C) 1994-2007 Lua.org, PUC-Rio. All rights reserved.
363363 *
364364 * Permission is hereby granted, free of charge, to any person obtaining
365365 * a copy of this software and associated documentation files (the
src/print.c+2−1
@@ -1,5 +1,5 @@
11 /*
2−** $Id: print.c,v 1.55 2006/05/31 13:30:05 lhf Exp $
2+** $Id: print.c,v 1.55a 2006/05/31 13:30:05 lhf Exp $
33 ** print bytecodes
44 ** See Copyright Notice in lua.h
55 */
@@ -32,6 +32,7 @@ static void PrintString(const TString* ts) · 26 unmodified lines
3232 switch (c)
3333 {
3434 case '"': printf("\\\""); break;
35+ case '\\': printf("\\\\"); break;
3536 case '\a': printf("\\a"); break;
3637 case '\b': printf("\\b"); break;
3738 case '\f': printf("\\f"); break;