summaryrefslogtreecommitdiffstatshomepage
path: root/tools
diff options
context:
space:
mode:
Diffstat (limited to 'tools')
-rwxr-xr-xtools/make-frozen.py36
-rw-r--r--tools/micropython-upip-0.6.3.tar.gzbin5226 -> 0 bytes
-rw-r--r--tools/micropython-upip-0.7.tar.gzbin0 -> 4614 bytes
-rwxr-xr-xtools/mpy-tool.py22
4 files changed, 46 insertions, 12 deletions
diff --git a/tools/make-frozen.py b/tools/make-frozen.py
index 84e589b985..1051b520e4 100755
--- a/tools/make-frozen.py
+++ b/tools/make-frozen.py
@@ -23,7 +23,7 @@ import os
def module_name(f):
- return f[:-len(".py")]
+ return f
modules = []
@@ -53,11 +53,31 @@ print("};")
print("const char mp_frozen_str_content[] = {")
for f, st in modules:
data = open(sys.argv[1] + "/" + f, "rb").read()
- # Python2 vs Python3 tricks
- data = repr(data)
- if data[0] == "b":
- data = data[1:]
- data = data[1:-1]
- data = data.replace('"', '\\"')
- print('"%s\\0"' % data)
+
+ # We need to properly escape the script data to create a C string.
+ # When C parses hex characters of the form \x00 it keeps parsing the hex
+ # data until it encounters a non-hex character. Thus one must create
+ # strings of the form "data\x01" "abc" to properly encode this kind of
+ # data. We could just encode all characters as hex digits but it's nice
+ # to be able to read the resulting C code as ASCII when possible.
+
+ data = bytearray(data) # so Python2 extracts each byte as an integer
+ esc_dict = {ord('\n'): '\\n', ord('\r'): '\\r', ord('"'): '\\"', ord('\\'): '\\\\'}
+ chrs = ['"']
+ break_str = False
+ for c in data:
+ try:
+ chrs.append(esc_dict[c])
+ except KeyError:
+ if 32 <= c <= 126:
+ if break_str:
+ chrs.append('" "')
+ break_str = False
+ chrs.append(chr(c))
+ else:
+ chrs.append('\\x%02x' % c)
+ break_str = True
+ chrs.append('\\0"')
+ print(''.join(chrs))
+
print("};")
diff --git a/tools/micropython-upip-0.6.3.tar.gz b/tools/micropython-upip-0.6.3.tar.gz
deleted file mode 100644
index 00ce80642d..0000000000
--- a/tools/micropython-upip-0.6.3.tar.gz
+++ /dev/null
Binary files differ
diff --git a/tools/micropython-upip-0.7.tar.gz b/tools/micropython-upip-0.7.tar.gz
new file mode 100644
index 0000000000..cd36d136e2
--- /dev/null
+++ b/tools/micropython-upip-0.7.tar.gz
Binary files differ
diff --git a/tools/mpy-tool.py b/tools/mpy-tool.py
index 74106f192a..972ede8325 100755
--- a/tools/mpy-tool.py
+++ b/tools/mpy-tool.py
@@ -450,6 +450,23 @@ def freeze_mpy(qcfgs, base_qstrs, raw_codes):
print('#include "py/emitglue.h"')
print()
+ print('#if MICROPY_OPT_CACHE_MAP_LOOKUP_IN_BYTECODE')
+ print('#error "MICROPY_OPT_CACHE_MAP_LOOKUP_IN_BYTECODE not supported with frozen mpy files"')
+ print('#endif')
+ print()
+
+ print('#if MICROPY_LONGINT_IMPL != %u' % config.MICROPY_LONGINT_IMPL)
+ print('#error "incompatible MICROPY_LONGINT_IMPL"')
+ print('#endif')
+ print()
+
+ if config.MICROPY_LONGINT_IMPL == config.MICROPY_LONGINT_IMPL_MPZ:
+ print('#if MPZ_DIG_SIZE != %u' % config.MPZ_DIG_SIZE)
+ print('#error "incompatible MPZ_DIG_SIZE"')
+ print('#endif')
+ print()
+
+
print('#if MICROPY_PY_BUILTINS_FLOAT')
print('typedef struct _mp_obj_float_t {')
print(' mp_obj_base_t base;')
@@ -485,10 +502,7 @@ def freeze_mpy(qcfgs, base_qstrs, raw_codes):
print()
print('const char mp_frozen_mpy_names[] = {')
for rc in raw_codes:
- module_name = rc.source_file.str[:-len(".py")]
- slash = module_name.rfind('/')
- if slash != -1:
- module_name = module_name[slash + 1:]
+ module_name = rc.source_file.str
print('"%s\\0"' % module_name)
print('"\\0"};')