bool: Bool, int: Int32, float: Float64, # These types are not actually supported str: Bytes, bytes: Bytes, } def typeof(value): """Python value -> type""" return typing_defaults[type(value)] # ______________________________________________________________________ # Convert conversion_map = invert(typing_defaults) conversion_map.update(dict.fromkeys(int_set, int)) conversion_map.update(dict.fromkeys(float_set, float)) # conversion_map.update(dict.fromkeys(complex_set, complex)) def convert(value, dst_type): """(python value, type) -> converted python value""" if dst_type.is_typedef: dst_type = dst_type.type converter = conversion_map[dst_type] return converter(value) # ______________________________________________________________________ type2name = dict((v, n) for n, v in globals().items() if hashable(v)) typename = type2name.__getitem__
"-": ops.usub, } binary_defs = { "+": ops.add, "-": ops.sub, "*": ops.mul, "/": ops.div, "%": ops.mod, "<<": ops.lshift, ">>": ops.rshift, "|": ops.bitor, "&": ops.bitand, "^": ops.bitxor, } compare_defs = { "<": ops.lt, "<=": ops.lte, ">": ops.gt, ">=": ops.gte, "==": ops.eq, "!=": ops.noteq, } unary_opcodes = invert(unary_defs) binary_opcodes = invert(binary_defs) compare_opcodes = invert(compare_defs) func2operator = mergedicts(invert(unary), invert(binary), invert(compare)) bitwise = set(["<<", ">>", "|", "&", "^", "~"])
"+": ops.uadd, "-": ops.usub, } binary_defs = { "+": ops.add, "-": ops.sub, "*": ops.mul, "/": ops.div, "%": ops.mod, "<<": ops.lshift, ">>": ops.rshift, "|": ops.bitor, "&": ops.bitand, "^": ops.bitxor, } compare_defs = { "<": ops.lt, "<=": ops.lte, ">": ops.gt, ">=": ops.gte, "==": ops.eq, "!=": ops.noteq, } unary_opcodes = invert(unary_defs) binary_opcodes = invert(binary_defs) compare_opcodes = invert(compare_defs) bitwise = set(["<<", ">>", "|", "&", "^", "~"])
ops.mod: '__mod__', ops.lshift: '__lshift__', ops.rshift: '__rshift__', ops.bitor: '__or__', ops.bitand: '__and__', ops.bitxor: '__xor__', # Compare ops.lt: '__lt__', ops.le: '__le__', ops.gt: '__gt__', ops.ge: '__ge__', ops.eq: '__eq__', ops.ne: '__ne__', } special2op = invert(special) def lookup_special(func): """Look up a special method name for an operator.* function""" operator = defs.operator2opcode[func] return special[operator] #===------------------------------------------------------------------=== # flypy-specific special methods #===------------------------------------------------------------------=== # We don't assume __setattr__ since there is no good way to implement them # with python semantics right now (e.g. using super()), and we do want # attributes to work properly in Python land.
} binary_defs = { "+": ops.add, "-": ops.sub, "*": ops.mul, "/": ops.div, "%": ops.mod, "<<": ops.lshift, ">>": ops.rshift, "|": ops.bitor, "&": ops.bitand, "^": ops.bitxor, } compare_defs = { "<": ops.lt, "<=": ops.le, ">": ops.gt, ">=": ops.ge, "==": ops.eq, "!=": ops.ne, } unary_opcodes = invert(unary_defs) binary_opcodes = invert(binary_defs) compare_opcodes = invert(compare_defs) opcode2operator = mergedicts(unary, binary, compare) operator2opcode = mergedicts(invert(unary), invert(binary), invert(compare)) bitwise = set(["<<", ">>", "|", "&", "^", "~"])
ops.mod : '__mod__', ops.lshift : '__lshift__', ops.rshift : '__rshift__', ops.bitor : '__or__', ops.bitand : '__and__', ops.bitxor : '__xor__', # Compare ops.lt : '__lt__', ops.le : '__le__', ops.gt : '__gt__', ops.ge : '__ge__', ops.eq : '__eq__', ops.ne : '__ne__', } special2op = invert(special) def lookup_special(func): """Look up a special method name for an operator.* function""" operator = defs.operator2opcode[func] return special[operator] #===------------------------------------------------------------------=== # flypy-specific special methods #===------------------------------------------------------------------=== # We don't assume __setattr__ since there is no good way to implement them # with python semantics right now (e.g. using super()), and we do want # attributes to work properly in Python land. # __setattribute__ semantics is that when an attribute is missing,