import ast


def doUnaryOp(op, val):
	"""Perform the given AST unary operation on the value"""
	top = type(op)
	if top == ast.Invert:
		return ~ val
	elif top == ast.Not:
		return not val
	elif top == ast.UAdd:
		return val
	elif top == ast.USub:
		return -val