paul@196 | 1 | #!/usr/bin/env python |
paul@196 | 2 | |
paul@196 | 3 | """ |
paul@196 | 4 | Translate the AST of a Python program into a more interpretable representation. |
paul@196 | 5 | |
paul@506 | 6 | Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012 Paul Boddie <paul@boddie.org.uk> |
paul@196 | 7 | |
paul@196 | 8 | This program is free software; you can redistribute it and/or modify it under |
paul@196 | 9 | the terms of the GNU General Public License as published by the Free Software |
paul@196 | 10 | Foundation; either version 3 of the License, or (at your option) any later |
paul@196 | 11 | version. |
paul@196 | 12 | |
paul@196 | 13 | This program is distributed in the hope that it will be useful, but WITHOUT |
paul@196 | 14 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
paul@196 | 15 | FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
paul@196 | 16 | details. |
paul@196 | 17 | |
paul@196 | 18 | You should have received a copy of the GNU General Public License along with |
paul@196 | 19 | this program. If not, see <http://www.gnu.org/licenses/>. |
paul@196 | 20 | """ |
paul@196 | 21 | |
paul@555 | 22 | from micropython.common import operator_functions |
paul@196 | 23 | from micropython.data import * |
paul@555 | 24 | from micropython.errors import * |
paul@196 | 25 | from micropython.rsvp import * |
paul@196 | 26 | import compiler.ast |
paul@196 | 27 | |
paul@196 | 28 | class Helper: |
paul@196 | 29 | |
paul@196 | 30 | "Internal helper methods for AST visitors." |
paul@196 | 31 | |
paul@196 | 32 | # Common methods. |
paul@196 | 33 | |
paul@279 | 34 | def _generateGuards(self, node): |
paul@279 | 35 | |
paul@599 | 36 | if not (self.optimiser.should_optimise_accesses_by_attribute_usage() and node._attrtypes): |
paul@279 | 37 | return |
paul@279 | 38 | |
paul@279 | 39 | # For each name, attempt to restrict the type employed. |
paul@279 | 40 | |
paul@381 | 41 | for name, targets in node._attrtypes.items(): |
paul@307 | 42 | |
paul@307 | 43 | # NOTE: Need to merge targets using the same type but suggesting |
paul@309 | 44 | # NOTE: different kinds of attributes (instance vs. class). |
paul@279 | 45 | |
paul@279 | 46 | # Where only one object type is suggested, produce a guard. |
paul@279 | 47 | # NOTE: This only supports classes as types, not modules. |
paul@279 | 48 | |
paul@297 | 49 | if len(targets) == 1: |
paul@307 | 50 | target_name, is_static = list(targets)[0] |
paul@279 | 51 | |
paul@279 | 52 | # Access the object table to get the attribute. |
paul@535 | 53 | # This depends on a special entry in the table for class |
paul@535 | 54 | # equivalence tests. |
paul@279 | 55 | |
paul@279 | 56 | try: |
paul@535 | 57 | obj = self.objtable.get_object(target_name) |
paul@291 | 58 | |
paul@291 | 59 | # Where no attribute entry exists, the target could be a module. |
paul@417 | 60 | # NOTE: Should perhaps raise an error. |
paul@291 | 61 | |
paul@279 | 62 | except TableError, exc: |
paul@291 | 63 | print "Possible guard for", target_name, "not enforceable." |
paul@291 | 64 | continue |
paul@279 | 65 | |
paul@299 | 66 | # NOTE: Could test the correctness of the guard where the nature |
paul@299 | 67 | # NOTE: of the name is known. |
paul@299 | 68 | # NOTE: The known value would be retrieved from the unit's |
paul@299 | 69 | # NOTE: locals and tested as being a class or an instance of a |
paul@299 | 70 | # NOTE: particular class. |
paul@299 | 71 | |
paul@299 | 72 | # Generate the guard by loading a reference to the class. |
paul@299 | 73 | |
paul@279 | 74 | after_test_block = self.new_block() |
paul@279 | 75 | |
paul@450 | 76 | self.new_op(LoadClass(obj, target="source")) |
paul@285 | 77 | |
paul@297 | 78 | # For only static attributes, classes are acceptable. |
paul@297 | 79 | |
paul@297 | 80 | if is_static: |
paul@297 | 81 | |
paul@297 | 82 | # Generate name is target (for classes). |
paul@285 | 83 | |
paul@297 | 84 | self.dispatch(compiler.ast.Name(name)) |
paul@450 | 85 | self.new_op(TestIdentity(source="source", target="status")) |
paul@285 | 86 | |
paul@297 | 87 | # Jump to the next guard or the code if successful. |
paul@285 | 88 | |
paul@450 | 89 | self.new_op(JumpIfTrue(after_test_block, working="status")) |
paul@297 | 90 | |
paul@297 | 91 | # Where instance attributes are involved, only instances are |
paul@297 | 92 | # acceptable. |
paul@285 | 93 | |
paul@563 | 94 | if not isinstance(obj, Module): |
paul@563 | 95 | |
paul@563 | 96 | # Generate isinstance(name, target). |
paul@279 | 97 | |
paul@563 | 98 | self.dispatch(compiler.ast.Name(name)) |
paul@563 | 99 | self.new_op(CheckInstance(source="source", target="status")) |
paul@279 | 100 | |
paul@563 | 101 | # Jump to the next guard or the code if successful. |
paul@279 | 102 | |
paul@563 | 103 | self.new_op(JumpIfTrue(after_test_block, working="status")) |
paul@279 | 104 | |
paul@279 | 105 | # Where the type is inappropriate, raise an exception. |
paul@279 | 106 | |
paul@446 | 107 | self.make_exception("TypeError") |
paul@450 | 108 | self.set_target("exception") |
paul@279 | 109 | self.new_op(RaiseException()) |
paul@279 | 110 | |
paul@279 | 111 | self.set_block(after_test_block) |
paul@279 | 112 | |
paul@196 | 113 | def _visitAttr(self, node, classes): |
paul@196 | 114 | |
paul@196 | 115 | """ |
paul@196 | 116 | Visit the attribute-related 'node', generating instructions based on the |
paul@196 | 117 | given 'classes'. |
paul@196 | 118 | """ |
paul@196 | 119 | |
paul@196 | 120 | self.dispatch(node.expr) |
paul@196 | 121 | self._generateAttr(node, node.attrname, classes) |
paul@196 | 122 | |
paul@196 | 123 | def _generateAttr(self, node, attrname, classes): |
paul@196 | 124 | |
paul@196 | 125 | """ |
paul@196 | 126 | Generate code for the access to 'attrname' using the given 'classes'. |
paul@196 | 127 | """ |
paul@196 | 128 | |
paul@196 | 129 | AddressInstruction, AddressContextInstruction, AddressContextCondInstruction, \ |
paul@226 | 130 | AttrInstruction, AttrIndexInstruction, AttrIndexContextCondInstruction = classes |
paul@196 | 131 | |
paul@196 | 132 | # Where the last operation (defining the attribute owner) yields a |
paul@196 | 133 | # constant... |
paul@196 | 134 | |
paul@401 | 135 | target_plus_name = self.optimiser.optimise_constant_accessor() |
paul@196 | 136 | |
paul@196 | 137 | # Only try and discover the position if the target can be resolved. |
paul@469 | 138 | # Since instances cannot be constants in general, this involves classes |
paul@469 | 139 | # and modules, but constants known at compile-time must also be handled. |
paul@196 | 140 | |
paul@401 | 141 | if target_plus_name is not None: |
paul@401 | 142 | target, target_name = target_plus_name |
paul@401 | 143 | |
paul@401 | 144 | # Check for class.__class__. |
paul@401 | 145 | |
paul@401 | 146 | if attrname == "__class__": |
paul@401 | 147 | if isinstance(target, Class): |
paul@405 | 148 | if AddressInstruction is LoadAddress: |
paul@484 | 149 | self.replace_active_value("working", LoadAddress(self.get_builtin("type"))) |
paul@405 | 150 | return |
paul@405 | 151 | else: |
paul@405 | 152 | raise TranslateError("Assigning to __class__ is not permitted.") |
paul@196 | 153 | |
paul@268 | 154 | # Access the object table to get the attribute. |
paul@196 | 155 | |
paul@196 | 156 | try: |
paul@268 | 157 | attr = self.objtable.access(target_name, attrname) |
paul@268 | 158 | except TableError, exc: |
paul@339 | 159 | raise TranslateError(exc.args[0]) |
paul@196 | 160 | |
paul@196 | 161 | # Produce a suitable instruction. |
paul@196 | 162 | |
paul@401 | 163 | if AddressInstruction is not None: |
paul@469 | 164 | |
paul@469 | 165 | # Where the target is a constant instance, the constant input |
paul@469 | 166 | # needs to be retained as the context of the resulting |
paul@469 | 167 | # attribute. |
paul@469 | 168 | |
paul@469 | 169 | if isinstance(target, Instance): |
paul@469 | 170 | self.new_op(AddressContextInstruction(attr)) |
paul@469 | 171 | |
paul@469 | 172 | # It is acceptable to replace the instruction providing the |
paul@469 | 173 | # constant input because doing so does not lose any input |
paul@469 | 174 | # information required by the replacement instructions. |
paul@469 | 175 | |
paul@469 | 176 | else: |
paul@484 | 177 | self.replace_active_value("working", AddressInstruction(attr)) |
paul@196 | 178 | else: |
paul@339 | 179 | raise TranslateError("Storing of class or module attribute %r via an object is not permitted." % attrname) |
paul@196 | 180 | |
paul@196 | 181 | return |
paul@196 | 182 | |
paul@196 | 183 | # Where the last operation involves the special 'self' name, check to |
paul@196 | 184 | # see if the attribute is acceptably positioned and produce a direct |
paul@196 | 185 | # access to the attribute. |
paul@196 | 186 | |
paul@196 | 187 | # This is the only reliable way of detecting instance accesses at |
paul@196 | 188 | # compile-time since in general, objects could be classes or modules, |
paul@196 | 189 | # but 'self' should only refer to instances. |
paul@196 | 190 | |
paul@196 | 191 | elif self.optimiser.optimise_self_access(self.unit, attrname): |
paul@196 | 192 | |
paul@196 | 193 | # Either generate an instruction operating on an instance attribute. |
paul@196 | 194 | |
paul@196 | 195 | try: |
paul@196 | 196 | attr = self.unit.parent.instance_attributes()[attrname] |
paul@196 | 197 | self.new_op(AttrInstruction(attr)) |
paul@196 | 198 | return |
paul@196 | 199 | |
paul@196 | 200 | # Or generate an instruction operating on a class attribute. |
paul@196 | 201 | # NOTE: Any simple instruction providing self is not removed. |
paul@196 | 202 | |
paul@196 | 203 | except KeyError: |
paul@196 | 204 | |
paul@196 | 205 | try: |
paul@196 | 206 | attr = self.unit.parent.all_attributes()[attrname] |
paul@196 | 207 | |
paul@196 | 208 | # Switch the context if the class attribute is compatible with |
paul@196 | 209 | # the instance. |
paul@196 | 210 | |
paul@196 | 211 | if attr.defined_within_hierarchy(): |
paul@196 | 212 | |
paul@196 | 213 | # Only permit loading (not storing) of class attributes via self. |
paul@196 | 214 | |
paul@196 | 215 | if AddressContextInstruction is not None: |
paul@196 | 216 | self.new_op(AddressContextInstruction(attr)) |
paul@196 | 217 | else: |
paul@339 | 218 | raise TranslateError("Storing of class attribute %r via self not permitted." % attrname) |
paul@196 | 219 | |
paul@196 | 220 | # Preserve the context if the class attribute comes from an |
paul@196 | 221 | # incompatible class. |
paul@196 | 222 | |
paul@196 | 223 | elif attr.defined_outside_hierarchy(): |
paul@196 | 224 | |
paul@196 | 225 | # Only permit loading (not storing) of class attributes via self. |
paul@196 | 226 | |
paul@196 | 227 | if AddressInstruction is not None: |
paul@196 | 228 | self.new_op(AddressInstruction(attr)) |
paul@196 | 229 | else: |
paul@339 | 230 | raise TranslateError("Storing of class attribute %r via self not permitted." % attrname) |
paul@196 | 231 | |
paul@196 | 232 | # Otherwise, test for a suitable context at run-time. |
paul@196 | 233 | |
paul@196 | 234 | else: |
paul@196 | 235 | |
paul@196 | 236 | # Only permit loading (not storing) of class attributes via self. |
paul@196 | 237 | |
paul@196 | 238 | if AddressContextCondInstruction is not None: |
paul@196 | 239 | self.new_op(AddressContextCondInstruction(attr)) |
paul@196 | 240 | else: |
paul@339 | 241 | raise TranslateError("Storing of class attribute %r via self not permitted." % attrname) |
paul@196 | 242 | |
paul@196 | 243 | return |
paul@196 | 244 | |
paul@196 | 245 | # Or delegate the attribute access to a general instruction |
paul@196 | 246 | # since the kind of attribute cannot be deduced. |
paul@196 | 247 | |
paul@196 | 248 | except KeyError: |
paul@196 | 249 | pass |
paul@196 | 250 | |
paul@279 | 251 | # Attempt to deduce the target of an attribute access by searching for a |
paul@279 | 252 | # unique type providing the names associated with the accessed object. |
paul@279 | 253 | |
paul@645 | 254 | elif self.optimiser.should_optimise_accesses_by_attribute_usage() and \ |
paul@645 | 255 | isinstance(node, compiler.ast.AttributeAccessor): |
paul@401 | 256 | |
paul@645 | 257 | targets = self.possible_accessors_from_usage(node) |
paul@268 | 258 | |
paul@645 | 259 | if targets and len(targets) == 1: |
paul@645 | 260 | target = list(targets)[0] |
paul@645 | 261 | attr = target.all_attributes().get(attrname) |
paul@357 | 262 | |
paul@357 | 263 | # Produce a suitable instruction. |
paul@292 | 264 | |
paul@645 | 265 | if attr: |
paul@357 | 266 | if AddressContextCondInstruction is not None and attr.is_static_attribute(): |
paul@357 | 267 | self.new_op(AddressContextCondInstruction(attr)) |
paul@357 | 268 | elif AttrInstruction is not None and not attr.is_static_attribute(): |
paul@357 | 269 | self.new_op(AttrInstruction(attr)) |
paul@268 | 270 | else: |
paul@357 | 271 | raise TranslateError("Storing of class or module attribute %r via an object is not permitted." % attrname) |
paul@268 | 272 | |
paul@357 | 273 | return |
paul@268 | 274 | |
paul@401 | 275 | # Check for class.__class__. |
paul@401 | 276 | |
paul@401 | 277 | if attrname == "__class__": |
paul@401 | 278 | |
paul@401 | 279 | # Remember the accessor. |
paul@401 | 280 | |
paul@450 | 281 | temp_accessor = self.get_temp() |
paul@401 | 282 | |
paul@401 | 283 | attr_block = self.new_block() |
paul@401 | 284 | end_block = self.new_block() |
paul@401 | 285 | |
paul@450 | 286 | self.new_op(CheckClass(target="status")) |
paul@450 | 287 | self.new_op(JumpIfFalse(attr_block, working="status")) |
paul@401 | 288 | self.load_builtin("type", node) |
paul@401 | 289 | self.new_op(Jump(end_block)) |
paul@401 | 290 | self.set_block(attr_block) |
paul@401 | 291 | |
paul@401 | 292 | # Recall the accessor. |
paul@401 | 293 | |
paul@464 | 294 | self.new_op(temp_accessor) |
paul@401 | 295 | |
paul@196 | 296 | # Otherwise, perform a normal operation. |
paul@196 | 297 | |
paul@196 | 298 | try: |
paul@196 | 299 | index = self.objtable.get_index(attrname) |
paul@196 | 300 | |
paul@196 | 301 | except self.objtable.TableError: |
paul@196 | 302 | |
paul@196 | 303 | # If this error arises on generated code, check the names_used |
paul@196 | 304 | # attribute on the Importer. |
paul@196 | 305 | |
paul@339 | 306 | raise TranslateError("No attribute entry exists for name %r." % attrname) |
paul@196 | 307 | |
paul@196 | 308 | # NOTE: Test for class vs. instance attributes, generating |
paul@196 | 309 | # NOTE: context-related instructions. |
paul@196 | 310 | |
paul@196 | 311 | if AttrIndexContextCondInstruction is not None: |
paul@196 | 312 | self.new_op(AttrIndexContextCondInstruction(index)) |
paul@196 | 313 | |
paul@196 | 314 | # Store instructions do not need to consider context modifications. |
paul@196 | 315 | |
paul@196 | 316 | else: |
paul@196 | 317 | self.new_op(AttrIndexInstruction(index)) |
paul@196 | 318 | |
paul@401 | 319 | # Where __class__ was involved, define the start of the following code. |
paul@401 | 320 | |
paul@401 | 321 | if attrname == "__class__": |
paul@401 | 322 | self.set_block(end_block) |
paul@450 | 323 | self.discard_temp(temp_accessor) |
paul@401 | 324 | |
paul@196 | 325 | # Invocations involve the following: |
paul@196 | 326 | # |
paul@196 | 327 | # 1. Reservation of a frame for the arguments |
paul@196 | 328 | # 2. Identification of the target which is then held in temporary storage |
paul@196 | 329 | # 3. Optional inclusion of a context (important for methods) |
paul@196 | 330 | # 4. Preparation of the argument frame |
paul@196 | 331 | # 5. Invocation of the target |
paul@196 | 332 | # 6. Discarding of the frame |
paul@196 | 333 | # |
paul@196 | 334 | # In order to support nested invocations - such as a(b(c)) - use of the |
paul@196 | 335 | # temporary storage is essential. |
paul@196 | 336 | |
paul@196 | 337 | def _startCallFunc(self): |
paul@196 | 338 | |
paul@196 | 339 | "Record the location of the invocation." |
paul@196 | 340 | |
paul@196 | 341 | op = MakeFrame() |
paul@196 | 342 | self.new_op(op) # records the start of the frame |
paul@196 | 343 | self.frame_makers.append(op) |
paul@196 | 344 | |
paul@196 | 345 | def _generateCallFunc(self, args, node): |
paul@196 | 346 | |
paul@196 | 347 | """ |
paul@196 | 348 | Support a generic function invocation using the given 'args', occurring |
paul@196 | 349 | on the given 'node', where the expression providing the invocation |
paul@196 | 350 | target has just been generated. |
paul@196 | 351 | |
paul@196 | 352 | In other situations, the invocation is much simpler and does not need to |
paul@196 | 353 | handle the full flexibility of a typical Python invocation. Internal |
paul@196 | 354 | invocations, such as those employed by operators and certain |
paul@196 | 355 | control-flow mechanisms, use predetermined arguments and arguably do not |
paul@196 | 356 | need to support the same things as the more general invocations. |
paul@196 | 357 | """ |
paul@196 | 358 | |
paul@234 | 359 | target, context, temp_target, temp_context = self._generateCallFuncContext() |
paul@234 | 360 | self._generateCallFuncArgs(target, context, temp_target, temp_context, args, node) |
paul@234 | 361 | return temp_target, target, temp_context |
paul@196 | 362 | |
paul@196 | 363 | def _generateCallFuncContext(self): |
paul@196 | 364 | |
paul@196 | 365 | """ |
paul@196 | 366 | Produce code which loads and checks the context of the current |
paul@196 | 367 | invocation, the instructions for whose target have already been |
paul@196 | 368 | produced, returning a list of instructions which reference the |
paul@196 | 369 | invocation target. |
paul@196 | 370 | """ |
paul@196 | 371 | |
paul@196 | 372 | t = self.optimiser.optimise_known_target() |
paul@196 | 373 | if t: |
paul@196 | 374 | target, context = t |
paul@331 | 375 | |
paul@331 | 376 | # Detect dynamic functions acting like instances. |
paul@331 | 377 | |
paul@331 | 378 | if isinstance(target, Function) and target.is_dynamic(): |
paul@196 | 379 | target, context = None, None |
paul@196 | 380 | else: |
paul@196 | 381 | target, context = None, None |
paul@196 | 382 | |
paul@196 | 383 | # Store the target in temporary storage for subsequent referencing. |
paul@196 | 384 | |
paul@234 | 385 | temp_target = self.optimiser.optimise_temp_storage() |
paul@196 | 386 | |
paul@196 | 387 | # Where a target or context are not known or where an instance is known |
paul@196 | 388 | # to be the context, load the context. |
paul@196 | 389 | |
paul@196 | 390 | if target is None or isinstance(context, Instance): |
paul@234 | 391 | self.new_op(temp_target) |
paul@450 | 392 | self.new_op(Transfer(source="working_context", target="working")) |
paul@234 | 393 | temp_context = self.optimiser.optimise_temp_storage() |
paul@196 | 394 | self.new_op(StoreFrame(0)) |
paul@196 | 395 | |
paul@234 | 396 | # Class contexts should be made available for testing of the first |
paul@234 | 397 | # argument. |
paul@234 | 398 | # NOTE: Class methods should eventually be supported. |
paul@234 | 399 | |
paul@234 | 400 | elif isinstance(context, Class): |
paul@234 | 401 | self.new_op(temp_target) |
paul@450 | 402 | self.new_op(Transfer(source="working_context", target="working")) |
paul@234 | 403 | temp_context = self.optimiser.optimise_temp_storage() |
paul@234 | 404 | |
paul@196 | 405 | # Otherwise omit the context. |
paul@196 | 406 | |
paul@196 | 407 | else: |
paul@234 | 408 | temp_context = None |
paul@196 | 409 | |
paul@234 | 410 | return target, context, temp_target, temp_context |
paul@196 | 411 | |
paul@234 | 412 | def _generateCallFuncArgs(self, target, context, temp_target, temp_context, args, node): |
paul@196 | 413 | |
paul@196 | 414 | """ |
paul@234 | 415 | Given invocation 'target' and 'context' information, the 'temp_target' |
paul@234 | 416 | reference to the target, the 'temp_context' reference to the context, a |
paul@234 | 417 | list of nodes representing the 'args' (arguments), generate instructions |
paul@234 | 418 | which load the arguments for the invocation defined by the given 'node'. |
paul@196 | 419 | """ |
paul@196 | 420 | |
paul@196 | 421 | # Evaluate the arguments. |
paul@196 | 422 | |
paul@196 | 423 | employed_positions = set() |
paul@196 | 424 | employed_keywords = set() |
paul@196 | 425 | extra_keywords = [] |
paul@234 | 426 | positional_args = [] |
paul@234 | 427 | keyword_args = [] |
paul@196 | 428 | |
paul@196 | 429 | # Find keyword arguments in advance in order to help resolve targets. |
paul@196 | 430 | |
paul@591 | 431 | have_keywords = False |
paul@234 | 432 | |
paul@196 | 433 | for arg in args: |
paul@196 | 434 | if isinstance(arg, compiler.ast.Keyword): |
paul@196 | 435 | employed_keywords.add(arg.name) |
paul@234 | 436 | keyword_args.append(arg) |
paul@591 | 437 | have_keywords = True |
paul@234 | 438 | elif not have_keywords: |
paul@234 | 439 | positional_args.append(arg) |
paul@196 | 440 | |
paul@196 | 441 | possible_targets = self.paramtable.all_possible_objects(employed_keywords) |
paul@196 | 442 | |
paul@196 | 443 | # Note the presence of the context in the frame where appropriate. |
paul@196 | 444 | |
paul@234 | 445 | # For unknown invocations and method invocations. |
paul@234 | 446 | |
paul@196 | 447 | if target is None or isinstance(context, Instance): |
paul@196 | 448 | ncontext = 1 |
paul@591 | 449 | expect_testable_self = False |
paul@196 | 450 | |
paul@234 | 451 | # Handle calls to classes by obtaining the instantiator function. |
paul@230 | 452 | # A context is reserved for the new instance, but this is not provided |
paul@230 | 453 | # in the invocation (since the instantiator will fill the locals slot |
paul@230 | 454 | # concerned). |
paul@196 | 455 | |
paul@196 | 456 | elif isinstance(target, Class): |
paul@230 | 457 | ncontext = 1 |
paul@591 | 458 | expect_testable_self = False |
paul@203 | 459 | target = target.get_instantiator() |
paul@196 | 460 | |
paul@196 | 461 | # Method calls via classes. |
paul@196 | 462 | |
paul@196 | 463 | elif isinstance(context, Class): |
paul@196 | 464 | ncontext = 0 |
paul@591 | 465 | expect_testable_self = True |
paul@196 | 466 | |
paul@196 | 467 | # Function calls. |
paul@196 | 468 | |
paul@196 | 469 | else: |
paul@196 | 470 | ncontext = 0 |
paul@591 | 471 | expect_testable_self = False |
paul@234 | 472 | |
paul@234 | 473 | # Traverse the positional arguments adding them using the incrementing |
paul@234 | 474 | # frame position. |
paul@196 | 475 | |
paul@591 | 476 | first = True |
paul@196 | 477 | frame_pos = ncontext |
paul@234 | 478 | temp_first_argument = None |
paul@196 | 479 | |
paul@234 | 480 | for arg in positional_args: |
paul@234 | 481 | self.dispatch(arg) |
paul@234 | 482 | self.new_op(StoreFrame(frame_pos)) |
paul@234 | 483 | employed_positions.add(frame_pos) |
paul@196 | 484 | |
paul@196 | 485 | # Check to see if the first argument is appropriate (compatible with |
paul@196 | 486 | # the target where methods are being invoked via classes). |
paul@196 | 487 | |
paul@234 | 488 | if first and (expect_testable_self or target is None): |
paul@196 | 489 | |
paul@196 | 490 | # Drop any test if the target and the context are known. |
paul@196 | 491 | |
paul@196 | 492 | if not self.optimiser.have_correct_self_for_target(context, self.unit): |
paul@196 | 493 | |
paul@234 | 494 | # Otherwise, remember the first argument for a subsequent |
paul@234 | 495 | # test. |
paul@196 | 496 | |
paul@234 | 497 | temp_first_argument = self.optimiser.optimise_temp_storage() |
paul@196 | 498 | |
paul@591 | 499 | first = False |
paul@196 | 500 | frame_pos += 1 |
paul@196 | 501 | |
paul@234 | 502 | # Adjust the invocation frame for unknown invocations. |
paul@234 | 503 | # Test the first argument if appropriate. |
paul@234 | 504 | |
paul@455 | 505 | self._generateCallFuncContextTest(target, temp_context, temp_first_argument, node) |
paul@234 | 506 | |
paul@234 | 507 | # Traverse the keyword arguments adding them at the appropriate frame |
paul@234 | 508 | # positions. |
paul@234 | 509 | |
paul@234 | 510 | max_keyword_pos = -1 |
paul@234 | 511 | |
paul@234 | 512 | for arg in keyword_args: |
paul@234 | 513 | |
paul@234 | 514 | # Optimise where the target is known now. |
paul@234 | 515 | |
paul@234 | 516 | if target is not None: |
paul@234 | 517 | |
paul@234 | 518 | # Find the parameter table entry for the target. |
paul@234 | 519 | |
paul@234 | 520 | target_name = target.full_name() |
paul@234 | 521 | |
paul@234 | 522 | # Look for a callable with the precise target name. |
paul@234 | 523 | |
paul@234 | 524 | table_entry = self.paramtable.table[target_name] |
paul@234 | 525 | |
paul@234 | 526 | # Look the name up in the parameter table entry. |
paul@234 | 527 | |
paul@234 | 528 | try: |
paul@234 | 529 | pos = table_entry[arg.name] |
paul@234 | 530 | |
paul@234 | 531 | # Where no position is found, this could be an extra keyword |
paul@234 | 532 | # argument. |
paul@234 | 533 | |
paul@234 | 534 | except KeyError: |
paul@234 | 535 | extra_keywords.append(arg) |
paul@234 | 536 | continue |
paul@234 | 537 | |
paul@234 | 538 | # Test for illegal conditions. |
paul@234 | 539 | |
paul@234 | 540 | if pos in employed_positions: |
paul@339 | 541 | raise TranslateError("Keyword argument %r overwrites parameter %r." % (arg.name, pos)) |
paul@234 | 542 | |
paul@234 | 543 | employed_positions.add(pos) |
paul@234 | 544 | |
paul@234 | 545 | # Generate code for the keyword and the positioning |
paul@234 | 546 | # operation. |
paul@234 | 547 | |
paul@234 | 548 | self.dispatch(arg.expr) |
paul@234 | 549 | self.new_op(StoreFrame(pos)) |
paul@234 | 550 | |
paul@234 | 551 | # Otherwise, generate the code needed to obtain the details of |
paul@234 | 552 | # the parameter location. |
paul@234 | 553 | |
paul@234 | 554 | else: |
paul@234 | 555 | |
paul@234 | 556 | # Combine the target details with the name to get the location. |
paul@234 | 557 | # See the access method on the List class. |
paul@234 | 558 | |
paul@234 | 559 | try: |
paul@234 | 560 | paramindex = self.paramtable.get_index(arg.name) |
paul@234 | 561 | |
paul@234 | 562 | # Where no position is found, this could be an extra keyword |
paul@234 | 563 | # argument. |
paul@234 | 564 | |
paul@234 | 565 | except self.paramtable.TableError: |
paul@234 | 566 | extra_keywords.append(arg) |
paul@234 | 567 | continue |
paul@234 | 568 | |
paul@234 | 569 | # Generate code for the keyword and the positioning |
paul@234 | 570 | # operation. Get the value as the source of the assignment. |
paul@234 | 571 | |
paul@234 | 572 | self.dispatch(arg.expr) |
paul@234 | 573 | self.record_value() |
paul@469 | 574 | self.start_target() |
paul@234 | 575 | |
paul@234 | 576 | # Store the source value using the callable's parameter |
paul@234 | 577 | # table information. |
paul@234 | 578 | |
paul@234 | 579 | self.new_op(temp_target) |
paul@234 | 580 | self.new_op(StoreFrameIndex(paramindex)) |
paul@234 | 581 | |
paul@451 | 582 | self.assign_value() |
paul@234 | 583 | self.discard_value() |
paul@234 | 584 | |
paul@234 | 585 | # Record the highest possible frame position for this argument. |
paul@234 | 586 | |
paul@234 | 587 | max_keyword_pos = max(max_keyword_pos, max(self.paramtable.all_attribute_positions(arg.name))) |
paul@234 | 588 | |
paul@234 | 589 | # Use the frame position counter as a general argument counter. |
paul@234 | 590 | |
paul@234 | 591 | frame_pos += 1 |
paul@234 | 592 | |
paul@196 | 593 | # NOTE: Extra keywords are not supported. |
paul@196 | 594 | # NOTE: Somehow, the above needs to be combined with * arguments. |
paul@196 | 595 | |
paul@196 | 596 | if extra_keywords: |
paul@196 | 597 | print "Warning: extra keyword argument(s) %s not handled." % ", ".join([arg.name for arg in extra_keywords]) |
paul@196 | 598 | |
paul@196 | 599 | # Either test for a complete set of arguments. |
paul@196 | 600 | |
paul@196 | 601 | if target is not None: |
paul@196 | 602 | |
paul@196 | 603 | # Make sure that enough arguments have been given. |
paul@196 | 604 | |
paul@196 | 605 | nargs_max = len(target.positional_names) |
paul@196 | 606 | ndefaults = len(target.defaults) |
paul@196 | 607 | nargs_min = nargs_max - ndefaults |
paul@196 | 608 | |
paul@213 | 609 | # Visit each argument position and look for a supplied argument. |
paul@213 | 610 | |
paul@196 | 611 | for i in range(ncontext, nargs_min): |
paul@196 | 612 | if i not in employed_positions: |
paul@339 | 613 | raise TranslateError( |
paul@196 | 614 | "Argument %r not supplied for %r: need at least %d argument(s)." % (i+1, target.name, nargs_min)) |
paul@196 | 615 | |
paul@196 | 616 | nargs = frame_pos |
paul@196 | 617 | |
paul@213 | 618 | # Determine whether too many arguments have been given and how big |
paul@213 | 619 | # the frame should be. |
paul@213 | 620 | |
paul@213 | 621 | # For parameter lists with * or ** parameters, accept as many |
paul@213 | 622 | # arguments as are allowed or as many as we have. |
paul@213 | 623 | |
paul@213 | 624 | if target.has_star or target.has_dstar: |
paul@213 | 625 | frame_size = max(nargs, nargs_max) |
paul@213 | 626 | |
paul@214 | 627 | # NOTE: We now need to pack these arguments into a suitable |
paul@214 | 628 | # NOTE: structure for the * parameter. |
paul@214 | 629 | |
paul@213 | 630 | # For other parameter lists, only accept as many arguments as we are |
paul@213 | 631 | # allowed. |
paul@213 | 632 | |
paul@213 | 633 | elif nargs > nargs_max: |
paul@339 | 634 | raise TranslateError( |
paul@196 | 635 | "Too many arguments for %r: need at most %d argument(s)." % (target.name, nargs_max)) |
paul@196 | 636 | |
paul@213 | 637 | else: |
paul@213 | 638 | frame_size = nargs_max |
paul@213 | 639 | |
paul@196 | 640 | # Where defaults are involved, put them into the frame. |
paul@196 | 641 | |
paul@234 | 642 | self._generateCallFuncDefaultArgs(target, temp_target, nargs_min, nargs_max, employed_positions) |
paul@196 | 643 | |
paul@196 | 644 | # Set the frame size. |
paul@196 | 645 | |
paul@213 | 646 | self._endCallFuncArgs(frame_size) |
paul@196 | 647 | |
paul@215 | 648 | # Or just set the frame size and have the function check the arguments. |
paul@196 | 649 | |
paul@196 | 650 | else: |
paul@196 | 651 | max_pos = max(max(employed_positions or [-1]), max_keyword_pos, frame_pos - 1) |
paul@196 | 652 | self._endCallFuncArgs(max_pos + 1) |
paul@196 | 653 | |
paul@234 | 654 | def _generateCallFuncDefaultArgs(self, target, temp_target, nargs_min, nargs_max, employed_positions): |
paul@196 | 655 | |
paul@196 | 656 | """ |
paul@234 | 657 | For the given 'target' and 'temp_target' reference to the target, |
paul@234 | 658 | generate default arguments for those positions in the range |
paul@234 | 659 | 'nargs_min'...'nargs_max' which are not present in the |
paul@234 | 660 | 'employed_positions' collection. |
paul@196 | 661 | """ |
paul@196 | 662 | |
paul@331 | 663 | # Where appropriate, construct a dynamic object to hold the defaults. |
paul@196 | 664 | |
paul@331 | 665 | dynamic = target.is_dynamic() |
paul@196 | 666 | |
paul@196 | 667 | # Here, we use negative index values to visit the right hand end of |
paul@196 | 668 | # the defaults list. |
paul@196 | 669 | |
paul@196 | 670 | for pos in range(nargs_min, nargs_max): |
paul@196 | 671 | if pos not in employed_positions: |
paul@196 | 672 | if dynamic: |
paul@234 | 673 | self.new_op(temp_target) |
paul@196 | 674 | self.new_op(LoadAttr(target.default_attrs[pos - nargs_min])) |
paul@196 | 675 | else: |
paul@196 | 676 | self.new_op(LoadAddress(target.default_attrs[pos - nargs_min])) |
paul@196 | 677 | self.new_op(StoreFrame(pos)) |
paul@196 | 678 | |
paul@455 | 679 | def _generateCallFuncContextTest(self, target, temp_context, temp_first_argument, node): |
paul@234 | 680 | |
paul@234 | 681 | """ |
paul@455 | 682 | Generate code involved in a call to the given 'target' to test the |
paul@455 | 683 | context provided by 'temp_context' against 'temp_first_argument', and to |
paul@479 | 684 | signal an exception if the context is incompatible with the first frame |
paul@479 | 685 | argument. |
paul@234 | 686 | |
paul@234 | 687 | In addition, the invocation frame will be shifted if 'temp_context' |
paul@234 | 688 | indicates a function or a class. |
paul@234 | 689 | """ |
paul@234 | 690 | |
paul@479 | 691 | # Need to store the explicit first argument in the working register for |
paul@479 | 692 | # the eventual test. |
paul@479 | 693 | |
paul@479 | 694 | if temp_first_argument is not None: |
paul@479 | 695 | self.new_op(temp_first_argument) |
paul@479 | 696 | |
paul@479 | 697 | # Put the context in the source register. |
paul@479 | 698 | |
paul@479 | 699 | if target is None or temp_first_argument is not None: |
paul@479 | 700 | if self.new_op(temp_context.copy()): |
paul@479 | 701 | self.last_op().target = "source" |
paul@479 | 702 | else: |
paul@479 | 703 | self.new_op(Transfer(source="working", target="source")) |
paul@234 | 704 | |
paul@234 | 705 | # Add some preliminary tests where the target is not known. |
paul@234 | 706 | |
paul@234 | 707 | if target is None: |
paul@479 | 708 | if temp_first_argument is not None: |
paul@479 | 709 | self.new_op(JumpInFrameDirect(self.native.getCallFuncUnknownTargetTestableSelf())) |
paul@479 | 710 | else: |
paul@479 | 711 | self.new_op(JumpInFrameDirect(self.native.getCallFuncUnknownTarget())) |
paul@234 | 712 | |
paul@479 | 713 | elif temp_first_argument is not None: |
paul@479 | 714 | self.new_op(JumpInFrameDirect(self.native.getCallFuncKnownTargetTestableSelf())) |
paul@234 | 715 | |
paul@234 | 716 | def _doCallFunc(self, temp_target, target=None): |
paul@196 | 717 | |
paul@196 | 718 | "Make the invocation." |
paul@196 | 719 | |
paul@203 | 720 | # For classes, the target itself is used, since the instantiator will be |
paul@203 | 721 | # obtained via the class. |
paul@203 | 722 | |
paul@215 | 723 | if isinstance(target, (Class, Function)): |
paul@450 | 724 | self.new_op(JumpWithFrameDirect(target, working="status")) |
paul@196 | 725 | else: |
paul@234 | 726 | self.new_op(temp_target) |
paul@215 | 727 | self.new_op(LoadCallable()) |
paul@215 | 728 | self.new_op(JumpWithFrame()) |
paul@196 | 729 | |
paul@196 | 730 | def _endCallFuncArgs(self, nargs): |
paul@196 | 731 | |
paul@196 | 732 | "Set the frame size." |
paul@196 | 733 | |
paul@196 | 734 | self.frame_makers[-1].attr = nargs |
paul@196 | 735 | self.frame_makers.pop() |
paul@196 | 736 | |
paul@464 | 737 | def _endCallFunc(self, temp_target=None, temp_context=None): |
paul@196 | 738 | |
paul@196 | 739 | "Finish the invocation and tidy up afterwards." |
paul@196 | 740 | |
paul@196 | 741 | self.new_op(DropFrame()) |
paul@196 | 742 | |
paul@196 | 743 | # Discard any temporary storage instructions. |
paul@196 | 744 | |
paul@234 | 745 | if temp_target is not None: |
paul@234 | 746 | self.discard_temp(temp_target) |
paul@234 | 747 | |
paul@234 | 748 | if temp_context is not None: |
paul@234 | 749 | self.discard_temp(temp_context) |
paul@196 | 750 | |
paul@330 | 751 | def _visitFunctionDeclaration(self, node): |
paul@330 | 752 | |
paul@330 | 753 | """ |
paul@330 | 754 | Visit the function declaration at 'node', which can be a lambda or a |
paul@330 | 755 | named function. As a consequence an instruction will be generated which |
paul@330 | 756 | provides a reference to the function. |
paul@330 | 757 | """ |
paul@330 | 758 | |
paul@330 | 759 | fn = node.unit |
paul@330 | 760 | ndefaults = len(fn.defaults) |
paul@330 | 761 | temp = self._generateFunctionDefaults(fn) |
paul@330 | 762 | |
paul@330 | 763 | # Populate the new object required for the function. |
paul@330 | 764 | |
paul@330 | 765 | if temp is not None: |
paul@331 | 766 | self.new_op(LoadConst(fn)) |
paul@450 | 767 | self.new_op(LoadCallable(target="source")) |
paul@330 | 768 | self.new_op(temp) |
paul@450 | 769 | self.new_op(StoreCallable(source="source")) |
paul@464 | 770 | self.new_op(temp) |
paul@330 | 771 | #self.discard_temp(temp) |
paul@331 | 772 | else: |
paul@331 | 773 | self.new_op(LoadFunction(fn)) |
paul@330 | 774 | |
paul@330 | 775 | def _visitFunctionDefinition(self, node): |
paul@330 | 776 | |
paul@330 | 777 | """ |
paul@330 | 778 | Visit the function definition at 'node', which can be a lambda or a |
paul@330 | 779 | named function, generating the prelude with argument and default |
paul@330 | 780 | checking, plus the body of the function itself. |
paul@330 | 781 | """ |
paul@330 | 782 | |
paul@330 | 783 | # Check frames using the function's details. |
paul@330 | 784 | |
paul@330 | 785 | fn = node.unit |
paul@330 | 786 | nparams = len(fn.positional_names) |
paul@330 | 787 | ndefaults = len(fn.defaults) |
paul@330 | 788 | |
paul@330 | 789 | fn.body_block = self.new_block() |
paul@330 | 790 | |
paul@330 | 791 | # Check the number of parameters and defaults. |
paul@330 | 792 | |
paul@450 | 793 | self.new_op(CheckFrame((nparams, ndefaults), target="status")) |
paul@331 | 794 | |
paul@354 | 795 | if ndefaults > 0: |
paul@354 | 796 | if fn.is_dynamic(): |
paul@354 | 797 | self.new_op(LoadTemp(0)) # context provides storage |
paul@354 | 798 | else: |
paul@354 | 799 | self.new_op(LoadFunction(fn)) |
paul@331 | 800 | |
paul@330 | 801 | self.new_op(FillDefaults((nparams, ndefaults))) |
paul@330 | 802 | |
paul@330 | 803 | # Produce the body. |
paul@330 | 804 | |
paul@330 | 805 | self.set_block(fn.body_block) |
paul@330 | 806 | |
paul@330 | 807 | # For functions with star parameters, make a special list for the |
paul@330 | 808 | # extra arguments and re-map the parameter. |
paul@330 | 809 | |
paul@330 | 810 | if fn.has_star: |
paul@330 | 811 | self.new_op(CopyExtra(nparams)) |
paul@330 | 812 | |
paul@330 | 813 | # Ensure that the star parameter has a slot in the frame. |
paul@330 | 814 | |
paul@450 | 815 | self.new_op(CheckExtra(nparams, target="status")) |
paul@330 | 816 | self.new_op(StoreTemp(nparams)) |
paul@330 | 817 | |
paul@408 | 818 | # Extend the frame for local usage. |
paul@408 | 819 | |
paul@408 | 820 | extend = ExtendFrame() |
paul@408 | 821 | self.new_op(extend) |
paul@408 | 822 | |
paul@408 | 823 | # Perform tuple assignment for any tuple parameters. |
paul@408 | 824 | |
paul@408 | 825 | self._visitFunctionTupleParameters(fn, node) |
paul@408 | 826 | |
paul@330 | 827 | # Add any attribute usage guards. |
paul@330 | 828 | |
paul@381 | 829 | self._generateGuards(node) |
paul@330 | 830 | |
paul@330 | 831 | # Visit the actual code. |
paul@330 | 832 | |
paul@330 | 833 | self.dispatch(node.code) |
paul@330 | 834 | |
paul@330 | 835 | # Add a return statement where one is not already produced. |
paul@330 | 836 | |
paul@330 | 837 | if not isinstance(self.last_op(), Return): |
paul@330 | 838 | |
paul@330 | 839 | # Return None for normal functions without explicit return |
paul@330 | 840 | # statements. |
paul@330 | 841 | |
paul@351 | 842 | if not fn.is_lambda(): |
paul@330 | 843 | self.dispatch(compiler.ast.Name("None")) |
paul@330 | 844 | |
paul@330 | 845 | self.new_op(Return()) |
paul@330 | 846 | |
paul@330 | 847 | # Make sure that enough frame space is reserved from the start. |
paul@330 | 848 | |
paul@330 | 849 | self.set_frame_usage(node, extend) |
paul@330 | 850 | |
paul@368 | 851 | def _visitFunctionTupleParameters(self, fn, node, parameters=None): |
paul@368 | 852 | |
paul@368 | 853 | """ |
paul@368 | 854 | Visit the tuple parameters for function 'fn', obtaining the appropriate |
paul@368 | 855 | elements from each supplied argument and assigning them to the specified |
paul@368 | 856 | names for each parameter. |
paul@368 | 857 | """ |
paul@368 | 858 | |
paul@368 | 859 | if parameters is not None: |
paul@368 | 860 | self._generateAttr(node, "__getitem__", self.attribute_load_instructions) |
paul@368 | 861 | temp_getitem = self.optimiser.optimise_temp_storage() |
paul@368 | 862 | |
paul@368 | 863 | for i, parameter in parameters or fn.tuple_parameters(): |
paul@368 | 864 | |
paul@368 | 865 | # Either load the parameter from the frame. |
paul@368 | 866 | |
paul@368 | 867 | if parameters is None: |
paul@368 | 868 | self.new_op(LoadName(Attr(i, None, None))) |
paul@368 | 869 | |
paul@368 | 870 | # Or load a value from the current collection. |
paul@368 | 871 | |
paul@368 | 872 | else: |
paul@368 | 873 | self._startCallFunc() |
paul@368 | 874 | self.new_op(temp_getitem) |
paul@368 | 875 | temp_target, target, temp_context = self._generateCallFunc([compiler.ast.Const(i)], node) |
paul@368 | 876 | self._doCallFunc(temp_target, target) |
paul@369 | 877 | self._endCallFunc() |
paul@368 | 878 | |
paul@368 | 879 | # Where a tuple is the target, attempt to descend into the value |
paul@368 | 880 | # obtained. |
paul@368 | 881 | |
paul@368 | 882 | if isinstance(parameter, list): |
paul@368 | 883 | self._visitFunctionTupleParameters(fn, node, parameter) |
paul@368 | 884 | |
paul@368 | 885 | # Store the item in the namespace entry for the given name. |
paul@368 | 886 | |
paul@368 | 887 | else: |
paul@391 | 888 | self.record_value() |
paul@469 | 889 | self.start_target() |
paul@368 | 890 | self.new_op(StoreName(fn[parameter])) |
paul@451 | 891 | self.assign_value() |
paul@391 | 892 | self.discard_value() |
paul@368 | 893 | |
paul@368 | 894 | if parameters is not None: |
paul@368 | 895 | self.discard_temp(temp_getitem) |
paul@368 | 896 | |
paul@196 | 897 | def _generateFunctionDefaults(self, function): |
paul@196 | 898 | |
paul@196 | 899 | """ |
paul@196 | 900 | Generate the default initialisation code for 'function', returning |
paul@196 | 901 | a temporary storage reference if a dynamic object was created for the |
paul@196 | 902 | function. |
paul@196 | 903 | """ |
paul@196 | 904 | |
paul@196 | 905 | attr_to_default = zip(function.default_attrs, function.defaults) |
paul@196 | 906 | if not attr_to_default: |
paul@196 | 907 | return None |
paul@196 | 908 | |
paul@330 | 909 | # Where non-constant defaults are involved, construct a dynamic object |
paul@330 | 910 | # to hold the defaults. |
paul@196 | 911 | |
paul@330 | 912 | dynamic = function.is_dynamic() |
paul@196 | 913 | |
paul@196 | 914 | if dynamic: |
paul@446 | 915 | self.make_instance(self.get_builtin_class("function"), len(attr_to_default)) |
paul@196 | 916 | temp = self.get_temp() |
paul@196 | 917 | |
paul@196 | 918 | for attr, default in attr_to_default: |
paul@196 | 919 | self.dispatch(default) |
paul@196 | 920 | |
paul@196 | 921 | self.record_value() |
paul@469 | 922 | self.start_target() |
paul@196 | 923 | if dynamic: |
paul@196 | 924 | self.new_op(temp) |
paul@196 | 925 | self.new_op(StoreAttr(attr)) |
paul@196 | 926 | else: |
paul@196 | 927 | self.new_op(StoreAddress(attr)) |
paul@451 | 928 | self.assign_value() |
paul@196 | 929 | self.discard_value() |
paul@196 | 930 | |
paul@196 | 931 | if dynamic: |
paul@464 | 932 | return temp |
paul@196 | 933 | else: |
paul@196 | 934 | return None |
paul@196 | 935 | |
paul@563 | 936 | def _storeName(self, node, name=None): |
paul@563 | 937 | |
paul@563 | 938 | """ |
paul@563 | 939 | A convenience method that stores the current working value using the |
paul@563 | 940 | name provided by the given 'node' or the specified 'name' if provided. |
paul@563 | 941 | """ |
paul@563 | 942 | |
paul@563 | 943 | self.record_value() |
paul@563 | 944 | self.start_target() |
paul@563 | 945 | self._generateName(name or node.name, self.name_store_instructions, node) |
paul@563 | 946 | self.assign_value() |
paul@563 | 947 | self.discard_value() |
paul@563 | 948 | |
paul@196 | 949 | def _visitName(self, node, classes): |
paul@196 | 950 | |
paul@196 | 951 | """ |
paul@196 | 952 | Visit the name-related 'node', generating instructions based on the |
paul@196 | 953 | given 'classes'. |
paul@196 | 954 | """ |
paul@196 | 955 | |
paul@196 | 956 | name = node.name |
paul@563 | 957 | self._generateName(name, classes, node) |
paul@334 | 958 | |
paul@563 | 959 | def _generateName(self, name, classes, node): |
paul@196 | 960 | |
paul@196 | 961 | """ |
paul@196 | 962 | Generate code for the access to 'name' in 'scope' using the given |
paul@196 | 963 | 'classes', and using the given 'node' as the source of the access. |
paul@196 | 964 | """ |
paul@196 | 965 | |
paul@223 | 966 | NameInstruction, AddressInstruction, AddressContextInstruction = classes |
paul@196 | 967 | |
paul@563 | 968 | # Get the expected scope of the name. |
paul@563 | 969 | |
paul@563 | 970 | scope = getattr(node, "_scope", None) or self.get_scope(name) |
paul@563 | 971 | |
paul@343 | 972 | # Handle names referring to constants. |
paul@343 | 973 | |
paul@343 | 974 | if scope == "constant": |
paul@343 | 975 | const = self.importer.get_predefined_constant(name) |
paul@343 | 976 | self.new_op(LoadConst(const)) |
paul@343 | 977 | |
paul@343 | 978 | # Handle all other names. |
paul@343 | 979 | |
paul@343 | 980 | elif scope == "local": |
paul@196 | 981 | unit = self.unit |
paul@196 | 982 | if isinstance(unit, Function): |
paul@196 | 983 | self.new_op(NameInstruction(unit.all_locals()[name])) |
paul@196 | 984 | elif isinstance(unit, Class): |
paul@223 | 985 | if AddressContextInstruction is not None: |
paul@223 | 986 | self.new_op(LoadConst(unit)) |
paul@223 | 987 | self.new_op(AddressContextInstruction(unit.all_class_attributes()[name])) |
paul@223 | 988 | else: |
paul@223 | 989 | self.new_op(AddressInstruction(unit.all_class_attributes()[name])) |
paul@196 | 990 | elif isinstance(unit, Module): |
paul@196 | 991 | self.new_op(AddressInstruction(unit.module_attributes()[name])) |
paul@196 | 992 | else: |
paul@339 | 993 | raise TranslateError("Program unit has no local %r." % name) |
paul@196 | 994 | |
paul@196 | 995 | elif scope == "global": |
paul@196 | 996 | globals = self.module.module_attributes() |
paul@196 | 997 | if globals.has_key(name): |
paul@196 | 998 | self.new_op(AddressInstruction(globals[name])) |
paul@196 | 999 | else: |
paul@339 | 1000 | raise TranslateError("Module has no attribute %r." % name) |
paul@196 | 1001 | |
paul@338 | 1002 | elif scope == "builtins": |
paul@446 | 1003 | self.new_op(AddressInstruction(self.get_builtin(name))) |
paul@338 | 1004 | |
paul@196 | 1005 | else: |
paul@343 | 1006 | # NOTE: This may happen because a class attribute is optimised away. |
paul@581 | 1007 | print >>sys.stderr, "Program unit uses unknown name %r." % name |
paul@196 | 1008 | |
paul@196 | 1009 | def _visitUnary(self, node): |
paul@196 | 1010 | |
paul@196 | 1011 | """ |
paul@354 | 1012 | Invoke the appropriate operator module function for the operation |
paul@354 | 1013 | represented by 'node'. |
paul@196 | 1014 | """ |
paul@196 | 1015 | |
paul@354 | 1016 | temp_fn = self._getOperatorFunction(node) |
paul@374 | 1017 | self._visitCall(node, temp_fn, (node.expr,)) |
paul@354 | 1018 | self.discard_temp(temp_fn) |
paul@354 | 1019 | |
paul@259 | 1020 | def _visitBinaryBit(self, node): |
paul@259 | 1021 | |
paul@259 | 1022 | """ |
paul@259 | 1023 | Need to impose binary rules over a sequence of nodes. The |
paul@259 | 1024 | short-circuiting of the similar logical operators is not imposed by the |
paul@259 | 1025 | bitwise operators. |
paul@259 | 1026 | """ |
paul@259 | 1027 | |
paul@354 | 1028 | temp_fn = self._getOperatorFunction(node) |
paul@259 | 1029 | left = None |
paul@259 | 1030 | |
paul@259 | 1031 | for right in node.nodes: |
paul@259 | 1032 | if left is not None: |
paul@374 | 1033 | self._visitCall(node, temp_fn, (left, right)) |
paul@259 | 1034 | left = right |
paul@259 | 1035 | |
paul@354 | 1036 | self.discard_temp(temp_fn) |
paul@354 | 1037 | |
paul@196 | 1038 | def _visitBinary(self, node): |
paul@196 | 1039 | |
paul@196 | 1040 | """ |
paul@354 | 1041 | Invoke the appropriate operator module function for the operation |
paul@354 | 1042 | represented by 'node'. |
paul@196 | 1043 | """ |
paul@196 | 1044 | |
paul@354 | 1045 | temp_fn = self._getOperatorFunction(node) |
paul@374 | 1046 | self._visitCall(node, temp_fn, (node.left, node.right)) |
paul@354 | 1047 | self.discard_temp(temp_fn) |
paul@354 | 1048 | |
paul@374 | 1049 | def _visitCall(self, node, temp_fn, args): |
paul@259 | 1050 | |
paul@354 | 1051 | """ |
paul@354 | 1052 | Invoke the appropriate operator module function for the operation |
paul@354 | 1053 | represented by 'node', given a 'temp_fn' reference to a function, along |
paul@374 | 1054 | with the 'args' (the operand nodes). |
paul@354 | 1055 | """ |
paul@196 | 1056 | |
paul@374 | 1057 | # Evaluate and store the operands in temporary storage. |
paul@196 | 1058 | |
paul@374 | 1059 | temp_list = [] |
paul@196 | 1060 | |
paul@374 | 1061 | for arg in args: |
paul@374 | 1062 | self.dispatch(arg) |
paul@374 | 1063 | temp_list.append(self.optimiser.optimise_temp_storage()) |
paul@196 | 1064 | |
paul@374 | 1065 | self._generateInvocation(temp_fn, temp_list) |
paul@196 | 1066 | |
paul@196 | 1067 | # Compilation duties... |
paul@196 | 1068 | |
paul@374 | 1069 | for temp in temp_list: |
paul@374 | 1070 | self.discard_temp(temp) |
paul@196 | 1071 | |
paul@354 | 1072 | def _generateInvocation(self, temp_fn, temp_list): |
paul@196 | 1073 | |
paul@196 | 1074 | """ |
paul@354 | 1075 | Invoke the function 'temp_fn' using the operands from 'temp_list' as |
paul@354 | 1076 | arguments. |
paul@196 | 1077 | """ |
paul@196 | 1078 | |
paul@196 | 1079 | self._startCallFunc() |
paul@354 | 1080 | |
paul@354 | 1081 | for i, temp in enumerate(temp_list): |
paul@354 | 1082 | self.new_op(temp) |
paul@354 | 1083 | self.new_op(StoreFrame(i)) |
paul@196 | 1084 | |
paul@354 | 1085 | self._endCallFuncArgs(len(temp_list)) |
paul@354 | 1086 | self._doCallFunc(temp_fn) |
paul@354 | 1087 | self._endCallFunc(temp_fn) |
paul@354 | 1088 | |
paul@374 | 1089 | def _getOperatorFunction(self, node, operator_name=None): |
paul@196 | 1090 | |
paul@354 | 1091 | "Return an operator function reference for the given 'node'." |
paul@354 | 1092 | |
paul@374 | 1093 | return self._generateOperatorFunction(operator_name or node.__class__.__name__) |
paul@354 | 1094 | |
paul@354 | 1095 | def _getOperatorAugAssignFunction(self, node): |
paul@196 | 1096 | |
paul@354 | 1097 | """ |
paul@354 | 1098 | Return an operator augmented assignment function reference for the given |
paul@354 | 1099 | 'node'. |
paul@354 | 1100 | """ |
paul@196 | 1101 | |
paul@354 | 1102 | return self._generateOperatorFunction(node.op) |
paul@354 | 1103 | |
paul@354 | 1104 | def _generateOperatorFunction(self, opname): |
paul@354 | 1105 | |
paul@354 | 1106 | "Return an operator function reference for the given 'opname'." |
paul@196 | 1107 | |
paul@354 | 1108 | operator_fn = operator_functions[opname] |
paul@196 | 1109 | |
paul@354 | 1110 | # Get the operator module. |
paul@232 | 1111 | |
paul@354 | 1112 | operator_module = self.importer.get_module("operator") |
paul@232 | 1113 | |
paul@354 | 1114 | # Get the appropriate function from the operator module. |
paul@354 | 1115 | |
paul@354 | 1116 | self.new_op(LoadAddress(operator_module[operator_fn])) |
paul@354 | 1117 | return self.optimiser.optimise_temp_storage() |
paul@196 | 1118 | |
paul@232 | 1119 | def _handleAttributeError(self, node, temp_method, handled_block): |
paul@196 | 1120 | |
paul@196 | 1121 | """ |
paul@196 | 1122 | Add exception handling to the method acquisition instructions where the |
paul@196 | 1123 | attribute access cannot be resolved at compile-time. |
paul@196 | 1124 | """ |
paul@196 | 1125 | |
paul@232 | 1126 | if not (self.optimiser.should_optimise_known_target() and self.optimiser.is_constant_input(temp_method)): |
paul@196 | 1127 | self.load_builtin("AttributeError", node) |
paul@450 | 1128 | self.new_op(CheckException(target="status")) |
paul@450 | 1129 | self.new_op(JumpIfTrue(handled_block, working="status")) |
paul@232 | 1130 | self.new_op(RaiseException()) |
paul@196 | 1131 | |
paul@246 | 1132 | def _generateTuple(self, node): |
paul@246 | 1133 | |
paul@246 | 1134 | "Make a tuple using the given program 'node'." |
paul@246 | 1135 | |
paul@401 | 1136 | # Reserve space for the elements themselves. |
paul@395 | 1137 | |
paul@446 | 1138 | self.make_instance(self.get_builtin_class("tuple"), len(node.nodes)) |
paul@246 | 1139 | temp = self.get_temp() |
paul@395 | 1140 | |
paul@401 | 1141 | # Store using 0-based index values. |
paul@395 | 1142 | |
paul@506 | 1143 | self._populateSequence(temp, node.nodes) |
paul@395 | 1144 | |
paul@464 | 1145 | self.new_op(temp) |
paul@246 | 1146 | self.discard_temp(temp) |
paul@246 | 1147 | |
paul@506 | 1148 | def _generateList(self, node, nodes=None): |
paul@246 | 1149 | |
paul@506 | 1150 | "Make a list using the given program 'node' and optional 'nodes'." |
paul@506 | 1151 | |
paul@506 | 1152 | nodes = nodes or [] |
paul@246 | 1153 | |
paul@246 | 1154 | # Make a fragment containing the list elements. |
paul@196 | 1155 | |
paul@506 | 1156 | self.new_op(MakeFragment(len(nodes) + 1)) |
paul@246 | 1157 | temp = self.get_temp() |
paul@506 | 1158 | self._populateSequence(temp, nodes) |
paul@246 | 1159 | self.new_op(temp) |
paul@246 | 1160 | self.record_value() |
paul@196 | 1161 | |
paul@401 | 1162 | # Reserve space for _elements (the fragment reference). |
paul@395 | 1163 | |
paul@446 | 1164 | self.make_instance(self.get_builtin_class("list"), 1) |
paul@246 | 1165 | list_temp = self.get_temp() |
paul@469 | 1166 | |
paul@469 | 1167 | self.start_target() |
paul@246 | 1168 | self.new_op(list_temp) |
paul@401 | 1169 | self.new_op(StoreAttr(Attr(0, None, None))) # _elements is at position 0 |
paul@451 | 1170 | self.assign_value() |
paul@246 | 1171 | self.discard_value() |
paul@246 | 1172 | |
paul@464 | 1173 | self.new_op(list_temp) |
paul@246 | 1174 | self.discard_temp(temp) |
paul@246 | 1175 | self.discard_temp(list_temp) |
paul@246 | 1176 | |
paul@506 | 1177 | def _populateSequence(self, temp, nodes, offset=0): |
paul@246 | 1178 | |
paul@246 | 1179 | """ |
paul@506 | 1180 | Populate a sequence using the given 'temp' reference and 'nodes'. |
paul@246 | 1181 | """ |
paul@196 | 1182 | |
paul@506 | 1183 | for i, n in enumerate(nodes): |
paul@196 | 1184 | self.dispatch(n) |
paul@196 | 1185 | self.record_value() |
paul@438 | 1186 | self._storeInSequence(temp, i, offset) |
paul@196 | 1187 | self.discard_value() |
paul@196 | 1188 | |
paul@438 | 1189 | def _storeInSequence(self, temp, i, offset=0): |
paul@438 | 1190 | |
paul@438 | 1191 | """ |
paul@438 | 1192 | Store the current active value in the fragment referenced by 'temp' at |
paul@438 | 1193 | position 'i' with the given starting 'offset'. |
paul@438 | 1194 | """ |
paul@438 | 1195 | |
paul@469 | 1196 | self.start_target() |
paul@438 | 1197 | self.new_op(temp) |
paul@438 | 1198 | self.new_op(StoreAttr(Attr(i + offset, None, None))) |
paul@451 | 1199 | self.assign_value() |
paul@438 | 1200 | |
paul@196 | 1201 | def _generateTestBoolean(self, node, temp): |
paul@196 | 1202 | |
paul@196 | 1203 | """ |
paul@196 | 1204 | Generate a test of the boolean status of the current value for the given |
paul@196 | 1205 | program 'node'. |
paul@196 | 1206 | """ |
paul@196 | 1207 | |
paul@196 | 1208 | # Get method on temp. |
paul@196 | 1209 | # NOTE: Using __bool__ instead of __nonzero__. |
paul@196 | 1210 | |
paul@196 | 1211 | self._generateAttr(node, "__bool__", self.attribute_load_instructions) |
paul@196 | 1212 | temp_method = self.optimiser.optimise_temp_storage() |
paul@196 | 1213 | |
paul@354 | 1214 | self._generateInvocation(temp_method, (temp,)) |
paul@196 | 1215 | |
paul@196 | 1216 | self.discard_temp(temp_method) |
paul@196 | 1217 | |
paul@196 | 1218 | # Convert result to boolean (a StoreBoolean operation). |
paul@196 | 1219 | |
paul@450 | 1220 | self.new_op(TestIdentityAddress(self.importer.get_predefined_constant("True"), target="status")) |
paul@196 | 1221 | |
paul@196 | 1222 | def _generateLoadBoolean(self, node): |
paul@196 | 1223 | |
paul@196 | 1224 | """ |
paul@196 | 1225 | Generate instructions to load the appropriate value given the current |
paul@196 | 1226 | boolean status. |
paul@196 | 1227 | """ |
paul@196 | 1228 | |
paul@452 | 1229 | false_block = self.get_block() |
paul@196 | 1230 | true_block = self.new_block() |
paul@196 | 1231 | end_block = self.new_block() |
paul@196 | 1232 | |
paul@450 | 1233 | self.new_op(JumpIfTrue(true_block, working="status")) |
paul@197 | 1234 | self.new_op(LoadConst(self.importer.get_predefined_constant("False"))) |
paul@196 | 1235 | self.new_op(Jump(end_block)) |
paul@196 | 1236 | |
paul@196 | 1237 | self.set_block(true_block) |
paul@197 | 1238 | self.new_op(LoadConst(self.importer.get_predefined_constant("True"))) |
paul@196 | 1239 | |
paul@452 | 1240 | self.set_block(end_block, [false_block, true_block]) |
paul@196 | 1241 | |
paul@506 | 1242 | # Common AST operations. |
paul@506 | 1243 | |
paul@506 | 1244 | def _startFor(self, node, else_=None): |
paul@506 | 1245 | |
paul@506 | 1246 | """ |
paul@506 | 1247 | Generate the start of a loop using the given 'node' and 'else_' clause, |
paul@506 | 1248 | if defined. The iterator and next, exit and else blocks are returned. |
paul@506 | 1249 | """ |
paul@506 | 1250 | |
paul@506 | 1251 | next_handler_block = self.new_block() |
paul@506 | 1252 | end_handler_block = self.new_block() |
paul@506 | 1253 | exit_block = self.new_block() |
paul@506 | 1254 | next_block = self.new_block() |
paul@506 | 1255 | else_block = self.new_block() |
paul@506 | 1256 | |
paul@506 | 1257 | temp_iterator = self._visitForList(node) |
paul@506 | 1258 | |
paul@506 | 1259 | # In the loop... |
paul@506 | 1260 | |
paul@506 | 1261 | self.set_block(next_block) |
paul@506 | 1262 | |
paul@506 | 1263 | # Handle exceptions when calling "next"... |
paul@506 | 1264 | |
paul@506 | 1265 | self.add_exception_blocks(next_handler_block, end_handler_block) |
paul@506 | 1266 | self.new_op(PushHandler(next_handler_block)) |
paul@506 | 1267 | |
paul@506 | 1268 | # Invoke the next method. |
paul@506 | 1269 | |
paul@506 | 1270 | self._visitForNext(node, temp_iterator) |
paul@506 | 1271 | |
paul@506 | 1272 | # Record the value to be assigned. |
paul@506 | 1273 | |
paul@506 | 1274 | self.record_value() |
paul@506 | 1275 | |
paul@506 | 1276 | # Skip the handler where the call was successful. |
paul@506 | 1277 | |
paul@506 | 1278 | self.new_op(PopHandler(1)) |
paul@506 | 1279 | self.new_op(Jump(end_handler_block)) |
paul@506 | 1280 | |
paul@506 | 1281 | # Enter the exception handler. |
paul@506 | 1282 | |
paul@506 | 1283 | self.set_block(next_handler_block) |
paul@506 | 1284 | self.new_op(PopHandler(1)) |
paul@506 | 1285 | |
paul@506 | 1286 | # Disable the handlers. |
paul@506 | 1287 | |
paul@506 | 1288 | self.drop_exception_blocks() |
paul@506 | 1289 | |
paul@506 | 1290 | # Test for StopIteration. |
paul@506 | 1291 | |
paul@506 | 1292 | self.load_builtin("StopIteration", node) |
paul@506 | 1293 | self.new_op(CheckException(target="status")) |
paul@506 | 1294 | if else_ is not None: |
paul@506 | 1295 | self.new_op(JumpIfTrue(else_block, working="status")) |
paul@506 | 1296 | else: |
paul@506 | 1297 | self.new_op(JumpIfTrue(exit_block, working="status")) |
paul@506 | 1298 | |
paul@506 | 1299 | # Re-raise the exception otherwise. |
paul@506 | 1300 | |
paul@506 | 1301 | self.new_op(RaiseException()) |
paul@506 | 1302 | |
paul@506 | 1303 | # After the handler, clear the exception. |
paul@506 | 1304 | |
paul@506 | 1305 | self.set_block(end_handler_block) |
paul@506 | 1306 | |
paul@506 | 1307 | # Assign to the target. |
paul@506 | 1308 | |
paul@506 | 1309 | self.dispatch(node.assign) |
paul@506 | 1310 | self.discard_value() |
paul@506 | 1311 | |
paul@506 | 1312 | # Process the body with the current next and exit points. |
paul@506 | 1313 | |
paul@506 | 1314 | self.add_loop_blocks(next_block, exit_block) |
paul@506 | 1315 | |
paul@506 | 1316 | return temp_iterator, next_block, exit_block, else_block |
paul@506 | 1317 | |
paul@506 | 1318 | def _endFor(self, node, temp_iterator, next_block, exit_block, else_block=None, else_=None): |
paul@506 | 1319 | |
paul@506 | 1320 | """ |
paul@506 | 1321 | Generate the end of a loop for the given 'node' using the given |
paul@506 | 1322 | 'temp_iterator' and 'next_block', 'exit_block' and 'else_block' |
paul@506 | 1323 | definitions, together with an 'else_' clause, if defined. |
paul@506 | 1324 | """ |
paul@506 | 1325 | |
paul@506 | 1326 | self.drop_loop_blocks() |
paul@506 | 1327 | |
paul@506 | 1328 | # Repeat the loop. |
paul@506 | 1329 | |
paul@506 | 1330 | self.new_op(Jump(next_block)) |
paul@506 | 1331 | |
paul@506 | 1332 | # Produce the "else" section. |
paul@506 | 1333 | |
paul@506 | 1334 | if else_ is not None: |
paul@506 | 1335 | self.set_block(else_block) |
paul@506 | 1336 | self.new_op(ClearException(target="exception")) |
paul@506 | 1337 | self.dispatch(else_) |
paul@506 | 1338 | |
paul@506 | 1339 | # After the loop... |
paul@506 | 1340 | |
paul@506 | 1341 | self.set_block(exit_block) |
paul@506 | 1342 | |
paul@506 | 1343 | else: |
paul@506 | 1344 | # After the loop... |
paul@506 | 1345 | |
paul@506 | 1346 | self.set_block(exit_block) |
paul@506 | 1347 | self.new_op(ClearException(target="exception")) |
paul@506 | 1348 | |
paul@506 | 1349 | # Compilation duties... |
paul@506 | 1350 | |
paul@506 | 1351 | self.discard_temp(temp_iterator) |
paul@506 | 1352 | |
paul@506 | 1353 | def _visitForList(self, node): |
paul@506 | 1354 | |
paul@506 | 1355 | "Get the list to be iterated over, returning its iterator." |
paul@506 | 1356 | |
paul@506 | 1357 | self._startCallFunc() |
paul@506 | 1358 | self.dispatch(node.list) |
paul@506 | 1359 | self._generateAttr(node, "__iter__", self.attribute_load_instructions) |
paul@506 | 1360 | temp_target, target, temp_context = self._generateCallFunc([], node) |
paul@506 | 1361 | self._doCallFunc(temp_target, target) |
paul@506 | 1362 | self._endCallFunc(temp_target, temp_context) |
paul@506 | 1363 | |
paul@506 | 1364 | # Use a long-lasting temporary storage slot, since any result from the |
paul@506 | 1365 | # __iter__ method will not remain around for long. |
paul@506 | 1366 | |
paul@506 | 1367 | return self.get_temp() |
paul@506 | 1368 | |
paul@506 | 1369 | def _visitForNext(self, node, temp_iterator): |
paul@506 | 1370 | |
paul@506 | 1371 | "Use the iterator to get the next value." |
paul@506 | 1372 | |
paul@506 | 1373 | self._startCallFunc() |
paul@506 | 1374 | self.new_op(temp_iterator) |
paul@506 | 1375 | self._generateAttr(node, "next", self.attribute_load_instructions) |
paul@506 | 1376 | temp_target, target, temp_context = self._generateCallFunc([], node) |
paul@506 | 1377 | self._doCallFunc(temp_target, target) |
paul@506 | 1378 | self._endCallFunc(temp_target, temp_context) |
paul@506 | 1379 | |
paul@393 | 1380 | def _visitPrint(self, node, function_name): |
paul@393 | 1381 | self._startCallFunc() |
paul@393 | 1382 | self.load_builtin(function_name, node) |
paul@393 | 1383 | |
paul@393 | 1384 | args = [node.dest or compiler.ast.Name("None")] + node.nodes |
paul@393 | 1385 | |
paul@393 | 1386 | temp_target, target, temp_context = self._generateCallFunc(args, node) |
paul@393 | 1387 | self._doCallFunc(temp_target, target) |
paul@393 | 1388 | self._endCallFunc(temp_target, temp_context) |
paul@393 | 1389 | |
paul@563 | 1390 | def _visitImport(self, node): |
paul@563 | 1391 | |
paul@563 | 1392 | """ |
paul@563 | 1393 | Although imported code already resides in any generated image, the |
paul@563 | 1394 | module code must be executed. Module code uses its own frame for any |
paul@563 | 1395 | temporary storage and thus behaves like a function. |
paul@563 | 1396 | """ |
paul@563 | 1397 | |
paul@563 | 1398 | modules = self.importer.importers.get(node) |
paul@563 | 1399 | if modules: |
paul@563 | 1400 | for module in modules: |
paul@563 | 1401 | self.new_op(MakeFrame(0)) |
paul@563 | 1402 | self.new_op(LoadConst(module)) |
paul@563 | 1403 | self.new_op(LoadCallable()) |
paul@563 | 1404 | self.new_op(JumpWithFrame()) |
paul@563 | 1405 | self.new_op(DropFrame()) |
paul@563 | 1406 | |
paul@563 | 1407 | def _importName(self, module, name, alias, node): |
paul@563 | 1408 | |
paul@563 | 1409 | # Get the source of the name. |
paul@563 | 1410 | |
paul@563 | 1411 | attr = module[name] |
paul@563 | 1412 | self.new_op(LoadAddress(attr)) |
paul@563 | 1413 | |
paul@563 | 1414 | # Record the object in the current namespace. |
paul@563 | 1415 | |
paul@563 | 1416 | self.record_value() |
paul@563 | 1417 | |
paul@563 | 1418 | self.start_target() |
paul@563 | 1419 | self._generateName(alias or name, self.name_store_instructions, node) # AssName equivalent |
paul@563 | 1420 | self.assign_value() |
paul@563 | 1421 | self.discard_value() |
paul@563 | 1422 | |
paul@196 | 1423 | # vim: tabstop=4 expandtab shiftwidth=4 |