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