Page 1 of 1
print(1, 2) prints "1_space_2"
Posted: Fri Jan 04, 2019 9:57 am
by kkimdev
Hi, I'm using Numworks port of Micropython
https://github.com/numworks/epsilon/ and just noticed print(1, 2) prints "1_space_2" which should be "1 2" instead., mp_builtin_print uses `MP_QSTR__space_` for the separator, which Numeoworks port defines as `Q(_space_)` . I guess original Micropython defined _space_ somewhere else as " "? But I couldn't find it
Re: print(1, 2) prints "1_space_2"
Posted: Fri Jan 04, 2019 10:31 am
by stijn
For normal micropython the definition is in a file generated by makeqstrdefs.py and makeqstrdata.py during the build, qstrdefs.generated.h, and looks like QDEF(MP_QSTR__space_, (const byte*)"\x85\xb5\x01" " ") (for my windows build, might be different depending on port). This is pulled from the Q( ) in qstrdefs.h which gets special treatment in makeqstrdata.py.
Re: print(1, 2) prints "1_space_2"
Posted: Sat Jan 05, 2019 11:54 am
by kkimdev
Thanks! I've found it.. I don't understand why it prints differently then lol.... shouldn't normal micropython also print _space_ ?
https://github.com/micropython/micropyt ... ins.c#L384
Re: print(1, 2) prints "1_space_2"
Posted: Sat Jan 05, 2019 4:39 pm
by stijn
kkimdev wrote: ↑Sat Jan 05, 2019 11:54 am
shouldn't normal micropython also print _space_ ?
No, because in qstrdefs.generated.h it reads
Code: Select all
QDEF(MP_QSTR__space_ blablabla " ")
and that last string is a space (as put there by the transform in makeqstrdata.py because it has codepoint2name[ord(' ')] = 'space'). So I assume the qstr generation for the port you're referring to does something wrong there.
Re: print(1, 2) prints "1_space_2"
Posted: Sat Jan 05, 2019 11:58 pm
by kkimdev
Oh I see. Numworks port has the same makeqstrdata.py
https://github.com/numworks/epsilon/blo ... strdata.py but somehow it was generating
Code: Select all
QDEF(MP_QSTR__space_, (const byte*)"\xe1\x07" "_space_")
But I think it should be straightforward to debug at this point. Thanks a lot!!
Re: print(1, 2) prints "1_space_2"
Posted: Sun Jan 06, 2019 2:50 am
by kkimdev
OK so the issue was that, for _space_ we actually need the following two lines and must be ordered in that way.
Re: print(1, 2) prints "1_space_2"
Posted: Sun Jan 06, 2019 9:50 am
by stijn
Good find!