Roberto Ierusalimschy
35296e1fde
Details
...
comments and other janitorial work.
2018-11-22 13:56:04 -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
5e76a4fd31
New macros for arithmetic/bitwise operations in 'luaV_execute'
...
The repetitive code of the arithmetic and bitwise operators in
the main iterpreter loop was moved to appropriate macros.
(As a detail, the function 'luaV_div' was renamed 'luaV_idiv',
as it does an "integer division" (floor division).
2018-11-05 16:10:42 -02:00
Roberto Ierusalimschy
e8c779736f
Removed internal cache for closures
...
The mechanism of "caching the last closure created for a prototype to
try to reuse it the next time a closure for that prototype is created"
was removed. There are several reasons:
- It is hard to find a natural example where this cache has a measurable
impact on performance.
- Programmers already perceive closure creation as something slow,
so they tend to avoid it inside hot paths. (Any case where the cache
could reuse a closure can be rewritten predefining the closure in some
variable and using that variable.)
- The implementation was somewhat complex, due to a bad interaction
with the generational collector. (Typically, new closures are new,
while prototypes are old. So, the cache breaks the invariant that
old objects should not point to new ones.)
2018-11-01 13:21:00 -03:00
Roberto Ierusalimschy
947a372f58
State in generic 'for' acts as a to-be-closed variable
...
The implicit variable 'state' in a generic 'for' is marked as a
to-be-closed variable, so that the state will be closed as soon
as the loop ends, no matter how.
Taking advantage of this new facility, the call 'io.lines(filename)'
now returns the open file as a second result. Therefore,
an iteraction like 'for l in io.lines(name)...' will close the
file even when the loop ends with a break or an error.
2018-10-31 14:54:45 -03:00
Roberto Ierusalimschy
e073cbc2e5
Better error messages for invalid operands in numeric 'for'
...
"Better" and similar to error messages for invalid function arguments.
*old message: 'for' limit must be a number
*new message: bad 'for' limit (number expected, got table)
2018-10-30 15:46:56 -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
41c800b352
Closing methods should not interfere with returning values
...
A closing method cannot be called in its own stack slot, as there may
be returning values in the stack after that slot, and the call would
corrupt those values. Instead, the closing method must be copied to the
top of the stack to be called.
Moreover, even when a function returns no value, its return istruction
still has to have its position (which will set the stack top) after
the local variables, otherwise a closing method might corrupt another
not-yet-called closing method.
2018-10-25 12:50:20 -03:00
Roberto Ierusalimschy
3c7dc52909
Handling of memory errors when creating to-be-closed upvalues
2018-10-18 16:15:09 -03:00
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
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
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
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
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
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
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
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
02ed0b2c30
in 'luaD_poscall', there is no need to compute 'firstResult' when 'nres==0'
2018-05-22 09:02:36 -03:00
Roberto Ierusalimschy
e64e20ac81
minimizing the code ran by 'vmfetch' + no more 'vra'
...
(the code is simpler without 'vra' and conversion is a no-op)
2018-05-02 15:17:59 -03:00
Roberto Ierusalimschy
03c6a05ec8
no more nil-in-table
2018-04-04 11:23:41 -03:00
Roberto Ierusalimschy
3d0b5edfe4
using unsigned comparison in 'l_intfitsf' (avoids one comparison)
2018-04-02 14:52:07 -03:00
Roberto Ierusalimschy
7b0b6b3b39
cannot use 'defined' inside a macro +
...
call to 'luaT_keydef' must be protected
2018-03-16 11:21:20 -03:00
Roberto Ierusalimschy
4a1612ff9b
new experimental syntax using reserved word 'undef'
2018-03-07 12:55:38 -03:00
Roberto Ierusalimschy
62a392ff46
using jump tables when available
2018-03-02 15:59:19 -03:00
Roberto Ierusalimschy
ef8263f81f
better names for macros for tags and types.
...
rttype -> rawtt; ttyperaw -> withvariant; ttype -> ttypetag;
tnov -> ttype
2018-02-26 11:16:05 -03:00
Roberto Ierusalimschy
9243c414d9
first version of empty entries in tables
...
(so that, in the future, tables can contain regular nil entries)
2018-02-23 10:16:18 -03:00
Roberto Ierusalimschy
c72ac048b9
conditional jumps "deunified"
...
(if a jump table is used, the unification may harm jump prediction.)
2018-02-21 16:43:44 -03:00
Roberto Ierusalimschy
212095a601
new opcodes OP_GTI/OP_GEI
2018-02-21 12:49:32 -03:00
Roberto Ierusalimschy
06865aa01d
simpler implementation for 'LTintfloat'/'LEintfloat'
...
+ 'LTfloatint'/'LEfloatint'
2018-02-21 10:47:03 -03:00
Roberto Ierusalimschy
465b474899
small reorganization of 'luaV_flttointeger'/'luaV_tointeger'
2018-02-21 09:54:26 -03:00
Roberto Ierusalimschy
1afd5a152d
more generic way to handle 'gclist'
2018-02-19 17:06:56 -03:00
Roberto Ierusalimschy
49dae52d08
correct way to check stack space for vararg functions
2018-02-17 17:20:00 -02: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
51280ef2ad
call hooks for Lua functions called by 'luaV_execute'
2018-02-06 17:16:56 -02:00
Roberto Ierusalimschy
dc0ab1e8ca
warnings in VS (implicit casts from ptrdiff_t to int)
2018-01-29 14:21:35 -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
d2fb34ac88
'OP_TAILCALL' calling C functions finishes the call and returns
...
(instead of waiting for following 'OP_RETURN')
2018-01-14 15:27:50 -02:00
Roberto Ierusalimschy
ab0a851db4
'luaD_tryfuncTM' can ensure it does not change the stack
2018-01-10 17:19:27 -02:00
Roberto Ierusalimschy
ad960095bf
avoid jumping into a variable scope (C++ does not allow that)
2018-01-09 12:23:40 -02:00
Roberto Ierusalimschy
a9295a2b8e
typos in comments
2017-12-30 18:46:18 -02:00
Roberto Ierusalimschy
cf7eff45f3
keep control of stack top in Lua functions concentrated in 'luaV_execute'
2017-12-28 13:42:57 -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
1d5b885437
when running Lua code, there is no need to keep 'L->top' "correct";
...
set it only when needed.
2017-12-20 12:58:05 -02:00
Roberto Ierusalimschy
3153a41e33
no need to save 'pc' in case of allocation errors
...
(allocation errors do not call message handlers)
2017-12-19 14:18:04 -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
86431a2f1c
new opcodes BANDK/BORK/BXORK. (They do not use immediate operands
...
because, too often, masks in bitwise operations are integers larger
than one byte.)
2017-12-13 16:32:09 -02:00
Roberto Ierusalimschy
c7ee7fe026
new opcodes OP_SHLI/OP_SHRI
2017-12-04 15:41:30 -02:00
Roberto Ierusalimschy
10b8c99bbb
small peephole optimizations
2017-11-30 11:29:18 -02:00
Roberto Ierusalimschy
745eb41993
new opcodes OP_RETURN0/OP_RETURN1
2017-11-29 14:57:36 -02:00
Roberto Ierusalimschy
c766e4103d
'luaV_execute' gets call info as extra argument (it is always
...
available on call sites)
2017-11-29 11:02:17 -02:00
Roberto Ierusalimschy
1a5e8c1014
conditional jumps unified in label "condjump' + new variable 'vra'
...
to avoid excessive use of macro 's2v'
2017-11-28 12:51:00 -02:00
Roberto Ierusalimschy
ff5fe51044
using register 'k' for conditions in tests (we only need one bit there)
2017-11-28 10:58:18 -02:00
Roberto Ierusalimschy
093c16b67b
new opcodes 'OP_LTI' and 'OP_LEI'
2017-11-27 15:44:31 -02:00
Roberto Ierusalimschy
73abfde2ef
small simplifications around 'luaT_callorderTM'
2017-11-23 17:18:10 -02:00
Roberto Ierusalimschy
196c87c9ce
no more 'stackless' implementation; 'luaV_execute' calls itself
...
recursively to execute function calls. 'unroll' continues all
executions suspended by an yield (through a long jump)
2017-11-23 14:41:16 -02:00
Roberto Ierusalimschy
3c230cc825
using 'A' for register instead of 'B' in relational opcodes
...
('R(A)' is already created by default for all instructions.)
2017-11-22 17:15:44 -02:00
Roberto Ierusalimschy
41f2936d8f
new opcode 'OP_EQI' for equality with immediate numbers
2017-11-22 16:41:20 -02:00
Roberto Ierusalimschy
14c3aa12b5
more direct implementation for tail calls.
2017-11-21 12:18:03 -02:00
Roberto Ierusalimschy
f3ca52bfa9
in order comparison opcodes, fast track for floats too
2017-11-20 10:57:39 -02:00
Roberto Ierusalimschy
4c0e36a46e
new instruction 'OP_EQK' (for equality with constants)
2017-11-16 10:59:14 -02:00
Roberto Ierusalimschy
5440b42f43
using 'trap' to stop 'luaV_execute' when necessary (tracing and
...
to update its copy of 'base' when the stack is reallocated)
2017-11-13 13:36:52 -02:00
Roberto Ierusalimschy
32fef60743
detail ('Protect' defined as an expression)
2017-11-08 17:01:02 -02:00
Roberto Ierusalimschy
26679ea35b
new function 'luaV_flttointeger' to convert floats to integers (without
...
string coercions) + string operands to bitwise operations handled
by string metamethods
2017-11-08 12:50:23 -02:00
Roberto Ierusalimschy
c3e5946fb2
new format for JUMP instructions (to allow larger offsets)
2017-11-07 15:20:42 -02:00
Roberto Ierusalimschy
ad0704e40c
back to 'CallInfo' (no gains with its removal)
2017-11-07 11:25:26 -02:00
Roberto Ierusalimschy
93fd67b793
no more 'CallInfo' structure
2017-11-04 10:57:02 -02:00
Roberto Ierusalimschy
7612f7735d
removing uses of 'CallInfo'
2017-11-03 17:33:22 -02:00
Roberto Ierusalimschy
472c560705
no more useful fields in CallInfo
2017-11-03 15:22:54 -02:00
Roberto Ierusalimschy
54eb35a8aa
more fields moved out of 'CallInfo'
2017-11-03 10:12:30 -02:00
Roberto Ierusalimschy
b9e76be8a6
using 'L->func' when possible
2017-11-01 16:20:48 -02:00
Roberto Ierusalimschy
c5482468fd
baby steps to remove 'CallInfo': keeping 'L->func' correct
2017-10-31 15:54:35 -02:00
Roberto Ierusalimschy
a1ef58b3a5
eplicit 1-bit opcode operand 'k'
2017-10-04 18:56:32 -03:00
Roberto Ierusalimschy
8fbe9e3470
new opcodes with immediate integer operand for all arithmetic operations
2017-10-04 12:49:24 -03:00
Roberto Ierusalimschy
bc1b0733b8
avoid the use of bit 'Bk' ('B' will lose this bit soon)
2017-10-01 16:13:43 -03:00
Roberto Ierusalimschy
722bdbe17d
no more 'getBMode'-'getCMode' (imprecise + we will need more space
...
for op mode) + better control of op modes
2017-09-28 13:53:29 -03:00
Roberto Ierusalimschy
1b10033583
new function 'luaT_trybiniTM'
...
to handle tag methods for instructions with immediate integer arguments
2017-09-27 15:59:08 -03:00
Roberto Ierusalimschy
00e728af88
binary operators use R instead of RK
...
faster + nobody uses RK(B), so B can be smaller (freeing one bit
for more opcodes, soon)
2017-09-26 15:14:45 -03:00
Roberto Ierusalimschy
abb17cf19b
new opcode OP_LOADF (load immediate float)
2017-09-19 15:38:14 -03:00
Roberto Ierusalimschy
80d9b09f35
jumps do not close upvalues (to be faster and simpler);
...
explicit instruction to close upvalues; command 'break' not
handled like a 'goto' (to optimize removal of uneeded 'close'
instructions)
2017-09-13 16:50:08 -03:00
Roberto Ierusalimschy
ac65bab25f
jumps in 'for' loops don't need to be signed
2017-08-14 15:33:14 -03:00
Roberto Ierusalimschy
4dff277255
coercion string->number in arithmetic operations moved to string
...
library
2017-07-07 13:34:32 -03:00
Roberto Ierusalimschy
07db10813c
'OP_VARARG' has the vararg parameter as an operand
2017-06-29 12:38:41 -03:00
Roberto Ierusalimschy
f96497397a
new type 'StackValue' for stack elements
...
(we may want to put extra info there in the future)
2017-06-29 12:06:44 -03:00
Roberto Ierusalimschy
d13a3fb070
detail
...
(removed empty spaces at the end of lines)
2017-06-09 16:16:41 -03:00
Roberto Ierusalimschy
b029e7ea20
macro 'luaV_fastget' may need protection ({}) to be used inside
...
'if's
2017-06-01 17:22:33 -03:00
Roberto Ierusalimschy
c25380c28d
details (using proper version of 'setobj')
2017-05-23 09:50:11 -03:00
Roberto Ierusalimschy
de74289049
table field names for dedicated opcodes can be restricted to
...
small strings for slightly faster access
2017-05-18 16:44:19 -03:00
Roberto Ierusalimschy
92b3deaffa
details in OP_CALL + comments
2017-05-18 16:34:39 -03:00
Roberto Ierusalimschy
6d95de83c6
no more field 'base' in CallInfo (base is always equal to 'func + 1',
...
with old/new vararg implementation)
2017-05-13 10:54:47 -03:00
Roberto Ierusalimschy
5c8770f896
back to old-style vararg system (with vararg table collecting extra
...
arguments)
2017-05-13 10:04:33 -03:00
Roberto Ierusalimschy
7647d5d13d
revamp of fast track for table access (table set uses the same
...
macros as table get + new macro for integer keys)
2017-05-11 15:57:46 -03:00
Roberto Ierusalimschy
7184f6343a
more integer fast tracks (for OP_LT, OP_LE, OP_SETTABLE, and OP_GETTABLE)
2017-05-10 14:32:19 -03:00
Roberto Ierusalimschy
ab5a650029
details (direct access to 'Ck' bit in instructions)
2017-05-08 13:08:01 -03:00
Roberto Ierusalimschy
e8757a73e6
'luaV_execute' keeps local copy of program counter and hook mask,
...
to avoid excessive access to globals.
2017-05-05 14:16:11 -03:00
Roberto Ierusalimschy
2376eb6347
barrier for prototype's cache (with new gray list 'protogray' to keep
...
prototypes to have their caches visited again) + constant 'MAXMISS'
2017-05-04 10:32:01 -03:00
Roberto Ierusalimschy
8634b2a011
added 'cachemiss' field to prototype to avoid wasting time checking
...
hits that fail too often
2017-04-30 17:43:26 -03:00