@@ -470,16 +470,27 @@ typedef struct _mp_stream_p_t {
470470} mp_stream_p_t ;
471471
472472struct _mp_obj_type_t {
473+ // A type is an object so must start with this entry, which points to mp_type_type.
473474 mp_obj_base_t base ;
475+
476+ // The name of this type.
474477 qstr name ;
478+
479+ // Corresponds to __repr__ and __str__ special methods.
475480 mp_print_fun_t print ;
476- mp_make_new_fun_t make_new ; // to make an instance of the type
477481
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(...).
478486 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
481487
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.
483494 //
484495 // dest[0] = MP_OBJ_NULL means load
485496 // return: for fail, do nothing
@@ -492,35 +503,33 @@ struct _mp_obj_type_t {
492503 // for success set dest[0] = MP_OBJ_NULL
493504 mp_attr_fun_t attr ;
494505
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 ;
498512
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.
502516 mp_getiter_fun_t getiter ;
503517
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 ;
505521
522+ // Implements the buffer protocol if supported by this type.
506523 mp_buffer_p_t buffer_p ;
524+
507525 // One of disjoint protocols (interfaces), like mp_stream_p_t, etc.
508526 const void * protocol ;
509527
510- // these are for dynamically created types (classes)
528+ // A tuple containing all the base types of this type.
511529 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:
516530
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 ;
524533};
525534
526535// Constant types, globally accessible
0 commit comments