Cours LUA generational collector

Cours LUA generational collector, tutoriel & guide de travaux pratiques en pdf.

Yieldable pcall/metamethods
another most-wanted feature
planned to be the main change for Lua 5.2 basic idea from Mike Pall
I long-jump over C functions and call them again when resuming
I lua_pcall lua_pcallk allows function to signalize whether it can yield at each point change from original implementation: resume calls a continuation function
I instead of the same function that was interrupted
I continuation passed as argument to lua_pcallk
metamethods resume through extra code to complete execution of interrupted opcodes

Generational Collector
garbage collector can use the generational algorithm
basic idea: only young objects are traversed/collected
infant mortality or generational hypothesis
I good: less work when traversing objects
I bad: less memory collected
implementation uses the same apparatus of the incremental collector
I black objects are equated to old objects
I black-to-white barriers become old-to-new barriers
seems to work as expected, but with no gains in performance 🙁
I hard to check without real programs

goto
Lua 5.2 will include a somewhat conventional goto statement
goto ts nicely with Lua philosophy of \mechanisms instead of policies »
I very powerful mechanism
I easy to explain
allows the implementation of several mechanisms
I continue, redo, break with labels, continue with labels, state machines, etc.
Yes, even break is redundant
I may be removed in the future
I not worth the trouble now
break does not need to be last statement in a block
I restriction in place to allow break label in the future
I restriction does not make sense for goto
goto implementation
quite simple for the VM
I small change to unify OP CLOSE and OP JMP
parser must keep pending gotos and visible labels
visibility rules
closing of upvalues
break implemented as goto break
I each loop followed by a virtual label ::break::
optimization for a common case:
if a == b then goto L end
NEQ a b EQ a b
JMP 1 JMP L
JMP L
17/28
Isn’t goto evil?
\The raptor fences aren’t out are they? »
continuations are much worse
I dynamic and unrestricted goto
I basic idea: l = getlabel(), goto(l)
I labels are rst-class values
yet nobody complains; it is \cool » to support continuations is the problem with goto that they are too restricted? demonized for years of abuse

New ENV scheme
Several parts
_ENV instead of dynamic environments
I any global name var replaced by _ENV.var
I main functions receive an upvalue named _ENV
I upvalue initialized with global table by default
no more fenv for functions
no more fenv for threads
simpli cation in the support for modules
I no more module function

setfenv
modules in general, and module in particular, were the main motivations for the introduction of dynamic environments and setfenv in Lua 5.0.
module was never very popular
setfenv, on the other hand, became popular for toying with other functions
setfenv runs against function encapsulation

Cours gratuitTélécharger le cours complet

Télécharger aussi :

Laisser un commentaire

Votre adresse e-mail ne sera pas publiée. Les champs obligatoires sont indiqués avec *