Commit Graph

5155 Commits

Author SHA1 Message Date
Roberto Ierusalimschy
bd96330d03 First "complete" implementation of to-be-closed variables
Still missing:
- handling of memory errors when creating upvalue (must run closing
method all the same)
- interaction with coroutines
2018-10-17 10:44:42 -03:00
Roberto Ierusalimschy
4cd1f4aac0 Towards "to closed" local variables
Start of the implementation of "scoped variables" or "to be closed"
variables, local variables whose '__close' (or themselves) are called
when they go out of scope. This commit implements the syntax, the
opcode, and the creation of the corresponding upvalue, but it still
does not call the finalizations when the variable goes out of scope
(the most important part).

Currently, the syntax is 'local scoped name = exp', but that will
probably change.
2018-10-08 10:42:07 -03:00
Roberto Ierusalimschy
b114c7d487 Added "cost" for the use of C stack by a coroutine invocation.
Resuming a coroutine uses more C stack than other operations (such as
function calls or recursive syntax). So, to avoid stack overflow
in recursive coroutine invocations, either LUAI_MAXCCALLS must be
too small or a coroutine invocation must "pay" a higher price.
New constant LUAL_COROCSTK ("COROutine C STaK") defines how much
is this price.
2018-09-11 14:24:14 -03:00
Roberto Ierusalimschy
9cbf17b0f1 Details (comments) 2018-09-11 08:39:12 -03:00
Roberto Ierusalimschy
5382a22e0e Corrections in the implementation of '%' for floats.
The multiplication (m*b) used to test whether 'm' is non-zero and
'm' and 'b' have different signs can underflow for very small numbers,
giving a wrong result. The use of explicit comparisons solves this
problem. This commit also adds several new tests for '%' (both for
floats and for integers) to exercise more corner cases, such as
very large and very small values.
2018-08-28 12:36:58 -03:00
Roberto Ierusalimschy
8c8a91f2ef Deprecated the emulation of '__le' using '__lt'
As hinted in the manual for Lua 5.3, the emulation of the metamethod
for '__le' using '__le' has been deprecated. It is slow, complicates
the logic, and it is easy to avoid this emulation by defining a proper
'__le' function.

Moreover, often this emulation was used wrongly, with a programmer
assuming that an order is total when it is not (e.g., NaN in
floating-point numbers).
2018-08-24 10:17:54 -03:00
Roberto Ierusalimschy
f99509581e Removed extra information from RCS keyword strings
Version numbers and dates (mostly wrong) from RCS keyword strings
removed from all source files; only the file name are kept.
2018-08-23 14:26:12 -03:00
Roberto Ierusalimschy
3dcd04ad61 details
Minor optimizations in 'lvm.c'. (Not exactly optimizations, but more
chances for optimizations.)
2018-08-17 15:53:39 -03:00
Roberto Ierusalimschy
faaf7e481f Removed use of 'rl_inhibit_completion' in 'lua.c'
Some old systems (e.g., Mac OS X 10.4) do not define
'rl_inhibit_completion', even when line history is available.
Anyway, the user can configure this option externally, using '~/.inputrc'.
2018-08-16 14:38:05 -03:00
Roberto Ierusalimschy
3d838f635c Added "emergency collection" to 'io.tmpfile' and 'os.tmpname'
These operations also can give errors for lack of resources, so they
also will try "emergency collections" in case of resource errors.
Because there are now two libraries with that kind of handling,
'resourcetryagain' was moved to the auxiliary library to be shared
by the libraries.
2018-07-27 15:50:53 -03:00
Roberto Ierusalimschy
aa4c5cf190 Added directory to test file names in '$Id:'
From the point of view of 'git', all names are relative to the root
directory of the project. So, file names in '$Id:' also should be
relative to that directory: the proper name for test file 'all.lua'
is 'testes/all.lua'.
2018-07-25 15:31:04 -03:00
Roberto Ierusalimschy
b47f2cd068 Small improvements in the manual 2018-07-25 14:56:42 -03:00
Roberto Ierusalimschy
e885dee5ab File operations try an "emergency collection" when failing
If a file operation fails do to lack of resources (too many open
files or not enough memory), it does a full garbage collection and
tries the operation again. Lack of resources are "too many open
files" (process wise and system wise) and "not enough memory".
The code is full of '#if's because error codes are not part
of the standard ISO C.
2018-07-25 11:44:46 -03:00
Roberto Ierusalimschy
ccae0f5aad Comments about OLD0/OLD1 ages
Improved the comments in file 'lgc.c' explaining the roles of "ages"
OLD0 and OLD1 in the generacional collector.
2018-07-18 11:43:45 -03:00
Roberto Ierusalimschy
2e297d6ab3 Fixed bug in generational collection of userdata
During generational collection, a userdatum must become gray and
go to a gray list after being traversed (like tables), so that
'correctgraylist' can handle it to its next stage.

This commit also added minimum tests for the generational collector,
including one that would detect this bug.
2018-07-13 15:43:02 -03:00
Roberto Ierusalimschy
fb18346ddd Avoid using 'int' for UTF-8 values
An 'int' may have only 16 bits, so it may not be big enough for UTF-8
values. The new type 'utfint' (in the utf8 library) ensures at least
21 bits for those values.
2018-07-12 15:56:44 -03:00
Roberto Ierusalimschy
96f9643f33 Bug: wrong 'nCcalls' when resuming a coroutine
The counter 'nCcalls' now includes the number of CallInfo structures
pre-allocated (so that these "potential" C calls can be made without
checking 'nCcalls'). So, when copying this value from a thread to
another, in 'lua_resume', it must be corrected to the number of
CallInfo structures in the thread being resumed.
2018-07-11 16:11:50 -03:00
Roberto Ierusalimschy
84058b1506 Added definition for LUA_VERSION_RELEASE_NUM
LUA_VERSION_RELEASE_NUM is set to the release number of the Lua
interpreter (e.g., 5.4.0 becomes the integer 50400).
2018-07-11 13:17:46 -03:00
Roberto Ierusalimschy
4d5de1c1fb Fixed bug in line info. when using 'not' operator
When creating code for a jump on a 'not' condition, the code generator
was removing an instruction (the OP_NOT) without adjusting its
corresponding line information.

This fix also added tests for this case and extra functionality in
the test library to debug line info. structures.
2018-07-11 12:53:23 -03:00
Roberto Ierusalimschy
9a825f6bb9 In tests of opcodes, avoid coercion in bitwise operation 2018-07-10 14:55:16 -03:00
Roberto Ierusalimschy
941b189d98 Improvements in the manual
- More precise use of 'argument' x 'parameter'.
- Clarification about what the lexer considers 'letter', 'space',
and 'digit'.
2018-07-10 13:48:19 -03:00
Roberto Ierusalimschy
21f663d29f Added missing $Id$ to file 'ljumptab.h' 2018-07-10 13:40:30 -03:00
Roberto Ierusalimschy
626cf0581b Generational mode may wait longer after a major collection
When Lua is building large long-duration structures, frequent small
minor collections just waste time. Trying to avoid this, the
collector will do a larger pause after a major collection when it
does not collect enough garbage (which is a hint that memory is
being used for long-lasting objects).
2018-07-09 14:22:09 -03:00
Roberto Ierusalimschy
ccf6d098f6 'searchpath' creates less temporary strings
When creating error messages, package loaders may create dozens of
temporary strings (one or more for each tried template). This change
reduces the number of these strings, and avoid creating some of
them if the search is successful.
2018-07-09 13:29:08 -03:00
Roberto Ierusalimschy
de2caf7ee4 Bit-library file removed from the project (as it was deprecated)
This commit only removed the file 'lbitlib.c' from the project; the
makefile already was not using it.
2018-07-09 12:54:51 -03:00
Roberto Ierusalimschy
b08c9079c5 Opcode names moved to a new header file
The array with the names of the opcodes was moved to a header file
('lopnames.h'), as it is not used by the Lua kernel. Files that need
that array ('luac.c' and 'ltests.c') include the header file to get
a private (static) copy.
2018-07-09 12:50:51 -03:00
Roberto Ierusalimschy
06e08c6d05 Fixed bug in OP_IDIVI
Opocode was using 'luai_numdiv' (float division) instead of
'luai_numidiv' (integer division).
2018-07-09 12:41:24 -03:00
Roberto Ierusalimschy
7c519dfbd0 Added manual and tests for version 5.4-w2 2018-07-09 12:33:01 -03:00
Roberto Ierusalimschy
f59e6a93c0 opening functions must be exported! 2018-06-19 16:23:57 -03:00
Roberto Ierusalimschy
6683f83b51 several details 2018-06-18 15:25:19 -03:00
Roberto Ierusalimschy
a314409dba in generational mode, an emergency collection can turn any object black
during any memory allocation +
'luaT_getvarargs' may reallocate the stack, and therefore the top must
be correct.
2018-06-18 14:58:21 -03:00
Roberto Ierusalimschy
15ce8d0904 in generational mode, an emergency collection can turn any object black
during any memory allocation.
2018-06-18 14:57:20 -03:00
Roberto Ierusalimschy
b43300c14f change in 'LUAI_DDEC' to allow variables to be static in 'onelua'
+ change in 'LUAMOD_API' as opening functions do not need to be global
2018-06-18 09:51:05 -03:00
Roberto Ierusalimschy
af70905246 no need to check whether libraries and host use the same kernel;
Lua should work correctly with several copies of the kernel
2018-06-18 09:08:10 -03:00
Roberto Ierusalimschy
b95e466218 new field 'nilvalue' in struct 'global_State' to avoid the use of
addresses of static variables
2018-06-15 16:31:22 -03:00
Roberto Ierusalimschy
d406d3d05f removed unused macros 'isstackindex'/'api_checkstackindex' +
macro 'api_checkvalidindex' (used only once) expanded and removed
2018-06-15 14:30:52 -03:00
Roberto Ierusalimschy
b6780ee41b detail (removed unused definition for 'LUA_QS') 2018-06-15 12:49:28 -03:00
Roberto Ierusalimschy
2c107e13a8 warning (comparison between signed and unsigned integers) 2018-06-15 11:18:40 -03:00
Roberto Ierusalimschy
6e600695f8 field 'sizearray' in struct 'Table' changed to 'alimit', which can
be used as a hint for '#t'
2018-06-15 11:14:20 -03:00
Roberto Ierusalimschy
06127927ff new macro 'ispow2' 2018-06-15 11:13:45 -03:00
Roberto Ierusalimschy
aedcfb9414 type 'Rand64' may not be long long, so it should not use 'LL' in its
constants
2018-06-14 15:47:22 -03:00
Roberto Ierusalimschy
992b6d2712 no more 'TESTGRAYBIT' (to free this bit for real uses) 2018-06-11 11:19:50 -03:00
Roberto Ierusalimschy
588dfa4ce5 detail in comment 2018-06-08 16:07:27 -03:00
Roberto Ierusalimschy
6f2b8e21c4 added 'const' to 'Proto*' when possible 2018-06-08 16:06:59 -03:00
Roberto Ierusalimschy
c5dc521d65 added patch for bug 5.3.4-7 2018-06-08 13:23:18 -03:00
Roberto Ierusalimschy
505fc91222 no more 'luaO_nilobject' to avoid comparison of global variable addresses
(now uses static variables)
2018-06-01 14:40:38 -03:00
Roberto Ierusalimschy
fb8fa66136 no more 'luaH_emptyobject' and comparisons of addresses of global variables
(instead, use a different kind of nil to signal the fake entry returned
when a key is not found in a table)
2018-06-01 13:51:34 -03:00
Roberto Ierusalimschy
b397064955 avoid craches when loading tampered code with NULL as a string constant 2018-06-01 13:45:58 -03:00
Roberto Ierusalimschy
34aa0c5bd7 new macros 'likely'/'unlikely' with hints for jump predictions
(used only in errors for now)
2018-05-30 11:25:52 -03:00
Roberto Ierusalimschy
97e394ba18 macro 'luai_makeseed' now controls the whole process of making the seed 2018-05-29 15:02:51 -03:00