def make_special_function_circle(self, expected_type=None): radius = self._operand.pop() angle = self._operand.pop() if expected_type is not None: if radius.type_var not in expected_type or angle.type_var not in expected_type: raise BigError.invalid_type( "Function {} only accepts expression of type {} ".format( SpecialFunction.STARTPOSITION.name, [item.name for item in expected_type])) self._quadruple.add( QuadruplePack(SpecialFunction.CIRCLE, None, radius, angle)) pass
def make_special_function_go(self, expected_type=None): """ Make quadruple to move to an x,y position :param expected_type: :return: """ x = self._operand.pop() y = self._operand.pop() if expected_type is not None: if x.type_var not in expected_type or y.type_var not in expected_type: raise BigError.invalid_type( "Function {} only accepts expression of type {} ".format( SpecialFunction.STARTPOSITION.name, [item.name for item in expected_type])) self._quadruple.add(QuadruplePack(SpecialFunction.GO, None, x, y))
def make_special_function_start_point(self, expected_type=None): """ Make quadruple for start point, define the starting point of the pencil :param expected_type: :return: """ x = self._operand.pop() y = self._operand.pop() if expected_type is not None: if x.type_var not in expected_type or y.type_var not in expected_type: raise BigError.invalid_type( "Function {} only accepts expression of type {} ".format( SpecialFunction.STARTPOSITION.name, [item.name for item in expected_type])) self._quadruple.add( QuadruplePack(SpecialFunction.STARTPOSITION, None, x, y))
def make_special_function_square(self, expected_type=None): """ Make quadruple for square, accept 1, 2 parameters :param expected_type: :return: """ p1 = self._operand.pop() p2 = self._operand.pop() if expected_type is not None: if p1.type_var not in expected_type or p2.type_var not in expected_type: raise BigError.invalid_type( "Function {} only accepts expression of type {} ".format( SpecialFunction.STARTPOSITION.name, [item.name for item in expected_type])) self._quadruple.add(QuadruplePack(SpecialFunction.SQUARE, None, p1, p2))
def make_special_function_screen_size(self, expected_type=None): """ Make quadruple for start screen size (x and y), define the starting point of the pencil :param sizes: :return: """ exp1 = self._operand.pop() exp2 = self._operand.pop() if expected_type is not None: if exp1.type_var not in expected_type or exp2.type_var not in expected_type: raise BigError.invalid_type( "Function {} only accepts expression of type {} ".format( SpecialFunction.STARTPOSITION.name, [item.name for item in expected_type])) self._quadruple.add( QuadruplePack(SpecialFunction.SCREENSIZES, result=exp1)) self._quadruple.add( QuadruplePack(SpecialFunction.SCREENSIZES, result=exp2))
def make_special_function(self, action_name, expected_type=None): """ Generic function for crating almost all special function :param action_name: :param expected_type: :return: None, Insert quadruple in stack """ action_name = self.text_to_special_operator(action_name) exp = self._operand.pop() if exp is None: raise BigError("Error getting value for function") if expected_type is not None: if exp.type_var not in expected_type: print(action_name) raise BigError.invalid_type( "Function {} only accepts expression of type {} ".format( action_name.name, [item.name for item in expected_type])) q = QuadruplePack(action_name, None, None, exp) self._quadruple.add(q)