Commit Graph

466 Commits

Author SHA1 Message Date
Roberto Ierusalimschy
28d829c867 Calls cannot be tail in the scope of a to-be-closed variable
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.
2018-12-04 15:01:42 -02:00
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
b8fed93215 New syntax for to-be-closed variables
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').
2018-11-07 10:03:05 -02: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
2316ec4c24 Back with optimization for 'if cond then goto'
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.)
2018-10-30 15:04:19 -03: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
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
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
9cbf17b0f1 Details (comments) 2018-09-11 08:39:12 -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
15ce8d0904 in generational mode, an emergency collection can turn any object black
during any memory allocation.
2018-06-18 14:57:20 -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
49dae52d08 correct way to check stack space for vararg functions 2018-02-17 17:20:00 -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
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
3064edead2 details (cleaning uses of 'exp1') 2017-12-18 10:33:54 -02:00
Roberto Ierusalimschy
b3f924bc69 'Proto->numparams' does not include vararg parameter
(one less subtraction when calling functions...)
2017-12-15 11:07:10 -02:00
Roberto Ierusalimschy
e001d5aea6 'VRELOCABLE' -> 'VRELOC' 2017-12-14 12:24:02 -02:00
Roberto Ierusalimschy
49dfaf7447 avoid using one function for different tasks (malloc, free, etc.) 2017-12-06 16:36:31 -02:00
Roberto Ierusalimschy
10b8c99bbb small peephole optimizations 2017-11-30 11:29:18 -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
283e7455ff detail 2017-10-04 18:53:03 -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
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
b77f792b23 comment 2017-08-12 10:12:21 -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
b42430fd3a 'lineinfo' in prototypes saved as differences instead of absolute
values, so that the array can use bytes instead of ints, reducing
its size. (A new array 'abslineinfo' is used when line differences
do not fit in a byte.)
2017-06-27 08:35:31 -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
5ecb31003f bug: cannot "skip" labels after if-goto before the jump over the
'then' part
2017-04-29 15:09:17 -03:00
Roberto Ierusalimschy
502a1d1108 new opcodes for table access with constant keys (strings and integers) 2017-04-28 17:57:45 -03:00
Roberto Ierusalimschy
6a98aa0bb0 new opcode LOADI (for loading immediate integers) 2017-04-20 16:53:55 -03:00
Roberto Ierusalimschy
e4a9e6fcca do not eliminate varargs from functions that do not use varargs
(confuses the debug lib and gains very little in performance)
2016-08-01 16:51:24 -03:00
Roberto Ierusalimschy
dcb2998aa6 bug: expression list with four or more expressions in
a 'for' loop can crash the interpreter. ('adjust_assign' must
remove extra expresssions from its registers.)
2016-06-22 12:48:25 -03:00
Roberto Ierusalimschy
b65252b39b 'singlevaraux' returns result only in 'var->k' 2016-05-13 16:10:16 -03:00
Roberto Ierusalimschy
e7b2e01d43 bug: label between local definitions can mix-up their initializations 2016-03-07 16:25:39 -03:00
Roberto Ierusalimschy
1f259be52a 'getcode' -> 'getinstruction' 2016-01-05 14:22:37 -02:00
Roberto Ierusalimschy
542dbd4c65 detail (moving bodies of 'while' to a separate line) 2015-12-09 13:21:28 -02:00
Roberto Ierusalimschy
8c1fb91802 macro 'incr_top' replaced by function 'luaD_inctop'. (It is not used
in critical time pathes, can save a few bytes without the macro)
2015-11-02 14:09:30 -02:00
Roberto Ierusalimschy
6707ce6349 function prepares vararg only if it really uses them (chunks
are always declared vararg but seldom uses them)
2015-10-28 15:28:40 -02:00
Roberto Ierusalimschy
de3933480e details 2014-12-27 18:31:43 -02:00
Roberto Ierusalimschy
9c41d9d1df removed unneeded barrier ('from' must be white) 2014-11-27 16:41:43 -02:00
Roberto Ierusalimschy
28fdbcf393 added include for 'lprefix.h', for stuff that must be added before
any other header file
2014-11-02 17:19:04 -02:00
Roberto Ierusalimschy
bdf566a8a3 `name' in comments changed to 'name' 2014-10-25 09:50:46 -02:00
Roberto Ierusalimschy
f97c64d7bf macros 'LUA_QL'/'LUA_QL' deprecated 2014-10-17 13:28:21 -03:00
Roberto Ierusalimschy
17ee57f8e0 'iswhite' and related macros now can work directly on any object
(no need to convert to 'GCObject')
2014-07-21 13:02:10 -03:00
Roberto Ierusalimschy
ca41b43f53 type 'TString' refers directly to the structure inside the union
(union used only for size purposes)
2014-07-18 10:36:14 -03:00
Roberto Ierusalimschy
56137d58ff added check for conversion 'obj2gco' (and corrections for small
problems detected by this check)
2014-07-18 09:17:54 -03:00
Roberto Ierusalimschy
89b56e7d84 more precision between closure types ('LClosure' x 'CClosure') 2014-06-19 15:27:20 -03:00
Roberto Ierusalimschy
1ea2d20f74 first implementation of '<<', '>>', and '~' (bitwise not) 2013-12-30 18:47:58 -02:00
Roberto Ierusalimschy
c0edab0f6d first implementation of bitwise operators '&' (band), '|' (bor),
and '~' (bxor)
2013-12-18 12:12:03 -02:00
Roberto Ierusalimschy
a948054a19 new order for binary operations (grouping them by type of result) 2013-12-16 17:06:52 -02:00
Roberto Ierusalimschy
8ef9e8460e bug (GC can collect long identifier during parser) + change (using
a single constant table for all functions in a chunk)
2013-08-30 13:01:37 -03:00
Roberto Ierusalimschy
439d74e29f added 'local' bit (true => object is only refered by local variables) 2013-08-16 15:55:49 -03:00
Roberto Ierusalimschy
a2f5c28a80 new operation '//' (integer division) 2013-04-26 10:08:29 -03:00
Roberto Ierusalimschy
5951c79ae1 default increment for 'for' loop is an integer (1, not 1.0) 2013-04-25 16:35:19 -03:00
Roberto Ierusalimschy
1294b09d8e first implementation of literal integers (no constant folding yet) 2013-04-16 15:46:28 -03:00
Roberto Ierusalimschy
1ce57628b2 comments 2013-02-06 11:37:39 -02:00
Roberto Ierusalimschy
233eac4d3a detail (avoid being picky about conversion from 'unsigned char'
to 'int')
2012-08-06 10:36:34 -03:00
Roberto Ierusalimschy
8d0e1ed52f extend optimization of 'if a then break end' for the case
'if a then break; end'
2012-05-20 11:51:23 -03:00
Roberto Ierusalimschy
3cadc37f47 no more 'Proto' objects on the stack. Protos are anchored on outer
Protos or on a Closure, which must be created before the Proto.
2012-05-08 10:53:33 -03:00
Roberto Ierusalimschy
c54f5f64c9 primaryexp -> suffixedexp; prefixexp -> primaryexp + more 'syntactical'
way to distinguish between function calls and assignments
2012-04-20 16:20:05 -03:00
Roberto Ierusalimschy
9f1a8dbdd3 'eqstr' -> 'luaS_eqstr' 2012-01-23 21:05:18 -02:00
Roberto Ierusalimschy
5999e14ad9 old error messages may be misleading 2011-12-02 11:23:56 -02:00
Roberto Ierusalimschy
6d8b672094 more uses of 'l_noret' 2011-11-30 10:43:51 -02:00
Roberto Ierusalimschy
fd8a849621 detail (avoid applying macro 'getstr' with a function-call argument) 2011-10-31 15:46:04 -02:00
Roberto Ierusalimschy
6819c2a98a silly bug in 5.2 beta: assignment conflict code did not test to check
whether variable was a table element
2011-10-24 12:51:44 -02:00
Roberto Ierusalimschy
e24f1ee9ff lint (unreachable code) 2011-09-30 09:44:45 -03:00
Roberto Ierusalimschy
500336efd0 small bug in if-goto optimization: block must be closed ('leaveblock')
*before* the jump out ('escapelist')
2011-09-14 14:40:26 -03:00
Roberto Ierusalimschy
c8f47c2934 optimization for |if cond then goto| 2011-08-30 13:38:58 -03:00
Roberto Ierusalimschy
121dc8af66 cleaner code for 'if' construct 2011-08-25 10:45:24 -03:00
Roberto Ierusalimschy
3dc5475e23 'nCcalls' should be local to each thread, as each thread may have its
own C stack (with LuaThreads or something similar)
2011-08-23 14:24:34 -03:00
Roberto Ierusalimschy
59bcd137ae reducing even more use of C stack by the parser: struct 'FuncState'
does not need field 'L' + number of labels/gotos in a chunk may be
limited to SHRT_MAX. (Also removed some non-needed 'unsigned's.)
2011-07-27 15:09:01 -03:00
Roberto Ierusalimschy
32a12e2f3f detail (cleaned whitespaces at end of lines) 2011-07-15 09:50:29 -03:00
Roberto Ierusalimschy
d93df22bf6 small simplifications (and assert was wrongly written) 2011-07-02 12:58:14 -03:00
Roberto Ierusalimschy
374773748b back to "one-label-per-block" 2011-06-27 15:18:59 -03:00
Roberto Ierusalimschy
719c01359f label syntax changed to ':🏷️:' 2011-06-20 13:52:48 -03:00
Roberto Ierusalimschy
fdede85419 label names must be unique inside a function 2011-06-16 13:36:39 -03:00
Roberto Ierusalimschy
c9ce754e38 comment 2011-05-02 14:33:01 -03:00
Roberto Ierusalimschy
f17e3624ef local function name only visible to debug info after being initialized 2011-04-18 16:48:24 -03:00
Roberto Ierusalimschy
7482e8f914 no need of lookahead in Zio 2011-02-23 10:13:10 -03:00
Roberto Ierusalimschy
c0a865fa54 error for repeated label + jumps allowed to labels followed by
'no-op' statements
2011-02-14 14:36:34 -02:00
Roberto Ierusalimschy
0009ac1f3a 'break' does not need to be last statement in a block +
'explist1' -> 'explist' + moving a few functions around
2011-02-14 12:59:28 -02:00
Roberto Ierusalimschy
bf8b08295a 'break' coded as 'goto' + small bug when closing multiple gotos
to the same label
2011-02-10 12:50:41 -02:00
Roberto Ierusalimschy
3f5b56c48b simpler code for repeat-until 2011-02-09 15:03:18 -02:00
Roberto Ierusalimschy
e7192dfdbb corrected 'follow' for checking whether label is last statement
in a block
2011-02-09 14:51:28 -02:00
Roberto Ierusalimschy
0539f48661 small changes in goto-related error messages 2011-02-09 12:45:19 -02:00
Roberto Ierusalimschy
fd6c1f4898 ensures that all local variables are declared inside some block,
opening a new block at 'open_func'
2011-02-07 17:00:30 -02:00
Roberto Ierusalimschy
f079749287 some reorganization of dynamic data structures used by the parser 2011-02-07 15:14:50 -02:00
Roberto Ierusalimschy
f8d677f94c no more 'OP_CLOSE' instructions (use jumps to close upvalues) 2011-02-07 10:28:27 -02:00
Roberto Ierusalimschy
7cc0e63d8a first implementation of 'goto' 2011-02-04 15:34:43 -02:00
Roberto Ierusalimschy
dd547c55c8 new scheme to close upvalues in 'break'; jump instructions may
do the close, avoiding the need for a OP_CLOSE instruction
2011-02-01 16:03:10 -02:00
Roberto Ierusalimschy
c4ea0c3b29 detail (cleaning trailing spaces) 2011-01-26 14:30:02 -02:00