Merge remote-tracking branch 'origin/main' into merge-weblate-manually

This commit is contained in:
Jeff Epler 2022-11-30 21:09:31 -06:00
commit 08d372aedc
No known key found for this signature in database
GPG Key ID: D5BF15AB975AB4DE
38 changed files with 188 additions and 162 deletions

82
locale/circuitpython.pot Executable file → Normal file
View File

@ -118,7 +118,7 @@ msgstr ""
msgid "%q is %q"
msgstr ""
#: py/argcheck.c
#: py/argcheck.c shared-bindings/usb_hid/Device.c
msgid "%q length must be %d"
msgstr ""
@ -134,10 +134,6 @@ msgstr ""
msgid "%q length must be >= %d"
msgstr ""
#: shared-bindings/busio/I2C.c
msgid "%q length must be >= 1"
msgstr ""
#: py/argcheck.c
msgid "%q must be %d"
msgstr ""
@ -163,15 +159,7 @@ msgstr ""
msgid "%q must be a bytearray or array of type 'h', 'H', 'b', or 'B'"
msgstr ""
#: py/argcheck.c
msgid "%q must be a string"
msgstr ""
#: py/argcheck.c
msgid "%q must be an int"
msgstr ""
#: py/argcheck.c py/obj.c
#: py/argcheck.c py/obj.c py/objstrunicode.c
msgid "%q must be of type %q"
msgstr ""
@ -201,8 +189,8 @@ msgstr ""
msgid "%q pin invalid"
msgstr ""
#: shared-bindings/usb_hid/Device.c
msgid "%q with a report ID of 0 must be of length 1"
#: py/objrange.c py/objslice.c shared-bindings/random/__init__.c
msgid "%q step cannot be zero"
msgstr ""
#: py/bc.c py/objnamedtuple.c
@ -511,10 +499,6 @@ msgstr ""
msgid "Array values should be single bytes."
msgstr ""
#: shared-bindings/microcontroller/Pin.c
msgid "At most %d %q may be specified (not %d)"
msgstr ""
#: shared-module/memorymonitor/AllocationAlarm.c
#, c-format
msgid "Attempt to allocate %d blocks"
@ -1260,10 +1244,6 @@ msgstr ""
msgid "Invalid multicast MAC address"
msgstr ""
#: shared-bindings/busio/UART.c
msgid "Invalid pins"
msgstr ""
#: ports/espressif/common-hal/espidf/__init__.c ports/espressif/esp_error.c
msgid "Invalid size"
msgstr ""
@ -1501,11 +1481,6 @@ msgstr ""
msgid "No long integer support"
msgstr ""
#: shared-module/usb_hid/__init__.c
#, c-format
msgid "No more than %d HID devices allowed"
msgstr ""
#: shared-bindings/wifi/Radio.c
msgid "No network with that ssid"
msgstr ""
@ -2545,10 +2520,6 @@ msgstr ""
msgid "buffer too small for requested bytes"
msgstr ""
#: shared-bindings/adafruit_pixelbuf/PixelBuf.c
msgid "byteorder is not a string"
msgstr ""
#: py/objarray.c
msgid "bytes length not a multiple of item size"
msgstr ""
@ -2590,14 +2561,10 @@ msgstr ""
msgid "can't cancel self"
msgstr ""
#: py/obj.c py/objint.c shared-module/adafruit_pixelbuf/PixelBuf.c
#: py/obj.c py/objint.c py/runtime.c shared-module/adafruit_pixelbuf/PixelBuf.c
msgid "can't convert %q to %q"
msgstr ""
#: py/runtime.c
msgid "can't convert %q to int"
msgstr ""
#: py/obj.c
#, c-format
msgid "can't convert %s to complex"
@ -2781,10 +2748,6 @@ msgstr ""
msgid "comparison of int and uint"
msgstr ""
#: py/objcomplex.c
msgid "complex division by zero"
msgstr ""
#: py/objfloat.c py/parsenum.c
msgid "complex values not supported"
msgstr ""
@ -2887,12 +2850,7 @@ msgstr ""
msgid "div/mod not implemented for uint"
msgstr ""
#: py/objfloat.c py/objint_mpz.c
msgid "divide by zero"
msgstr ""
#: py/modmath.c py/objint_longlong.c py/runtime.c
#: shared-bindings/math/__init__.c
#: py/runtime.c
msgid "division by zero"
msgstr ""
@ -3264,10 +3222,6 @@ msgstr ""
msgid "inputs are not iterable"
msgstr ""
#: py/parsenum.c
msgid "int() arg 2 must be >= 2 and <= 36"
msgstr ""
#: extmod/ulab/code/numpy/approx.c
msgid "interp is defined for 1D iterables of equal length"
msgstr ""
@ -3405,10 +3359,6 @@ msgstr ""
msgid "local variable referenced before assignment"
msgstr ""
#: py/objint.c
msgid "long int not supported in this build"
msgstr ""
#: ports/espressif/common-hal/canio/CAN.c
msgid "loopback + silent mode not supported by peripheral"
msgstr ""
@ -3943,10 +3893,6 @@ msgstr ""
msgid "slice step can't be zero"
msgstr ""
#: py/objslice.c
msgid "slice step cannot be zero"
msgstr ""
#: py/nativeglue.c
msgid "slice unsupported"
msgstr ""
@ -3995,10 +3941,6 @@ msgstr ""
msgid "start/end indices"
msgstr ""
#: shared-bindings/random/__init__.c
msgid "step must be non-zero"
msgstr ""
#: shared-bindings/random/__init__.c
msgid "stop not reachable from start"
msgstr ""
@ -4007,10 +3949,6 @@ msgstr ""
msgid "stream operation not supported"
msgstr ""
#: py/objstrunicode.c
msgid "string indices must be integers, not %q"
msgstr ""
#: py/stream.c
msgid "string not supported; use bytes or bytearray"
msgstr ""
@ -4043,10 +3981,6 @@ msgstr ""
msgid "syntax error in uctypes descriptor"
msgstr ""
#: shared-bindings/time/__init__.c
msgid "time.struct_time() takes a 9-sequence"
msgstr ""
#: ports/atmel-samd/common-hal/watchdog/WatchDogTimer.c
#: ports/espressif/common-hal/watchdog/WatchDogTimer.c
#: ports/nrf/common-hal/watchdog/WatchDogTimer.c
@ -4328,10 +4262,6 @@ msgstr ""
msgid "y value out of bounds"
msgstr ""
#: py/objrange.c
msgid "zero step"
msgstr ""
#: extmod/ulab/code/scipy/signal/signal.c
msgid "zi must be an ndarray"
msgstr ""

View File

@ -282,7 +282,7 @@ msgstr "Inaasahan ng '%s' ang hangang r%d"
#: py/emitinlinethumb.c
#, c-format
msgid "'%s' expects {r0, r1, ...}"
msgstr "Inaasahan ng '%s' ay {r0, r1, }"
msgstr "Inaasahan ng '%s' ay {r0, r1, ...}"
#: py/emitinlinextensa.c
#, c-format
@ -2797,7 +2797,7 @@ msgstr ""
#: shared-bindings/displayio/Palette.c
msgid "color buffer must be a bytearray or array of type 'b' or 'B'"
msgstr "ang color buffer ay dapat bytearray o array na type b or B"
msgstr "ang color buffer ay dapat bytearray o array na type 'b' or 'B'"
#: shared-bindings/displayio/Palette.c
msgid "color must be between 0x000000 and 0xffffff"
@ -3915,7 +3915,7 @@ msgstr "return annotation ay dapat na identifier"
#: py/emitnative.c
msgid "return expected '%q' but got '%q'"
msgstr "return umasa ng '%q' pero ang nakuha ay %q"
msgstr "return umasa ng '%q' pero ang nakuha ay '%q'"
#: shared-bindings/rgbmatrix/RGBMatrix.c
#, c-format
@ -4625,7 +4625,7 @@ msgstr ""
#~ "Mangyaring bisitahin ang learn.adafruit.com/category/circuitpython para "
#~ "sa project guides.\n"
#~ "\n"
#~ "Para makita ang listahan ng modules, `help(“modules”)`.\n"
#~ "Para makita ang listahan ng modules, `help(\"modules\")`.\n"
#~ msgid "integer required"
#~ msgstr "kailangan ng int"

View File

@ -684,7 +684,7 @@ msgstr "Les blocs CBC doivent être des multiples de 16 octets"
#: supervisor/shared/safe_mode.c
msgid "CIRCUITPY drive could not be found or created."
msgstr "Lappareil CIRCUITPY ne peut pas être trouvé ou créé."
msgstr "L'appareil CIRCUITPY ne peut pas être trouvé ou créé."
#: ports/espressif/common-hal/espidf/__init__.c ports/espressif/esp_error.c
msgid "CRC or checksum was invalid"
@ -842,11 +842,11 @@ msgstr "Fichier .mpy corrompu"
#: ports/espressif/common-hal/neopixel_write/__init__.c
msgid "Could not retrieve clock"
msgstr "Impossible dobtenir lhorloge"
msgstr "Impossible d'obtenir l'horloge"
#: shared-bindings/_bleio/Adapter.c
msgid "Could not set address"
msgstr "Impossible de définir ladresse"
msgstr "Impossible de définir l'adresse"
#: shared-bindings/pwmio/PWMOut.c
msgid "Could not start PWM"
@ -1010,7 +1010,7 @@ msgstr "Échec d'allocation du tampon %q"
#: ports/espressif/common-hal/wifi/__init__.c
msgid "Failed to allocate Wifi memory"
msgstr "Impossible dallouer la mémoire pour Wifi"
msgstr "Impossible d'allouer la mémoire pour Wifi"
#: ports/espressif/common-hal/wifi/ScannedNetworks.c
msgid "Failed to allocate wifi scan memory"
@ -1837,7 +1837,7 @@ msgstr "Ainsi que tout autres modules présents sur le système de fichiers\n"
#: shared-module/vectorio/Polygon.c
msgid "Polygon needs at least 3 points"
msgstr "Polygon a besoin dau moins 3 points"
msgstr "Polygon a besoin d'au moins 3 points"
#: shared-bindings/_bleio/Adapter.c
msgid "Prefix buffer must be on the heap"
@ -2560,7 +2560,7 @@ msgstr "matrice/octets requis à la droite"
#: extmod/ulab/code/numpy/numerical.c
msgid "attempt to get (arg)min/(arg)max of empty sequence"
msgstr "tentative dobtenir (arg)min/(arg)max d'une séquence vide"
msgstr "tentative d'obtenir (arg)min/(arg)max d'une séquence vide"
#: extmod/ulab/code/numpy/numerical.c
msgid "attempt to get argmin/argmax of an empty sequence"
@ -2628,7 +2628,7 @@ msgstr "tampon est plus petit que la taille demandée"
#: extmod/ulab/code/numpy/create.c extmod/ulab/code/utils/utils.c
msgid "buffer size must be a multiple of element size"
msgstr "taille du tampon doit être un multiple de la taille de lélément"
msgstr "taille du tampon doit être un multiple de la taille de l'élément"
#: shared-module/struct/__init__.c
msgid "buffer size must match format"
@ -3189,7 +3189,7 @@ msgstr "la fonction a reçu plusieurs valeurs pour l'argument '%q'"
#: extmod/ulab/code/scipy/optimize/optimize.c
msgid "function has the same sign at the ends of interval"
msgstr "la fonction a le même signe aux extrémités de lintervalle"
msgstr "la fonction a le même signe aux extrémités de l'intervalle"
#: extmod/ulab/code/ndarray.c
msgid "function is defined for ndarrays only"
@ -4190,11 +4190,11 @@ msgstr "le délai (timeout) doit être < 655.35 secondes"
#: shared-module/sdcardio/SDCard.c
msgid "timeout waiting for v1 card"
msgstr "Délai dexpiration dépassé en attendant une carte v1"
msgstr "Délai d'expiration dépassé en attendant une carte v1"
#: shared-module/sdcardio/SDCard.c
msgid "timeout waiting for v2 card"
msgstr "Délai dexpiration dépassé en attendant une carte v2"
msgstr "Délai d'expiration dépassé en attendant une carte v2"
#: ports/stm/common-hal/pwmio/PWMOut.c
msgid "timer re-init"
@ -4394,7 +4394,7 @@ msgstr "width doit être plus que zero"
#: ports/espressif/common-hal/wifi/Radio.c
#: ports/raspberrypi/common-hal/wifi/Radio.c
msgid "wifi is not enabled"
msgstr "wifi nest pas activé"
msgstr "wifi n'est pas activé"
#: ports/raspberrypi/common-hal/wifi/Monitor.c
msgid "wifi.Monitor not available"

View File

@ -283,7 +283,7 @@ msgstr "'%s' verwacht op zijn meest r%d"
#: py/emitinlinethumb.c
#, c-format
msgid "'%s' expects {r0, r1, ...}"
msgstr "'%s' verwacht {r0, r1, }"
msgstr "'%s' verwacht {r0, r1, ...}"
#: py/emitinlinextensa.c
#, c-format

41
main.c
View File

@ -218,12 +218,10 @@ void supervisor_execution_status(void) {
}
#endif
#define STRING_LIST(...) {__VA_ARGS__, ""}
// Look for the first file that exists in the list of filenames, using mp_import_stat().
// Return its index. If no file found, return -1.
STATIC const char *first_existing_file_in_list(const char *const *filenames) {
for (int i = 0; filenames[i] != (char *)""; i++) {
STATIC const char *first_existing_file_in_list(const char *const *filenames, size_t n_filenames) {
for (size_t i = 0; i < n_filenames; i++) {
mp_import_stat_t stat = mp_import_stat(filenames[i]);
if (stat == MP_IMPORT_STAT_FILE) {
return filenames[i];
@ -232,11 +230,11 @@ STATIC const char *first_existing_file_in_list(const char *const *filenames) {
return NULL;
}
STATIC bool maybe_run_list(const char *const *filenames) {
STATIC bool maybe_run_list(const char *const *filenames, size_t n_filenames) {
_exec_result.return_code = 0;
_exec_result.exception = MP_OBJ_NULL;
_exec_result.exception_line = 0;
_current_executing_filename = first_existing_file_in_list(filenames);
_current_executing_filename = first_existing_file_in_list(filenames, n_filenames);
if (_current_executing_filename == NULL) {
return false;
}
@ -391,12 +389,14 @@ STATIC bool run_code_py(safe_mode_t safe_mode, bool *simulate_reset) {
filesystem_flush();
}
if (safe_mode == NO_SAFE_MODE && !autoreload_pending()) {
static const char *const supported_filenames[] = STRING_LIST(
"code.txt", "code.py", "main.py", "main.txt");
static const char *const supported_filenames[] = {
"code.txt", "code.py", "main.py", "main.txt"
};
#if CIRCUITPY_FULL_BUILD
static const char *const double_extension_filenames[] = STRING_LIST(
static const char *const double_extension_filenames[] = {
"code.txt.py", "code.py.txt", "code.txt.txt","code.py.py",
"main.txt.py", "main.py.txt", "main.txt.txt","main.py.py");
"main.txt.py", "main.py.txt", "main.txt.txt","main.py.py"
};
#endif
supervisor_allocation *heap = allocate_remaining_memory();
@ -410,14 +410,15 @@ STATIC bool run_code_py(safe_mode_t safe_mode, bool *simulate_reset) {
// Check if a different run file has been allocated
if (next_code_allocation) {
((next_code_info_t *)next_code_allocation->ptr)->options &= ~SUPERVISOR_NEXT_CODE_OPT_NEWLY_SET;
next_code_options = ((next_code_info_t *)next_code_allocation->ptr)->options;
if (((next_code_info_t *)next_code_allocation->ptr)->filename[0] != '\0') {
const char *next_list[] = {((next_code_info_t *)next_code_allocation->ptr)->filename, ""};
next_code_info_t *info = ((next_code_info_t *)next_code_allocation->ptr);
info->options &= ~SUPERVISOR_NEXT_CODE_OPT_NEWLY_SET;
next_code_options = info->options;
if (info->filename[0] != '\0') {
// This is where the user's python code is actually executed:
found_main = maybe_run_list(next_list);
const char *const filenames[] = { info->filename };
found_main = maybe_run_list(filenames, MP_ARRAY_SIZE(filenames));
if (!found_main) {
serial_write(((next_code_info_t *)next_code_allocation->ptr)->filename);
serial_write(info->filename);
serial_write_compressed(translate(" not found.\n"));
}
}
@ -425,11 +426,11 @@ STATIC bool run_code_py(safe_mode_t safe_mode, bool *simulate_reset) {
// Otherwise, default to the standard list of filenames
if (!found_main) {
// This is where the user's python code is actually executed:
found_main = maybe_run_list(supported_filenames);
found_main = maybe_run_list(supported_filenames, MP_ARRAY_SIZE(supported_filenames));
// If that didn't work, double check the extensions
#if CIRCUITPY_FULL_BUILD
if (!found_main) {
found_main = maybe_run_list(double_extension_filenames);
found_main = maybe_run_list(double_extension_filenames, MP_ARRAY_SIZE(double_extension_filenames));
if (found_main) {
serial_write_compressed(translate("WARNING: Your code filename has two extensions\n"));
}
@ -741,7 +742,7 @@ STATIC void __attribute__ ((noinline)) run_boot_py(safe_mode_t safe_mode) {
&& safe_mode == NO_SAFE_MODE
&& MP_STATE_VM(vfs_mount_table) != NULL;
static const char *const boot_py_filenames[] = STRING_LIST("boot.py", "boot.txt");
static const char *const boot_py_filenames[] = {"boot.py", "boot.txt"};
// Do USB setup even if boot.py is not run.
@ -778,7 +779,7 @@ STATIC void __attribute__ ((noinline)) run_boot_py(safe_mode_t safe_mode) {
port_boot_info();
#endif
bool found_boot = maybe_run_list(boot_py_filenames);
bool found_boot = maybe_run_list(boot_py_filenames, MP_ARRAY_SIZE(boot_py_filenames));
(void)found_boot;

View File

@ -24,6 +24,7 @@
* THE SOFTWARE.
*/
#if CIRCUITPY_BUSIO_UART
#include "shared-bindings/microcontroller/__init__.h"
#include "shared-bindings/microcontroller/Pin.h"
#include "shared-bindings/busio/UART.h"
@ -485,3 +486,4 @@ bool common_hal_busio_uart_ready_to_tx(busio_uart_obj_t *self) {
usart_async_get_status(usart_desc_p, &async_status);
return !(async_status.flags & USART_ASYNC_STATUS_BUSY);
}
#endif

View File

@ -33,6 +33,8 @@
#define MICROPY_USE_INTERNAL_PRINTF (0)
#define MICROPY_PY_SYS_PLATFORM "Espressif"
#define CIRCUITPY_DIGITALIO_HAVE_INPUT_ONLY (1)
#include "py/circuitpy_mpconfig.h"
#if CIRCUITPY_BLEIO

View File

@ -145,9 +145,11 @@ void mp_arg_parse_all_kw_array(size_t n_pos, size_t n_kw, const mp_obj_t *args,
mp_arg_parse_all(n_pos, args, &kw_args, n_allowed, allowed, out_vals);
}
#if MICROPY_ERROR_REPORTING <= MICROPY_ERROR_REPORTING_TERSE
NORETURN void mp_arg_error_terse_mismatch(void) {
mp_raise_TypeError(MP_ERROR_TEXT("argument num/types mismatch"));
}
#endif
#if MICROPY_CPYTHON_COMPAT
NORETURN void mp_arg_error_unimpl_kw(void) {
@ -239,7 +241,7 @@ mp_obj_t mp_arg_validate_type(mp_obj_t obj, const mp_obj_type_t *type, qstr arg_
mp_obj_t mp_arg_validate_type_string(mp_obj_t obj, qstr arg_name) {
if (!mp_obj_is_str(obj)) {
mp_raise_TypeError_varg(translate("%q must be a string"), arg_name);
mp_raise_TypeError_varg(translate("%q must be of type %q"), arg_name, MP_QSTR_str);
}
return obj;
}
@ -247,7 +249,7 @@ mp_obj_t mp_arg_validate_type_string(mp_obj_t obj, qstr arg_name) {
mp_int_t mp_arg_validate_type_int(mp_obj_t obj, qstr arg_name) {
mp_int_t an_int;
if (!mp_obj_get_int_maybe(obj, &an_int)) {
mp_raise_TypeError_varg(translate("%q must be an int"), arg_name);
mp_raise_TypeError_varg(translate("%q must be of type %q"), arg_name, MP_QSTR_int);
}
return an_int;
}

View File

@ -582,6 +582,10 @@ void supervisor_run_background_tasks_if_tick(void);
#define MICROPY_WRAP_MP_EXECUTE_BYTECODE PLACE_IN_ITCM
#endif
#ifndef CIRCUITPY_DIGITALIO_HAVE_INPUT_ONLY
#define CIRCUITPY_DIGITALIO_HAVE_INPUT_ONLY (0)
#endif
#ifndef CIRCUITPY_DIGITALIO_HAVE_INVALID_PULL
#define CIRCUITPY_DIGITALIO_HAVE_INVALID_PULL (0)
#endif

View File

@ -12,7 +12,7 @@ import subprocess
from makeqstrdefs import qstr_unescape, QSTRING_BLOCK_LIST
re_line = re.compile(r"#[line]*\s(\d+)\s\"([^\"]+)\"", re.DOTALL)
re_qstr = re.compile(r"MP_QSTR_[_a-zA-Z0-9]+", re.DOTALL)
re_qstr = re.compile(r"\bMP_QSTR_[_a-zA-Z0-9]+", re.DOTALL)
re_translate = re.compile(r"translate\(\"((?:(?=(\\?))\2.)*?)\"\)", re.DOTALL)

View File

@ -10,6 +10,7 @@ supervisor/shared/translate/translate.h
from __future__ import print_function
import bisect
from dataclasses import dataclass
import re
import sys
@ -146,15 +147,69 @@ def iter_substrings(s, minlen, maxlen):
yield s[begin : begin + n]
def compute_huffman_coding(translations, f):
translation_requires_uint16 = {"cs", "ja", "ko", "pl", "tr", "zh_Latn_pinyin"}
def compute_unicode_offset(texts):
all_ch = set(" ".join(texts))
ch_160 = sorted(c for c in all_ch if 160 <= ord(c) < 255)
ch_256 = sorted(c for c in all_ch if 255 < ord(c))
if not ch_256:
return 0, 0
min_256 = ord(min(ch_256))
span = ord(max(ch_256)) - ord(min(ch_256)) + 1
if ch_160:
max_160 = ord(max(ch_160)) + 1
else:
max_160 = max(160, 255 - span)
if max_160 + span > 256:
return 0, 0
offstart = max_160
offset = min_256 - max_160
return offstart, offset
@dataclass
class EncodingTable:
values: object
lengths: object
words: object
canonical: object
extractor: object
apply_offset: object
remove_offset: object
def compute_huffman_coding(translation_name, translations, f):
texts = [t[1] for t in translations]
words = []
start_unused = 0x80
end_unused = 0xFF
max_ord = 0
offstart, offset = compute_unicode_offset(texts)
def apply_offset(c):
oc = ord(c)
if oc >= offstart:
oc += offset
return chr(oc)
def remove_offset(c):
oc = ord(c)
if oc >= offstart:
oc = oc - offset
try:
return chr(oc)
except Exception as e:
raise ValueError(f"remove_offset {offstart=} {oc=}") from e
for text in texts:
for c in text:
c = remove_offset(c)
ord_c = ord(c)
max_ord = max(ord_c, max_ord)
if 0x80 <= ord_c < 0xFF:
@ -163,6 +218,12 @@ def compute_huffman_coding(translations, f):
bits_per_codepoint = 16 if max_ord > 255 else 8
values_type = "uint16_t" if max_ord > 255 else "uint8_t"
translation_name = translation_name.split("/")[-1].split(".")[0]
if max_ord > 255 and translation_name not in translation_requires_uint16:
raise ValueError(
f"Translation {translation_name} expected to fit in 8 bits but required 16 bits"
)
while len(words) < max_words:
# Until the dictionary is filled to capacity, use a heuristic to find
# the best "word" (2- to 11-gram) to add to it.
@ -267,15 +328,17 @@ def compute_huffman_coding(translations, f):
length_count[length] += 1
if last_length:
renumbered <<= length - last_length
canonical[atom] = "{0:0{width}b}".format(renumbered, width=length)
# print(f"atom={repr(atom)} code={code}", file=sys.stderr)
canonical[atom] = "{0:0{width}b}".format(renumbered, width=length)
if len(atom) > 1:
o = words.index(atom) + 0x80
s = "".join(C_ESCAPES.get(ch1, ch1) for ch1 in atom)
f.write(f"// {o} {s} {counter[atom]} {canonical[atom]} {renumbered}\n")
else:
s = C_ESCAPES.get(atom, atom)
canonical[atom] = "{0:0{width}b}".format(renumbered, width=length)
o = ord(atom)
f.write(f"// {o} {s} {counter[atom]} {canonical[atom]} {renumbered}\n")
f.write(f"// {o} {s} {counter[atom]} {canonical[atom]} {renumbered}\n")
renumbered += 1
last_length = length
lengths = bytearray()
@ -297,7 +360,11 @@ def compute_huffman_coding(translations, f):
f.write("typedef {} mchar_t;\n".format(values_type))
f.write("const uint8_t lengths[] = {{ {} }};\n".format(", ".join(map(str, lengths))))
f.write("const mchar_t values[] = {{ {} }};\n".format(", ".join(str(ord(u)) for u in values)))
f.write(
"const mchar_t values[] = {{ {} }};\n".format(
", ".join(str(ord(remove_offset(u))) for u in values)
)
)
f.write(
"#define compress_max_length_bits ({})\n".format(
max_translation_encoded_length.bit_length()
@ -305,7 +372,7 @@ def compute_huffman_coding(translations, f):
)
f.write(
"const mchar_t words[] = {{ {} }};\n".format(
", ".join(str(ord(c)) for w in words for c in w)
", ".join(str(ord(remove_offset(c))) for w in words for c in w)
)
)
f.write("const uint8_t wlencount[] = {{ {} }};\n".format(", ".join(str(p) for p in wlencount)))
@ -313,12 +380,17 @@ def compute_huffman_coding(translations, f):
f.write("#define word_end {}\n".format(word_end))
f.write("#define minlen {}\n".format(minlen))
f.write("#define maxlen {}\n".format(maxlen))
f.write("#define translation_offstart {}\n".format(offstart))
f.write("#define translation_offset {}\n".format(offset))
return (values, lengths, words, canonical, extractor)
return EncodingTable(values, lengths, words, canonical, extractor, apply_offset, remove_offset)
def decompress(encoding_table, encoded, encoded_length_bits):
(values, lengths, words, _, _) = encoding_table
values = encoding_table.values
lengths = encoding_table.lengths
words = encoding_table.words
dec = []
this_byte = 0
this_bit = 7
@ -376,7 +448,8 @@ def decompress(encoding_table, encoded, encoded_length_bits):
def compress(encoding_table, decompressed, encoded_length_bits, len_translation_encoded):
if not isinstance(decompressed, str):
raise TypeError()
(_, _, _, canonical, extractor) = encoding_table
canonical = encoding_table.canonical
extractor = encoding_table.extractor
enc = bytearray(len(decompressed) * 3)
current_bit = 7
@ -522,5 +595,7 @@ if __name__ == "__main__":
i18ns = parse_input_headers(args.infiles)
i18ns = sorted(i18ns)
translations = translate(args.translation, i18ns)
encoding_table = compute_huffman_coding(translations, args.compression_filename)
encoding_table = compute_huffman_coding(
args.translation, translations, args.compression_filename
)
output_translation_data(encoding_table, translations, args.translation_filename)

View File

@ -254,7 +254,7 @@ STATIC mp_obj_t mp_math_log(size_t n_args, const mp_obj_t *args) {
if (base <= (mp_float_t)0.0) {
math_error();
} else if (base == (mp_float_t)1.0) {
mp_raise_msg(&mp_type_ZeroDivisionError, MP_ERROR_TEXT("division by zero"));
mp_raise_ZeroDivisionError();
}
return mp_obj_new_float(l / MICROPY_FLOAT_C_FUN(log)(base));
}

View File

@ -217,7 +217,7 @@ mp_obj_t mp_obj_complex_binary_op(mp_binary_op_t op, mp_float_t lhs_real, mp_flo
case MP_BINARY_OP_INPLACE_TRUE_DIVIDE:
if (rhs_imag == 0) {
if (rhs_real == 0) {
mp_raise_msg(&mp_type_ZeroDivisionError, MP_ERROR_TEXT("complex division by zero"));
mp_raise_ZeroDivisionError();
}
lhs_real /= rhs_real;
lhs_imag /= rhs_real;

View File

@ -266,7 +266,7 @@ mp_obj_t mp_obj_float_binary_op(mp_binary_op_t op, mp_float_t lhs_val, mp_obj_t
case MP_BINARY_OP_INPLACE_FLOOR_DIVIDE:
if (rhs_val == 0) {
zero_division_error:
mp_raise_msg(&mp_type_ZeroDivisionError, MP_ERROR_TEXT("divide by zero"));
mp_raise_ZeroDivisionError();
}
// Python specs require that x == (x//y)*y + (x%y) so we must
// call divmod to compute the correct floor division, which

View File

@ -396,7 +396,7 @@ mp_obj_t mp_obj_int_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_t rhs_i
// This is called only with strings whose value doesn't fit in SMALL_INT
mp_obj_t mp_obj_new_int_from_str_len(const char **str, size_t len, bool neg, unsigned int base) {
mp_raise_msg(&mp_type_OverflowError, MP_ERROR_TEXT("long int not supported in this build"));
mp_raise_msg(&mp_type_OverflowError, MP_ERROR_TEXT("small int overflow"));
return mp_const_none;
}

View File

@ -236,7 +236,7 @@ mp_obj_t mp_obj_int_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_t rhs_i
}
zero_division:
mp_raise_msg(&mp_type_ZeroDivisionError, MP_ERROR_TEXT("division by zero"));
mp_raise_ZeroDivisionError();
}
mp_obj_t mp_obj_new_int(mp_int_t value) {

View File

@ -244,7 +244,7 @@ mp_obj_t mp_obj_int_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_t rhs_i
case MP_BINARY_OP_INPLACE_FLOOR_DIVIDE: {
if (mpz_is_zero(zrhs)) {
zero_division_error:
mp_raise_msg(&mp_type_ZeroDivisionError, MP_ERROR_TEXT("divide by zero"));
mp_raise_ZeroDivisionError();
}
mpz_t rem;
mpz_init_zero(&rem);

View File

@ -110,7 +110,7 @@ STATIC mp_obj_t range_make_new(const mp_obj_type_t *type, size_t n_args, size_t
if (n_args == 3) {
o->step = mp_obj_get_int(args[2]);
if (o->step == 0) {
mp_raise_ValueError(MP_ERROR_TEXT("zero step"));
mp_raise_ValueError_varg(MP_ERROR_TEXT("%q step cannot be zero"), MP_QSTR_range);
}
}
}

View File

@ -157,7 +157,7 @@ void mp_obj_slice_indices(mp_obj_t self_in, mp_int_t length, mp_bound_slice_t *r
} else {
step = mp_obj_get_int(self->step);
if (step == 0) {
mp_raise_ValueError(MP_ERROR_TEXT("slice step cannot be zero"));
mp_raise_ValueError_varg(MP_ERROR_TEXT("%q step cannot be zero"), MP_QSTR_slice);
}
}

View File

@ -159,7 +159,7 @@ const byte *str_index_to_ptr(const mp_obj_type_t *type, const byte *self_data, s
if (mp_obj_is_small_int(index)) {
i = MP_OBJ_SMALL_INT_VALUE(index);
} else if (!mp_obj_get_int_maybe(index, &i)) {
mp_raise_TypeError_varg(MP_ERROR_TEXT("string indices must be integers, not %q"), mp_obj_get_type_qstr(index));
mp_raise_TypeError_varg(translate("%q must be of type %q"), MP_QSTR_index, MP_QSTR_int);
}
const byte *s, *top = self_data + self_len;
if (i < 0) {

View File

@ -55,9 +55,9 @@ mp_obj_t mp_parse_num_integer(const char *restrict str_, size_t len, int base, m
mp_obj_t ret_val;
// check radix base
if ((base != 0 && base < 2) || base > 36) {
if (base != 0) {
// this won't be reached if lex!=NULL
mp_raise_ValueError(MP_ERROR_TEXT("int() arg 2 must be >= 2 and <= 36"));
mp_arg_validate_int_range(base, 2, 36, MP_QSTR_base);
}
// skip leading space

View File

@ -262,8 +262,15 @@ $(HEADER_BUILD)/qstrdefs.generated.h: $(PY_SRC)/makeqstrdata.py $(HEADER_BUILD)/
$(STEPECHO) "GEN $@"
$(Q)$(PYTHON) $(PY_SRC)/makeqstrdata.py --output_type=data $(HEADER_BUILD)/qstrdefs.preprocessed.h > $@
$(PY_BUILD)/translations-$(TRANSLATION).c $(HEADER_BUILD)/compression.generated.h: $(PY_SRC)/maketranslationdata.py $(HEADER_BUILD)/$(TRANSLATION).mo $(HEADER_BUILD)/qstrdefs.preprocessed.h
# Is generated as a side-effect of building compression.generated.h
# Specifying both in a single rule actually causes the rule to be run twice!
# This alternative makes it run just once.
$(PY_BUILD)/translations-$(TRANSLATION).c: $(HEADER_BUILD)/compression.generated.h
@true
$(HEADER_BUILD)/compression.generated.h: $(PY_SRC)/maketranslationdata.py $(HEADER_BUILD)/$(TRANSLATION).mo $(HEADER_BUILD)/qstrdefs.preprocessed.h
$(STEPECHO) "GEN $@"
$(Q)mkdir -p $(PY_BUILD)
$(Q)$(PYTHON) $(PY_SRC)/maketranslationdata.py --compression_filename $(HEADER_BUILD)/compression.generated.h --translation $(HEADER_BUILD)/$(TRANSLATION).mo --translation_filename $(PY_BUILD)/translations-$(TRANSLATION).c $(HEADER_BUILD)/qstrdefs.preprocessed.h
PY_CORE_O += $(PY_BUILD)/translations-$(TRANSLATION).o

View File

@ -49,7 +49,6 @@ Q({:#x})
Q({:#b})
Q( )
Q(\n)
Q(maximum recursion depth exceeded)
Q(<module>)
Q(<lambda>)
Q(<listcomp>)
@ -63,7 +62,3 @@ Q(utf-8)
#if MICROPY_MODULE_FROZEN
Q(.frozen)
#endif
#if MICROPY_ENABLE_PYSTACK
Q(pystack exhausted)
#endif

View File

@ -310,7 +310,7 @@ mp_obj_t mp_unary_op(mp_unary_op_t op, mp_obj_t arg) {
}
#else
if (op == MP_UNARY_OP_INT) {
mp_raise_TypeError_varg(MP_ERROR_TEXT("can't convert %q to int"), mp_obj_get_type_qstr(arg));
mp_raise_TypeError_varg(MP_ERROR_TEXT("can't convert %q to %q"), mp_obj_get_type_qstr(arg), MP_QSTR_int);
} else {
mp_raise_TypeError_varg(MP_ERROR_TEXT("unsupported type for %q: '%q'"),
mp_unary_op_method_name[op], mp_obj_get_type_qstr(arg));
@ -631,7 +631,7 @@ unsupported_op:
#endif
zero_division:
mp_raise_msg(&mp_type_ZeroDivisionError, MP_ERROR_TEXT("division by zero"));
mp_raise_ZeroDivisionError();
}
mp_obj_t mp_call_function_0(mp_obj_t fun) {
@ -1765,3 +1765,7 @@ NORETURN void mp_raise_recursion_depth(void) {
mp_raise_RuntimeError(MP_ERROR_TEXT("maximum recursion depth exceeded"));
}
#endif
NORETURN void mp_raise_ZeroDivisionError(void) {
mp_raise_msg(&mp_type_ZeroDivisionError, MP_ERROR_TEXT("division by zero"));
}

View File

@ -91,7 +91,9 @@ static inline void mp_arg_check_num(size_t n_args, size_t n_kw, size_t n_args_mi
}
void mp_arg_parse_all(size_t n_pos, const mp_obj_t *pos, mp_map_t *kws, size_t n_allowed, const mp_arg_t *allowed, mp_arg_val_t *out_vals);
void mp_arg_parse_all_kw_array(size_t n_pos, size_t n_kw, const mp_obj_t *args, size_t n_allowed, const mp_arg_t *allowed, mp_arg_val_t *out_vals);
#if MICROPY_ERROR_REPORTING <= MICROPY_ERROR_REPORTING_TERSE
NORETURN void mp_arg_error_terse_mismatch(void);
#endif
NORETURN void mp_arg_error_unimpl_kw(void);
NORETURN void mp_arg_error_invalid(qstr arg_name);
@ -226,6 +228,7 @@ NORETURN void mp_raise_NotImplementedError(const compressed_string_t *msg);
NORETURN void mp_raise_NotImplementedError_varg(const compressed_string_t *fmt, ...);
NORETURN void mp_raise_OverflowError_varg(const compressed_string_t *fmt, ...);
NORETURN void mp_raise_recursion_depth(void);
NORETURN void mp_raise_ZeroDivisionError(void);
#endif
#if MICROPY_BUILTIN_METHOD_CHECK_SELF_ARG

View File

@ -105,9 +105,13 @@ STATIC mp_obj_t adafruit_bus_device_spidevice_make_new(const mp_obj_type_t *type
if (args[ARG_chip_select].u_obj != MP_OBJ_NULL) {
digitalinout_result_t result = common_hal_digitalio_digitalinout_switch_to_output(MP_OBJ_TO_PTR(args[ARG_chip_select].u_obj),
true, DRIVE_MODE_PUSH_PULL);
#if CIRCUITPY_DIGITALIO_HAVE_INPUT_ONLY
if (result == DIGITALINOUT_INPUT_ONLY) {
mp_raise_NotImplementedError(translate("Pin is input only"));
}
#else
(void)result;
#endif
}
return (mp_obj_t)self;

View File

@ -129,9 +129,7 @@ STATIC mp_obj_t pixelbuf_pixelbuf_make_new(const mp_obj_type_t *type, size_t n_a
}
static void parse_byteorder(mp_obj_t byteorder_obj, pixelbuf_byteorder_details_t *parsed) {
if (!mp_obj_is_str(byteorder_obj)) {
mp_raise_TypeError(translate("byteorder is not a string"));
}
mp_arg_validate_type_string(byteorder_obj, MP_QSTR_byteorder);
size_t bo_len;
const char *byteorder = mp_obj_str_get_data(byteorder_obj, &bo_len);

View File

@ -344,9 +344,7 @@ STATIC mp_obj_t busio_i2c_writeto_then_readfrom(size_t n_args, const mp_obj_t *p
int32_t in_start = args[ARG_in_start].u_int;
const int32_t in_end = args[ARG_in_end].u_int;
normalize_buffer_bounds(&in_start, in_end, &in_length);
if (in_length == 0) {
mp_raise_ValueError_varg(translate("%q length must be >= 1"), MP_QSTR_out_buffer);
}
mp_arg_validate_length_min(in_length, 1, MP_QSTR_out_buffer);
uint8_t status = common_hal_busio_i2c_write_read(self, args[ARG_address].u_int,
((uint8_t *)out_bufinfo.buf) + out_start, out_length,((uint8_t *)in_bufinfo.buf) + in_start, in_length);

View File

@ -155,7 +155,7 @@ STATIC mp_obj_t busio_uart_make_new(const mp_obj_type_t *type, size_t n_args, si
args[ARG_receiver_buffer_size].u_int, NULL, false);
return (mp_obj_t)self;
#else
mp_raise_ValueError(translate("Invalid pins"));
mp_raise_NotImplementedError(NULL);
#endif // CIRCUITPY_BUSIO_UART
}

View File

@ -53,8 +53,10 @@ STATIC void check_result(digitalinout_result_t result) {
return;
case DIGITALINOUT_PIN_BUSY:
mp_raise_ValueError_varg(translate("%q in use"), MP_QSTR_Pin);
#if CIRCUITPY_DIGITALIO_HAVE_INPUT_ONLY
case DIGITALINOUT_INPUT_ONLY:
mp_raise_ValueError_varg(translate("Invalid %q"), MP_QSTR_direction);
#endif
#if CIRCUITPY_DIGITALIO_HAVE_INVALID_PULL
case DIGITALINOUT_INVALID_PULL:
mp_raise_ValueError_varg(translate("Invalid %q"), MP_QSTR_pull);

View File

@ -38,7 +38,9 @@ extern const mp_obj_type_t digitalio_digitalinout_type;
typedef enum {
DIGITALINOUT_OK,
DIGITALINOUT_PIN_BUSY,
#if CIRCUITPY_DIGITALIO_HAVE_INPUT_ONLY
DIGITALINOUT_INPUT_ONLY,
#endif
#if CIRCUITPY_DIGITALIO_HAVE_INVALID_PULL
DIGITALINOUT_INVALID_PULL,
#endif

View File

@ -371,7 +371,7 @@ STATIC mp_obj_t mp_math_log(size_t n_args, const mp_obj_t *args) {
#pragma GCC diagnostic ignored "-Wfloat-equal"
} else if (base == (mp_float_t)1.0) {
#pragma GCC diagnostic pop
mp_raise_msg(&mp_type_ZeroDivisionError, translate("division by zero"));
math_error();
}
return mp_obj_new_float(l / MICROPY_FLOAT_C_FUN(log)(base));
}

View File

@ -156,9 +156,7 @@ void validate_no_duplicate_pins_2(mp_obj_t seq1, mp_obj_t seq2, qstr arg_name1,
// Validate every element in the list to be a free pin.
void validate_list_is_free_pins(qstr what, const mcu_pin_obj_t **pins_out, mp_int_t max_pins, mp_obj_t seq, uint8_t *count_out) {
mp_int_t len = MP_OBJ_SMALL_INT_VALUE(mp_obj_len(seq));
if (len > max_pins) {
mp_raise_ValueError_varg(translate("At most %d %q may be specified (not %d)"), max_pins, what, len);
}
mp_arg_validate_length_max(len, max_pins, what);
*count_out = len;
for (mp_int_t i = 0; i < len; i++) {
pins_out[i] = validate_obj_is_free_pin(mp_obj_subscr(seq, MP_OBJ_NEW_SMALL_INT(i), MP_OBJ_SENTINEL));

View File

@ -108,7 +108,7 @@ STATIC mp_obj_t random_randrange(size_t n_args, const mp_obj_t *args) {
} else if (step < 0) {
n = (stop - start + step + 1) / step;
} else {
mp_raise_ValueError(translate("step must be non-zero"));
mp_raise_ValueError_varg(MP_ERROR_TEXT("%q step cannot be zero"), MP_QSTR_randrange);
}
if (n <= 0) {
mp_raise_ValueError(translate("invalid step"));

View File

@ -97,9 +97,7 @@ STATIC mp_obj_t struct_time_make_new(const mp_obj_type_t *type, size_t n_args, s
size_t len;
mp_obj_t *items;
mp_obj_get_array(args[0], &len, &items);
if (len != 9) {
mp_raise_TypeError(translate("time.struct_time() takes a 9-sequence"));
}
mp_arg_validate_length(len, 9, MP_QSTR_value);
return namedtuple_make_new(type, len, 0, items);
}

View File

@ -155,7 +155,7 @@ STATIC mp_obj_t usb_hid_device_make_new(const mp_obj_type_t *type, size_t n_args
}
if (report_ids_array[0] == 0 && report_ids_count > 1) {
mp_raise_ValueError_varg(translate("%q with a report ID of 0 must be of length 1"), MP_QSTR_report_ids);
mp_raise_ValueError_varg(translate("%q length must be %d"), MP_QSTR_report_id_space_0, 1);
}
common_hal_usb_hid_device_construct(

View File

@ -220,9 +220,7 @@ bool common_hal_usb_hid_enable(const mp_obj_t devices, uint8_t boot_device) {
}
const mp_int_t num_devices = MP_OBJ_SMALL_INT_VALUE(mp_obj_len(devices));
if (num_devices > MAX_HID_DEVICES) {
mp_raise_ValueError_varg(translate("No more than %d HID devices allowed"), MAX_HID_DEVICES);
}
mp_arg_validate_length_max(num_devices, MAX_HID_DEVICES, MP_QSTR_devices);
num_hid_devices = num_devices;

View File

@ -57,6 +57,9 @@ STATIC void get_word(int n, const mchar_t **pos, const mchar_t **end) {
}
STATIC int put_utf8(char *buf, int u) {
if (u >= translation_offstart) {
u += translation_offset;
}
if (u <= 0x7f) {
*buf = u;
return 1;