def Set(self, c): """ Moves value and type of given constant to the variable. """ if c.GetType() == None: raise Err.MissingValueException('missing value') if self.GetType() == None: Variable.varcount += 1 if c.GetType() == int: self.value = Const.IntConstant(c.GetValue()) elif c.GetType() == str: self.value = Const.StringConstant(c.GetValue()) elif c.GetType() == bool: self.value = Const.BoolConstant(c.GetValue()) else: raise Err.SemanticException('incompatible types')
def __eq__(self, c): """ EQ operation. """ if self.GetType() == None or c.GetType() == None: raise Err.MissingValueException('invalid operation') return self.value.__eq__(c)
def __repr__(self): """ Makes Variable representable as str. """ if self.GetType() == None: raise Err.MissingValueException('invalid operation') return repr(self.value)
def __getitem__(self, pos): """ GETCHAR operation. """ if self.GetType() == None or pos.GetType() == None: raise Err.MissingValueException('invalid operation') return self.value.__getitem__(pos)
def __len__(self): """ STRLEN operation. """ if self.GetType() == None: raise Err.MissingValueException('invalid operation') return self.value.__len__()
def Pops(self): """ Pops and returns top item from the datastack. """ try: return self.datastack.Pop() except: raise Err.MissingValueException('Empty data stack!')
def PopPC(self): """ Pops program counter position from the callstack. """ try: self.pc = self.callstack.Pop() except: raise Err.MissingValueException('Empty call stack!')