diff options
author | Li Jin <dragon-fly@qq.com> | 2021-03-11 08:56:23 +0800 |
---|---|---|
committer | Li Jin <dragon-fly@qq.com> | 2021-03-11 08:56:23 +0800 |
commit | b359d1a69e9c2db09444264a8d9d874e156fd14b (patch) | |
tree | 388e0ef24a1537e8f9cd75c3754dd1e133b8c902 | |
parent | 3eedd027bddc1ad9099d647e83ae4a83589db191 (diff) | |
download | yuescript-b359d1a69e9c2db09444264a8d9d874e156fd14b.tar.gz yuescript-b359d1a69e9c2db09444264a8d9d874e156fd14b.tar.bz2 yuescript-b359d1a69e9c2db09444264a8d9d874e156fd14b.zip |
update Lua.
-rw-r--r-- | src/lua/lapi.c | 15 | ||||
-rw-r--r-- | src/lua/lauxlib.h | 9 | ||||
-rw-r--r-- | src/lua/ldebug.c | 5 | ||||
-rw-r--r-- | src/lua/lfunc.c | 40 | ||||
-rw-r--r-- | src/lua/lobject.h | 5 | ||||
-rw-r--r-- | src/lua/lua.h | 6 | ||||
-rw-r--r-- | src/lua/luaconf.h | 18 |
7 files changed, 62 insertions, 36 deletions
diff --git a/src/lua/lapi.c b/src/lua/lapi.c index a9cf2fd..f8f70cd 100644 --- a/src/lua/lapi.c +++ b/src/lua/lapi.c | |||
@@ -173,7 +173,7 @@ LUA_API int lua_gettop (lua_State *L) { | |||
173 | 173 | ||
174 | LUA_API void lua_settop (lua_State *L, int idx) { | 174 | LUA_API void lua_settop (lua_State *L, int idx) { |
175 | CallInfo *ci; | 175 | CallInfo *ci; |
176 | StkId func; | 176 | StkId func, newtop; |
177 | ptrdiff_t diff; /* difference for new top */ | 177 | ptrdiff_t diff; /* difference for new top */ |
178 | lua_lock(L); | 178 | lua_lock(L); |
179 | ci = L->ci; | 179 | ci = L->ci; |
@@ -188,12 +188,13 @@ LUA_API void lua_settop (lua_State *L, int idx) { | |||
188 | api_check(L, -(idx+1) <= (L->top - (func + 1)), "invalid new top"); | 188 | api_check(L, -(idx+1) <= (L->top - (func + 1)), "invalid new top"); |
189 | diff = idx + 1; /* will "subtract" index (as it is negative) */ | 189 | diff = idx + 1; /* will "subtract" index (as it is negative) */ |
190 | } | 190 | } |
191 | #if defined(LUA_COMPAT_5_4_0) | 191 | api_check(L, L->tbclist < L->top, "previous pop of an unclosed slot"); |
192 | if (diff < 0 && hastocloseCfunc(ci->nresults)) | 192 | newtop = L->top + diff; |
193 | luaF_close(L, L->top + diff, CLOSEKTOP, 0); | 193 | if (diff < 0 && L->tbclist >= newtop) { |
194 | #endif | 194 | lua_assert(hastocloseCfunc(ci->nresults)); |
195 | api_check(L, L->tbclist < L->top + diff, "cannot pop an unclosed slot"); | 195 | luaF_close(L, newtop, CLOSEKTOP, 0); |
196 | L->top += diff; | 196 | } |
197 | L->top = newtop; /* correct top only after closing any upvalue */ | ||
197 | lua_unlock(L); | 198 | lua_unlock(L); |
198 | } | 199 | } |
199 | 200 | ||
diff --git a/src/lua/lauxlib.h b/src/lua/lauxlib.h index 9058e26..72f70e7 100644 --- a/src/lua/lauxlib.h +++ b/src/lua/lauxlib.h | |||
@@ -12,6 +12,7 @@ | |||
12 | #include <stddef.h> | 12 | #include <stddef.h> |
13 | #include <stdio.h> | 13 | #include <stdio.h> |
14 | 14 | ||
15 | #include "luaconf.h" | ||
15 | #include "lua.h" | 16 | #include "lua.h" |
16 | 17 | ||
17 | 18 | ||
@@ -122,10 +123,6 @@ LUALIB_API void (luaL_requiref) (lua_State *L, const char *modname, | |||
122 | ** =============================================================== | 123 | ** =============================================================== |
123 | */ | 124 | */ |
124 | 125 | ||
125 | #if !defined(l_likely) | ||
126 | #define l_likely(x) x | ||
127 | #endif | ||
128 | |||
129 | 126 | ||
130 | #define luaL_newlibtable(L,l) \ | 127 | #define luaL_newlibtable(L,l) \ |
131 | lua_createtable(L, 0, sizeof(l)/sizeof((l)[0]) - 1) | 128 | lua_createtable(L, 0, sizeof(l)/sizeof((l)[0]) - 1) |
@@ -134,10 +131,10 @@ LUALIB_API void (luaL_requiref) (lua_State *L, const char *modname, | |||
134 | (luaL_checkversion(L), luaL_newlibtable(L,l), luaL_setfuncs(L,l,0)) | 131 | (luaL_checkversion(L), luaL_newlibtable(L,l), luaL_setfuncs(L,l,0)) |
135 | 132 | ||
136 | #define luaL_argcheck(L, cond,arg,extramsg) \ | 133 | #define luaL_argcheck(L, cond,arg,extramsg) \ |
137 | ((void)(l_likely(cond) || luaL_argerror(L, (arg), (extramsg)))) | 134 | ((void)(luai_likely(cond) || luaL_argerror(L, (arg), (extramsg)))) |
138 | 135 | ||
139 | #define luaL_argexpected(L,cond,arg,tname) \ | 136 | #define luaL_argexpected(L,cond,arg,tname) \ |
140 | ((void)(l_likely(cond) || luaL_typeerror(L, (arg), (tname)))) | 137 | ((void)(luai_likely(cond) || luaL_typeerror(L, (arg), (tname)))) |
141 | 138 | ||
142 | #define luaL_checkstring(L,n) (luaL_checklstring(L, (n), NULL)) | 139 | #define luaL_checkstring(L,n) (luaL_checklstring(L, (n), NULL)) |
143 | #define luaL_optstring(L,n,d) (luaL_optlstring(L, (n), (d), NULL)) | 140 | #define luaL_optstring(L,n,d) (luaL_optlstring(L, (n), (d), NULL)) |
diff --git a/src/lua/ldebug.c b/src/lua/ldebug.c index 8e3657a..1feaab2 100644 --- a/src/lua/ldebug.c +++ b/src/lua/ldebug.c | |||
@@ -50,6 +50,8 @@ static int currentpc (CallInfo *ci) { | |||
50 | ** an integer division gets the right place. When the source file has | 50 | ** an integer division gets the right place. When the source file has |
51 | ** large sequences of empty/comment lines, it may need extra entries, | 51 | ** large sequences of empty/comment lines, it may need extra entries, |
52 | ** so the original estimate needs a correction. | 52 | ** so the original estimate needs a correction. |
53 | ** If the original estimate is -1, the initial 'if' ensures that the | ||
54 | ** 'while' will run at least once. | ||
53 | ** The assertion that the estimate is a lower bound for the correct base | 55 | ** The assertion that the estimate is a lower bound for the correct base |
54 | ** is valid as long as the debug info has been generated with the same | 56 | ** is valid as long as the debug info has been generated with the same |
55 | ** value for MAXIWTHABS or smaller. (Previous releases use a little | 57 | ** value for MAXIWTHABS or smaller. (Previous releases use a little |
@@ -63,7 +65,8 @@ static int getbaseline (const Proto *f, int pc, int *basepc) { | |||
63 | else { | 65 | else { |
64 | int i = cast_uint(pc) / MAXIWTHABS - 1; /* get an estimate */ | 66 | int i = cast_uint(pc) / MAXIWTHABS - 1; /* get an estimate */ |
65 | /* estimate must be a lower bond of the correct base */ | 67 | /* estimate must be a lower bond of the correct base */ |
66 | lua_assert(i < f->sizeabslineinfo && f->abslineinfo[i].pc <= pc); | 68 | lua_assert(i < 0 || |
69 | (i < f->sizeabslineinfo && f->abslineinfo[i].pc <= pc)); | ||
67 | while (i + 1 < f->sizeabslineinfo && pc >= f->abslineinfo[i + 1].pc) | 70 | while (i + 1 < f->sizeabslineinfo && pc >= f->abslineinfo[i + 1].pc) |
68 | i++; /* low estimate; adjust it */ | 71 | i++; /* low estimate; adjust it */ |
69 | *basepc = f->abslineinfo[i].pc; | 72 | *basepc = f->abslineinfo[i].pc; |
diff --git a/src/lua/lfunc.c b/src/lua/lfunc.c index b4c04bd..f5889a2 100644 --- a/src/lua/lfunc.c +++ b/src/lua/lfunc.c | |||
@@ -155,6 +155,15 @@ static void prepcallclosemth (lua_State *L, StkId level, int status, int yy) { | |||
155 | 155 | ||
156 | 156 | ||
157 | /* | 157 | /* |
158 | ** Maximum value for deltas in 'tbclist', dependent on the type | ||
159 | ** of delta. (This macro assumes that an 'L' is in scope where it | ||
160 | ** is used.) | ||
161 | */ | ||
162 | #define MAXDELTA \ | ||
163 | ((256ul << ((sizeof(L->stack->tbclist.delta) - 1) * 8)) - 1) | ||
164 | |||
165 | |||
166 | /* | ||
158 | ** Insert a variable in the list of to-be-closed variables. | 167 | ** Insert a variable in the list of to-be-closed variables. |
159 | */ | 168 | */ |
160 | void luaF_newtbcupval (lua_State *L, StkId level) { | 169 | void luaF_newtbcupval (lua_State *L, StkId level) { |
@@ -162,13 +171,11 @@ void luaF_newtbcupval (lua_State *L, StkId level) { | |||
162 | if (l_isfalse(s2v(level))) | 171 | if (l_isfalse(s2v(level))) |
163 | return; /* false doesn't need to be closed */ | 172 | return; /* false doesn't need to be closed */ |
164 | checkclosemth(L, level); /* value must have a close method */ | 173 | checkclosemth(L, level); /* value must have a close method */ |
165 | while (level - L->tbclist > USHRT_MAX) { /* is delta too large? */ | 174 | while (cast_uint(level - L->tbclist) > MAXDELTA) { |
166 | L->tbclist += USHRT_MAX; /* create a dummy node at maximum delta */ | 175 | L->tbclist += MAXDELTA; /* create a dummy node at maximum delta */ |
167 | L->tbclist->tbclist.delta = USHRT_MAX; | 176 | L->tbclist->tbclist.delta = 0; |
168 | L->tbclist->tbclist.isdummy = 1; | ||
169 | } | 177 | } |
170 | level->tbclist.delta = level - L->tbclist; | 178 | level->tbclist.delta = cast(unsigned short, level - L->tbclist); |
171 | level->tbclist.isdummy = 0; | ||
172 | L->tbclist = level; | 179 | L->tbclist = level; |
173 | } | 180 | } |
174 | 181 | ||
@@ -202,6 +209,19 @@ void luaF_closeupval (lua_State *L, StkId level) { | |||
202 | 209 | ||
203 | 210 | ||
204 | /* | 211 | /* |
212 | ** Remove firt element from the tbclist plus its dummy nodes. | ||
213 | */ | ||
214 | static void poptbclist (lua_State *L) { | ||
215 | StkId tbc = L->tbclist; | ||
216 | lua_assert(tbc->tbclist.delta > 0); /* first element cannot be dummy */ | ||
217 | tbc -= tbc->tbclist.delta; | ||
218 | while (tbc > L->stack && tbc->tbclist.delta == 0) | ||
219 | tbc -= MAXDELTA; /* remove dummy nodes */ | ||
220 | L->tbclist = tbc; | ||
221 | } | ||
222 | |||
223 | |||
224 | /* | ||
205 | ** Close all upvalues and to-be-closed variables up to the given stack | 225 | ** Close all upvalues and to-be-closed variables up to the given stack |
206 | ** level. | 226 | ** level. |
207 | */ | 227 | */ |
@@ -210,11 +230,9 @@ void luaF_close (lua_State *L, StkId level, int status, int yy) { | |||
210 | luaF_closeupval(L, level); /* first, close the upvalues */ | 230 | luaF_closeupval(L, level); /* first, close the upvalues */ |
211 | while (L->tbclist >= level) { /* traverse tbc's down to that level */ | 231 | while (L->tbclist >= level) { /* traverse tbc's down to that level */ |
212 | StkId tbc = L->tbclist; /* get variable index */ | 232 | StkId tbc = L->tbclist; /* get variable index */ |
213 | L->tbclist -= tbc->tbclist.delta; /* remove it from list */ | 233 | poptbclist(L); /* remove it from list */ |
214 | if (!tbc->tbclist.isdummy) { /* not a dummy entry? */ | 234 | prepcallclosemth(L, tbc, status, yy); /* close variable */ |
215 | prepcallclosemth(L, tbc, status, yy); /* close variable */ | 235 | level = restorestack(L, levelrel); |
216 | level = restorestack(L, levelrel); | ||
217 | } | ||
218 | } | 236 | } |
219 | } | 237 | } |
220 | 238 | ||
diff --git a/src/lua/lobject.h b/src/lua/lobject.h index 1a7a737..950bebb 100644 --- a/src/lua/lobject.h +++ b/src/lua/lobject.h | |||
@@ -139,13 +139,14 @@ typedef struct TValue { | |||
139 | ** Entries in a Lua stack. Field 'tbclist' forms a list of all | 139 | ** Entries in a Lua stack. Field 'tbclist' forms a list of all |
140 | ** to-be-closed variables active in this stack. Dummy entries are | 140 | ** to-be-closed variables active in this stack. Dummy entries are |
141 | ** used when the distance between two tbc variables does not fit | 141 | ** used when the distance between two tbc variables does not fit |
142 | ** in an unsigned short. | 142 | ** in an unsigned short. They are represented by delta==0, and |
143 | ** their real delta is always the maximum value that fits in | ||
144 | ** that field. | ||
143 | */ | 145 | */ |
144 | typedef union StackValue { | 146 | typedef union StackValue { |
145 | TValue val; | 147 | TValue val; |
146 | struct { | 148 | struct { |
147 | TValuefields; | 149 | TValuefields; |
148 | lu_byte isdummy; | ||
149 | unsigned short delta; | 150 | unsigned short delta; |
150 | } tbclist; | 151 | } tbclist; |
151 | } StackValue; | 152 | } StackValue; |
diff --git a/src/lua/lua.h b/src/lua/lua.h index aec70da..820535b 100644 --- a/src/lua/lua.h +++ b/src/lua/lua.h | |||
@@ -18,14 +18,14 @@ | |||
18 | 18 | ||
19 | #define LUA_VERSION_MAJOR "5" | 19 | #define LUA_VERSION_MAJOR "5" |
20 | #define LUA_VERSION_MINOR "4" | 20 | #define LUA_VERSION_MINOR "4" |
21 | #define LUA_VERSION_RELEASE "2" | 21 | #define LUA_VERSION_RELEASE "3" |
22 | 22 | ||
23 | #define LUA_VERSION_NUM 504 | 23 | #define LUA_VERSION_NUM 504 |
24 | #define LUA_VERSION_RELEASE_NUM (LUA_VERSION_NUM * 100 + 0) | 24 | #define LUA_VERSION_RELEASE_NUM (LUA_VERSION_NUM * 100 + 0) |
25 | 25 | ||
26 | #define LUA_VERSION "Lua " LUA_VERSION_MAJOR "." LUA_VERSION_MINOR | 26 | #define LUA_VERSION "Lua " LUA_VERSION_MAJOR "." LUA_VERSION_MINOR |
27 | #define LUA_RELEASE LUA_VERSION "." LUA_VERSION_RELEASE | 27 | #define LUA_RELEASE LUA_VERSION "." LUA_VERSION_RELEASE |
28 | #define LUA_COPYRIGHT LUA_RELEASE " Copyright (C) 1994-2020 Lua.org, PUC-Rio" | 28 | #define LUA_COPYRIGHT LUA_RELEASE " Copyright (C) 1994-2021 Lua.org, PUC-Rio" |
29 | #define LUA_AUTHORS "R. Ierusalimschy, L. H. de Figueiredo, W. Celes" | 29 | #define LUA_AUTHORS "R. Ierusalimschy, L. H. de Figueiredo, W. Celes" |
30 | 30 | ||
31 | 31 | ||
@@ -492,7 +492,7 @@ struct lua_Debug { | |||
492 | 492 | ||
493 | 493 | ||
494 | /****************************************************************************** | 494 | /****************************************************************************** |
495 | * Copyright (C) 1994-2020 Lua.org, PUC-Rio. | 495 | * Copyright (C) 1994-2021 Lua.org, PUC-Rio. |
496 | * | 496 | * |
497 | * Permission is hereby granted, free of charge, to any person obtaining | 497 | * Permission is hereby granted, free of charge, to any person obtaining |
498 | * a copy of this software and associated documentation files (the | 498 | * a copy of this software and associated documentation files (the |
diff --git a/src/lua/luaconf.h b/src/lua/luaconf.h index ae73e2f..38e14ed 100644 --- a/src/lua/luaconf.h +++ b/src/lua/luaconf.h | |||
@@ -665,20 +665,26 @@ | |||
665 | ** macros to improve jump prediction, used mostly for error handling | 665 | ** macros to improve jump prediction, used mostly for error handling |
666 | ** and debug facilities. | 666 | ** and debug facilities. |
667 | */ | 667 | */ |
668 | #if (defined(LUA_CORE) || defined(LUA_LIB)) && !defined(l_likely) | 668 | #if !defined(luai_likely) |
669 | 669 | ||
670 | #include <stdio.h> | ||
671 | #if defined(__GNUC__) | 670 | #if defined(__GNUC__) |
672 | #define l_likely(x) (__builtin_expect(((x) != 0), 1)) | 671 | #define luai_likely(x) (__builtin_expect(((x) != 0), 1)) |
673 | #define l_unlikely(x) (__builtin_expect(((x) != 0), 0)) | 672 | #define luai_unlikely(x) (__builtin_expect(((x) != 0), 0)) |
674 | #else | 673 | #else |
675 | #define l_likely(x) (x) | 674 | #define luai_likely(x) (x) |
676 | #define l_unlikely(x) (x) | 675 | #define luai_unlikely(x) (x) |
677 | #endif | 676 | #endif |
678 | 677 | ||
679 | #endif | 678 | #endif |
680 | 679 | ||
681 | 680 | ||
681 | #if defined(LUA_CORE) || defined(LUA_LIB) | ||
682 | /* shorter names for Lua's own use */ | ||
683 | #define l_likely(x) luai_likely(x) | ||
684 | #define l_unlikely(x) luai_unlikely(x) | ||
685 | #endif | ||
686 | |||
687 | |||
682 | 688 | ||
683 | /* }================================================================== */ | 689 | /* }================================================================== */ |
684 | 690 | ||