import jit import tree_ir BINARY_INTRINSICS = { 'value_eq' : '==', 'value_neq' : '!=', 'bool_and' : 'and', 'bool_or' : 'or', 'integer_addition' : '+', 'integer_subtraction' : '-', 'integer_multiplication' : '*', 'integer_division' : '/', 'integer_gt' : '>', 'integer_gte' : '>=', 'integer_lt' : '<', 'integer_lte' : '<=', 'float_addition' : '+', 'float_subtraction' : '-', 'float_multiplication' : '*', 'float_division' : '/', 'float_gt' : '>', 'float_gte' : '>=', 'float_lt' : '<', 'float_lte' : '<=' } UNARY_INTRINSICS = { 'bool_not' : 'not', 'integer_neg' : '-', 'float_neg' : '-' } MISC_INTRINSICS = { 'element_eq' : ( lambda lhs, rhs: tree_ir.CreateNodeWithValueInstruction( tree_ir.BinaryInstruction(lhs, '==', rhs))), 'element_neq' : ( lambda lhs, rhs: tree_ir.CreateNodeWithValueInstruction( tree_ir.BinaryInstruction(lhs, '!=', rhs))) } def register_intrinsics(target_jit): """Registers all intrinsics in the module with the given JIT.""" for (key, value) in BINARY_INTRINSICS.items(): target_jit.register_binary_intrinsic(key, value) for (key, value) in UNARY_INTRINSICS.items(): target_jit.register_unary_intrinsic(key, value) for (key, value) in MISC_INTRINSICS.items(): target_jit.register_intrinsic(key, value)