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, codedetails, name, size, funccode=None): 29 self.classcode = classcode 30 self.attrcode = attrcode 31 self.codeaddr = codeaddr 32 self.codedetails = codedetails 33 self.name = name 34 self.size = size 35 self.funccode = funccode 36 37 def with_size(self, size): 38 return DataObject(self.classcode, self.attrcode, self.codeaddr, self.codedetails, self.name, size, self.funccode) 39 40 def __repr__(self): 41 return "%r # %s" % ( 42 (self.classcode, self.attrcode, self.codeaddr, self.codedetails, self.funccode, self.size), self.name 43 ) 44 45 # vim: tabstop=4 expandtab shiftwidth=4