wip: fixing compilation

This commit is contained in:
Dan Halbert 2024-07-26 18:38:46 -04:00
parent e16467da85
commit 71f17b08fb
20 changed files with 78 additions and 63 deletions

View file

@ -358,9 +358,9 @@ STATIC mp_obj_t fat_vfs_stat(mp_obj_t vfs_in, mp_obj_t path_in) {
#if MICROPY_LONGINT_IMPL == MICROPY_LONGINT_IMPL_NONE
// On non-longint builds, the number of seconds since 1970 (epoch) is too
// large to fit in a smallint, so just return 31-DEC-1999 (0).
mp_obj_t seconds = MP_OBJ_NEW_SMALL_INT(946684800);
mp_obj_t seconds_obj = MP_OBJ_NEW_SMALL_INT(946684800);
#else
mp_obj_t seconds = mp_obj_new_int_from_uint(
mp_obj_t seconds_obj = mp_obj_new_int_from_uint(
timeutils_seconds_since_epoch(
1980 + ((fno.fdate >> 9) & 0x7f),
(fno.fdate >> 5) & 0x0f,
@ -377,9 +377,10 @@ STATIC mp_obj_t fat_vfs_stat(mp_obj_t vfs_in, mp_obj_t path_in) {
t->items[4] = MP_OBJ_NEW_SMALL_INT(0); // st_uid
t->items[5] = MP_OBJ_NEW_SMALL_INT(0); // st_gid
t->items[6] = mp_obj_new_int_from_uint(fno.fsize); // st_size
t->items[7] = mp_obj_new_int_from_uint(seconds); // st_atime
t->items[8] = mp_obj_new_int_from_uint(seconds); // st_mtime
t->items[9] = mp_obj_new_int_from_uint(seconds); // st_ctime
// CIRCUITPY-CHANGE: already converted to obj
t->items[7] = seconds_obj; // st_atime
t->items[8] = seconds_obj; // st_mtime
t->items[9] = seconds_obj; // st_ctime
return MP_OBJ_FROM_PTR(t);
}

View file

@ -6,6 +6,11 @@
#include <string.h>
#include "mpconfigboard.h"
#include "mphalport.h"
#include "reset.h"
#include "supervisor/shared/tick.h"
#include "shared/readline/readline.h"
#include "shared/runtime/interrupt_char.h"
#include "py/mphal.h"
@ -21,10 +26,6 @@
#include "hal/include/hal_sleep.h"
#include "sam.h"
#include "mpconfigboard.h"
#include "mphalport.h"
#include "reset.h"
#include "supervisor/shared/tick.h"
extern uint32_t common_hal_mcu_processor_get_frequency(void);

View file

@ -5,9 +5,3 @@
// SPDX-License-Identifier: MIT
#pragma once
#ifndef MICROPY_INCLUDED_ESPRESSIF_COMMON_HAL_SOCKETPOOL___INIT___H
#define MICROPY_INCLUDED_ESPRESSIF_COMMON_HAL_SOCKETPOOL___INIT___H
#endif // MICROPY_INCLUDED_ESPRESSIF_COMMON_HAL_SOCKETPOOL___INIT___H

View file

@ -323,7 +323,8 @@ def qstr_escape(qst):
static_qstr_list_ident = list(map(qstr_escape, static_qstr_list))
def parse_input_headers(infiles):
# CIRCUITPY-CHANGE: add translations handling
def parse_input_headers_with_translations(infiles):
qcfgs = {}
qstrs = {}
# CIRCUITPY-CHANGE: add translations
@ -428,6 +429,9 @@ def print_qstr_data(qcfgs, qstrs, translations):
qbytes = make_bytes(cfg_bytes_len, cfg_bytes_hash, qstr)
print("QDEF0(MP_QSTR_%s, %s)" % (qstr_escape(qstr), qbytes))
# CIRCUITPY-CHANGE: track total qstr size
total_qstr_size = 0
# add remaining qstrs to the sorted (by value) pool (unless they're in
# operator_qstr_list, in which case add them to the unsorted pool)
for ident, qstr in sorted(qstrs.values(), key=lambda x: x[1]):
@ -435,6 +439,9 @@ def print_qstr_data(qcfgs, qstrs, translations):
pool = 0 if qstr in operator_qstr_list else 1
print("QDEF%d(MP_QSTR_%s, %s)" % (pool, ident, qbytes))
# CIRCUITPY-CHANGE: track total qstr size
total_qstr_size += len(qstr)
# CIRCUITPY-CHANGE: translations
print(
"// Enumerate translated texts but don't actually include translations. Instead, the linker will link them in."

View file

@ -152,8 +152,8 @@ def process_file(f):
)
elif args.mode == _MODE_ROOT_POINTER:
re_match = re.compile(r"MP_REGISTER_ROOT_POINTER\(.*?\);")
# CIRCUITPY-CHANGE: added
re_translate = re.compile(r"MP_COMPRESSED_ROM_TEXT\(\"((?:(?=(\\?))\2.)*?)\"\)")
# CIRCUITPY-CHANGE: added
re_translate = re.compile(r"MP_COMPRESSED_ROM_TEXT\(\"((?:(?=(\\?))\2.)*?)\"\)")
output = []
last_fname = None
for line in f:

View file

@ -527,7 +527,7 @@ def qstr_escape(qst):
def parse_qstrs(infile):
r = {}
rx = re.compile(r'QDEF\([A-Za-z0-9_]+,\s*\d+,\s*\d+,\s*(?P<cstr>"(?:[^"\\\\]*|\\.)")\)')
rx = re.compile(r'QDEF[01]\([A-Za-z0-9_]+,\s*\d+,\s*\d+,\s*(?P<cstr>"(?:[^"\\\\]*|\\.)")\)')
content = infile.read()
for i, mat in enumerate(rx.findall(content, re.M)):
mat = eval(mat)

View file

@ -1,7 +1,7 @@
"""
Generate header file with macros defining MicroPython version info.
# CIRCUITPY-CHANGE: This script is thoroughly reword for use with CircuitPython.
# CIRCUITPY-CHANGE: This script is thoroughly reworked for use with CircuitPython.
This script works with Python 3.7 and newer
"""
@ -117,6 +117,7 @@ def make_version_header(repo_path, filename):
#define MICROPY_VERSION_MAJOR (%s)
#define MICROPY_VERSION_MINOR (%s)
#define MICROPY_VERSION_MICRO (%s)
#define MICROPY_VERSION_PRERELEASE 0
#define MICROPY_VERSION_STRING "%s"
// Combined version as a 32-bit number for convenience
#define MICROPY_VERSION (MICROPY_VERSION_MAJOR << 16 | MICROPY_VERSION_MINOR << 8 | MICROPY_VERSION_MICRO)

View file

@ -82,20 +82,12 @@ STATIC const mp_rom_obj_tuple_t mp_sys_implementation_version_info_obj = {
}
};
STATIC const MP_DEFINE_STR_OBJ(mp_sys_implementation_machine_obj, MICROPY_BANNER_MACHINE);
// CIRCUITPY-CHANGE: MP_QSTR_circuitpython
#define SYS_IMPLEMENTATION_ELEMS_BASE \
MP_ROM_QSTR(MP_QSTR_circuitpython), \
MP_ROM_PTR(&mp_sys_implementation_version_info_obj), \
MP_ROM_PTR(&mp_sys_implementation_machine_obj)
#if MICROPY_PERSISTENT_CODE_LOAD
#define SYS_IMPLEMENTATION_ELEMS__MPY \
, MP_ROM_INT(MPY_FILE_HEADER_INT)
#else
#define SYS_IMPLEMENTATION_ELEMS \
MP_ROM_QSTR(MP_QSTR_micropython), \
MP_ROM_PTR(&mp_sys_implementation_version_info_obj), \
MP_ROM_PTR(&mp_sys_implementation_machine_obj)
#if MICROPY_PERSISTENT_CODE_LOAD
#define SYS_IMPLEMENTATION_ELEMS__MPY \
, MP_ROM_INT(MPY_FILE_HEADER_INT)

View file

@ -61,6 +61,8 @@
#define MICROPY_VERSION_STRING MICROPY_VERSION_STRING_BASE
#endif
#endif // CIRCUITPY
// If this is enabled, then in-progress/breaking changes slated for the 2.x
// release will be enabled.
#ifndef MICROPY_PREVIEW_VERSION_2

View file

@ -573,7 +573,7 @@ mp_obj_t mp_obj_new_exception_msg_vlist(const mp_obj_type_t *exc_type, mp_rom_er
// We have some memory to format the string.
struct _exc_printer_t exc_pr = {!used_emg_buf, o_str_alloc, 0, o_str_buf};
mp_print_t print = {&exc_pr, exc_add_strn};
mp_vcprintf(&print, fmt, ap);
mp_vcprintf(&print, fmt, args);
exc_pr.buf[exc_pr.len] = '\0';
o_str->len = exc_pr.len;
o_str->data = exc_pr.buf;

View file

@ -101,7 +101,8 @@ const qstr_len_t mp_qstr_const_lengths_static[] = {
#undef QDEF0
#undef QDEF1
// CIRCUITPY-CHANGE: translations
#undef TRANSLATION #endif
#undef TRANSLATION
#endif
};
const qstr_pool_t mp_qstr_const_pool_static = {

View file

@ -36,15 +36,26 @@
// for qstrs that are referenced this way, but you don't want to have them in ROM.
// first entry in enum will be MP_QSTRnull=0, which indicates invalid/no qstr
// CIRCUITPY-CHANGE: TODO: Check QDEF0 QDEF1 stuff here from MicroPython
enum {
#ifndef NO_QSTR
#define QDEF(id, hash, len, str) id,
#define QDEF0(id, hash, len, str) id,
#define QDEF1(id, hash, len, str)
// CIRCUITPY-CHANGE
#define TRANSLATION(english_id, number)
#include "genhdr/qstrdefs.generated.h"
#undef QDEF
#undef QDEF0
#undef QDEF1
#endif
MP_QSTRnumber_of_static,
MP_QSTRstart_of_main = MP_QSTRnumber_of_static - 1, // unused but shifts the enum counter back one
#ifndef NO_QSTR
#define QDEF0(id, hash, len, str)
#define QDEF1(id, hash, len, str) id,
#define TRANSLATION(english_id, number)
#include "genhdr/qstrdefs.generated.h"
#undef QDEF0
#undef QDEF1
#undef TRANSLATION
#endif
MP_QSTRnumber_of, // no underscore so it can't clash with any of the above
@ -71,8 +82,8 @@ typedef uint16_t qstr_len_t;
typedef struct _qstr_pool_t {
const struct _qstr_pool_t *prev;
// CIRCUITPY-CHANGE: TODO, check bitfield width here from MicroPython
size_t total_prev_len;
size_t total_prev_len : (8 * sizeof(size_t) - 1);
size_t is_sorted : 1;
size_t alloc;
size_t len;
qstr_hash_t *hashes;
@ -82,7 +93,7 @@ typedef struct _qstr_pool_t {
#define QSTR_TOTAL() (MP_STATE_VM(last_pool)->total_prev_len + MP_STATE_VM(last_pool)->len)
// CIRCUITPY-CHANGE: added
// CIRCUITPY-CHANGE: reset() added
void qstr_reset(void);
void qstr_init(void);
@ -101,7 +112,7 @@ void qstr_pool_info(size_t *n_pool, size_t *n_qstr, size_t *n_str_data_bytes, si
void qstr_dump_data(void);
#if MICROPY_ROM_TEXT_COMPRESSION
// CIRCUITPY-CHANGE: not const previusly, should it be??
// CIRCUITPY-CHANGE: TODO not const previusly, should it be??
// TEST COMPILE with const ******************
void mp_decompress_rom_string(byte *dst, const mp_rom_error_text_t src);
#define MP_IS_COMPRESSED_ROM_STRING(s) (*(byte *)(s) == 0xff)

View file

@ -1445,7 +1445,7 @@ unwind_loop:
// - constant GeneratorExit object, because it's const
// - exceptions re-raised by END_FINALLY
// - exceptions re-raised explicitly by "raise"
// CIRCUITPY-CHANGE: do always
// CIRCUITPY-CHANGE: MICROPY_CONST_GENERATOREXIT_OBJ check; true just helps formatting.
if ( true
#if MICROPY_CONST_GENERATOREXIT_OBJ
&& nlr.ret_val != &mp_const_GeneratorExit_obj
@ -1495,14 +1495,14 @@ unwind_loop:
#endif
// save this exception in the stack so it can be used in a reraise, if needed
exc_sp->prev_exc = nlr.ret_val;
mp_obj_t obj = MP_OBJ_FROM_PTR(nlr.ret_val);
mp_obj_t ret_val_obj = MP_OBJ_FROM_PTR(nlr.ret_val);
#if MICROPY_CPYTHON_EXCEPTION_CHAIN
if (active_exception != MP_OBJ_NULL && active_exception != obj) {
if (active_exception != MP_OBJ_NULL && active_exception != ret_val_obj) {
mp_store_attr(obj, MP_QSTR___context__, active_exception);
}
#endif
// push exception object so it can be handled by bytecode
PUSH(MP_OBJ_FROM_PTR(nlr.ret_val));
PUSH(MP_OBJ_FROM_PTR(ret_val_obj));
code_state->sp = sp;
#if MICROPY_STACKLESS

View file

@ -5,8 +5,3 @@
// SPDX-License-Identifier: MIT
#pragma once
#ifndef SHARED_MODULE_TERMINALIO___INIT___H
#define SHARED_MODULE_TERMINALIO___INIT___H
#endif /* SHARED_MODULE_TERMINALIO___INIT___H */

View file

@ -26,7 +26,7 @@
#ifndef MICROPY_INCLUDED_LIB_MP_READLINE_READLINE_H
#define MICROPY_INCLUDED_LIB_MP_READLINE_READLINE_H
// CIRCUITPY-CHANGE
// CIRCUITPY-CHANGE: for vstr_t
#include "py/misc.h"
#define CHAR_CTRL_A (1)
@ -36,7 +36,7 @@
#define CHAR_CTRL_E (5)
#define CHAR_CTRL_F (6)
#define CHAR_CTRL_K (11)
// CIRCUITPY-CHANGE: new functionality
// CIRCUITPY-CHANGE: ctrl-L support
#define CHAR_CTRL_L (12)
#define CHAR_CTRL_N (14)
#define CHAR_CTRL_P (16)

View file

@ -26,7 +26,7 @@
#include <string.h>
// CIRCUITPY-CHANGE
#include <bool.h>
#include <stdbool.h>
#include "py/mphal.h"
/*

View file

@ -36,7 +36,7 @@ int mp_hal_stdin_rx_chr(void) {
}
}
void mp_hal_stdout_tx_strn(const char *str, size_t len) {
mp_uint_t mp_hal_stdout_tx_strn(const char *str, size_t len) {
toggle_tx_led();
#ifdef CIRCUITPY_BOOT_OUTPUT_FILE
@ -58,7 +58,7 @@ void mp_hal_stdout_tx_strn(const char *str, size_t len) {
}
#endif
serial_write_substring(str, len);
return serial_write_substring(str, len);
}
uintptr_t mp_hal_stdio_poll(uintptr_t poll_flags) {

View file

@ -318,25 +318,31 @@ uint32_t serial_bytes_available(void) {
return count;
}
void serial_write_substring(const char *text, uint32_t length) {
uint32_t serial_write_substring(const char *text, uint32_t length) {
if (length == 0) {
return;
return 0;
}
// See https://github.com/micropython/micropython/pull/11850 for the motivation for returning
// the number of chars written.
// Assume that unless otherwise reported, we sent all that we got.
uint32_t length_sent = length;
#if CIRCUITPY_TERMINALIO
int errcode;
if (!_serial_display_write_disabled) {
common_hal_terminalio_terminal_write(&supervisor_terminal, (const uint8_t *)text, length, &errcode);
length_sent = common_hal_terminalio_terminal_write(&supervisor_terminal, (const uint8_t *)text, length, &errcode);
}
#endif
if (_serial_console_write_disabled) {
return;
return length_sent;
}
#if CIRCUITPY_USB_DEVICE && CIRCUITPY_USB_VENDOR
if (tud_vendor_connected()) {
tud_vendor_write(text, length);
length_sent = tud_vendor_write(text, length);
}
#endif
@ -346,7 +352,7 @@ void serial_write_substring(const char *text, uint32_t length) {
_first_write_done = true;
}
int uart_errcode;
common_hal_busio_uart_write(&console_uart, (const uint8_t *)text, length, &uart_errcode);
length_sent = common_hal_busio_uart_write(&console_uart, (const uint8_t *)text, length, &uart_errcode);
#endif
#if CIRCUITPY_SERIAL_BLE
@ -359,7 +365,7 @@ void serial_write_substring(const char *text, uint32_t length) {
#if CIRCUITPY_USB_DEVICE && CIRCUITPY_USB_CDC
if (!usb_cdc_console_enabled()) {
return;
return length;
}
#endif
@ -384,6 +390,8 @@ void serial_write_substring(const char *text, uint32_t length) {
board_serial_write_substring(text, length);
port_serial_write_substring(text, length);
return length_sent;
}
void serial_write(const char *text) {

View file

@ -23,7 +23,7 @@ void serial_early_init(void);
void serial_init(void);
void serial_write(const char *text);
// Only writes up to given length. Does not check for null termination at all.
void serial_write_substring(const char *text, uint32_t length);
uint32_t serial_write_substring(const char *text, uint32_t length);
char serial_read(void);
uint32_t serial_bytes_available(void);
bool serial_connected(void);

View file

@ -13,11 +13,13 @@
#include "supervisor/shared/translate/compressed_string.h"
#ifndef NO_QSTR
#define QDEF(id, hash, len, str)
#define QDEF0(id, hash, len, str)
#define QDEF1(id, hash, len, str)
#define TRANSLATION(english_id, number) extern struct compressed_string translation##number;
#include "genhdr/qstrdefs.generated.h"
#undef QDEF0
#undef QDEF1
#undef TRANSLATION
#undef QDEF
#endif
#if CIRCUITPY_TRANSLATE_OBJECT == 0