1. Stephen Tu
  2. mino-pypy

Commits

Stephen Tu  committed 52884c1

more complete impl

  • Participants
  • Parent commits 7af2b13
  • Branches default

Comments (0)

Files changed (1)

File pypy/interpreter/astcompiler/codegen.py

View file
  • Ignore whitespace
     def _break_if_file_matches(self, filename):
         pass
 
-        if self.symbols.compile_info.filename.find(filename) != -1:
-            import pdb
-            pdb.set_trace()
+        #if self.symbols.compile_info.filename.find(filename) != -1:
+        #    import pdb
+        #    pdb.set_trace()
 
     def _break_if_cond_fails(self, cond):
         pass
         ast.GenericASTVisitor.visit_Return(self, node)
 
     def visit_Assign(self, node):
+        #self._break_if_file_matches('x2.py')
         ntargets = len(node.targets)
         if ntargets == 1:
             self._assignment_like(node.targets[0], node.value, False)
     ### Visitor helpers ###
 
     def _note_assignment(self, target, value):
-        konst_type = self._literal_type(value)
+        konst_type = self._effective_literal_type(value)
         if konst_type:
             sym = self._logical_symbol_by_node(target)
             if sym:
     _SET_TYPE     = 8
     _TUPLE_TYPE   = 9
 
+    def _effective_literal_type(self, value):
+        konst_type = self._literal_type(value)
+        if konst_type:
+            return konst_type
+        sym = self._logical_symbol_by_node(value)
+        if sym:
+            try:
+                return self.scope_const_maps[sym.scope][sym.name]
+            except KeyError:
+                pass
+        return self._UNKNOWN_TYPE
+
     def _literal_type(self, value):
         if isinstance(value, ast.Num):
             konst_type = self.symbols.space.type(value.n)
             return self._SET_TYPE
         elif isinstance(value, ast.Tuple):
             return self._TUPLE_TYPE
+        elif isinstance(value, ast.Const):
+            konst_type = self.symbols.space.type(value.value)
+            if konst_type == self.symbols.space.w_tuple:
+                return self._TUPLE_TYPE
+            elif konst_type == self.symbols.space.w_list:
+                return self._LIST_TYPE
+            elif konst_type == self.symbols.space.w_dict:
+                return self._DICT_TYPE
+            # XXX: handle
         return self._UNKNOWN_TYPE
 
     _TypeToFeatureName = {
     }
 
     def _assignment_like(self, target, value, aug):
-        konst_type = self._literal_type(value)
+        konst_type = self._effective_literal_type(value)
         if konst_type:
             try:
                 k = self._TypeToFeatureName[konst_type]
                 self._record_binary_feature(target, feature_name)
             except KeyError:
                 print '[WARNING]: unknown literal type: %s' % (str(konst_type))
-        else:
-            # check the awesome const symbol map
-            sym = self._logical_symbol_by_node(value)
-            if sym:
-                try:
-                    # XXX: code duplication is bad!
-                    tt = self.scope_const_maps[sym.scope][sym.name]
-                    k = self._TypeToFeatureName[tt]
-                    feature_name = ('aug_assigned_%s' % (k)) if aug else ('assigned_%s' % (k))
-                    self._record_binary_feature(target, feature_name)
-                except KeyError:
-                    pass
 
     # XXX: this is arbitrary how we assign which binops/cmps to distinguish
     # between: we'll need to refine this
             self._BinopTypeToFeatureName
 
         # check two special cases: lhs is const, and rhs is const
-        lhs_const_type = self._literal_type(lhs)
-        rhs_const_type = self._literal_type(rhs)
+        lhs_const_type = self._effective_literal_type(lhs)
+        rhs_const_type = self._effective_literal_type(rhs)
         done = False
         if lhs_const_type:
             try: