321 Commits

Author SHA1 Message Date
Roberto Ierusalimschy
07b009c371 No need to limit variable declarations to 250
Only local variables, which use registers, need this low limit.
2025-06-18 16:45:55 -03:00
Roberto Ierusalimschy
9386e49a31 New metatable in an all-weak table can fool the GC
All-weak tables are not being revisited after being visited during
propagation; if it gets a new metatable after that, the new metatable
may not be marked.
2025-06-16 16:29:32 -03:00
Roberto Ierusalimschy
8cd7ae7da0 Simpler code for 'traversetable'
Check the mode in a separate function (getmode), instead of using
comma expressions inside the 'if' condition.
2025-06-16 15:50:12 -03:00
Roberto Ierusalimschy
0cecf1ab6d Dump uses varints also for integer constants
Unlike sizes, these constants can be negative, so it encodes those
integers into unsigned integers in a way that keeps small numbers
small.
2025-06-13 14:14:50 -03:00
Roberto Ierusalimschy
e657a48ea5 The main thread cannot be closed
No thread started with pcall (instead of resume) can be closed,
because coroutine.close would not respect the expected number of
results from the protected call.
2025-06-13 14:08:38 -03:00
Roberto Ierusalimschy
fd897027f1 A coroutine can close itself
A call to close itself will close all its to-be-closed variables and
return to the resume that (re)started the coroutine.
2025-06-12 11:15:09 -03:00
Roberto Ierusalimschy
be05c44481 New way to control preambular declaration
Validity of the preambular global declaration in controled together
with all declarations, when checking variable names.
2025-05-20 17:36:05 -03:00
Roberto Ierusalimschy
6d53701c7a Proper error message when jumping into 'global *'
A goto cannot jump into the scope of any variable declaration,
including 'global *'. To report the error, it needs a "name" for
the scope it is entering.
2025-05-18 12:03:54 -03:00
Roberto Ierusalimschy
abbae57c78 Variable attributes can prefix name list
In this format, the attribute applies to all names in the list;
e.g. "global<const> print, require, math".
2025-05-18 11:43:43 -03:00
Roberto Ierusalimschy
f2c1531e6c Detail
Reports errors with "?:?:" (instead of "?👎") when there is no debug
information.
2025-05-16 15:20:32 -03:00
Roberto Ierusalimschy
3b9dd52be0 Collective declaration for globals ('global *') 2025-05-13 11:43:10 -03:00
Roberto Ierusalimschy
7dc6aae290 Correct line in error message for constant function 2025-05-12 11:42:45 -03:00
Roberto Ierusalimschy
3f0ea90aa8 New syntax 'global function' 2025-05-08 11:08:03 -03:00
Roberto Ierusalimschy
4365a45d68 Checks for read-only globals 2025-05-06 15:54:05 -03:00
Roberto Ierusalimschy
be81209063 First implementation of global declarations 2025-05-05 16:24:59 -03:00
Roberto Ierusalimschy
9b014d4bcd Details (typos in comments) 2025-04-23 11:36:09 -03:00
Roberto Ierusalimschy
3dd8ea54da Order change in 'pushfuncname'
'pushglobalfuncname' can be quite slow (as it traverses all globals and
all loaded modules), so try first to get a name from the code.
2025-04-03 15:31:22 -03:00
Roberto Ierusalimschy
620f49a7aa Tiny refactoring in io.flush 2025-04-03 12:56:52 -03:00
Roberto Ierusalimschy
3f4f28010a io.write returns number of written bytes on error 2025-04-03 11:32:49 -03:00
Roberto Ierusalimschy
cad5a4fdbb Details
Small changes in test library:
- execute mode added to 'all.lua';
- more information about subtypes (tags) when printing a stack.
2025-03-24 15:23:55 -03:00
Roberto Ierusalimschy
921832be8d New function 'resetCI'
New function 'resetCI' resets the CallInfo list of a thread, ensuring
a proper state when creating a new thread, closing a thread, or
closing a state, so that we can run code after that. (When closing a
thread, we need to run its __close metamethods; when closing a
state, we need to run its __close metamethods and its finalizers.)
2025-03-17 14:32:08 -03:00
Roberto Ierusalimschy
94d38560c3 Wrong error message when using "_ENV" fields
The string "_ENV" is erroneously identified as a variable _ENV,
so that results from a field is classified as a global.
2025-03-14 15:16:09 -03:00
Roberto Ierusalimschy
c2dc6e8e94 Missing GC barrier in 'luaV_finishset' 2025-03-14 12:37:19 -03:00
Roberto Ierusalimschy
22974326ca Use after free in 'luaV_finishset'
If a metatable is a weak table, its __newindex field could be collected
by an emergency collection while being used in 'luaV_finishset'. (This
bug has similarities with bug 5.3.2-1, fixed in commit a272fa66.)
2025-03-13 15:30:52 -03:00
Roberto Ierusalimschy
c931d86e98 'luaD_seterrorobj' should not raise errors
This function can be called unprotected, so it should not raise any
kind of errors. (It could raise a memory-allocation error when creating
a message).
2025-03-12 15:51:16 -03:00
Roberto Ierusalimschy
ab66652b32 Removed copyright notice from 'testes/all.lua'
All test files refer to the main copyright notice in 'lua.h'.
2025-03-12 14:00:58 -03:00
Roberto Ierusalimschy
4398e488e6 New test file 'memerr.lua'
Tests for memory-allocation errors moved from 'api.lua' to this new
file, as 'api.lua' was already too big. (Besides, these tests have
nothing to do with the API.)
2025-03-12 13:52:35 -03:00
Roberto Ierusalimschy
b5b1995f29 Checks for type 'int' added to binary header
The structure 'AbsLineInfo' is hard-dumped into binary chunks, and
it comprises two 'int' fields.
2025-03-10 15:21:32 -03:00
Roberto Ierusalimschy
ee99452158 Error object cannot be nil
Lua will change a nil as error object to a string message, so that it
never reports an error with nil as the error object.
2025-02-28 14:53:58 -03:00
Roberto Ierusalimschy
127a8e80fe '__close' gets no error object if there is no error
Instead of receiving nil as a second argument, __close metamethods are
called with just one argument when there are no errors.
2025-02-28 10:10:27 -03:00
Roberto Ierusalimschy
f9e35627ed 'lua_State.nci' must be an integer
Lua can easily overflow an unsigned short counting nested calls.
(The limit to this value is the maximum stack size, LUAI_MAXSTACK,
which is currently 1e6.)
2025-02-26 11:31:10 -03:00
Roberto Ierusalimschy
ceac82f78b Details
Comments, small changes in the manual, an extra test for errors in
error handling, small changes in tests.
2025-02-26 11:29:54 -03:00
Roberto Ierusalimschy
39a14ea7d7 CallInfo bit CIST_CLSRET broken in two
Since commit f407b3c4a, it was being used for two distinct (and
incompatible) meanings:
A: Function has TBC variables (now bit CIST_TBC)
B: Interpreter is closing TBC variables (original bit CIST_CLSRET)

B implies A, but A does not imply B.
2025-01-28 11:45:45 -03:00
Roberto Ierusalimschy
7d7ae8781e Parameters for 'lua_createtable' back to int
Tables don't accept sizes larger than int.
2025-01-21 13:33:59 -03:00
Roberto Ierusalimschy
664bda02ba fixing 'lua_status' in panic.
'luaD_throw' may call 'luaE_resetthread', which returns an error code
but clears 'L->status'; so, 'luaD_throw' should set that status again.
2025-01-16 16:07:39 -03:00
Roberto Ierusalimschy
2d8d5c74b5 Details
New year (2024->2025), typos in comments
2025-01-16 11:51:16 -03:00
Roberto Ierusalimschy
3cdd49c94a Fixed conversion warnings from clang
Plus some other details. (Option '-Wuninitialized' was removed from
the makefile because it is already enabled by -Wall.)
2025-01-14 16:24:46 -03:00
Roberto Ierusalimschy
7ca3c40b50 Another way to compile goto's
The compilation of a goto or a label just create an entry and generate
boilerplate code for the gotos. As we don't know yet whether it needs a
CLOSE, we code a jump followed by a CLOSE, which is then dead code.

When a block ends (and then we know for sure whether there are variables
that need to be closed), we check the goto's against the labels of that
block. When closing a goto against a label, if it needs a CLOSE, the
compiler swaps the order of the jump and the CLOSE, making the CLOSE
active.
2025-01-10 13:54:51 -03:00
Roberto Ierusalimschy
25a491fe34 OP_SELF restricted to constant short strings
Optimize this opcode for the common case. For long names or method
calls after too many constants, operation can be coded as a move
followed by 'gettable'.
2024-12-11 13:56:03 -03:00
Roberto Ierusalimschy
002beeebe7 New way to keep hints for table length
Instead of using 'alimit' for keeping the size of the array and at
the same time being a hint for '#t', a table now keeps these two
values separate. The Table structure has a field 'asize' with the
size of the array, while the length hint is kept in the array itself.
That way, tables with no array part waste no space with that field.
Moreover, the space for the hint may have zero cost for small arrays,
if the array of tags plus the hint still fits in a single word.
2024-11-29 17:26:20 -03:00
Roberto Ierusalimschy
682efe2678 Change to macro 'LUAI_TRY'
The call to 'f' is done by the macro, to give it more flexibility.
2024-11-25 15:47:08 -03:00
Roberto Ierusalimschy
50c7c915ee Debug information about extra arguments from __call
'debug.getinfo' can return number of extra arguments added to a call by
a chain of __call metavalues. That information is being used to improve
error messages about errors in these extra arguments.
2024-11-19 14:09:18 -03:00
Roberto Ierusalimschy
b117bdb344 Counter for length of chains of __call metamethods
This counter will allow (in a later commit) error messages to correct
argument numbers in functions called through __call metamethods.
2024-11-16 12:00:28 -03:00
Roberto Ierusalimschy
9a91fe1640 Add extra size when resizing tables with deleted keys
Without this extra space, sequences of insertions/deletions (and
some other uses) can have unpexpected low performances.  See the
added tests for an example, and *Mathematical Models to Analyze Lua
Hybrid Tables and Why They Need a Fix* (Martínez, Nicaud, Rotondo;
arXiv:2208.13602v2) for detais.
2024-11-14 11:48:25 -03:00
Roberto Ierusalimschy
2491b87c10 New rule for size of array part
Array part needs 1/3 of its elements filled, instead of 1/2.
Array entries use ~1/3 the memory of hash entries, so this new rule
still ensures that array parts do not use more memory than keeping
the values in the hash, while allowing more uses of the array part,
which is more efficient than the hash.
2024-11-13 13:37:24 -03:00
Roberto Ierusalimschy
853311e5b1 Table rehash can resize only the hash part
If there are no integer keys outside the array part, there is no
reason to resize it, saving the time to count its elements.  Moreover,
assignments to non-integer keys will not collapse a table created with
'table.create'.
2024-10-28 10:54:36 -03:00
Roberto Ierusalimschy
258355734d Better support in 'ltests' for tracing the GC 2024-10-21 15:18:20 -03:00
Roberto Ierusalimschy
e4f418f07c Local declaration in the REPL generates a warning 2024-09-27 10:00:35 -03:00
Roberto Ierusalimschy
3e88b72b8e A return can have at most 254 values 2024-08-19 18:39:25 -03:00
Roberto Ierusalimschy
8b752ddf14 Bug: wrong code gen. for indices with comparisons
In function 'luaK_exp2val', used to generate code for indices: Macro
'hasjumps' does not consider the case when the whole expression is a
"jump" (a test). In all other of its uses, the surrounding code ensures
that the expression cannot be VJMP.
2024-08-17 12:47:28 -03:00