.mpy file format specification

C programming, build, interpreter/VM.
Target audience: MicroPython Developers.
Post Reply
carolino
Posts: 2
Joined: Thu Aug 30, 2018 4:29 pm

.mpy file format specification

Post by carolino » Thu Aug 30, 2018 4:35 pm

Hello
I'm new here and perhaps at the wrong place .
Can somebody tels me where in can find the description of a mpy file . result of the mpy-cross compilation ?
I want to write my VM on a new hardware
many thanks

[MODERATOR NOTE]
I have moved this post: it was in the wrong place and was not relevant to the discussion of DHT/ESP8266.

pfalcon
Posts: 1153
Joined: Fri Feb 28, 2014 2:05 pm

Re: .mpy file format specification

Post by pfalcon » Tue Sep 04, 2018 12:59 pm

Can somebody tels me where in can find the description of a mpy file . result of the mpy-cross compilation ?
The definitive specification of .mpy format is the source code of MicroPython. You can also have a look at tools/mpy-tool.py
I want to write my VM on a new hardware
You don't need to write a VM - that MicroPython source code, it already has it. Though if you have too much time on your hands, why not?
Awesome MicroPython list
Pycopy - A better MicroPython https://github.com/pfalcon/micropython
MicroPython standard library for all ports and forks - https://github.com/pfalcon/micropython-lib
More up to date docs - http://pycopy.readthedocs.io/

carolino
Posts: 2
Joined: Thu Aug 30, 2018 4:29 pm

Re: .mpy file format specification

Post by carolino » Wed Sep 05, 2018 2:10 pm

The advice you gave me mpy-tool.py is exactly what I'm looking for .
Unfortunatly I didn't succed to use it .
If i create a small file .py with at least 2 instructions and I produce a .mpy file with the cross-compiler I've got nothing when I execute "python mpy-tool -d hello.mpy"

pfalcon
Posts: 1153
Joined: Fri Feb 28, 2014 2:05 pm

Re: .mpy file format specification

Post by pfalcon » Wed Sep 05, 2018 3:16 pm

Yes, that's because it's not finished, as TODO in the source says. If you want to see something from -d, try defining a function, not just do something on the module level. But you want see much comparing to -f flag, which is what mpt-tool.py effectively implements so far.

Either way, the code to parse .mpy is all there. And .mpy format is WIP and not guaranteed to be finished or stable.

It so happens that I was looking at it these days too, and of course I'd like to implement detailed dumper, then assembler (builder) for .mpy, then as much as possible of "dis" module for micropython-lib, but those are just a few of dozens of tasks I have in queue, so it will be months if not years.
Awesome MicroPython list
Pycopy - A better MicroPython https://github.com/pfalcon/micropython
MicroPython standard library for all ports and forks - https://github.com/pfalcon/micropython-lib
More up to date docs - http://pycopy.readthedocs.io/

Post Reply