aboutsummaryrefslogtreecommitdiff
path: root/lvm.c (follow)
Commit message (Collapse)AuthorAgeFilesLines
...
* Don't use tointegerns when luaV_tointegerns will doRoberto Ierusalimschy2021-02-241-2/+7
| | | | | | | | Some places don't need the "fast path" macro tointegerns, either because speed is not essential (lcode.c) or because the value is not supposed to be an integer already (luaV_equalobj and luaG_tointerror). Moreover, luaV_equalobj should always use F2Ieq, even if Lua is compiled to "round to floor".
* DetailsRoberto Ierusalimschy2021-02-241-2/+2
| | | | | Added documentation and asserts that constants for arithmetic opcodes must be numbers.
* Broadening the use of branch hintsRoberto Ierusalimschy2021-02-241-19/+20
| | | | | | More uses of macros 'likely'/'unlikely' (renamed to 'l_likely'/'l_unlikely'), both in range (extended to the libraries) and in scope (extended to hooks, stack growth).
* New implementation for to-be-closed variablesRoberto Ierusalimschy2021-02-091-4/+2
| | | | | | | | To-be-closed variables are linked in their own list, embedded into the stack elements. (Due to alignment, this information does not change the size of the stack elements in most architectures.) This new list does not produce garbage and avoids memory errors when creating tbc variables.
* Fixed some bugs around stack reallocationRoberto Ierusalimschy2021-02-051-0/+2
| | | | Long time without using HARDSTACKTESTS...
* Allow yields inside '__close' metamethodsRoberto Ierusalimschy2021-01-131-3/+7
| | | | | | | Initial implementation to allow yields inside '__close' metamethods. This current version still does not allow a '__close' metamethod to yield when called due to an error. '__close' metamethods from C functions also are not allowed to yield.
* Cleaner handling of errors in '__close' metamethodsRoberto Ierusalimschy2020-12-281-1/+1
| | | | | Instead of protecting each individual metamethod call, protect the entire call to 'luaF_close'.
* Changes in the API of 'luaH_set' and related functionsRoberto Ierusalimschy2020-12-041-4/+1
| | | | | Functions to set values in a table (luaH_set, luaH_newkey, etc.) receive the new value, instead of returning a slot where to put the value.
* Fixed wrong trace of vararg functionsRoberto Ierusalimschy2020-10-191-20/+25
| | | | | Trace of vararg functions was skipping an instruction when returning from a call. (Bug introduced by commit 5d8ce05b3.)
* No more field 'lua_State.stacksize'Roberto Ierusalimschy2020-10-121-1/+1
| | | | | | The stack size is derived from 'stack_last', when needed. Moreover, the handling of stack sizes is more consistent, always excluding the extra space except when allocating/deallocating the array.
* Correct handling of 'luaV_execute' invocationsRoberto Ierusalimschy2020-10-121-12/+13
| | | | | | | | | The previous stackless implementations marked all 'luaV_execute' invocations as fresh. However, re-entering 'luaV_execute' when resuming a coroutine should not be a fresh invocation. (It works because 'unroll' called 'luaV_execute' for each call entry, but it was slower than letting 'luaV_execute' finish all non-fresh invocations.)
* Revision of stackless implementationRoberto Ierusalimschy2020-10-121-3/+3
| | | | | | - more organized handling of 'nCcalls' - comments - deprecation of 'setcstacklimit'
* Back to a stackless implementationRoberto Ierusalimschy2020-10-121-7/+20
| | | | | | | | | | | | | A "with stack" implementation gains too little in performance to be worth all the noise from C-stack overflows. This commit is almost a sketch, to test performance. There are several pending stuff: - review control of C-stack overflow and error messages; - what to do with setcstacklimit; - review comments; - review unroll of Lua calls.
* Fixed bug: invalid 'oldpc' when returning to a functionRoberto Ierusalimschy2020-07-171-1/+1
| | | | | | | | | | The field 'L->oldpc' is not always updated when control returns to a function; an invalid value can seg. fault when computing 'changedline'. (One example is an error in a finalizer; control can return to 'luaV_execute' without executing 'luaD_poscall'.) Instead of trying to fix all possible corner cases, it seems safer to be resilient to invalid values for 'oldpc'. Valid but wrong values at most cause an extra call to a line hook.
* Fixed bug of access violation in finalizersRoberto Ierusalimschy2020-07-081-4/+3
| | | | | | Errors in finalizers need a valid 'pc' to produce an error message, even if the error is not propagated. Therefore, calls to the GC (which may call finalizers) inside luaV_execute must save the 'pc'.
* Fixed bugs of stack reallocation x GCRoberto Ierusalimschy2020-07-071-1/+1
| | | | | | | | Macro 'checkstackGC' was doing a GC step after resizing the stack; the GC could shrink the stack and undo the resize. Moreover, macro 'checkstackp' also does a GC step, which could remove the preallocated CallInfo when calling a function. (Its name has been changed to 'checkstackGCp' to emphasize that it calls the GC.)
* 'luaV_concat' can "concat" one single valueRoberto Ierusalimschy2020-07-031-5/+4
| | | | | Several of its callers needed that case and had to do the check themselves.
* DetailsRoberto Ierusalimschy2020-02-271-6/+7
| | | | | Several details in code (e.g., moving a variable to the most inner scope that encloses its uses), comments, parameter names, extra tests.
* OP_LOADFALSE broken in two instructionsRoberto Ierusalimschy2020-02-111-1/+5
|
* Clearer distinction between types and tagsRoberto Ierusalimschy2020-01-311-12/+12
| | | | | LUA_T* represents only types; tags (types + Variants) are represented by LUA_V* constants.
* Changed internal representation of booleansRoberto Ierusalimschy2020-01-061-7/+12
| | | | | | | 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.)
* Comment about LUA_COMPAT_LT_LE moved to proper placeRoberto Ierusalimschy2019-12-101-6/+3
|
* Simplifications in 'op_arith*' family of macrosRoberto Ierusalimschy2019-12-051-47/+27
|
* Using an enumeration for float->integer coercion modesRoberto Ierusalimschy2019-12-051-14/+11
|
* 'l_mathlim' renamed to 'l_floatatt'Roberto Ierusalimschy2019-12-051-1/+1
| | | | That macro is applied to float attributes, not to limits.
* Better comments about the use of 'k' in opcodesRoberto Ierusalimschy2019-12-051-11/+11
|
* Code reorganization for opcodes OP_FORPREP and OP_FORLOOPRoberto Ierusalimschy2019-12-041-75/+116
| | | | | Parts of the code for opcodes OP_FORPREP and OP_FORLOOP were moved to functions outside the interpreter loop.
* DetailsRoberto Ierusalimschy2019-11-181-1/+1
|
* Fixed bug in tail calls of __call chainsRoberto Ierusalimschy2019-10-281-1/+2
| | | | | A tail call of a __call chain (a __call metamethod that itself is also not a function) was being perfomed as a regular call.
* Fixed warnings from Keil compilerRoberto Ierusalimschy2019-10-251-6/+3
|
* Removed arithmetic opcodes with immediate operandRoberto Ierusalimschy2019-09-101-24/+0
| | | | | | | 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.)
* Undo change in the handling of 'L->top' (commit b80077b8f3)Roberto Ierusalimschy2019-08-291-10/+9
| | | | | | With MMBIN instructions, there are fewer opcodes that need to update 'L->top', so that change does not seem to pay for the increased complexity.
* Use of 'MMBIN' opcodes extended to shift operatorsRoberto Ierusalimschy2019-08-281-62/+40
| | | | Plus, this commit removes useless 'tm' parameters in 'op_*' macros.
* First version of OP_MMBIN opcodesRoberto Ierusalimschy2019-08-271-39/+46
| | | | | | | | | | | 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.)
* Fixed missing case in 'luaV_finishOp'Roberto Ierusalimschy2019-08-271-1/+1
| | | | | A metamethod call like '1 << a' was not being properly resumed if it got yielded.
* Fixed bug when yiedling inside OP_ADDK opcodeRoberto Ierusalimschy2019-08-211-0/+3
| | | | | | The family of opcodes OP_ADDK (arithmetic operators with K constant) were not being handled in 'luaV_finishOp', which completes their task after an yield.
* To-be-closed variables must be closed on initializationRoberto Ierusalimschy2019-07-311-4/+2
| | | | | | | | | When initializing a to-be-closed variable, check whether it has a '__close' metamethod (or is a false value) and raise an error if if it hasn't. This produces more accurate error messages. (The check before closing still need to be done: in the C API, the value is not constant; and the object may lose its '__close' metamethod during the block.)
* Change in the handling of 'L->top' when calling metamethodsRoberto Ierusalimschy2019-07-261-20/+24
| | | | | | | Instead of updating 'L->top' in every place that may call a metamethod, the metamethod functions themselves (luaT_trybinTM and luaT_callorderTM) correct the top. (When calling metamethods from the C API, however, the callers must preserve 'L->top'.)
* Small corrections when setting 'L->top'Roberto Ierusalimschy2019-07-251-4/+3
| | | | | | | | | - OP_NEWTABLE can use 'ra + 1' to set top (instead of ci->top); - OP_CLOSE doesn't need to set top ('Protect' already does that); - OP_TFORCALL must use 'ProtectNT', to preserve the top already set. (That was a small bug, because iterators could be called with extra parameters besides the state and the control variable.) - Comments and an extra test for the bug in previous item.
* Do not collect open upvaluesRoberto Ierusalimschy2019-07-221-1/+1
| | | | | | | | Open upvalues are kept alive together with their corresponding stack. This change makes a simpler and safer fix to the issue in commit 440a5ee78c8, about upvalues in the list of open upvalues being collected while others are being created. (That previous fix may not be correct.)
* Fixed bug for emergency collection in upvalue creationRoberto Ierusalimschy2019-07-191-1/+1
| | | | | | | | | | | When creating an upvalue, an emergency collection can collect the previous upvalue where the new one would be linked. The following code can trigger the bug, using valgrind on Lua compiled with the -DHARDMEMTESTS option: local x; local y (function () return y end)(); (function () return x end)()
* Reviving HARDMEMTESTSRoberto Ierusalimschy2019-07-181-3/+6
| | | | | | | | | | | This commit brings a new implementation for HARDMEMTESTS, which forces an emergency GC whenever possible. It also fixes some issues detected with this option: - A small bug in lvm.c: a closure could be collected by an emergency GC while being initialized. - Some tests: a memory address can be immediatly reused after a GC; for instance, two consecutive '{}' expressions can return exactly the same address, if the first one is not anchored.
* Small bug with stack reallocationRoberto Ierusalimschy2019-07-181-3/+6
| | | | | | | | OP_RETURN must update trap before updating stack. (Bug detected with -DHARDSTACKTESTS). Also, in 'luaF_close', do not create a variable with 'uplevel(uv)', as the stack may change and invalidate this value. (This is not a bug, but could become one if 'upl' was used again.)
* Micro optimization in OP_RETURN and OP_TAILCALLRoberto Ierusalimschy2019-07-161-7/+6
| | | | | Many functions are vararg but create no upvalues, so it is better to separate the tests for these two kinds of "extra work".
* Avoid setting the stack top below upvalues to be closedRoberto Ierusalimschy2019-07-161-2/+4
| | | | | | When leaving a scope, the new stack top should be set only after closing any upvalue, to avoid manipulating values in an "invalid" part of the stack.
* Unification of size representation in OP_NEWTABLE and OP_SETLISTRoberto Ierusalimschy2019-07-151-14/+14
| | | | | | 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).
* Reordering of instructions in the main loopRoberto Ierusalimschy2019-07-121-44/+44
| | | | | The instructions in the main interpreter loop were reordered to the same order of their enumeration in 'lopcodes.h'.
* OP_NEWTABLE keeps exact size of arraysRoberto Ierusalimschy2019-07-121-1/+5
| | | | | | 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.)
* DetailsRoberto Ierusalimschy2019-07-101-3/+2
| | | | | | | | In the generic for loop, it is simpler for OP_TFORLOOP to use the same 'ra' as OP_TFORCALL. Moreover, the internal names of the loop temporaries "(for ...)" don't need to leak internal details (even because the numerical for loop doesn't have a fixed role for each of its temporaries).
* Cleaning macros in 'luaV_execute'Roberto Ierusalimschy2019-06-211-6/+14
| | | | | | Ensure that operation macros, such as 'luai_numdiv' and 'luai_numidiv', operate only on variables, or at most at 's2v(ra)'. ('s2v' is a nop, a cast from pointer to pointer.)