1.1 --- a/micropython/ast.py Sat Jun 05 15:11:26 2010 +0200
1.2 +++ b/micropython/ast.py Sun Jun 06 03:03:09 2010 +0200
1.3 @@ -586,70 +586,20 @@
1.4 # Only store the name when visiting this node from outside.
1.5
1.6 if self.unit is not node.unit:
1.7 - self.new_op(LoadFunction(node.unit))
1.8 + self._visitFunctionDeclaration(node)
1.9 +
1.10 + # Record the declared function.
1.11 +
1.12 self.record_value()
1.13
1.14 self._visitName(node, self.name_store_instructions) # AssName equivalent
1.15 self.set_source()
1.16 self.discard_value()
1.17
1.18 - self._generateFunctionDefaults(node.unit)
1.19 -
1.20 # Visiting of the code occurs when get_code is invoked on this node.
1.21
1.22 else:
1.23 - # Check frames using the function's details.
1.24 -
1.25 - fn = node.unit
1.26 - nparams = len(fn.positional_names)
1.27 - ndefaults = len(fn.defaults)
1.28 -
1.29 - fn.body_block = self.new_block()
1.30 -
1.31 - # Check the number of parameters and defaults.
1.32 -
1.33 - self.new_op(CheckFrame((nparams, ndefaults)))
1.34 - if ndefaults > 0:
1.35 - self.new_op(LoadFunction(fn))
1.36 - self.new_op(FillDefaults((nparams, ndefaults)))
1.37 -
1.38 - # Produce the body.
1.39 -
1.40 - self.set_block(fn.body_block)
1.41 -
1.42 - extend = ExtendFrame()
1.43 - self.new_op(extend)
1.44 -
1.45 - # For functions with star parameters, make a special list for the
1.46 - # extra arguments and re-map the parameter.
1.47 -
1.48 - if fn.has_star:
1.49 - self.new_op(CopyExtra(nparams))
1.50 -
1.51 - # Ensure that the star parameter has a slot in the frame.
1.52 -
1.53 - self.new_op(CheckExtra(nparams))
1.54 - self.new_op(StoreTemp(nparams))
1.55 -
1.56 - # Add any attribute usage guards.
1.57 -
1.58 - if self.optimiser.should_optimise_accesses_by_attribute_usage() and hasattr(node, "_attrnames"):
1.59 - self._generateGuards(node)
1.60 -
1.61 - # Visit the actual code.
1.62 -
1.63 - self.dispatch(node.code)
1.64 -
1.65 - # Add a return statement where one is not already produced.
1.66 -
1.67 - if not isinstance(self.last_op(), Return):
1.68 - self.dispatch(compiler.ast.Name("None"))
1.69 - self.new_op(StoreResult())
1.70 - self.new_op(Return())
1.71 -
1.72 - # Make sure that enough frame space is reserved from the start.
1.73 -
1.74 - self.set_frame_usage(node, extend)
1.75 + self._visitFunctionDefinition(node)
1.76
1.77 def visitGlobal(self, node): pass
1.78
1.79 @@ -675,58 +625,15 @@
1.80 # outside.
1.81
1.82 if self.unit is not node.unit:
1.83 - fn = node.unit
1.84 - ndefaults = len(fn.defaults)
1.85 - temp = self._generateFunctionDefaults(fn)
1.86 -
1.87 - if ndefaults > 0:
1.88 - self.new_op(LoadConst(fn))
1.89 - else:
1.90 - self.new_op(LoadFunction(fn))
1.91
1.92 - # Populate the new object required for the function.
1.93 + # Provide the declared function.
1.94
1.95 - if temp is not None:
1.96 - self.new_op(LoadCallable())
1.97 - self.new_op(temp)
1.98 - self.new_op(StoreCallable())
1.99 -
1.100 - self.new_op(temp)
1.101 - #self.discard_temp(temp)
1.102 + self._visitFunctionDeclaration(node)
1.103
1.104 # Visiting of the code occurs when get_code is invoked on this node.
1.105
1.106 else:
1.107 - # Check frames using the function's details.
1.108 -
1.109 - fn = node.unit
1.110 - nparams = len(fn.positional_names)
1.111 - ndefaults = len(fn.defaults)
1.112 -
1.113 - fn.body_block = self.new_block()
1.114 -
1.115 - # Check the number of parameters and defaults.
1.116 -
1.117 - self.new_op(CheckFrame((nparams, ndefaults)))
1.118 - if ndefaults > 0:
1.119 - self.new_op(LoadTemp(0)) # context provides storage
1.120 - self.new_op(FillDefaults((nparams, ndefaults)))
1.121 -
1.122 - # Produce the body.
1.123 -
1.124 - self.set_block(fn.body_block)
1.125 -
1.126 - extend = ExtendFrame()
1.127 - self.new_op(extend)
1.128 -
1.129 - self.dispatch(node.code)
1.130 -
1.131 - self.new_op(StoreResult())
1.132 - self.new_op(Return())
1.133 -
1.134 - # Make sure that enough frame space is reserved from the start.
1.135 -
1.136 - self.set_frame_usage(node, extend)
1.137 + self._visitFunctionDefinition(node)
1.138
1.139 def visitModule(self, node):
1.140 extend = ExtendFrame()