2014-05-03 18:27:38 -04:00
|
|
|
/*
|
2017-06-30 03:22:17 -04:00
|
|
|
* This file is part of the MicroPython project, http://micropython.org/
|
2014-05-03 18:27:38 -04:00
|
|
|
*
|
|
|
|
* The MIT License (MIT)
|
|
|
|
*
|
2020-06-03 18:40:05 -04:00
|
|
|
* SPDX-FileCopyrightText: Copyright (c) 2013, 2014 Damien P. George
|
2014-05-03 18:27:38 -04:00
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
* THE SOFTWARE.
|
|
|
|
*/
|
all: Unify header guard usage.
The code conventions suggest using header guards, but do not define how
those should look like and instead point to existing files. However, not
all existing files follow the same scheme, sometimes omitting header guards
altogether, sometimes using non-standard names, making it easy to
accidentally pick a "wrong" example.
This commit ensures that all header files of the MicroPython project (that
were not simply copied from somewhere else) follow the same pattern, that
was already present in the majority of files, especially in the py folder.
The rules are as follows.
Naming convention:
* start with the words MICROPY_INCLUDED
* contain the full path to the file
* replace special characters with _
In addition, there are no empty lines before #ifndef, between #ifndef and
one empty line before #endif. #endif is followed by a comment containing
the name of the guard macro.
py/grammar.h cannot use header guards by design, since it has to be
included multiple times in a single C file. Several other files also do not
need header guards as they are only used internally and guaranteed to be
included only once:
* MICROPY_MPHALPORT_H
* mpconfigboard.h
* mpconfigport.h
* mpthreadport.h
* pin_defs_*.h
* qstrdefs*.h
2017-06-29 17:14:58 -04:00
|
|
|
#ifndef MICROPY_INCLUDED_PY_RUNTIME_H
|
|
|
|
#define MICROPY_INCLUDED_PY_RUNTIME_H
|
2014-12-28 20:02:19 -05:00
|
|
|
|
2021-05-04 14:40:55 -04:00
|
|
|
#include <stdarg.h>
|
|
|
|
|
2015-01-01 18:30:53 -05:00
|
|
|
#include "py/mpstate.h"
|
py: Introduce a Python stack for scoped allocation.
This patch introduces the MICROPY_ENABLE_PYSTACK option (disabled by
default) which enables a "Python stack" that allows to allocate and free
memory in a scoped, or Last-In-First-Out (LIFO) way, similar to alloca().
A new memory allocation API is introduced along with this Py-stack. It
includes both "local" and "nonlocal" LIFO allocation. Local allocation is
intended to be equivalent to using alloca(), whereby the same function must
free the memory. Nonlocal allocation is where another function may free
the memory, so long as it's still LIFO.
Follow-up patches will convert all uses of alloca() and VLA to the new
scoped allocation API. The old behaviour (using alloca()) will still be
available, but when MICROPY_ENABLE_PYSTACK is enabled then alloca() is no
longer required or used.
The benefits of enabling this option are (or will be once subsequent
patches are made to convert alloca()/VLA):
- Toolchains without alloca() can use this feature to obtain correct and
efficient scoped memory allocation (compared to using the heap instead
of alloca(), which is slower).
- Even if alloca() is available, enabling the Py-stack gives slightly more
efficient use of stack space when calling nested Python functions, due to
the way that compilers implement alloca().
- Enabling the Py-stack with the stackless mode allows for even more
efficient stack usage, as well as retaining high performance (because the
heap is no longer used to build and destroy stackless code states).
- With Py-stack and stackless enabled, Python-calling-Python is no longer
recursive in the C mp_execute_bytecode function.
The micropython.pystack_use() function is included to measure usage of the
Python stack.
2017-11-26 07:28:40 -05:00
|
|
|
#include "py/pystack.h"
|
2014-05-03 18:27:38 -04:00
|
|
|
|
2020-01-08 23:32:45 -05:00
|
|
|
#include "supervisor/linker.h"
|
|
|
|
|
2022-05-27 15:59:54 -04:00
|
|
|
#include "supervisor/shared/translate/translate.h"
|
|
|
|
|
2014-03-30 16:14:55 -04:00
|
|
|
typedef enum {
|
|
|
|
MP_VM_RETURN_NORMAL,
|
|
|
|
MP_VM_RETURN_YIELD,
|
|
|
|
MP_VM_RETURN_EXCEPTION,
|
|
|
|
} mp_vm_return_kind_t;
|
|
|
|
|
2014-04-19 19:13:22 -04:00
|
|
|
typedef enum {
|
2014-04-26 06:19:17 -04:00
|
|
|
MP_ARG_BOOL = 0x001,
|
|
|
|
MP_ARG_INT = 0x002,
|
|
|
|
MP_ARG_OBJ = 0x003,
|
|
|
|
MP_ARG_KIND_MASK = 0x0ff,
|
|
|
|
MP_ARG_REQUIRED = 0x100,
|
|
|
|
MP_ARG_KW_ONLY = 0x200,
|
|
|
|
} mp_arg_flag_t;
|
|
|
|
|
|
|
|
typedef union _mp_arg_val_t {
|
2014-04-19 19:13:22 -04:00
|
|
|
bool u_bool;
|
2014-07-03 08:25:24 -04:00
|
|
|
mp_int_t u_int;
|
2014-04-19 19:13:22 -04:00
|
|
|
mp_obj_t u_obj;
|
2015-11-27 08:38:15 -05:00
|
|
|
mp_rom_obj_t u_rom_obj;
|
2014-04-26 06:19:17 -04:00
|
|
|
} mp_arg_val_t;
|
2014-04-19 19:13:22 -04:00
|
|
|
|
2014-04-26 06:19:17 -04:00
|
|
|
typedef struct _mp_arg_t {
|
2016-09-22 22:13:51 -04:00
|
|
|
uint16_t qst;
|
|
|
|
uint16_t flags;
|
2014-04-26 06:19:17 -04:00
|
|
|
mp_arg_val_t defval;
|
|
|
|
} mp_arg_t;
|
2014-04-19 19:13:22 -04:00
|
|
|
|
2017-10-03 20:31:05 -04:00
|
|
|
// Tables mapping operator enums to qstrs, defined in objtype.c
|
2017-10-21 04:06:32 -04:00
|
|
|
extern const byte mp_unary_op_method_name[];
|
|
|
|
extern const byte mp_binary_op_method_name[];
|
2015-01-27 13:02:25 -05:00
|
|
|
|
2014-03-30 08:35:08 -04:00
|
|
|
void mp_init(void);
|
|
|
|
void mp_deinit(void);
|
|
|
|
|
2021-04-27 20:52:19 -04:00
|
|
|
void mp_sched_exception(mp_obj_t exc);
|
2021-04-27 20:57:34 -04:00
|
|
|
void mp_sched_keyboard_interrupt(void);
|
2020-02-05 09:05:47 -05:00
|
|
|
void mp_handle_pending(bool raise_exc);
|
2017-02-16 02:05:06 -05:00
|
|
|
void mp_handle_pending_tail(mp_uint_t atomic_state);
|
|
|
|
|
|
|
|
#if MICROPY_ENABLE_SCHEDULER
|
|
|
|
void mp_sched_lock(void);
|
|
|
|
void mp_sched_unlock(void);
|
2020-05-02 03:49:15 -04:00
|
|
|
#define mp_sched_num_pending() (MP_STATE_VM(sched_len))
|
2017-02-16 02:05:06 -05:00
|
|
|
bool mp_sched_schedule(mp_obj_t function, mp_obj_t arg);
|
|
|
|
#endif
|
|
|
|
|
2015-04-09 18:56:15 -04:00
|
|
|
// extra printing method specifically for mp_obj_t's which are integral type
|
|
|
|
int mp_print_mp_int(const mp_print_t *print, mp_obj_t x, int base, int base_char, int flags, char fill, int width, int prec);
|
|
|
|
|
2018-09-13 23:39:17 -04:00
|
|
|
void mp_arg_check_num_sig(size_t n_args, size_t n_kw, uint32_t sig);
|
2023-02-28 18:07:35 -05:00
|
|
|
static MP_INLINE void mp_arg_check_num(size_t n_args, size_t n_kw, size_t n_args_min, size_t n_args_max, bool takes_kw) {
|
2019-01-25 00:03:05 -05:00
|
|
|
mp_arg_check_num_sig(n_args, n_kw, MP_OBJ_FUN_MAKE_SIG(n_args_min, n_args_max, takes_kw));
|
2018-09-13 23:39:17 -04:00
|
|
|
}
|
2016-03-14 18:35:48 -04:00
|
|
|
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);
|
2022-11-08 16:40:59 -05:00
|
|
|
#if MICROPY_ERROR_REPORTING <= MICROPY_ERROR_REPORTING_TERSE
|
2015-01-01 10:33:50 -05:00
|
|
|
NORETURN void mp_arg_error_terse_mismatch(void);
|
2022-11-08 16:40:59 -05:00
|
|
|
#endif
|
2014-05-06 12:52:35 -04:00
|
|
|
NORETURN void mp_arg_error_unimpl_kw(void);
|
2014-03-30 08:35:08 -04:00
|
|
|
|
2022-05-13 15:33:43 -04:00
|
|
|
NORETURN void mp_arg_error_invalid(qstr arg_name);
|
|
|
|
mp_int_t mp_arg_validate_int(mp_int_t i, mp_int_t required_i, qstr arg_name);
|
2021-06-21 12:13:39 -04:00
|
|
|
mp_int_t mp_arg_validate_int_min(mp_int_t i, mp_int_t min, qstr arg_name);
|
|
|
|
mp_int_t mp_arg_validate_int_max(mp_int_t i, mp_int_t j, qstr arg_name);
|
|
|
|
mp_int_t mp_arg_validate_int_range(mp_int_t i, mp_int_t min, mp_int_t max, qstr arg_name);
|
2022-02-18 09:45:50 -05:00
|
|
|
#if MICROPY_PY_BUILTINS_FLOAT
|
2021-06-21 12:13:39 -04:00
|
|
|
mp_float_t mp_arg_validate_obj_float_non_negative(mp_obj_t float_in, mp_float_t default_for_null, qstr arg_name);
|
2023-05-01 10:39:40 -04:00
|
|
|
mp_float_t mp_arg_validate_obj_float_range(mp_obj_t float_in, mp_int_t min, mp_int_t max, qstr arg_name);
|
|
|
|
mp_float_t mp_arg_validate_float_range(mp_float_t float_in, mp_int_t min, mp_int_t max, qstr arg_name);
|
2023-04-23 10:43:25 -04:00
|
|
|
mp_float_t mp_arg_validate_type_float(mp_obj_t obj, qstr arg_name);
|
2022-02-18 09:45:50 -05:00
|
|
|
#endif
|
2022-05-13 15:33:43 -04:00
|
|
|
mp_uint_t mp_arg_validate_length_min(mp_uint_t length, mp_uint_t min, qstr arg_name);
|
|
|
|
mp_uint_t mp_arg_validate_length_max(mp_uint_t length, mp_uint_t max, qstr arg_name);
|
2021-08-26 09:34:02 -04:00
|
|
|
mp_uint_t mp_arg_validate_length_range(mp_uint_t length, mp_uint_t min, mp_uint_t max, qstr arg_name);
|
2022-05-13 15:33:43 -04:00
|
|
|
mp_uint_t mp_arg_validate_length(mp_uint_t length, mp_uint_t required_length, qstr arg_name);
|
2022-05-20 10:10:55 -04:00
|
|
|
mp_int_t mp_arg_validate_index_range(mp_int_t index, mp_int_t min, mp_int_t max, qstr arg_name);
|
2021-06-21 12:13:39 -04:00
|
|
|
mp_obj_t mp_arg_validate_type(mp_obj_t obj, const mp_obj_type_t *type, qstr arg_name);
|
2023-01-10 13:39:10 -05:00
|
|
|
mp_obj_t mp_arg_validate_type_in(mp_obj_t obj, const mp_obj_type_t *type, qstr arg_name);
|
|
|
|
mp_obj_t mp_arg_validate_type_or_none(mp_obj_t obj, const mp_obj_type_t *type, qstr arg_name);
|
2022-05-13 15:33:43 -04:00
|
|
|
mp_int_t mp_arg_validate_type_int(mp_obj_t obj, qstr arg_name);
|
|
|
|
mp_obj_t mp_arg_validate_type_string(mp_obj_t obj, qstr arg_name);
|
2021-06-21 12:13:39 -04:00
|
|
|
|
2023-02-28 18:07:35 -05:00
|
|
|
static MP_INLINE mp_obj_dict_t *mp_locals_get(void) {
|
2021-03-15 09:57:36 -04:00
|
|
|
return MP_STATE_THREAD(dict_locals);
|
|
|
|
}
|
2023-02-28 18:07:35 -05:00
|
|
|
static MP_INLINE void mp_locals_set(mp_obj_dict_t *d) {
|
2021-03-15 09:57:36 -04:00
|
|
|
MP_STATE_THREAD(dict_locals) = d;
|
|
|
|
}
|
2023-02-28 18:07:35 -05:00
|
|
|
static MP_INLINE mp_obj_dict_t *mp_globals_get(void) {
|
2021-03-15 09:57:36 -04:00
|
|
|
return MP_STATE_THREAD(dict_globals);
|
|
|
|
}
|
2023-02-28 18:07:35 -05:00
|
|
|
static MP_INLINE void mp_globals_set(mp_obj_dict_t *d) {
|
2021-03-15 09:57:36 -04:00
|
|
|
MP_STATE_THREAD(dict_globals) = d;
|
|
|
|
}
|
2014-03-30 08:35:08 -04:00
|
|
|
|
2015-01-20 06:55:10 -05:00
|
|
|
mp_obj_t mp_load_name(qstr qst);
|
|
|
|
mp_obj_t mp_load_global(qstr qst);
|
2014-03-30 08:35:08 -04:00
|
|
|
mp_obj_t mp_load_build_class(void);
|
2015-01-20 06:55:10 -05:00
|
|
|
void mp_store_name(qstr qst, mp_obj_t obj);
|
|
|
|
void mp_store_global(qstr qst, mp_obj_t obj);
|
|
|
|
void mp_delete_name(qstr qst);
|
|
|
|
void mp_delete_global(qstr qst);
|
2014-03-30 08:35:08 -04:00
|
|
|
|
2017-08-28 23:04:01 -04:00
|
|
|
mp_obj_t mp_unary_op(mp_unary_op_t op, mp_obj_t arg);
|
|
|
|
mp_obj_t mp_binary_op(mp_binary_op_t op, mp_obj_t lhs, mp_obj_t rhs);
|
2014-03-30 08:35:08 -04:00
|
|
|
|
|
|
|
mp_obj_t mp_call_function_0(mp_obj_t fun);
|
|
|
|
mp_obj_t mp_call_function_1(mp_obj_t fun, mp_obj_t arg);
|
|
|
|
mp_obj_t mp_call_function_2(mp_obj_t fun, mp_obj_t arg1, mp_obj_t arg2);
|
2017-02-15 23:32:34 -05:00
|
|
|
mp_obj_t mp_call_function_n_kw(mp_obj_t fun, size_t n_args, size_t n_kw, const mp_obj_t *args);
|
|
|
|
mp_obj_t mp_call_method_n_kw(size_t n_args, size_t n_kw, const mp_obj_t *args);
|
|
|
|
mp_obj_t mp_call_method_n_kw_var(bool have_self, size_t n_args_n_kw, const mp_obj_t *args);
|
2016-11-21 17:33:55 -05:00
|
|
|
mp_obj_t mp_call_method_self_n_kw(mp_obj_t meth, mp_obj_t self, size_t n_args, size_t n_kw, const mp_obj_t *args);
|
2016-04-25 12:28:12 -04:00
|
|
|
// Call function and catch/dump exception - for Python callbacks from C code
|
2017-12-04 17:38:41 -05:00
|
|
|
// (return MP_OBJ_NULL in case of exception).
|
|
|
|
mp_obj_t mp_call_function_1_protected(mp_obj_t fun, mp_obj_t arg);
|
|
|
|
mp_obj_t mp_call_function_2_protected(mp_obj_t fun, mp_obj_t arg1, mp_obj_t arg2);
|
2014-03-30 08:35:08 -04:00
|
|
|
|
2015-04-01 18:31:30 -04:00
|
|
|
typedef struct _mp_call_args_t {
|
2015-03-27 19:14:45 -04:00
|
|
|
mp_obj_t fun;
|
2017-02-15 23:32:34 -05:00
|
|
|
size_t n_args, n_kw, n_alloc;
|
2015-03-27 19:14:45 -04:00
|
|
|
mp_obj_t *args;
|
2015-04-01 18:31:30 -04:00
|
|
|
} mp_call_args_t;
|
2015-03-27 19:14:45 -04:00
|
|
|
|
2015-04-01 18:31:30 -04:00
|
|
|
#if MICROPY_STACKLESS
|
2015-03-27 19:14:45 -04:00
|
|
|
// Takes arguments which are the most general mix of Python arg types, and
|
|
|
|
// prepares argument array suitable for passing to ->call() method of a
|
|
|
|
// function object (and mp_call_function_n_kw()).
|
2015-04-01 18:31:30 -04:00
|
|
|
// (Only needed in stackless mode.)
|
2017-02-15 23:32:34 -05:00
|
|
|
void mp_call_prepare_args_n_kw_var(bool have_self, size_t n_args_n_kw, const mp_obj_t *args, mp_call_args_t *out_args);
|
2015-04-01 18:31:30 -04:00
|
|
|
#endif
|
2015-03-27 19:14:45 -04:00
|
|
|
|
2017-02-15 23:32:34 -05:00
|
|
|
void mp_unpack_sequence(mp_obj_t seq, size_t num, mp_obj_t *items);
|
|
|
|
void mp_unpack_ex(mp_obj_t seq, size_t num, mp_obj_t *items);
|
2014-03-30 08:35:08 -04:00
|
|
|
mp_obj_t mp_store_map(mp_obj_t map, mp_obj_t key, mp_obj_t value);
|
|
|
|
mp_obj_t mp_load_attr(mp_obj_t base, qstr attr);
|
2015-03-21 10:21:54 -04:00
|
|
|
void mp_convert_member_lookup(mp_obj_t obj, const mp_obj_type_t *type, mp_obj_t member, mp_obj_t *dest);
|
2014-03-30 08:35:08 -04:00
|
|
|
void mp_load_method(mp_obj_t base, qstr attr, mp_obj_t *dest);
|
2014-03-31 17:57:56 -04:00
|
|
|
void mp_load_method_maybe(mp_obj_t base, qstr attr, mp_obj_t *dest);
|
2018-05-10 09:00:04 -04:00
|
|
|
void mp_load_method_protected(mp_obj_t obj, qstr attr, mp_obj_t *dest, bool catch_all_exc);
|
2017-04-18 19:45:59 -04:00
|
|
|
void mp_load_super_method(qstr attr, mp_obj_t *dest);
|
2014-03-30 08:35:08 -04:00
|
|
|
void mp_store_attr(mp_obj_t base, qstr attr, mp_obj_t val);
|
|
|
|
|
2016-01-09 18:14:54 -05:00
|
|
|
mp_obj_t mp_getiter(mp_obj_t o, mp_obj_iter_buf_t *iter_buf);
|
2014-04-17 18:19:36 -04:00
|
|
|
mp_obj_t mp_iternext_allow_raise(mp_obj_t o); // may return MP_OBJ_STOP_ITERATION instead of raising StopIteration()
|
|
|
|
mp_obj_t mp_iternext(mp_obj_t o); // will always return MP_OBJ_STOP_ITERATION instead of raising StopIteration(...)
|
2014-03-30 16:14:55 -04:00
|
|
|
mp_vm_return_kind_t mp_resume(mp_obj_t self_in, mp_obj_t send_value, mp_obj_t throw_value, mp_obj_t *ret_val);
|
2014-03-30 08:35:08 -04:00
|
|
|
|
2023-02-28 18:07:35 -05:00
|
|
|
static MP_INLINE mp_obj_t mp_make_stop_iteration(mp_obj_t o) {
|
2021-06-29 03:34:34 -04:00
|
|
|
MP_STATE_THREAD(stop_iteration_arg) = o;
|
|
|
|
return MP_OBJ_STOP_ITERATION;
|
|
|
|
}
|
|
|
|
|
2014-03-30 08:35:08 -04:00
|
|
|
mp_obj_t mp_make_raise_obj(mp_obj_t o);
|
|
|
|
|
|
|
|
mp_obj_t mp_import_name(qstr name, mp_obj_t fromlist, mp_obj_t level);
|
|
|
|
mp_obj_t mp_import_from(mp_obj_t module, qstr name);
|
|
|
|
void mp_import_all(mp_obj_t module);
|
2014-04-12 23:43:18 -04:00
|
|
|
|
2021-04-21 22:13:58 -04:00
|
|
|
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_NONE
|
|
|
|
NORETURN void mp_raise_type(const mp_obj_type_t *exc_type);
|
|
|
|
NORETURN void mp_raise_ValueError_no_msg(void);
|
|
|
|
NORETURN void mp_raise_TypeError_no_msg(void);
|
|
|
|
NORETURN void mp_raise_NotImplementedError_no_msg(void);
|
|
|
|
#define mp_raise_msg(exc_type, msg) mp_raise_type(exc_type)
|
|
|
|
#define mp_raise_msg_varg(exc_type, ...) mp_raise_type(exc_type)
|
|
|
|
#define mp_raise_ValueError(msg) mp_raise_ValueError_no_msg()
|
|
|
|
#define mp_raise_TypeError(msg) mp_raise_TypeError_no_msg()
|
|
|
|
#define mp_raise_NotImplementedError(msg) mp_raise_NotImplementedError_no_msg()
|
|
|
|
#else
|
2020-02-10 21:17:41 -05:00
|
|
|
#define mp_raise_type(exc_type) mp_raise_msg(exc_type, NULL)
|
2021-07-14 08:56:52 -04:00
|
|
|
NORETURN void mp_raise_type_arg(const mp_obj_type_t *exc_type, mp_obj_t arg);
|
2018-08-15 21:32:37 -04:00
|
|
|
NORETURN void mp_raise_msg(const mp_obj_type_t *exc_type, const compressed_string_t *msg);
|
|
|
|
NORETURN void mp_raise_msg_varg(const mp_obj_type_t *exc_type, const compressed_string_t *fmt, ...);
|
2020-08-01 14:05:30 -04:00
|
|
|
NORETURN void mp_raise_msg_vlist(const mp_obj_type_t *exc_type, const compressed_string_t *fmt, va_list argptr);
|
2021-04-23 15:26:42 -04:00
|
|
|
// Only use this string version in native mpy files. Otherwise, use the compressed string version.
|
|
|
|
NORETURN void mp_raise_msg_str(const mp_obj_type_t *exc_type, const char *msg);
|
2018-08-15 21:32:37 -04:00
|
|
|
NORETURN void mp_raise_ValueError(const compressed_string_t *msg);
|
|
|
|
NORETURN void mp_raise_ValueError_varg(const compressed_string_t *fmt, ...);
|
|
|
|
NORETURN void mp_raise_TypeError(const compressed_string_t *msg);
|
|
|
|
NORETURN void mp_raise_TypeError_varg(const compressed_string_t *fmt, ...);
|
|
|
|
NORETURN void mp_raise_AttributeError(const compressed_string_t *msg);
|
|
|
|
NORETURN void mp_raise_RuntimeError(const compressed_string_t *msg);
|
2023-07-20 19:00:43 -04:00
|
|
|
NORETURN void mp_raise_RuntimeError_varg(const compressed_string_t *fmt, ...);
|
2018-08-15 21:32:37 -04:00
|
|
|
NORETURN void mp_raise_ImportError(const compressed_string_t *msg);
|
|
|
|
NORETURN void mp_raise_IndexError(const compressed_string_t *msg);
|
2020-08-01 13:14:55 -04:00
|
|
|
NORETURN void mp_raise_IndexError_varg(const compressed_string_t *msg, ...);
|
2021-06-29 03:34:34 -04:00
|
|
|
NORETURN void mp_raise_StopIteration(mp_obj_t arg);
|
2016-10-06 22:31:59 -04:00
|
|
|
NORETURN void mp_raise_OSError(int errno_);
|
2020-02-04 16:19:40 -05:00
|
|
|
NORETURN void mp_raise_OSError_errno_str(int errno_, mp_obj_t str);
|
2018-11-20 23:04:58 -05:00
|
|
|
NORETURN void mp_raise_OSError_msg(const compressed_string_t *msg);
|
2018-12-27 00:04:04 -05:00
|
|
|
NORETURN void mp_raise_OSError_msg_varg(const compressed_string_t *fmt, ...);
|
2020-08-21 14:00:02 -04:00
|
|
|
NORETURN void mp_raise_ConnectionError(const compressed_string_t *msg);
|
2020-08-18 20:06:59 -04:00
|
|
|
NORETURN void mp_raise_BrokenPipeError(void);
|
2018-08-15 21:32:37 -04:00
|
|
|
NORETURN void mp_raise_NotImplementedError(const compressed_string_t *msg);
|
2019-04-09 14:36:10 -04:00
|
|
|
NORETURN void mp_raise_NotImplementedError_varg(const compressed_string_t *fmt, ...);
|
2019-05-09 03:20:15 -04:00
|
|
|
NORETURN void mp_raise_OverflowError_varg(const compressed_string_t *fmt, ...);
|
2017-11-20 01:29:58 -05:00
|
|
|
NORETURN void mp_raise_recursion_depth(void);
|
2022-11-08 16:24:49 -05:00
|
|
|
NORETURN void mp_raise_ZeroDivisionError(void);
|
2021-06-18 11:54:19 -04:00
|
|
|
#endif
|
2014-06-07 16:22:41 -04:00
|
|
|
|
2016-08-12 14:58:56 -04:00
|
|
|
#if MICROPY_BUILTIN_METHOD_CHECK_SELF_ARG
|
|
|
|
#undef mp_check_self
|
|
|
|
#define mp_check_self(pred)
|
|
|
|
#else
|
|
|
|
// A port may define to raise TypeError for example
|
|
|
|
#ifndef mp_check_self
|
|
|
|
#define mp_check_self(pred) assert(pred)
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2014-08-16 17:06:11 -04:00
|
|
|
// helper functions for native/viper code
|
2021-04-22 20:55:39 -04:00
|
|
|
int mp_native_type_from_qstr(qstr qst);
|
|
|
|
mp_uint_t mp_native_from_obj(mp_obj_t obj, mp_uint_t type);
|
|
|
|
mp_obj_t mp_native_to_obj(mp_uint_t val, mp_uint_t type);
|
2014-08-15 18:47:59 -04:00
|
|
|
|
2015-11-27 12:01:44 -05:00
|
|
|
#define mp_sys_path (MP_OBJ_FROM_PTR(&MP_STATE_VM(mp_sys_path_obj)))
|
|
|
|
#define mp_sys_argv (MP_OBJ_FROM_PTR(&MP_STATE_VM(mp_sys_argv_obj)))
|
2014-12-28 20:02:19 -05:00
|
|
|
|
2015-01-01 02:29:28 -05:00
|
|
|
#if MICROPY_WARNINGS
|
2021-04-22 20:55:39 -04:00
|
|
|
#ifndef mp_warning
|
|
|
|
void mp_warning(const char *category, const char *msg, ...);
|
|
|
|
#endif
|
2015-01-01 02:29:28 -05:00
|
|
|
#else
|
2017-09-13 06:33:55 -04:00
|
|
|
#define mp_warning(...)
|
2015-01-01 02:29:28 -05:00
|
|
|
#endif
|
|
|
|
|
all: Unify header guard usage.
The code conventions suggest using header guards, but do not define how
those should look like and instead point to existing files. However, not
all existing files follow the same scheme, sometimes omitting header guards
altogether, sometimes using non-standard names, making it easy to
accidentally pick a "wrong" example.
This commit ensures that all header files of the MicroPython project (that
were not simply copied from somewhere else) follow the same pattern, that
was already present in the majority of files, especially in the py folder.
The rules are as follows.
Naming convention:
* start with the words MICROPY_INCLUDED
* contain the full path to the file
* replace special characters with _
In addition, there are no empty lines before #ifndef, between #ifndef and
one empty line before #endif. #endif is followed by a comment containing
the name of the guard macro.
py/grammar.h cannot use header guards by design, since it has to be
included multiple times in a single C file. Several other files also do not
need header guards as they are only used internally and guaranteed to be
included only once:
* MICROPY_MPHALPORT_H
* mpconfigboard.h
* mpconfigport.h
* mpthreadport.h
* pin_defs_*.h
* qstrdefs*.h
2017-06-29 17:14:58 -04:00
|
|
|
#endif // MICROPY_INCLUDED_PY_RUNTIME_H
|