Changeset 3545:2b85769b8d17 in livinglogic.python.xist

Show
Ignore:
Timestamp:
07/29/08 13:11:00 (11 years ago)
Author:
Walter Doerwald <walter@…>
Branch:
default
Message:

Store the source code location in a two level structure, so no duplicate location objects are used.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • src/ll/ul4c.py

    r3532 r3545  
    788788        _code("source = %r" % self.source) 
    789789        _code('variables = dict((key.decode("utf-8"), value) for (key, value) in variables.iteritems())') # FIXME: This can be dropped in Python 3.0 where strings are unicode 
    790         locations = tuple((oc.location.type, oc.location.starttag, oc.location.endtag, oc.location.startcode, oc.location.endcode) for oc in self.opcodes) 
    791         locations = marshal.dumps(locations) 
     790        locations = [] 
     791        lines2locs = [] 
     792        index = -1 
     793        for oc in self.opcodes: 
     794            loc = (oc.location.type, oc.location.starttag, oc.location.endtag, oc.location.startcode, oc.location.endcode) 
     795            if not locations or locations[-1] != loc: 
     796                locations.append(loc) 
     797                index += 1 
     798            lines2locs.append(index) 
     799        locations = marshal.dumps(tuple(locations)) 
     800        lines2locs = tuple(lines2locs) 
    792801        _code("locations = marshal.loads(%r)" % locations) 
     802        _code("lines2locs = %r" % (lines2locs,)) 
    793803        _code("".join("reg%d = " % i for i in xrange(10)) + "None") 
    794804 
     
    10221032            raise Error(opcode.location, exc) 
    10231033        indent -= 1 
    1024         buildloc = "ul4c.Location(source, *locations[sys.exc_info()[2].tb_lineno-startline])" 
    10251034        _code("except Exception, exc:") 
    10261035        indent += 1 
    1027         _code("raise ul4c.Error(%s, exc)" % buildloc) 
     1036        _code("raise ul4c.Error(ul4c.Location(source, *locations[lines2locs[sys.exc_info()[2].tb_lineno-startline]]), exc)") 
    10281037        return "\n".join(output) 
    10291038