예제 #1
0
    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')
예제 #2
0
 def __eq__(self, c):
     """ EQ operation. """
     if self.GetType() == None or c.GetType() == None:
         raise Err.MissingValueException('invalid operation')
     return self.value.__eq__(c)
예제 #3
0
 def __repr__(self):
     """ Makes Variable representable as str. """
     if self.GetType() == None:
         raise Err.MissingValueException('invalid operation')
     return repr(self.value)
예제 #4
0
 def __getitem__(self, pos):
     """ GETCHAR operation. """
     if self.GetType() == None or pos.GetType() == None:
         raise Err.MissingValueException('invalid operation')
     return self.value.__getitem__(pos)
예제 #5
0
 def __len__(self):
     """ STRLEN operation. """
     if self.GetType() == None:
         raise Err.MissingValueException('invalid operation')
     return self.value.__len__()
예제 #6
0
 def Pops(self):
     """ Pops and returns top item from the datastack. """
     try:
         return self.datastack.Pop()
     except:
         raise Err.MissingValueException('Empty data stack!')
예제 #7
0
 def PopPC(self):
     """ Pops program counter position from the callstack. """
     try:
         self.pc = self.callstack.Pop()
     except:
         raise Err.MissingValueException('Empty call stack!')