diff options
| author | Damien George <damien@micropython.org> | 2022-04-07 22:18:37 +1000 |
|---|---|---|
| committer | Damien George <damien@micropython.org> | 2022-04-14 22:44:04 +1000 |
| commit | 42d0bd2c17fd76860c3dc0ef5c62faa48efeb121 (patch) | |
| tree | 9bba461ddcca0641750c9b761bdaa6d0aabf7433 /tools/mpy-tool.py | |
| parent | 988827b85a9b09f1164e101ea2520562dd31634e (diff) | |
py/persistentcode: Define enum values for obj types instead of letters.
To keep the separate parts of the code that use these values in sync. And
make it easier to add new object types.
Signed-off-by: Damien George <damien@micropython.org>
Diffstat (limited to 'tools/mpy-tool.py')
| -rwxr-xr-x | tools/mpy-tool.py | 26 |
1 files changed, 17 insertions, 9 deletions
diff --git a/tools/mpy-tool.py b/tools/mpy-tool.py index 84c09a0c6..fc0b7c09c 100755 --- a/tools/mpy-tool.py +++ b/tools/mpy-tool.py @@ -121,6 +121,14 @@ MP_NATIVE_ARCH_ARMV7EMDP = 8 MP_NATIVE_ARCH_XTENSA = 9 MP_NATIVE_ARCH_XTENSAWIN = 10 +MP_PERSISTENT_OBJ_FUN_TABLE = 0 +MP_PERSISTENT_OBJ_ELLIPSIS = 1 +MP_PERSISTENT_OBJ_STR = 2 +MP_PERSISTENT_OBJ_BYTES = 3 +MP_PERSISTENT_OBJ_INT = 4 +MP_PERSISTENT_OBJ_FLOAT = 5 +MP_PERSISTENT_OBJ_COMPLEX = 6 + MP_SCOPE_FLAG_VIPERRELOC = 0x10 MP_SCOPE_FLAG_VIPERRODATA = 0x20 MP_SCOPE_FLAG_VIPERBSS = 0x40 @@ -1104,26 +1112,26 @@ def read_qstr(reader, segments): def read_obj(reader, segments): - obj_type = reader.read_bytes(1) - if obj_type == b"t": + obj_type = reader.read_byte() + if obj_type == MP_PERSISTENT_OBJ_FUN_TABLE: return MPFunTable() - elif obj_type == b"e": + elif obj_type == MP_PERSISTENT_OBJ_ELLIPSIS: return Ellipsis else: ln = reader.read_uint() start_pos = reader.tell() buf = reader.read_bytes(ln) - if obj_type in (b"s", b"b"): + if obj_type in (MP_PERSISTENT_OBJ_STR, MP_PERSISTENT_OBJ_BYTES): reader.read_byte() # read and discard null terminator - if obj_type == b"s": + if obj_type == MP_PERSISTENT_OBJ_STR: obj = str_cons(buf, "utf8") - elif obj_type == b"b": + elif obj_type == MP_PERSISTENT_OBJ_BYTES: obj = buf - elif obj_type == b"i": + elif obj_type == MP_PERSISTENT_OBJ_INT: obj = int(str_cons(buf, "ascii"), 10) - elif obj_type == b"f": + elif obj_type == MP_PERSISTENT_OBJ_FLOAT: obj = float(str_cons(buf, "ascii")) - elif obj_type == b"c": + elif obj_type == MP_PERSISTENT_OBJ_COMPLEX: obj = complex(str_cons(buf, "ascii")) else: raise MPYReadError(reader.filename, "corrupt .mpy file") |
