diff --git a/include/pocketpy/vm.h b/include/pocketpy/vm.h index 3ef87d8a..2741718c 100644 --- a/include/pocketpy/vm.h +++ b/include/pocketpy/vm.h @@ -458,31 +458,23 @@ inline constexpr bool is_immutable_v = is_integral_v || is_floating_point_v || std::is_same_v || std::is_pointer_v || std::is_enum_v; -constexpr std::pair _const_cxx_typeid_map[] = { - {&typeid(Str), VM::tp_str}, - {&typeid(List), VM::tp_list}, - {&typeid(Tuple), VM::tp_tuple}, - {&typeid(Function), VM::tp_function}, - {&typeid(NativeFunc), VM::tp_native_func}, - {&typeid(BoundMethod), VM::tp_bound_method}, - {&typeid(Range), VM::tp_range}, - {&typeid(Slice), VM::tp_slice}, - {&typeid(Exception), VM::tp_exception}, - {&typeid(Bytes), VM::tp_bytes}, - {&typeid(MappingProxy), VM::tp_mappingproxy}, - {&typeid(Dict), VM::tp_dict}, - {&typeid(Property), VM::tp_property}, - {&typeid(StarWrapper), VM::tp_star_wrapper}, - {&typeid(StaticMethod), VM::tp_staticmethod}, - {&typeid(ClassMethod), VM::tp_classmethod}, - /***************************************/ -}; - -template -constexpr Type _find_type_in_const_cxx_typeid_map(){ - for(auto [id, type] : _const_cxx_typeid_map) if(id == &typeid(T)) return type; - return -1; -} +template constexpr Type _find_type_in_const_cxx_typeid_map(){ return -1; } +template<> constexpr Type _find_type_in_const_cxx_typeid_map(){ return VM::tp_str; } +template<> constexpr Type _find_type_in_const_cxx_typeid_map(){ return VM::tp_list; } +template<> constexpr Type _find_type_in_const_cxx_typeid_map(){ return VM::tp_tuple; } +template<> constexpr Type _find_type_in_const_cxx_typeid_map(){ return VM::tp_function; } +template<> constexpr Type _find_type_in_const_cxx_typeid_map(){ return VM::tp_native_func; } +template<> constexpr Type _find_type_in_const_cxx_typeid_map(){ return VM::tp_bound_method; } +template<> constexpr Type _find_type_in_const_cxx_typeid_map(){ return VM::tp_range; } +template<> constexpr Type _find_type_in_const_cxx_typeid_map(){ return VM::tp_slice; } +template<> constexpr Type _find_type_in_const_cxx_typeid_map(){ return VM::tp_exception; } +template<> constexpr Type _find_type_in_const_cxx_typeid_map(){ return VM::tp_bytes; } +template<> constexpr Type _find_type_in_const_cxx_typeid_map(){ return VM::tp_mappingproxy; } +template<> constexpr Type _find_type_in_const_cxx_typeid_map(){ return VM::tp_dict; } +template<> constexpr Type _find_type_in_const_cxx_typeid_map(){ return VM::tp_property; } +template<> constexpr Type _find_type_in_const_cxx_typeid_map(){ return VM::tp_star_wrapper; } +template<> constexpr Type _find_type_in_const_cxx_typeid_map(){ return VM::tp_staticmethod; } +template<> constexpr Type _find_type_in_const_cxx_typeid_map(){ return VM::tp_classmethod; } template PyObject* py_var(VM* vm, __T&& value){ diff --git a/tests/01_int.py b/tests/01_int.py index e8967d69..7ff7b692 100644 --- a/tests/01_int.py +++ b/tests/01_int.py @@ -127,6 +127,7 @@ assert not 1 < 2 > 3 try: eval("231231312312312312312312312312312312314354657553423345632") + print("eval should fail with SyntaxError") exit(1) except SyntaxError: pass