Commit Graph

227 Commits

Author SHA1 Message Date
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
934e77a286 Details
- Better comments about short strings in opcodes.
- luaH_newkey made static.
2023-05-15 10:07:25 -03:00
Roberto Ierusalimschy
1de2f31694 Corrected support for 16-bit systems
We still need access to a 16-bit system to correctly test
these changes.
2023-03-09 11:10:04 -03:00
Roberto Ierusalimschy
bef250eb8d Details
Comments and small improvements in the manual.
2021-03-29 11:47:12 -03:00
Roberto Ierusalimschy
31925e4cc2 Details
Added documentation and asserts that constants for arithmetic opcodes
must be numbers.
2021-02-24 11:30:46 -03:00
Roberto Ierusalimschy
c23cc86c54 Details
- After converting a generic GCObject to a specific type ('gco2*'),
  avoid using the original GCObject (to reduce aliasing).
- Small corrections in comments in 'lopcodes.h'
- Added tests about who calls __close metamethods
2020-10-12 12:29:09 -03:00
Roberto Ierusalimschy
0ddc0f47bd Several details about 5.4.0 rc1
Corrected several small details: added 'const', adjusts in tabs x
spaces, removed unused #includes and #defines, misspellings, etc.
2020-04-23 14:48:15 -03:00
Roberto Ierusalimschy
9e0a8475cd Added 'simplesect' sections to the manual
'simplesect' encloses the introductory text of sections with
subsections, so that each section either is all text or is all
subsections. (This commit also corrects a small brace error in the
manual and extra spaces/tabs in some other files.)
2020-04-13 13:42:40 -03:00
Roberto Ierusalimschy
9b7987a9d1 OP_LOADFALSE broken in two instructions 2020-02-11 11:12:33 -03:00
Roberto Ierusalimschy
46c3587a6f Clearer distinction between types and tags
LUA_T* represents only types; tags (types + Variants) are represented
by LUA_V* constants.
2020-01-31 11:09:53 -03:00
Roberto Ierusalimschy
5ff408d218 Changed internal representation of booleans
Instead of an explicit value (field 'b'), true and false use different
tag variants. This avoids reading an extra field and results in more
direct code. (Most code that uses booleans needs to distinguish between
true and false anyway.)
2020-01-06 11:38:31 -03:00
Roberto Ierusalimschy
490ecfcaa1 Better comments about the use of 'k' in opcodes 2019-12-05 12:59:42 -03:00
Roberto Ierusalimschy
5f83fb6582 Details 2019-11-18 14:54:06 -03:00
Roberto Ierusalimschy
1499680f9e Comments in 'lopcodes.h'
Both 'R' and 'K' are arrays, so the comments should use square
brackets to index them.
2019-11-07 10:57:57 -03:00
Roberto Ierusalimschy
b2a580bdb1 Janitorial work
- Several details in 'lcode.c'
- A few more tests for code generation
- Bug in assert in 'lcode.c' ("=" x "==")
- Comments in 'lopcodes.h' and 'ltable.c'
2019-10-01 17:24:37 -03:00
Roberto Ierusalimschy
6b2e202df5 Janitorial work in 'lcode.c' 2019-09-19 14:29:21 -03:00
Roberto Ierusalimschy
91dad09f65 Removed arithmetic opcodes with immediate operand
The difference in performance between immediate operands and K operands
does not seem to justify all those extra opcodes. We only keep OP_ADDI,
due to its ubiquity and because the difference is a little more relevant.
(Later, OP_SUBI will be implemented by OP_ADDI, negating the constant.)
2019-09-10 13:20:03 -03:00
Roberto Ierusalimschy
4518e5df24 Added macro 'testMMMode'
Macro 'testMMMode' checks whether opcode is an MM opcode.
2019-09-06 14:14:11 -03:00
Roberto Ierusalimschy
df13f25948 First version of OP_MMBIN opcodes
In arithmetic/bitwise operators, the call to metamethods is made
in a separate opcode following the main one. (The main
opcode skips this next one when the operation succeeds.) This
change reduces slightly the size of the binary and the complexity
of the arithmetic/bitwise opcodes. It also simplfies the treatment
of errors and yeld/resume in these operations, as there are much
fewer cases to consider. (Only OP_MMBIN/OP_MMBINI/OP_MMBINK,
instead of all variants of all arithmetic/bitwise operators.)
2019-08-27 13:59:39 -03:00
Roberto Ierusalimschy
4846f7e3bb Micro optimization in OP_RETURN and OP_TAILCALL
Many functions are vararg but create no upvalues, so it is better
to separate the tests for these two kinds of "extra work".
2019-07-16 15:44:37 -03:00
Roberto Ierusalimschy
758c1ef445 Unification of size representation in OP_NEWTABLE and OP_SETLIST
Opcodes OP_NEWTABLE and OP_SETLIST use the same representation to
store the size of the array part of a table. This new representation
can go up to 2^33 (8 + 25 bits).
2019-07-15 14:59:35 -03:00
Roberto Ierusalimschy
1fb4d53925 OP_NEWTABLE keeps exact size of arrays
OP_NEWTABLE is followed by an OP_EXTRAARG, so that it can keep
the exact size of the array part of the table to be created.
(Functions 'luaO_int2fb'/'luaO_fb2int' were removed.)
2019-07-12 16:13:50 -03:00
Roberto Ierusalimschy
e888976bc6 Details (typos in comments) 2019-07-05 15:03:15 -03:00
Roberto Ierusalimschy
279c3a6961 A few changes in tests about number of bits in integers
- The preprocessor must work with at least 'long', and therefore must
do shifts of up to 31 bits correctly.
- Whenever possible, use unsigned types in shifts.
2019-05-13 16:17:21 -03:00
Roberto Ierusalimschy
23e6bac8a0 Keep correct type for immediate operands in comparisons
When calling metamethods for things like 'a < 3.0', which generates
the opcode OP_LTI, the C register tells that the operand was
converted to an integer, so that it can be corrected to float when
calling a metamethod.

This commit also includes some other stuff:
- file 'onelua.c' added to the project
- opcode OP_PREPVARARG renamed to OP_VARARGPREP
- comparison opcodes rewritten through macros
2019-03-22 13:37:17 -03:00
Roberto Ierusalimschy
9b37a4695e New semantics for the integer 'for' loop
The numerical 'for' loop over integers now uses a precomputed counter
to control its number of iteractions. This change eliminates several
weird cases caused by overflows (wrap-around) in the control variable.
(It also ensures that every integer loop halts.)

Also, the special opcodes for the usual case of step==1 were removed.
(The new code is already somewhat complex for the usual case,
but efficient.)
2019-03-19 10:53:18 -03:00
Roberto Ierusalimschy
cf71a5ddc7 Details
Several small improvements (code style, warnings, comments, more tests),
in particular:

- 'lua_topointer' extended to handle strings
- raises an error in 'string.format("%10q")' ('%q' with modifiers)
- in the manual for 'string.format', the term "option" replaced by
  "conversion specifier" (the term used by the C standard)
2019-03-13 13:16:53 -03:00
Roberto Ierusalimschy
84e32ad2eb Added opcodes for arithmetic with K operands
Added opcodes for all seven arithmetic operators with K operands
(that is, operands that are numbers in the array of constants of
the function). They cover the cases of constant float operands
(e.g., 'x + .0.0', 'x^0.5') and large integer operands (e.g.,
'x % 10000').
2018-11-23 12:23:45 -02:00
Roberto Ierusalimschy
7f6f70853c To-be-closed variable in 'for' loop separated from the state
The variable to be closed in a generic 'for' loop now is the
4th value produced in the loop initialization, instead of being
the loop state (the 2nd value produced). That allows a loop to
use a state with a '__toclose' metamethod but do not close it.
(As an example, 'f:lines()' might use the file 'f' as a state
for the loop, but it should not close the file when the loop ends.)
2018-11-07 14:42:05 -02:00
Roberto Ierusalimschy
a006514ea1 Big revamp in the implmentation of labels/gotos
Added restriction that, when a label is created, there cannot be
another label with the same name visible. That allows backward goto's
to be resolved when they are read. Backward goto's get a close if
they jump out of the scope of some variable; labels get a close only
if previous goto to it jumps out of the scope of some upvalue.
2018-10-29 14:26:48 -03:00
Roberto Ierusalimschy
6e9b719694 More uniformity in code generation for 'for' loops
Added new instruction 'OP_TFORPREP' to prepare a generic for loop.
Currently it is equivalent to a jump (but with a format 'iABx',
similar to other for-loop preparing instructions), but soon it will
be the place to create upvalues for closing loop states.
2018-10-26 10:38:50 -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
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
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
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
588dfa4ce5 detail in comment 2018-06-08 16:07:27 -03:00
Roberto Ierusalimschy
03c6a05ec8 no more nil-in-table 2018-04-04 11:23:41 -03:00
Roberto Ierusalimschy
4a1612ff9b new experimental syntax using reserved word 'undef' 2018-03-07 12:55:38 -03:00
Roberto Ierusalimschy
212095a601 new opcodes OP_GTI/OP_GEI 2018-02-21 12:49:32 -03:00
Roberto Ierusalimschy
0682fe8169 some simplifications/optimizations in returns from Lua functions 2018-02-15 13:34:29 -02:00
Roberto Ierusalimschy
b1379936cf vararg back to '...' (but with another implementation)
new implementation should have zero overhead for non-vararg functions
2018-02-09 13:16:06 -02:00
Roberto Ierusalimschy
318a9a5859 new opcode 'PREPVARARG'
(avoids test for vararg function in all function calls)
2018-02-07 13:18:04 -02:00
Roberto Ierusalimschy
73d797ce7e detail
(order of 'OT' and 'IT' bits corresponds with macro 'opmode')
2018-02-07 13:04:41 -02:00
Roberto Ierusalimschy
e2b15aa21d janitor work on casts 2018-01-28 13:13:26 -02:00
Roberto Ierusalimschy
5bd8d388de OP_CONCAT does not move its result (to simplify its execution) 2018-01-27 14:56:33 -02:00
Roberto Ierusalimschy
33e3774f44 keep more opcode arguments byte-aligned 2018-01-09 09:24:12 -02:00
Roberto Ierusalimschy
4676f6599e new macros 'isOT'/'isIT'
(plus exchanged parameters of OP_VARARG to make it similar to other
'isOT' instructions)
2017-12-22 12:16:46 -02:00
Roberto Ierusalimschy
d388c165ef new opcodes 'FORLOOP1'/'FORPREP1' for "basic for" (integer variable
with increment of 1)
2017-12-18 15:53:50 -02:00
Roberto Ierusalimschy
f8c1c1469a some cleaning on signed opcode parameters 2017-12-15 16:53:48 -02:00
Roberto Ierusalimschy
4b6928e7f5 (1 << 31) with signed integer has undefined behavior in C 2017-12-15 16:35:22 -02:00