Advertisement
Guest User

Untitled

a guest
Jan 3rd, 2012
167
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Function(object):
  2.     def __init__(self, name, code=None):
  3.         self.name = name
  4.         self.code = []
  5.         self.labels = {}
  6.  
  7.         if code is not None:
  8.             self.load(code)
  9.    
  10.     def load(self, code):
  11.         pc = 0
  12.        
  13.         for inst in code:
  14.             if inst[0] == "label":
  15.                 label = inst[1]
  16.                 self.labels[label] = pc
  17.             else:
  18.                 self.code.insert(pc, inst)
  19.                 pc += 1
  20.    
  21.     def label(self, label):
  22.         return self.labels[label]
Advertisement
RAW Paste Data Copied
Advertisement