Commit Graph

440 Commits

Author SHA1 Message Date
Roberto Ierusalimschy
fdc25a1ebf New functions 'lua_resetthread' and 'coroutine.kill'
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...)
2018-12-13 13:07:53 -02:00
Roberto Ierusalimschy
3b06f983ae Details
- 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.
2018-12-11 11:54:14 -02:00
Roberto Ierusalimschy
7e63d3da02 Some bugs with stack reallocation by 'luaF_close'
(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.
2018-11-24 11:59:15 -02:00
Roberto Ierusalimschy
34840301b5 To-be-closed variables in the C API 2018-10-25 15:30:15 -03:00
Roberto Ierusalimschy
c90176f969 Complete implementation of to-be-closed variables 2018-10-22 14:55:51 -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
b114c7d487 Added "cost" for the use of C stack by a coroutine invocation.
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.
2018-09-11 14:24:14 -03:00
Roberto Ierusalimschy
96f9643f33 Bug: wrong 'nCcalls' when resuming a coroutine
The counter 'nCcalls' now includes the number of CallInfo structures
pre-allocated (so that these "potential" C calls can be made without
checking 'nCcalls'). So, when copying this value from a thread to
another, in 'lua_resume', it must be corrected to the number of
CallInfo structures in the thread being resumed.
2018-07-11 16:11:50 -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
4907444db9 'fTransfer' -> 'ftransfer' / 'nTransfer' -> 'ntransfer'
(keep the standard of names in lower case)
2018-03-16 12:33:34 -03:00
Roberto Ierusalimschy
6480e73599 details (avoid using non-C89 '//' comment) 2018-03-07 13:26:01 -03:00
Roberto Ierusalimschy
8c429311a3 typo in comment 2018-03-05 11:13:55 -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
422318f677 two new fields 'fTransfer'/'nTransfer' in 'lua_Debug' structure
(for information about values being given and returned in function calls)
2018-02-17 17:29:29 -02:00
Roberto Ierusalimschy
104d249ffb in return hook, 'top' must be corrected only if smaller than 'ci->top'.
(It may be larger when returning multiple values, and then it must
be larger to preserve that stack slice.)
2018-02-17 16:22: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
4e0de3a43c details 2018-02-07 13:55:18 -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
89110986d7 bug in tailcall of vararg functions
(when adjusting missing parameters)
2018-01-28 11:39:52 -02:00
Roberto Ierusalimschy
53979dfe0d calling a vararg function needs to check GC
(because it creates a new table)
2018-01-28 10:08:04 -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
28323aeaa6 by-one error when filling missing arguments in a tail call 2017-12-29 13:44:51 -02:00
Roberto Ierusalimschy
8691612f01 when calling a hook, cannot decrease 'ci->top' (to preserve stack
size if the stack is reallocated)
2017-12-28 12:17:09 -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
4dc0be950a new macro 'isLuacode' (to distinguish regular Lua code from
hooks, where C code can run inside a Lua function).
2017-12-19 14:40:17 -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
725c15a4ca when shrinking stack, always shrinks the CI list.
(Stack overflow is not corelated to CI overflow anymore.)
2017-12-12 09:57:30 -02:00
Roberto Ierusalimschy
bfb88e99e9 'luaD_growstack' cannot raise any errors when 'raiseerror' is
false (+ some comments)
2017-12-11 10:43:40 -02:00
Roberto Ierusalimschy
e663a24ab0 more freedom in handling memory-allocation errors (not all allocations
automatically raise an error), which allows fixing a bug when resizing
a table.
2017-12-08 15:28:25 -02:00
Roberto Ierusalimschy
e0bece77d6 detail 2017-12-01 13:44:51 -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
194a4f9710 small simplifications in 'luaD_poscall' 2017-11-23 16:29:41 -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
14c3aa12b5 more direct implementation for tail calls. 2017-11-21 12:18:03 -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
7d4828cc9f avoid accessing wrong union field 2017-11-13 10:26:30 -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
6bb3e40a8d 'lua_Debug' not using 'CallInfo' 2017-11-03 18:41:05 -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
ba36180fd7 new API for 'lua_resume' + cleaning the uses of the 'extra' field in
'CallInfo'
2017-11-02 09:28:56 -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
6d998055c8 no more reference 'memerrmsg' + new reference to "n"
(both can be retrieved by 'luaS_newliteral' without creating anything,
because they are fixed, but "n" deserves fast access while 'memerrmsg'
does not)
2017-07-27 10:50:16 -03:00