@@ -470,16 +470,27 @@ typedef struct _mp_stream_p_t {
470
470
} mp_stream_p_t ;
471
471
472
472
struct _mp_obj_type_t {
473
+ // A type is an object so must start with this entry, which points to mp_type_type.
473
474
mp_obj_base_t base ;
475
+
476
+ // The name of this type.
474
477
qstr name ;
478
+
479
+ // Corresponds to __repr__ and __str__ special methods.
475
480
mp_print_fun_t print ;
476
- mp_make_new_fun_t make_new ; // to make an instance of the type
477
481
482
+ // Corresponds to __new__ and __init__ special methods, to make an instance of the type.
483
+ mp_make_new_fun_t make_new ;
484
+
485
+ // Corresponds to __call__ special method, ie T(...).
478
486
mp_call_fun_t call ;
479
- mp_unary_op_fun_t unary_op ; // can return MP_OBJ_NULL if op not supported
480
- mp_binary_op_fun_t binary_op ; // can return MP_OBJ_NULL if op not supported
481
487
482
- // implements load, store and delete attribute
488
+ // Implements unary and binary operations.
489
+ // Can return MP_OBJ_NULL if the operation is not supported.
490
+ mp_unary_op_fun_t unary_op ;
491
+ mp_binary_op_fun_t binary_op ;
492
+
493
+ // Implements load, store and delete attribute.
483
494
//
484
495
// dest[0] = MP_OBJ_NULL means load
485
496
// return: for fail, do nothing
@@ -492,35 +503,33 @@ struct _mp_obj_type_t {
492
503
// for success set dest[0] = MP_OBJ_NULL
493
504
mp_attr_fun_t attr ;
494
505
495
- mp_subscr_fun_t subscr ; // implements load, store, delete subscripting
496
- // value=MP_OBJ_NULL means delete, value=MP_OBJ_SENTINEL means load, else store
497
- // can return MP_OBJ_NULL if op not supported
506
+ // Implements load, store and delete subscripting:
507
+ // - value = MP_OBJ_SENTINEL means load
508
+ // - value = MP_OBJ_NULL means delete
509
+ // - all other values mean store the value
510
+ // Can return MP_OBJ_NULL if operation not supported.
511
+ mp_subscr_fun_t subscr ;
498
512
499
- // corresponds to __iter__ special method
500
- // can use given mp_obj_iter_buf_t to store iterator
501
- // otherwise can return a pointer to an object on the heap
513
+ // Corresponds to __iter__ special method.
514
+ // Can use the given mp_obj_iter_buf_t to store iterator object,
515
+ // otherwise can return a pointer to an object on the heap.
502
516
mp_getiter_fun_t getiter ;
503
517
504
- mp_fun_1_t iternext ; // may return MP_OBJ_STOP_ITERATION as an optimisation instead of raising StopIteration() (with no args)
518
+ // Corresponds to __next__ special method. May return MP_OBJ_STOP_ITERATION
519
+ // as an optimisation instead of raising StopIteration() with no args.
520
+ mp_fun_1_t iternext ;
505
521
522
+ // Implements the buffer protocol if supported by this type.
506
523
mp_buffer_p_t buffer_p ;
524
+
507
525
// One of disjoint protocols (interfaces), like mp_stream_p_t, etc.
508
526
const void * protocol ;
509
527
510
- // these are for dynamically created types (classes)
528
+ // A tuple containing all the base types of this type.
511
529
struct _mp_obj_tuple_t * bases_tuple ;
512
- struct _mp_obj_dict_t * locals_dict ;
513
-
514
- /*
515
- What we might need to add here:
516
530
517
- len str tuple list map
518
- abs float complex
519
- hash bool int none str
520
- equal int str
521
-
522
- unpack seq list tuple
523
- */
531
+ // A dict mapping qstrs to objects local methods/constants/etc.
532
+ struct _mp_obj_dict_t * locals_dict ;
524
533
};
525
534
526
535
// Constant types, globally accessible
0 commit comments