def __init__(self, node_type, rhs): '''Initializes the UnaryExpression with the specified arguments. Arguments: node_type - Specifies the type of operation that this UnaryExpression represents rhs - Right-hand site of the operation. Since this is an unary operation, this is the only argument. ''' Guard.against_empty(node_type, "The UnaryExpression node type is required") if node_type == self.CollectionLength: Guard.accepts(rhs, (ConstantExpression,), "The CollectionLength unary expression can only take ConstantExpressions that hold tuples or lists as parameters.") if not isinstance(rhs.evaluate(), (list, tuple)): raise ValueError("The CollectionLength unary expression can only take ConstantExpressions that hold tuples or lists as parameters.") self.node_type = node_type self.rhs = rhs
def __init__(self, node_type, lhs, rhs): '''Initializes the BinaryExpression with the specified arguments. Arguments: node_type - Specifies the type of operation that this BinaryExpression represents lhs - Left-hand side of the operation (as in the first argument) rhs - Right-hand site of the operation (as in the second argument) ''' Guard.against_empty(node_type, "The BinaryExpression node type is required") Guard.accepts(lhs, (Expression,), "Lhs must be an expression (an instance of a class that inherits from pynq.Expression), but was %s" % lhs.__class__.__name__) Guard.accepts(rhs, (Expression,), "Rhs must be an expression (an instance of a class that inherits from pynq.Expression) but was %s" % rhs.__class__.__name__) self.node_type = node_type self.lhs = lhs self.rhs = rhs
def __init__(self, node_type, rhs): '''Initializes the UnaryExpression with the specified arguments. Arguments: node_type - Specifies the type of operation that this UnaryExpression represents rhs - Right-hand site of the operation. Since this is an unary operation, this is the only argument. ''' Guard.against_empty(node_type, "The UnaryExpression node type is required") if node_type == self.CollectionLength: Guard.accepts( rhs, (ConstantExpression, ), "The CollectionLength unary expression can only take ConstantExpressions that hold tuples or lists as parameters." ) if not isinstance(rhs.evaluate(), (list, tuple)): raise ValueError( "The CollectionLength unary expression can only take ConstantExpressions that hold tuples or lists as parameters." ) self.node_type = node_type self.rhs = rhs
def __init__(self, node_type, lhs, rhs): '''Initializes the BinaryExpression with the specified arguments. Arguments: node_type - Specifies the type of operation that this BinaryExpression represents lhs - Left-hand side of the operation (as in the first argument) rhs - Right-hand site of the operation (as in the second argument) ''' Guard.against_empty(node_type, "The BinaryExpression node type is required") Guard.accepts( lhs, (Expression, ), "Lhs must be an expression (an instance of a class that inherits from pynq.Expression), but was %s" % lhs.__class__.__name__) Guard.accepts( rhs, (Expression, ), "Rhs must be an expression (an instance of a class that inherits from pynq.Expression) but was %s" % rhs.__class__.__name__) self.node_type = node_type self.lhs = lhs self.rhs = rhs
def do(self, a): Guard.accepts(a, (int, float)) pass
def do(self, a): Guard.accepts(a, (int, float), "Argument a must be an integer or a float") pass
def do(self, a): Guard.accepts(a, (int, float)) pass
def do(self, a): Guard.accepts(a, (int, float), "Argument a must be an integer or a float") pass