1.1 --- a/micropython/trans.py Sun Jun 06 03:03:09 2010 +0200
1.2 +++ b/micropython/trans.py Sun Jun 06 15:27:50 2010 +0200
1.3 @@ -619,7 +619,10 @@
1.4 t = self.optimiser.optimise_known_target()
1.5 if t:
1.6 target, context = t
1.7 - if isinstance(target, Instance): # lambda object
1.8 +
1.9 + # Detect dynamic functions acting like instances.
1.10 +
1.11 + if isinstance(target, Function) and target.is_dynamic():
1.12 target, context = None, None
1.13 else:
1.14 target, context = None, None
1.15 @@ -904,10 +907,9 @@
1.16 'employed_positions' collection.
1.17 """
1.18
1.19 - # Where a lambda is involved, construct a dynamic object to hold the
1.20 - # defaults.
1.21 + # Where appropriate, construct a dynamic object to hold the defaults.
1.22
1.23 - dynamic = target.name is None
1.24 + dynamic = target.is_dynamic()
1.25
1.26 # Here, we use negative index values to visit the right hand end of
1.27 # the defaults list.
1.28 @@ -1031,20 +1033,18 @@
1.29 ndefaults = len(fn.defaults)
1.30 temp = self._generateFunctionDefaults(fn)
1.31
1.32 - if ndefaults > 0:
1.33 - self.new_op(LoadConst(fn))
1.34 - else:
1.35 - self.new_op(LoadFunction(fn))
1.36 -
1.37 # Populate the new object required for the function.
1.38
1.39 if temp is not None:
1.40 + self.new_op(LoadConst(fn))
1.41 self.new_op(LoadCallable())
1.42 self.new_op(temp)
1.43 self.new_op(StoreCallable())
1.44
1.45 self.new_op(temp)
1.46 #self.discard_temp(temp)
1.47 + else:
1.48 + self.new_op(LoadFunction(fn))
1.49
1.50 def _visitFunctionDefinition(self, node):
1.51
1.52 @@ -1065,11 +1065,13 @@
1.53 # Check the number of parameters and defaults.
1.54
1.55 self.new_op(CheckFrame((nparams, ndefaults)))
1.56 +
1.57 + if fn.is_dynamic():
1.58 + self.new_op(LoadTemp(0)) # context provides storage
1.59 + else:
1.60 + self.new_op(LoadFunction(fn))
1.61 +
1.62 if ndefaults > 0:
1.63 - if fn.is_dynamic():
1.64 - self.new_op(LoadTemp(0)) # context provides storage
1.65 - else:
1.66 - self.new_op(LoadFunction(fn))
1.67 self.new_op(FillDefaults((nparams, ndefaults)))
1.68
1.69 # Produce the body.