aboutsummaryrefslogtreecommitdiff
Commit message (Collapse)AuthorAgeFilesLines
...
* Bug: Long brackets with a huge number of '=' causes overflowRoberto Ierusalimschy2018-12-142-14/+35
| | | | | | | A long bracket with too many equal signs can overflow the 'int' used for the counting and some arithmetic done on the value. Changing the counter to 'size_t' avoids that. (Because what is counted goes to a buffer, an overflow in the counter will first raise a buffer-overflow error.)
* New functions 'lua_resetthread' and 'coroutine.kill'Roberto Ierusalimschy2018-12-1311-32/+195
| | | | | | New functions to reset/kill a thread/coroutine, mainly (only?) to close any pending to-be-closed variable. ('lua_resetthread' also allows a thread to be reused...)
* DetailsRoberto Ierusalimschy2018-12-112-17/+14
| | | | | | | | - in 'luaB_tonumber', do not need to "checkany" when argument is a number. - in 'lua_resume', the call to 'luaD_rawrunprotected' cannot return a status equal to -1.
* 'math.rand()' uses higher bits to produce float valueRoberto Ierusalimschy2018-12-112-26/+46
| | | | | | | The call 'math.rand()' converts the higher bits of the internal unsigned integer random to a float, instead of its lower bits. That ensures that Lua compiled with different float precisions always generates equal (up to the available precision) random numbers when given the same seed.
* Better error messages for some polymorphic functionsRoberto Ierusalimschy2018-12-107-12/+41
| | | | | | | | | New auxiliary functions/macros 'luaL_argexpected'/'luaL_typeerror' ease the creation of error messages such as bad argument #2 to 'setmetatable' (nil or table expected, got boolean) (The novelty being the "got boolean" part...)
* Calls cannot be tail in the scope of a to-be-closed variableRoberto Ierusalimschy2018-12-044-16/+21
| | | | | | A to-be-closed variable must be closed when a block ends, so even a 'return foo()' cannot directly returns the results of 'foo'; the function must close the scope before returning.
* A to-be-closed variable must have a closable value (or be nil)Roberto Ierusalimschy2018-11-299-39/+83
| | | | | | | It is an error for a to-be-closed variable to have a non-closable non-nil value when it is being closed. This situation does not seem to be useful and often hints to an error. (Particularly in the C API, it is easy to change a to-be-closed index by mistake.)
* Auxiliary buffer cannot close box with 'lua_remove'Roberto Ierusalimschy2018-11-263-23/+49
| | | | | | | To remove a to-be-closed variable from the stack in the C API a function must use 'lua_settop' or 'lua_pop'. Previous implementation of 'luaL_pushresult' was not closing the box. (This commit also added tests to check that box is being closed "as soon as possible".)
* Some bugs with stack reallocation by 'luaF_close'Roberto Ierusalimschy2018-11-244-17/+17
| | | | | | | (Long time without testing with '-DHARDSTACKTESTS'...) With the introduction of to-be-closed variables, calls to 'luaF_close' can move the stack, but some call sites where keeping pointers to the stack without correcting them.
* Added opcodes for arithmetic with K operandsRoberto Ierusalimschy2018-11-2311-87/+228
| | | | | | | | 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').
* DetailsRoberto Ierusalimschy2018-11-223-39/+93
| | | | comments and other janitorial work.
* Documentation for to-be-closed variablesRoberto Ierusalimschy2018-11-131-26/+122
|
* Visibility of non-API functions changed to "internal"Roberto Ierusalimschy2018-11-131-1/+1
| | | | | | | The visibility for functions marked as LUAI_FUNC was changed from "hidden" to "internal". These functions cannot be called from outside the Lua kernel, and "internal" visibility offers more chances for optimizations.
* String buffer using to-be-closed variableRoberto Ierusalimschy2018-11-132-11/+47
| | | | | The string buffers in the C API now mark their boxes as to-be-closed variables, to release their buffers in case of errors.
* 'lua_toclose' gets the index to be closed as an argumentRoberto Ierusalimschy2018-11-124-13/+22
| | | | | | Sometimes it is useful to mark to-be-closed an index that is not at the top of the stack (e.g., if the value to be closed came from a function call returning multiple values).
* New implementation for 'luaL_addvalue'Roberto Ierusalimschy2018-11-091-22/+59
| | | | | | The function 'luaL_addvalue' (from the buffer system) was rewritten so that it does not change the position of the box (if present) in the stack.
* To-be-closed variable in 'for' loop separated from the stateRoberto Ierusalimschy2018-11-076-29/+76
| | | | | | | | | 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.)
* New syntax for to-be-closed variablesRoberto Ierusalimschy2018-11-078-47/+48
| | | | | | | The new syntax is <local *toclose x = f()>. The mark '*' allows other attributes to be added later without the need of new keywords; it also allows better error messages. The API function was also renamed ('lua_tobeclosed' -> 'lua_toclose').
* New macros for arithmetic/bitwise operations in 'luaV_execute'Roberto Ierusalimschy2018-11-055-220/+156
| | | | | | | 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).
* Removed internal cache for closuresRoberto Ierusalimschy2018-11-019-123/+10
| | | | | | | | | | | | | | | | | | | 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.)
* Removed resource-related "emergency collections"Roberto Ierusalimschy2018-10-315-80/+2
| | | | | New to-be-closed variables is a better way to ensure the proper release of resources.
* State in generic 'for' acts as a to-be-closed variableRoberto Ierusalimschy2018-10-315-24/+111
| | | | | | | | | | | 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.
* Better error messages for invalid operands in numeric 'for'Roberto Ierusalimschy2018-10-304-4/+22
| | | | | | "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)
* Back with optimization for 'if cond then goto'Roberto Ierusalimschy2018-10-303-20/+100
| | | | | | | | | | | | Statements like 'if cond then goto label' generate code so that the jump in the 'if' goes directly to the given label. This optimization cannot be done when the jump is backwards leaving the scope of some variable, as it cannot add the needed 'close' instruction. (The jumps were already generated by the 'if'.) This commit also added 'likely'/'unlikely' for tests for errors in the parser, and it changed the way breaks outside loops are detected. (Now they are detected like other goto's with undefined labels.)
* Big revamp in the implmentation of labels/gotosRoberto Ierusalimschy2018-10-298-182/+131
| | | | | | | | 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.
* More uniformity in code generation for 'for' loopsRoberto Ierusalimschy2018-10-266-10/+14
| | | | | | | 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.
* To-be-closed variables in the C APIRoberto Ierusalimschy2018-10-256-16/+122
|
* Closing methods should not interfere with returning valuesRoberto Ierusalimschy2018-10-254-42/+98
| | | | | | | | | | | | 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.
* Added a '__close' metamethod to file handlesRoberto Ierusalimschy2018-10-232-22/+36
|
* Detail: bad assertion in 'luaM_free_'Roberto Ierusalimschy2018-10-231-1/+1
|
* Removed extra information from RCS keyword strings in testsRoberto Ierusalimschy2018-10-226-4/+4
| | | | | Version numbers and dates (mostly wrong) from RCS keyword strings removed from all test files; only the file name are kept.
* Small improvements in the manualRoberto Ierusalimschy2018-10-221-8/+18
|
* Complete implementation of to-be-closed variablesRoberto Ierusalimschy2018-10-223-12/+39
|
* Handling of memory errors when creating to-be-closed upvaluesRoberto Ierusalimschy2018-10-184-40/+148
|
* First "complete" implementation of to-be-closed variablesRoberto Ierusalimschy2018-10-1713-26/+145
| | | | | | | Still missing: - handling of memory errors when creating upvalue (must run closing method all the same) - interaction with coroutines
* Towards "to closed" local variablesRoberto Ierusalimschy2018-10-0815-22/+81
| | | | | | | | | | | | 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.
* Added "cost" for the use of C stack by a coroutine invocation.Roberto Ierusalimschy2018-09-111-2/+8
| | | | | | | | | Resuming a coroutine uses more C stack than other operations (such as function calls or recursive syntax). So, to avoid stack overflow in recursive coroutine invocations, either LUAI_MAXCCALLS must be too small or a coroutine invocation must "pay" a higher price. New constant LUAL_COROCSTK ("COROutine C STaK") defines how much is this price.
* Details (comments)Roberto Ierusalimschy2018-09-113-4/+11
|
* Corrections in the implementation of '%' for floats.Roberto Ierusalimschy2018-08-285-18/+87
| | | | | | | | | 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.
* Deprecated the emulation of '__le' using '__lt'Roberto Ierusalimschy2018-08-248-40/+44
| | | | | | | | | | | 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).
* Removed extra information from RCS keyword stringsRoberto Ierusalimschy2018-08-2351-51/+51
| | | | | Version numbers and dates (mostly wrong) from RCS keyword strings removed from all source files; only the file name are kept.
* detailsRoberto Ierusalimschy2018-08-171-6/+6
| | | | | Minor optimizations in 'lvm.c'. (Not exactly optimizations, but more chances for optimizations.)
* Removed use of 'rl_inhibit_completion' in 'lua.c'Roberto Ierusalimschy2018-08-161-3/+2
| | | | | | Some old systems (e.g., Mac OS X 10.4) do not define 'rl_inhibit_completion', even when line history is available. Anyway, the user can configure this option externally, using '~/.inputrc'.
* Added "emergency collection" to 'io.tmpfile' and 'os.tmpname'Roberto Ierusalimschy2018-07-275-50/+71
| | | | | | | | These operations also can give errors for lack of resources, so they also will try "emergency collections" in case of resource errors. Because there are now two libraries with that kind of handling, 'resourcetryagain' was moved to the auxiliary library to be shared by the libraries.
* Added directory to test file names in '$Id:'Roberto Ierusalimschy2018-07-2529-29/+29
| | | | | | | From the point of view of 'git', all names are relative to the root directory of the project. So, file names in '$Id:' also should be relative to that directory: the proper name for test file 'all.lua' is 'testes/all.lua'.
* Small improvements in the manualRoberto Ierusalimschy2018-07-251-5/+7
|
* File operations try an "emergency collection" when failingRoberto Ierusalimschy2018-07-252-6/+65
| | | | | | | | | If a file operation fails do to lack of resources (too many open files or not enough memory), it does a full garbage collection and tries the operation again. Lack of resources are "too many open files" (process wise and system wise) and "not enough memory". The code is full of '#if's because error codes are not part of the standard ISO C.
* Comments about OLD0/OLD1 agesRoberto Ierusalimschy2018-07-181-24/+30
| | | | | Improved the comments in file 'lgc.c' explaining the roles of "ages" OLD0 and OLD1 in the generacional collector.
* Fixed bug in generational collection of userdataRoberto Ierusalimschy2018-07-134-15/+102
| | | | | | | | | During generational collection, a userdatum must become gray and go to a gray list after being traversed (like tables), so that 'correctgraylist' can handle it to its next stage. This commit also added minimum tests for the generational collector, including one that would detect this bug.
* Avoid using 'int' for UTF-8 valuesRoberto Ierusalimschy2018-07-121-11/+22
| | | | | | An 'int' may have only 16 bits, so it may not be big enough for UTF-8 values. The new type 'utfint' (in the utf8 library) ensures at least 21 bits for those values.