[SOLVED]why is there no mp_obj type for small int?
[SOLVED]why is there no mp_obj type for small int?
why is there no mp_obj type for small int?
Last edited by jickster on Wed Apr 18, 2018 4:24 pm, edited 1 time in total.
Re: why is there no mp_obj type for small int?
Because small ints are stuffed directly into the pointers themselves.
Re: why is there no mp_obj type for small int?
And in particular, this is where it's documented:
https://github.com/micropython/micropyt ... .h#L51-L93
The pyboard uses MICROPY_OBJ_REPR_A
https://github.com/micropython/micropyt ... .h#L51-L93
The pyboard uses MICROPY_OBJ_REPR_A
Re: why is there no mp_obj type for small int?
dhylands wrote: ↑Mon Apr 09, 2018 4:40 pmAnd in particular, this is where it's documented:
https://github.com/micropython/micropyt ... .h#L51-L93
The pyboard uses MICROPY_OBJ_REPR_A
Then why is there a `qstr` typedef?
Now I know the typedef `qstr` is not an MP_OBJ - you have to use MP_OBJ_NEW_QSTR() to shift the bits to turn it into an MP_OBJ - but the fact remains that the typedef `qstr` exists.
I like that `qstr` exists - for reasons of type safety - so then wouldn't it similarly make sense to also have a `small_int` type?
Re: why is there no mp_obj type for small int?
Having a qstr typedef serves mostly as documentation.
A qstr is really just an integer, and if you saw a function: then you know that the name argument is a qstr, whereas wouldn't tell you that same thing.
And a qstr isn't an mp_obj type. It has to be converted to an mp_obj type using the appropriate macro.
A qstr is really just an integer, and if you saw a function:
Code: Select all
void some_function(qstr name);
Code: Select all
void some_function(size_t name);
And a qstr isn't an mp_obj type. It has to be converted to an mp_obj type using the appropriate macro.
Re: why is there no mp_obj type for small int?
And the same argument could be made about small int.dhylands wrote:Having a qstr typedef serves mostly as documentation.
A qstr is really just an integer, and if you saw a function:then you know that the name argument is a qstr, whereasCode: Select all
void some_function(qstr name);
wouldn't tell you that same thing.Code: Select all
void some_function(size_t name);
And a qstr isn't an mp_obj type. It has to be converted to an mp_obj type using the appropriate macro.
So why isn’t there a typedef for small int?
Sent from my iPhone using Tapatalk
Re: why is there no mp_obj type for small int?
Isn't that mp_int_t ?
Re: why is there no mp_obj type for small int?
I'm not aware of any (or many) functions which would take just a small int as an argument, except for the macros which convert to/from the mp_obj_t and the small int.
Re: why is there no mp_obj type for small int?
Well, yes, but like Dave says: just like functions wanting a qstr take a qstr and not a pointer-sized type, functions wanting an int use mp_int_t. Or maybe I'm missing the point.