502 Commits

Author SHA1 Message Date
Roberto I
104b0fc700 Details
- Avoid fixing name "_ENV" in the code
- Small improvements in the manual
2025-12-08 13:09:47 -03:00
Roberto I
a07f6a8241 Functions with vararg tables don't need hidden args.
Vararg functions with vararg tables don't use the arguments hidden in
the stack; therfore, it doesn't need to build/keep them.
2025-11-28 15:12:51 -03:00
Roberto I
f33cc4ddec New conceptual model for vararg
Conceptually, all functions get their vararg arguments in a vararg
table. The storing of vararg arguments in the stack is always treated
as an optimization.
2025-11-26 11:18:29 -03:00
Roberto I
e44f3a2ffc Global initialization checks name conflict
Initialization "global a = 10" raises an error if global 'a' is already
defined, that is, it has a non-nil value.
2025-11-08 11:43:42 -03:00
Roberto I
d342328e5b Vertical bar removed from syntax of vararg table
The syntax 'function foo (a, b, ...arg)' is already used by JavaScript
for this same semantics, so it seems natural to use the same notation in
Lua.
2025-10-30 11:07:01 -03:00
Roberto I
d4eff00234 Fixed initialization of global variables
When calling 'luaK_storevar', the 'expdesc' for the variable must be
created before the one for the expression, to satisfy the assumptions
for register allocation. So, in a statement like 'global a = exp', where
'a' is actually '_ENV.a', this variable must be handled before the
initializing expression 'exp'.
2025-10-29 13:14:48 -03:00
Roberto I
3347c9d32d Initialization of too many locals break assertion
The check for limit of local variables is made after generating code to
initialize them. If there are too many local variables not initialized,
the coding of instruction OP_LOADNIL could overflow an argument.
2025-10-10 13:22:19 -03:00
Roberto I
25c54fe60e Optimization for vararg tables
A vararg table can be virtual. If the vararg table is used only as
a base in indexing expressions, the code does not need to create an
actual table for it. Instead, it compiles the indexing expressions
into direct accesses to the internal vararg data.
2025-09-24 18:33:08 -03:00
Roberto I
8fb1af0e33 Varag parameter is a new kind of variable
To allow some optimizations on its use.
2025-09-17 16:07:48 -03:00
Roberto I
140b672e2e Vararg table
Not yet optimized nor documented.
2025-09-16 13:26:24 -03:00
Roberto I
f87416f1a3 Added limit to number of elements in a constructor
The reasoning in commit 519c57d5 is wrong: A sequence of nils generates
several fields with just one OP_LOADNIL.
2025-08-27 10:30:54 -03:00
Roberto I
5b179eaf6a Details 2025-08-09 15:08:53 -03:00
Roberto Ierusalimschy
942c10a5e3 Optional initialization for global declarations 2025-07-08 13:33:57 -03:00
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
519c57d597 Removed uneeded check in parser
In a constructor, each field generates at least one opcode, and the
number of opcodes is limited by INT_MAX. Therefore, the counters for
number of fields cannot exceed this limit. (The current limit for
items in the hash part of a table has a limit smaller than INT_MAX.
However, as long as there are no overflows, the logic for table
resizing will handle that limit.)
2025-06-04 09:54:31 -03:00
Roberto Ierusalimschy
c15543b9af Bug: check for constructor overflow in [exp] fields
The check for constructor overflow was considering only fields with
explicit names, ignoring fields with syntax '[exp]=exp'.
2025-05-20 17:50:56 -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
ded2ad2d86 Slightly faster way to check for "global" 2025-05-16 14:51:07 -03:00
Roberto Ierusalimschy
3fb7a77731 Internalized string "break" kept by the parser
The parser uses "break" as fake label to compile "break" as "goto
break". To avoid producing this string at each use, it keeps it
available in its state.
2025-05-15 12:43:37 -03:00
Roberto Ierusalimschy
fded0b4a84 Remove compat code in parser when not needed 2025-05-13 11:50:43 -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
5b1ab8efdc 'expdesc' doesn't depend on 'actvar' for var. info.
In preparation for 'global *', the structure 'expdesc' does not point
to 'actvar.arr' for information about global variables.
2025-05-11 11:51:58 -03:00
Roberto Ierusalimschy
7ade155762 Janitorial work on casts 2025-05-08 15:18:57 -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
50fd8d03c3 Function 'luaK_semerror' made vararg
All calls to 'luaK_semerror' were using 'luaO_pushfstring' to create
the error messages.
2025-04-17 14:58:55 -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
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
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
9b72355f99 USHRT_MAX changed to SHRT_MAX
USHRT_MAX does not fit in an 'int' in 16-bit systems.
2024-09-19 19:06:16 -03:00
Roberto Ierusalimschy
75620b45ae 'lcode.c' can use 'checklimit', too 2024-08-20 15:15:23 -03:00
Roberto Ierusalimschy
0acd55898d Added gcc option '-Wconversion'
No warnings for standard numerical types. Still pending alternative
numerical types.
2024-07-27 13:32:59 -03:00
Roberto Ierusalimschy
c403e456b6 New instruction format for SETLIST/NEWTABLE
New instruction format 'ivABC' (a variant of iABC where parameter vC has
10 bits) allows constructors of up to 1024 elements to be coded without
EXTRAARG.
2024-06-28 11:18:14 -03:00
Roberto Ierusalimschy
9904c253da Flexible limit for use of registers by constructors
Instead of a fixed limit of 50 registers (which, in a bad worst case,
can limit the nesting of constructors to 5 levels), the compiler
computes an individual limit for each constructor based on how many
registers are available when it runs. This limit then controls the
frequency of SETLIST instructions.
2024-06-27 11:24:27 -03:00
Roberto Ierusalimschy
55ac40f859 Cleaning of llimits.h
Several definitions that don't need to be "global" (that is, that
concerns only specific parts of the code) moved out of llimits.h,
to more appropriate places.
2024-06-20 13:43:33 -03:00
Roberto Ierusalimschy
f33cda8d6e New macro 'getlstr'
Accesses content and length of a 'TString'.
2023-08-30 11:26:16 -03:00
Roberto Ierusalimschy
96f7714237 Field 'Proto.is_vararg' uses only one bit
So that the other bits can be used for other purposes.
2023-08-30 10:44:28 -03:00
Roberto Ierusalimschy
c815c2f0eb Merge branch 'master' into nextversion 2023-08-23 15:14:03 -03:00
Roberto Ierusalimschy
5ab6a5756b Bug: Wrong line number for function calls 2023-08-23 13:49:27 -03:00
Roberto Ierusalimschy
ab6a949522 Merge branch 'master' into nextversion 2023-06-22 11:41:48 -03:00
Roberto Ierusalimschy
e15f1f2bb7 Details
Typos in comments and details in the manual.
2023-04-18 09:44:10 -03:00
Roberto Ierusalimschy
7d4c7ae2af Changes in opcodes for generic 'for'
Again, as the control variable is read only, the code doesn't need
to keep an internal copy of it.
2022-12-22 13:52:53 -03:00
Roberto Ierusalimschy
873588dc5f Simplification in opcodes for numerical 'for'
As the control variable is read only, the code doesn't need to keep
an internal copy of it.
2022-12-21 15:35:40 -03:00