paul@201 | 1 | #!/usr/bin/env python |
paul@201 | 2 | |
paul@201 | 3 | """ |
paul@201 | 4 | Program code and data representations. |
paul@201 | 5 | """ |
paul@201 | 6 | |
paul@201 | 7 | class Block: |
paul@201 | 8 | |
paul@201 | 9 | "A code block." |
paul@201 | 10 | |
paul@201 | 11 | def __init__(self): |
paul@201 | 12 | self.code = [] |
paul@201 | 13 | self.location = None |
paul@201 | 14 | |
paul@201 | 15 | def __repr__(self): |
paul@201 | 16 | return "Block(%r, location=%r)" % (id(self), self.location) |
paul@201 | 17 | |
paul@201 | 18 | def as_raw(self, objtable, paramtable): |
paul@201 | 19 | for i, item in enumerate(self.code): |
paul@201 | 20 | if hasattr(item, "location"): |
paul@201 | 21 | item.location = location + i |
paul@201 | 22 | return self.code |
paul@201 | 23 | |
paul@201 | 24 | class DataObject: |
paul@201 | 25 | |
paul@201 | 26 | "A representation of a raw program data object." |
paul@201 | 27 | |
paul@203 | 28 | def __init__(self, classcode, attrcode, codeaddr, codedetails, instance, name, size, funccode=None): |
paul@201 | 29 | self.classcode = classcode |
paul@201 | 30 | self.attrcode = attrcode |
paul@201 | 31 | self.codeaddr = codeaddr |
paul@201 | 32 | self.codedetails = codedetails |
paul@201 | 33 | self.instance = instance |
paul@201 | 34 | self.name = name |
paul@203 | 35 | self.size = size |
paul@201 | 36 | self.funccode = funccode |
paul@201 | 37 | |
paul@203 | 38 | def with_size(self, size): |
paul@203 | 39 | return DataObject(self.classcode, self.attrcode, self.codeaddr, self.codedetails, self.instance, self.name, size, self.funccode) |
paul@203 | 40 | |
paul@201 | 41 | def __repr__(self): |
paul@203 | 42 | return "%r # %s" % ( |
paul@203 | 43 | (self.classcode, self.attrcode, self.codeaddr, self.codedetails, self.instance, self.funccode, self.size), self.name |
paul@203 | 44 | ) |
paul@201 | 45 | |
paul@201 | 46 | # vim: tabstop=4 expandtab shiftwidth=4 |