Commit Graph

5706 Commits

Author SHA1 Message Date
Roberto Ierusalimschy
d9e0f64a5d Small changes in the manual 2025-03-12 15:45:39 -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
808976bb59 Small correction in 'traverseweakvalue'
After a weak table is traversed in the atomic phase, if it does not
have white values ('hasclears') it does not need to be retraversed
again. (Comments were correct, but code did not agree with them.)
2025-03-12 12:35:36 -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
cb88c1cd5d Detail
Added macro LUA_FAILISFALSE to make easier to change the fail value
from nil to false.
2025-02-28 15:48:45 -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
e5f4927a0b Array sizes in undump changed from unsigned to int
Array sizes are always int and are dumped as int, so there is no reason
to read them back as unsigned.
2025-02-20 10:09:04 -03:00
Roberto Ierusalimschy
cd38fe8cf3 Added macro LUAI_STRICT_ADDRESS
By default, the code assumes it is safe to use a dealocated pointer
as long as the code does not access it.
2025-02-18 17:02:32 -03:00
Roberto Ierusalimschy
fa1382b5cd Main thread is a regular field of global_State
They were already allocated as a single block, so there is no need
for the global_State to point to its main thread.
2025-01-31 13:51:38 -03:00
Roberto Ierusalimschy
d1e677c52b New type 'TStatus' for thread status/error codes 2025-01-30 11:41:39 -03:00
Roberto Ierusalimschy
f7439112a5 Details (in test library)
- Added support for negative stack indices in the "C interpreter"
- Improved format when printing values
2025-01-29 14:47:06 -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
c4e7cdb541 Renaming two new functions
'lua_numbertostrbuff' -> 'lua_numbertocstring'
'lua_pushextlstring' -> 'lua_pushexternalstring'
2025-01-27 16:09:55 -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
724012d3d0 Small change in macro 'isvalid'
The "faster way" to check whether a value is not 'nilvalue' is not
faster. (Both forms entail one memory access.)
2025-01-16 16:11:49 -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
10e931da82 Error "break outside loop" made a syntax error
Syntax errors are easier to handle than semantic errors.
2025-01-13 11:23:07 -03:00
Roberto Ierusalimschy
4b107a8776 Details in lparser.c
Added comments so that all braces pair correctly. (The parser has
several instances of unmatched braces as characters ('{' or '}'), which
hinders matching regular braces in the code.)
2025-01-10 15:27:17 -03:00
Roberto Ierusalimschy
429761d7d2 New optimization option for testing
Using gcc's option '-Og' (instead of '-O0') for testing/debugging.
2025-01-10 15:14:01 -03:00
Roberto Ierusalimschy
915c29f8bd Improvements in the manual
Plus details
2025-01-10 15:11:54 -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
8a3a49250c Detail
Small improvement in line-tracing for internal debugging.
2025-01-06 14:44:06 -03:00
Roberto Ierusalimschy
1ec251e091 Detail (debugging aid)
When compiling with option HARDMEMTESTS, every creation of a new key
in a table forces an emergency GC.
2025-01-06 12:41:39 -03:00
Roberto Ierusalimschy
5894ca7b95 Scanner doesn't need to anchor reserved words 2024-12-30 16:53:51 -03:00
Roberto Ierusalimschy
abf8b1cd4a Small optimization in 'luaH_psetshortstr'
Do not optimize only for table updates (key already present).
Creation of new short keys in new tables can be quite common in
programs that create lots of small tables, for instance with
constructors like {x=e1,y=e2}.
2024-12-28 15:05:01 -03:00
Roberto Ierusalimschy
2a307f898b When parser reuses constants, only floats can collide
Ensure that float constants never use integer keys, so that only
floats can collide in 'k2proto'.
2024-12-28 15:03:48 -03:00
Roberto Ierusalimschy
f81d0bbd4f Detail in 'luaD_inctop'
Protect stack top before possible stack reallocation. (In the current
implementation, a stack reallocation cannot call an emergency
collection, so there is no bug, but it is safer not to depend on that.)
2024-12-17 13:36:12 -03:00
Roberto Ierusalimschy
1c40ff9faa Scanner and parser use different tables for constants
Moreover, each function being parsed has its own table.

The code is cleaner when each table is used for one specific purpose:
The scanner uses its table to anchor and unify strings, mapping strings
to themselves; the parser uses it to reuse constants in the code,
mapping constants to their indices in the constant table. A different
table for each task avoids false collisions.
2024-12-17 11:23:22 -03:00
Roberto Ierusalimschy
7538f3886d 'addk' broken in two functions 2024-12-16 14:13:49 -03:00
Roberto Ierusalimschy
412e9a4d95 'luaH_fastseti' uses 'checknoTM'
The extra check in checknoTM (versus only checking whether there is a
metatable) is cheap, and it is not that uncommon for a table to have a
metatable without a __newindex metafield.
2024-12-11 15:32:43 -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
b4b616bdf2 Rehash reinserts elements with "lighter" functions
When reinserting elements into a table during a rehash, the code does
not need to invoke all the complexity of a full 'luaH_set':

- The table has space for all keys.
- The key cannot exist in the new hash.
- The keys are valid (not NaN nor nil).
- The keys are normalized (1.0 -> 1).
- The values cannot be nil.
- No barrier needed (the table already pointed to the key and value).
2024-12-05 17:34:08 -03:00
Roberto Ierusalimschy
bb93f04d87 Refactoring of 'luaH_newkey'
Function broke in two and some checks moved to the caller. (We may
want to call it without the checks.)
2024-12-05 14:27:58 -03:00
Roberto Ierusalimschy
975d4e0592 Fix in the definition of 'sizeLclosure'
The array at the end of a Lua closure has pointers to upvalues, not
to tagged values. This bug cannot cause any issue: The ISO C standard
requires that all pointers to structures have the same representation,
so sizeof(TValue*) must be equal to sizeof(UpVal*).
2024-12-03 10:53:46 -03:00
Roberto Ierusalimschy
04e495403b New function 'lua_printvalue' for internal debugging 2024-12-02 11:19:03 -03:00
Roberto Ierusalimschy
62afbc6bfc Details
Added two warnings to the makefile.
2024-11-29 17:39:20 -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
9329eeac3b Avoid an extra call to 'concretesize' in 'resizearray' 2024-11-27 18:37:29 -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
f12ce4029d More integration of 'nresults' into 'callstatus' 2024-11-15 15:25:11 -03:00
Roberto Ierusalimschy
a4762b6ffe 'objsize' returns 'l_mem'
Sums of size_t may not fit in a size_t.
2024-11-15 12:04:53 -03:00
Roberto Ierusalimschy
d4247befa1 New macro 'assert_code'
It allows code that is only used by assertions but that are not
assertions (e.g., declaration of a variable used in a later assertion).
2024-11-15 11:57:18 -03:00