8000 Remove nlr by GeorgeWort · Pull Request #3 · microbit-foundation/micropython-simulator · GitHub
[go: up one dir, main page]

Skip to content

Remove nlr #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 10 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions inc/microbit/filesystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ int persistent_write(const void *dest, const void *src, uint32_t byte_count);
*/
int persistent_write_byte(const uint8_t *dest, const uint8_t val);

void persistent_write_unchecked(const void *dest, const void *src, uint32_t byte_count);
void persistent_write_byte_unchecked(const uint8_t *dest, const uint8_t val);
int persistent_write_unchecked(const void *dest, const void *src, uint32_t byte_count);
int persistent_write_byte_unchecked(const uint8_t *dest, const uint8_t val);

void persistent_erase_page(const void *page);

Expand Down Expand Up @@ -120,7 +120,7 @@ mp_obj_t microbit_file_size(mp_obj_t filename);

mp_lexer_t *microbit_file_lexer(qstr src_name, file_descriptor_obj *fd);

void microbit_filesystem_init(void);
int microbit_filesystem_init(void);

extern const mp_obj_type_t microbit_bytesio_type;
extern const mp_obj_type_t microbit_textio_type;
Expand Down
6 changes: 3 additions & 3 deletions inc/microbit/modmicrobit.h
< C958 deferred-diff-lines class="awaiting-highlight" data-url="/microbit-foundation/micropython-simulator/diffs/a92ca9b1f907c07a01116b0eb464ca4743a28bf1..07050af94e6be8585c8dceb795a049b01b1a0a1b?base_sha=a92ca9b1f907c07a01116b0eb464ca4743a28bf1&whitespace_ignored=false">
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ void microbit_obj_pin_free(const microbit_pin_obj_t *pin);
// If pin is already in specified mode, this is a no-op and returns "false".
// Otherwise if the acquisition succeeds then it returns "true".
// Not safe to call in an interrupt as it may raise if pin can't be acquired.
bool microbit_obj_pin_acquire(const microbit_pin_obj_t *pin, const microbit_pinmode_t *mode);
int microbit_obj_pin_acquire(const microbit_pin_obj_t *pin, const microbit_pinmode_t *mode);

const microbit_pinmode_t *microbit_pin_get_mode(const microbit_pin_obj_t *pin);
bool microbit_obj_pin_can_be_acquired(const microbit_pin_obj_t *pin);
Expand Down Expand Up @@ -205,8 +205,8 @@ void microbit_display_clear(void);
mp_int_t microbit_display_get_pixel(microbit_display_obj_t *display, mp_int_t x, mp_int_t y);
void microbit_display_set_pixel(microbit_display_obj_t *display, mp_int_t x, mp_int_t y, mp_int_t val);
void microbit_display_show(microbit_display_obj_t *display, microbit_image_obj_t *image);
void microbit_display_animate(microbit_display_obj_t *display, mp_obj_t iterable, mp_int_t delay, bool clear, bool wait);
void microbit_display_scroll(microbit_display_obj_t *display, const char* str);
int microbit_display_animate(microbit_display_obj_t *display, mp_obj_t iterable, mp_int_t delay, bool clear, bool wait);
int microbit_display_scroll(microbit_display_obj_t *display, const char* str);

/****************************************************************/
// microbit.compass object
Expand Down
2 changes: 1 addition & 1 deletion inc/microbit/mphalport.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ int mp_hal_stdin_rx_any(void);
void mp_hal_move_cursor_back(unsigned int pos);
void mp_hal_erase_line_from_cursor(unsigned int n_chars);

void mp_hal_display_string(const char*);
int mp_hal_display_string(const char*);

// MicroPython low-level C API for pins
#include "nrf_gpio.h"
Expand Down
2 changes: 1 addition & 1 deletion inc/py/bc.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ const byte *mp_decode_uint_skip(const byte *ptr);

mp_vm_return_kind_t mp_execute_bytecode(mp_code_state_t *code_state, volatile mp_obj_t inject_exc);
mp_code_state_t *mp_obj_fun_bc_prepare_codestate(mp_obj_t func, size_t n_args, size_t n_kw, const mp_obj_t *args);
void mp_setup_code_state(mp_code_state_t *code_state, size_t n_args, size_t n_kw, const mp_obj_t *args);
int mp_setup_code_state(mp_code_state_t *code_state, size_t n_args, size_t n_kw, const mp_obj_t *args);
void mp_bytecode_print(const void *descr, const byte *code, mp_uint_t len, const mp_uint_t *const_table);
void mp_bytecode_print2(const byte *code, size_t len, const mp_uint_t *const_table);
const byte *mp_bytecode_print_str(const byte *ip);
Expand Down
4 changes: 2 additions & 2 deletions inc/py/emit.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@ typedef struct _emit_method_table_t {
void (*end_except_handler)(emit_t *emit);
} emit_method_table_t;

void mp_emit_common_get_id_for_load(scope_t *scope, qstr qst);
void mp_emit_common_get_id_for_modification(scope_t *scope, qstr qst);
int mp_emit_common_get_id_for_load(scope_t *scope, qstr qst);
int mp_emit_common_get_id_for_modification(scope_t *scope, qstr qst);
void mp_emit_common_id_op(emit_t *emit, const mp_emit_method_table_id_ops_t *emit_method_table, scope_t *scope, qstr qst);

extern const emit_method_table_t emit_bc_method_table;
Expand Down
3 changes: 2 additions & 1 deletion inc/py/lexer.h
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ mp_lexer_t *mp_lexer_new(qstr src_name, mp_reader_t reader);
mp_lexer_t *mp_lexer_new_from_str_len(qstr src_name, const char *str, size_t len, size_t free_len);

void mp_lexer_free(mp_lexer_t *lex);
void mp_lexer_to_next(mp_lexer_t *lex);
int mp_lexer_to_next(mp_lexer_t *lex);

/******************************************************************/
// platform specific import function; must be implemented for a specific port
Expand All @@ -183,6 +183,7 @@ typedef enum {
MP_IMPORT_STAT_NO_EXIST,
MP_IMPORT_STAT_DIR,
MP_IMPORT_STAT_FILE,
MP_IMPORT_STAT_EXC
} mp_import_stat_t;

mp_import_stat_t mp_import_stat(const char *path);
Expand Down
8 changes: 4 additions & 4 deletions inc/py/misc.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ void *m_realloc(void *ptr, size_t new_num_bytes);
void *m_realloc_maybe(void *ptr, size_t new_num_bytes, bool allow_move);
void m_free(void *ptr);
#endif
NORETURN void *m_malloc_fail(size_t num_bytes);
void *m_malloc_fail(size_t num_bytes);

#if MICROPY_MEM_STATS
size_t m_get_total_bytes_allocated(void);
Expand Down Expand Up @@ -149,11 +149,11 @@ typedef struct _vstr_t {
// convenience macro to declare a vstr with a fixed size buffer on the stack
#define VSTR_FIXED(vstr, alloc) vstr_t vstr; char vstr##_buf[(alloc)]; vstr_init_fixed_buf(&vstr, (alloc), vstr##_buf);

void vstr_init(vstr_t *vstr, size_t alloc);
void vstr_init_len(vstr_t *vstr, size_t len);
int vstr_init(vstr_t *vstr, size_t alloc);
int vstr_init_len(vstr_t *vstr, size_t len);
void vstr_init_fixed_buf(vstr_t *vstr, size_t alloc, char *buf);
struct _mp_print_t;
void vstr_init_print(vstr_t *vstr, size_t alloc, struct _mp_print_t *print);
int vstr_init_print(vstr_t *vstr, size_t alloc, struct _mp_print_t *print);
void vstr_clear(vstr_t *vstr);
vstr_t *vstr_new(size_t alloc);
void vstr_free(vstr_t *vstr);
Expand Down
8 changes: 5 additions & 3 deletions inc/py/mpstate.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@
#include "py/mpconfig.h"
#include "py/mpthread.h"
#include "py/misc.h"
#include "py/nlr.h"
#include <limits.h>
#include <assert.h>
#include "py/mpconfig.h"
#include "py/mpstate.h"
#include "py/obj.h"
#include "py/objlist.h"
#include "py/objexcept.h"
Expand Down Expand Up @@ -211,8 +214,7 @@ typedef struct _mp_state_thread_t {
mp_obj_dict_t *dict_locals;
mp_obj_dict_t *dict_globals;

// Note: nlr asm code has the offset of this hard-coded
nlr_buf_t *nlr_top; // ROOT POINTER
mp_obj_base_t *cur_exc;

// Stack top at the start of program
char *stack_top;
Expand Down
38 changes: 19 additions & 19 deletions inc/py/mpz.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,37 +98,37 @@ typedef struct _mpz_t {
#define MPZ_CONST_INT(z, val) mpz_t z; mpz_dig_t z ## _digits[MPZ_NUM_DIG_FOR_INT]; mpz_init_fixed_from_int(&z, z_digits, MPZ_NUM_DIG_FOR_INT, val);

void mpz_init_zero(mpz_t *z);
void mpz_init_from_int(mpz_t *z, mp_int_t val);
void mpz_init_fixed_from_int(mpz_t *z, mpz_dig_t *dig, size_t dig_alloc, mp_int_t val);
int mpz_init_from_int(mpz_t *z, mp_int_t val);
int mpz_init_fixed_from_int(mpz_t *z, mpz_dig_t *dig, size_t dig_alloc, mp_int_t val);
void mpz_deinit(mpz_t *z);

void mpz_set(mpz_t *dest, const mpz_t *src);
void mpz_set_from_int(mpz_t *z, mp_int_t src);
void mpz_set_from_ll(mpz_t *z, long long i, bool is_signed);
int mpz_set(mpz_t *dest, const mpz_t *src);
int mpz_set_from_int(mpz_t *z, mp_int_t src);
int mpz_set_from_ll(mpz_t *z, long long i, bool is_signed);
#if MICROPY_PY_BUILTINS_FLOAT
void mpz_set_from_float(mpz_t *z, mp_float_t src);
int mpz_set_from_float(mpz_t *z, mp_float_t src);
#endif
size_t mpz_set_from_str(mpz_t *z, const char *str, size_t len, bool neg, unsigned int base);
void mpz_set_from_bytes(mpz_t *z, bool big_endian, size_t len, const byte *buf);
int mpz_set_from_bytes(mpz_t *z, bool big_endian, size_t len, const byte *buf);

static inline bool mpz_is_zero(const mpz_t *z) { return z->len == 0; }
static inline bool mpz_is_neg(const mpz_t *z) { return z->len != 0 && z->neg != 0; }
int mpz_cmp(const mpz_t *lhs, const mpz_t *rhs);

void mpz_abs_inpl(mpz_t *dest, const mpz_t *z);
void mpz_neg_inpl(mpz_t *dest, const mpz_t *z);
void mpz_not_inpl(mpz_t *dest, const mpz_t *z);
void mpz_shl_inpl(mpz_t *dest, const mpz_t *lhs, mp_uint_t rhs);
void mpz_shr_inpl(mpz_t *dest, const mpz_t *lhs, mp_uint_t rhs);
void mpz_add_inpl(mpz_t *dest, const mpz_t *lhs, const mpz_t *rhs);
void mpz_sub_inpl(mpz_t *dest, const mpz_t *lhs, const mpz_t *rhs);
void mpz_mul_inpl(mpz_t *dest, const mpz_t *lhs, const mpz_t *rhs);
void mpz_pow_inpl(mpz_t *dest, const mpz_t *lhs, const mpz_t *rhs);
void mpz_pow3_inpl(mpz_t *dest, const mpz_t *lhs, const mpz_t *rhs, const mpz_t *mod);
void mpz_and_inpl(mpz_t *dest, const mpz_t *lhs, const mpz_t *rhs);
void mpz_or_inpl(mpz_t *dest, const mpz_t *lhs, const mpz_t *rhs);
void mpz_xor_inpl(mpz_t *dest, const mpz_t *lhs, const mpz_t *rhs);
void mpz_divmod_inpl(mpz_t *dest_quo, mpz_t *dest_rem, const mpz_t *lhs, const mpz_t *rhs);
int mpz_not_inpl(mpz_t *dest, const mpz_t *z);
int mpz_shl_inpl(mpz_t *dest, const mpz_t *lhs, mp_uint_t rhs);
int mpz_shr_inpl(mpz_t *dest, const mpz_t *lhs, mp_uint_t rhs);
int mpz_add_inpl(mpz_t *dest, const mpz_t *lhs, const mpz_t *rhs);
int mpz_sub_inpl(mpz_t *dest, const mpz_t *lhs, const mpz_t *rhs);
int mpz_mul_inpl(mpz_t *dest, const mpz_t *lhs, const mpz_t *rhs);
int mpz_pow_inpl(mpz_t *dest, const mpz_t *lhs, const mpz_t *rhs);
int mpz_pow3_inpl(mpz_t *dest, const mpz_t *lhs, const mpz_t *rhs, const mpz_t *mod);
int mpz_and_inpl(mpz_t *dest, const mpz_t *lhs, const mpz_t *rhs);
int mpz_or_inpl(mpz_t *dest, const mpz_t *lhs, const mpz_t *rhs);
int mpz_xor_inpl(mpz_t *dest, const mpz_t *lhs, const mpz_t *rhs);
int mpz_divmod_inpl(mpz_t *dest_quo, mpz_t *dest_rem, const mpz_t *lhs, const mpz_t *rhs);

static inline size_t mpz_max_num_bits(const mpz_t *z) { return z->len * MPZ_DIG_SIZE; }
mp_int_t mpz_hash(const mpz_t *z);
Expand Down
17 changes: 8 additions & 9 deletions inc/py/obj.h
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ extern const mp_map_t mp_const_empty_map;

static inline bool MP_MAP_SLOT_IS_FILLED(const mp_map_t *map, size_t pos) { return ((map)->table[pos].key != MP_OBJ_NULL && (map)->table[pos].key != MP_OBJ_SENTINEL); }

void mp_map_init(mp_map_t *map, size_t n);
int mp_map_init(mp_map_t *map, size_t n);
void mp_map_init_fixed_table(mp_map_t *map, size_t n, const mp_obj_t *table);
mp_map_t *mp_map_new(size_t n);
void mp_map_deinit(mp_map_t *map);
Expand All @@ -395,7 +395,7 @@ typedef struct _mp_set_t {

static inline bool MP_SET_SLOT_IS_FILLED(const mp_set_t *set, size_t pos) { return ((set)->table[pos] != MP_OBJ_NULL && (set)->table[pos] != MP_OBJ_SENTINEL); }

void mp_set_init(mp_set_t *set, size_t n);
int mp_set_init(mp_set_t *set, size_t n);
mp_obj_t mp_set_lookup(mp_set_t *set, mp_obj_t index, mp_map_lookup_kind_t lookup_kind);
mp_obj_t mp_set_remove_first(mp_set_t *set);
void mp_set_clear(mp_set_t *set);
Expand Down Expand Up @@ -460,7 +460,7 @@ typedef struct _mp_buffer_p_t {
mp_int_t (*get_buffer)(mp_obj_t obj, mp_buffer_info_t *bufinfo, mp_uint_t flags);
} mp_buffer_p_t;
bool mp_get_buffer(mp_obj_t obj, mp_buffer_info_t *bufinfo, mp_uint_t flags);
void mp_get_buffer_raise(mp_obj_t obj, mp_buffer_info_t *bufinfo, mp_uint_t flags);
bool mp_get_buffer_raise(mp_obj_t obj, mp_buffer_info_t *bufinfo, mp_uint_t flags);

// Stream protocol
typedef struct _mp_stream_p_t {
Expand Down Expand Up @@ -687,11 +687,11 @@ mp_int_t mp_obj_get_int_truncated(mp_const_obj_t arg);
bool mp_obj_get_int_maybe(mp_const_obj_t arg, mp_int_t *value);
#if MICROPY_PY_BUILTINS_FLOAT
mp_float_t mp_obj_get_float(mp_obj_t self_in);
void mp_obj_get_complex(mp_obj_t self_in, mp_float_t *real, mp_float_t *imag);
int mp_obj_get_complex(mp_obj_t self_in, mp_float_t *real, mp_float_t *imag);
#endif
//qstr mp_obj_get_qstr(mp_obj_t arg);
void mp_obj_get_array(mp_obj_t o, size_t *len, mp_obj_t **items); // *items may point inside a GC block
void mp_obj_get_array_fixed_n(mp_obj_t o, size_t len, mp_obj_t **items); // *items may point inside a GC block
int mp_obj_get_array(mp_obj_t o, size_t *len, mp_obj_t **items); // *items may point inside a GC block
int mp_obj_get_array_fixed_n(mp_obj_t o, size_t len, mp_obj_t **items); // *items may point inside a GC block
size_t mp_get_index(const mp_obj_type_t *type, size_t len, mp_obj_t index, bool is_slice);
mp_obj_t mp_obj_id(mp_obj_t o_in);
mp_obj_t mp_obj_len(mp_obj_t o_in);
Expand Down Expand Up @@ -753,7 +753,6 @@ mp_int_t mp_obj_tuple_hash(mp_obj_t self_in);

// list
struct _mp_obj_list_t;
void mp_obj_list_init(struct _mp_obj_list_t *o, size_t n);
mp_obj_t mp_obj_list_append(mp_obj_t self_in, mp_obj_t arg);
mp_obj_t mp_obj_list_remove(mp_obj_t self_in, mp_obj_t value);
void mp_obj_list_get(mp_obj_t self_in, size_t *len, mp_obj_t **items);
Expand All @@ -766,7 +765,7 @@ typedef struct _mp_obj_dict_t {
mp_obj_base_t base;
mp_map_t map;
} mp_obj_dict_t;
void mp_obj_dict_init(mp_obj_dict_t *dict, size_t n_args);
int mp_obj_dict_init(mp_obj_dict_t *dict, size_t n_args);
size_t mp_obj_dict_len(mp_obj_t self_in);
mp_obj_t mp_obj_dict_get(mp_obj_t self_in, mp_obj_t index);
mp_obj_t mp_obj_dict_store(mp_obj_t self_in, mp_obj_t key, mp_obj_t value);
Expand Down Expand Up @@ -860,7 +859,7 @@ typedef struct {

void mp_seq_multiply(const void *items, size_t item_sz, size_t len, size_t times, void *dest);
#if MICROPY_PY_BUILTINS_SLICE
bool mp_seq_get_fast_slice_indexes(mp_uint_t len, mp_obj_t slice, mp_bound_slice_t *indexes);
int mp_seq_get_fast_slice_indexes(mp_uint_t len, mp_obj_t slice, mp_bound_slice_t *indexes);
#endif
#define mp_seq_copy(dest, src, len, item_t) memcpy(dest, src, len * sizeof(item_t))
#define mp_seq_cat(dest, src1, len1, src2, len2, item_t) { memcpy(dest, src1, (len1) * sizeof(item_t)); memcpy(dest + (len1), src2, (len2) * sizeof(item_t)); }
Expand Down
2 changes: 2 additions & 0 deletions inc/py/objlist.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,6 @@ typedef struct _mp_obj_list_t {
mp_obj_t *items;
} mp_obj_list_t;

mp_obj_list_t *mp_obj_list_init(struct _mp_obj_list_t *o, size_t n);

#endif // MICROPY_INCLUDED_PY_OBJLIST_H
40 changes: 0 additions & 40 deletions inc/py/persistentcode.h

This file was deleted.

2 changes: 1 addition & 1 deletion inc/py/reader.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ typedef struct _mp_reader_t {
void (*close)(void *data);
} mp_reader_t;

void mp_reader_new_mem(mp_reader_t *reader, const byte *buf, size_t len, size_t free_len);
int mp_reader_new_mem(mp_reader_t *reader, const byte *buf, size_t len, size_t free_len);
void mp_reader_new_file(mp_reader_t *reader, const char *filename);
void mp_reader_new_file_from_fd(mp_reader_t *reader, int fd, bool close_fd);

Expand Down
Loading
0