@@ -103,9 +103,23 @@ void rt_init(void) {
103
103
map_locals = map_globals = mp_map_new (MP_MAP_QSTR , 1 );
104
104
mp_qstr_map_lookup (map_globals , qstr_from_str_static ("__name__" ), true)-> value = mp_obj_new_str (qstr_from_str_static ("__main__" ));
105
105
106
+ // init built-in hash table
106
107
mp_map_init (& map_builtins , MP_MAP_QSTR , 3 );
108
+
109
+ // built-in exceptions (TODO, make these proper classes)
110
+ mp_qstr_map_lookup (& map_builtins , rt_q_AttributeError , true)-> value = mp_obj_new_exception (rt_q_AttributeError );
111
+ mp_qstr_map_lookup (& map_builtins , rt_q_IndexError , true)-> value = mp_obj_new_exception (rt_q_IndexError );
112
+ mp_qstr_map_lookup (& map_builtins , rt_q_KeyError , true)-> value = mp_obj_new_exception (rt_q_KeyError );
113
+ mp_qstr_map_lookup (& map_builtins , rt_q_NameError , true)-> value = mp_obj_new_exception (rt_q_NameError );
114
+ mp_qstr_map_lookup (& map_builtins , rt_q_TypeError , true)-> value = mp_obj_new_exception (rt_q_TypeError );
115
+ mp_qstr_map_lookup (& map_builtins , rt_q_SyntaxError , true)-> value = mp_obj_new_exception (rt_q_SyntaxError );
116
+ mp_qstr_map_lookup (& map_builtins , rt_q_ValueError , true)-> value = mp_obj_new_exception (rt_q_ValueError );
117
+
118
+ // built-in core functions
107
119
mp_qstr_map_lookup (& map_builtins , rt_q___build_class__ , true)-> value = rt_make_function_2 (mp_builtin___build_class__ );
108
120
mp_qstr_map_lookup (& map_builtins , qstr_from_str_static ("__repl_print__" ), true)-> value = rt_make_function_1 (mp_builtin___repl_print__ );
121
+
122
+ // built-in user functions
109
123
mp_qstr_map_lookup (& map_builtins , qstr_from_str_static ("abs" ), true)-> value = rt_make_function_1 (mp_builtin_abs );
110
124
mp_qstr_map_lookup (& map_builtins , qstr_from_str_static ("all" ), true)-> value = rt_make_function_1 (mp_builtin_all );
111
125
mp_qstr_map_lookup (& map_builtins , qstr_from_str_static ("any" ), true)-> value = rt_make_function_1 (mp_builtin_any );
@@ -550,6 +564,18 @@ mp_obj_t rt_compare_op(int op, mp_obj_t lhs, mp_obj_t rhs) {
550
564
}
551
565
}
552
566
567
+ // deal with exception_match
568
+ if (op == RT_COMPARE_OP_EXCEPTION_MATCH ) {
569
+ // TODO properly! at the moment it just compares the exception identifier for equality
570
+ if (MP_OBJ_IS_TYPE (lhs , & exception_type ) && MP_OBJ_IS_TYPE (rhs , & exception_type )) {
571
+ if (mp_obj_exception_get_type (lhs ) == mp_obj_exception_get_type (rhs )) {
572
+ return mp_const_true ;
573
+ } else {
574
+ return mp_const_false ;
575
+ }
576
+ }
577
+ }
578
+
553
579
// deal with small ints
554
580
if (MP_OBJ_IS_SMALL_INT (lhs ) && MP_OBJ_IS_SMALL_INT (rhs )) {
555
581
mp_small_int_t lhs_val = MP_OBJ_SMALL_INT_VALUE (lhs );
0 commit comments