(a, b)
define a general purpose ordering for (possibly complex) values.

    useful when rendering the memory map, which has signature Dict[Any, Any],
     where the key is any of our types or nodes (I32, LocalVarable, etc).
define a general purpose ordering for (possibly complex) values.
define a general purpose ordering for ( possibly complex ) values .
def cmp(a, b):
    '''
    define a general purpose ordering for (possibly complex) values.

    useful when rendering the memory map, which has signature Dict[Any, Any],
     where the key is any of our types or nodes (I32, LocalVarable, etc).
    '''
    at = get_type_sort_order(a)
    bt = get_type_sort_order(b)

    if at != bt:
        return at < bt

    if isinstance(a, I32):
        return a.value < b.value

    elif isinstance(a, LocalVariable):
        return a.local_index < b.local_index

    elif isinstance(a, GlobalVariable):
        return a.global_index < b.global_index

    elif isinstance(a, Memory):
        return cmp(a.address, b.address)

    elif isinstance(a, BinaryOperation):
        if a.operation != b.operation:
            return a.operation < b.operation

        # a.lhs != b.lhs
        if a.lhs < b.lhs or b.lhs < a.lhs:
            return cmp(a.lhs, b.lhs)
        # a.rhs != b.rhs
        elif a.rhs != b.rhs or b.rhs < a.rhs:
            return cmp(a.rhs, b.rhs)

        return False

    else:
        raise ValueError('unexpected value type: ' + str(type(self)))
def cmp ( a , b ) : at = get_type_sort_order ( a ) bt = get_type_sort_order ( b ) if at != bt : return at < bt if isinstance ( a , I32 ) : return a . value < b . value elif isinstance ( a , LocalVariable ) : return a . local_index < b . local_index elif isinstance ( a , GlobalVariable ) : return a . global_index < b . global_index elif isinstance ( a , Memory ) : return cmp ( a . address , b . address ) elif isinstance ( a , BinaryOperation ) : if a . operation != b . operation : return a . operation < b . operation # a.lhs != b.lhs if a . lhs < b . lhs or b . lhs < a . lhs : return cmp ( a . lhs , b . lhs ) # a.rhs != b.rhs elif a . rhs != b . rhs or b . rhs < a . rhs : return cmp ( a . rhs , b . rhs ) return False else : raise ValueError ( 'unexpected value type: ' + str ( type ( self ) ) )