2014-05-03 23:27:38 +01:00
|
|
|
/*
|
2017-06-30 08:22:17 +01:00
|
|
|
* This file is part of the MicroPython project, http://micropython.org/
|
2014-05-03 23:27:38 +01:00
|
|
|
*
|
|
|
|
* The MIT License (MIT)
|
|
|
|
*
|
|
|
|
* Copyright (c) 2013, 2014 Damien P. George
|
|
|
|
*
|
|
|
|
* 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 22:14:58 +01:00
|
|
|
#ifndef MICROPY_INCLUDED_PY_RUNTIME_H
|
|
|
|
#define MICROPY_INCLUDED_PY_RUNTIME_H
|
2014-12-29 01:02:19 +00:00
|
|
|
|
2015-01-01 23:30:53 +00: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 12:28:40 +00:00
|
|
|
#include "py/pystack.h"
|
2014-05-03 23:27:38 +01:00
|
|
|
|
2023-09-05 09:12:26 +01:00
|
|
|
// For use with mp_call_function_1_from_nlr_jump_callback.
|
|
|
|
#define MP_DEFINE_NLR_JUMP_CALLBACK_FUNCTION_1(ctx, f, a) \
|
|
|
|
nlr_jump_callback_node_call_function_1_t ctx = { \
|
|
|
|
.func = (void (*)(void *))(f), \
|
|
|
|
.arg = (a), \
|
|
|
|
}
|
|
|
|
|
2014-03-30 21:14:55 +01:00
|
|
|
typedef enum {
|
|
|
|
MP_VM_RETURN_NORMAL,
|
|
|
|
MP_VM_RETURN_YIELD,
|
|
|
|
MP_VM_RETURN_EXCEPTION,
|
|
|
|
} mp_vm_return_kind_t;
|
|
|
|
|
2014-04-20 00:13:22 +01:00
|
|
|
typedef enum {
|
2014-04-26 11:19:17 +01: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-20 00:13:22 +01:00
|
|
|
bool u_bool;
|
2014-07-03 13:25:24 +01:00
|
|
|
mp_int_t u_int;
|
2014-04-20 00:13:22 +01:00
|
|
|
mp_obj_t u_obj;
|
2015-11-27 13:38:15 +00:00
|
|
|
mp_rom_obj_t u_rom_obj;
|
2014-04-26 11:19:17 +01:00
|
|
|
} mp_arg_val_t;
|
2014-04-20 00:13:22 +01:00
|
|
|
|
2014-04-26 11:19:17 +01:00
|
|
|
typedef struct _mp_arg_t {
|
2016-09-23 03:13:51 +01:00
|
|
|
uint16_t qst;
|
|
|
|
uint16_t flags;
|
2014-04-26 11:19:17 +01:00
|
|
|
mp_arg_val_t defval;
|
|
|
|
} mp_arg_t;
|
2014-04-20 00:13:22 +01:00
|
|
|
|
2022-03-23 06:13:03 +00:00
|
|
|
struct _mp_sched_node_t;
|
|
|
|
|
|
|
|
typedef void (*mp_sched_callback_t)(struct _mp_sched_node_t *);
|
|
|
|
|
|
|
|
typedef struct _mp_sched_node_t {
|
|
|
|
mp_sched_callback_t callback;
|
|
|
|
struct _mp_sched_node_t *next;
|
|
|
|
} mp_sched_node_t;
|
|
|
|
|
2023-05-09 02:03:17 +01:00
|
|
|
// For use with mp_globals_locals_set_from_nlr_jump_callback.
|
|
|
|
typedef struct _nlr_jump_callback_node_globals_locals_t {
|
|
|
|
nlr_jump_callback_node_t callback;
|
|
|
|
mp_obj_dict_t *globals;
|
|
|
|
mp_obj_dict_t *locals;
|
|
|
|
} nlr_jump_callback_node_globals_locals_t;
|
|
|
|
|
2023-09-05 09:12:26 +01:00
|
|
|
// For use with mp_call_function_1_from_nlr_jump_callback.
|
|
|
|
typedef struct _nlr_jump_callback_node_call_function_1_t {
|
|
|
|
nlr_jump_callback_node_t callback;
|
|
|
|
void (*func)(void *);
|
|
|
|
void *arg;
|
|
|
|
} nlr_jump_callback_node_call_function_1_t;
|
|
|
|
|
2017-10-04 01:31:05 +01:00
|
|
|
// Tables mapping operator enums to qstrs, defined in objtype.c
|
2017-10-21 09:06:32 +01:00
|
|
|
extern const byte mp_unary_op_method_name[];
|
|
|
|
extern const byte mp_binary_op_method_name[];
|
2015-01-27 18:02:25 +00:00
|
|
|
|
2014-03-30 13:35:08 +01:00
|
|
|
void mp_init(void);
|
|
|
|
void mp_deinit(void);
|
|
|
|
|
2021-04-28 01:52:19 +01:00
|
|
|
void mp_sched_exception(mp_obj_t exc);
|
2021-04-28 01:57:34 +01:00
|
|
|
void mp_sched_keyboard_interrupt(void);
|
2022-12-16 06:31:21 +00:00
|
|
|
#if MICROPY_ENABLE_VM_ABORT
|
|
|
|
void mp_sched_vm_abort(void);
|
|
|
|
#endif
|
2020-02-05 14:05:47 +00:00
|
|
|
void mp_handle_pending(bool raise_exc);
|
2017-02-16 07:05:06 +00:00
|
|
|
|
|
|
|
#if MICROPY_ENABLE_SCHEDULER
|
|
|
|
void mp_sched_lock(void);
|
|
|
|
void mp_sched_unlock(void);
|
2020-05-02 08:49:15 +01:00
|
|
|
#define mp_sched_num_pending() (MP_STATE_VM(sched_len))
|
2017-02-16 07:05:06 +00:00
|
|
|
bool mp_sched_schedule(mp_obj_t function, mp_obj_t arg);
|
2022-03-23 06:13:03 +00:00
|
|
|
bool mp_sched_schedule_node(mp_sched_node_t *node, mp_sched_callback_t callback);
|
2017-02-16 07:05:06 +00:00
|
|
|
#endif
|
|
|
|
|
2023-11-30 05:06:32 +00:00
|
|
|
// Handles any pending MicroPython events without waiting for an interrupt or event.
|
|
|
|
void mp_event_handle_nowait(void);
|
|
|
|
|
|
|
|
// Handles any pending MicroPython events and then suspends execution until the
|
|
|
|
// next interrupt or event.
|
|
|
|
//
|
|
|
|
// Note: on "tickless" ports this can suspend execution for a long time,
|
|
|
|
// don't call unless you know an interrupt is coming to continue execution.
|
|
|
|
// On "ticked" ports it may return early due to the tick interrupt.
|
|
|
|
void mp_event_wait_indefinite(void);
|
|
|
|
|
|
|
|
// Handle any pending MicroPython events and then suspends execution until the
|
|
|
|
// next interrupt or event, or until timeout_ms milliseconds have elapsed.
|
|
|
|
//
|
|
|
|
// On "ticked" ports it may return early due to the tick interrupt.
|
|
|
|
void mp_event_wait_ms(mp_uint_t timeout_ms);
|
|
|
|
|
2015-04-09 23:56:15 +01: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-14 04:39:17 +01:00
|
|
|
void mp_arg_check_num_sig(size_t n_args, size_t n_kw, uint32_t sig);
|
|
|
|
static 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 05:03:05 +00: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-14 04:39:17 +01:00
|
|
|
}
|
2016-03-14 22:35:48 +00: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);
|
2015-01-01 15:33:50 +00:00
|
|
|
NORETURN void mp_arg_error_terse_mismatch(void);
|
2014-05-06 17:52:35 +01:00
|
|
|
NORETURN void mp_arg_error_unimpl_kw(void);
|
2014-03-30 13:35:08 +01:00
|
|
|
|
2017-03-24 07:43:28 +00:00
|
|
|
static inline mp_obj_dict_t *mp_locals_get(void) {
|
|
|
|
return MP_STATE_THREAD(dict_locals);
|
|
|
|
}
|
|
|
|
static inline void mp_locals_set(mp_obj_dict_t *d) {
|
|
|
|
MP_STATE_THREAD(dict_locals) = d;
|
|
|
|
}
|
|
|
|
static inline mp_obj_dict_t *mp_globals_get(void) {
|
|
|
|
return MP_STATE_THREAD(dict_globals);
|
|
|
|
}
|
|
|
|
static inline void mp_globals_set(mp_obj_dict_t *d) {
|
|
|
|
MP_STATE_THREAD(dict_globals) = d;
|
|
|
|
}
|
2014-03-30 13:35:08 +01:00
|
|
|
|
2023-05-09 02:03:17 +01:00
|
|
|
void mp_globals_locals_set_from_nlr_jump_callback(void *ctx_in);
|
2023-09-05 09:12:26 +01:00
|
|
|
void mp_call_function_1_from_nlr_jump_callback(void *ctx_in);
|
2023-05-09 02:03:17 +01:00
|
|
|
|
2015-01-20 11:55:10 +00:00
|
|
|
mp_obj_t mp_load_name(qstr qst);
|
|
|
|
mp_obj_t mp_load_global(qstr qst);
|
2014-03-30 13:35:08 +01:00
|
|
|
mp_obj_t mp_load_build_class(void);
|
2015-01-20 11:55:10 +00: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 13:35:08 +01:00
|
|
|
|
2017-08-29 04:04:01 +01: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 13:35:08 +01: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-16 04:32:34 +00: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 22:33:55 +00: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 17:28:12 +01:00
|
|
|
// Call function and catch/dump exception - for Python callbacks from C code
|
2017-12-04 22:38:41 +00: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 13:35:08 +01:00
|
|
|
|
2015-04-01 23:31:30 +01:00
|
|
|
typedef struct _mp_call_args_t {
|
2015-03-27 23:14:45 +00:00
|
|
|
mp_obj_t fun;
|
2017-02-16 04:32:34 +00:00
|
|
|
size_t n_args, n_kw, n_alloc;
|
2015-03-27 23:14:45 +00:00
|
|
|
mp_obj_t *args;
|
2015-04-01 23:31:30 +01:00
|
|
|
} mp_call_args_t;
|
2015-03-27 23:14:45 +00:00
|
|
|
|
2015-04-01 23:31:30 +01:00
|
|
|
#if MICROPY_STACKLESS
|
2015-03-27 23:14:45 +00: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 23:31:30 +01:00
|
|
|
// (Only needed in stackless mode.)
|
2017-02-16 04:32:34 +00: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 23:31:30 +01:00
|
|
|
#endif
|
2015-03-27 23:14:45 +00:00
|
|
|
|
2017-02-16 04:32:34 +00: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 13:35:08 +01: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 14:21:54 +00: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 13:35:08 +01:00
|
|
|
void mp_load_method(mp_obj_t base, qstr attr, mp_obj_t *dest);
|
2014-03-31 22:57:56 +01:00
|
|
|
void mp_load_method_maybe(mp_obj_t base, qstr attr, mp_obj_t *dest);
|
2018-05-10 14:00:04 +01:00
|
|
|
void mp_load_method_protected(mp_obj_t obj, qstr attr, mp_obj_t *dest, bool catch_all_exc);
|
2017-04-19 00:45:59 +01:00
|
|
|
void mp_load_super_method(qstr attr, mp_obj_t *dest);
|
2014-03-30 13:35:08 +01:00
|
|
|
void mp_store_attr(mp_obj_t base, qstr attr, mp_obj_t val);
|
|
|
|
|
2016-01-09 23:14:54 +00:00
|
|
|
mp_obj_t mp_getiter(mp_obj_t o, mp_obj_iter_buf_t *iter_buf);
|
2014-04-17 23:19:36 +01: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 21:14:55 +01: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 13:35:08 +01:00
|
|
|
|
2021-06-29 08:34:34 +01:00
|
|
|
static inline mp_obj_t mp_make_stop_iteration(mp_obj_t o) {
|
|
|
|
MP_STATE_THREAD(stop_iteration_arg) = o;
|
|
|
|
return MP_OBJ_STOP_ITERATION;
|
|
|
|
}
|
|
|
|
|
2014-03-30 13:35:08 +01: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-13 04:43:18 +01:00
|
|
|
|
2021-04-22 03:13:58 +01: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-11 02:17:41 +00:00
|
|
|
#define mp_raise_type(exc_type) mp_raise_msg(exc_type, NULL)
|
2020-01-29 03:27:33 +00:00
|
|
|
NORETURN void mp_raise_msg(const mp_obj_type_t *exc_type, mp_rom_error_text_t msg);
|
|
|
|
NORETURN void mp_raise_msg_varg(const mp_obj_type_t *exc_type, mp_rom_error_text_t fmt, ...);
|
|
|
|
NORETURN void mp_raise_ValueError(mp_rom_error_text_t msg);
|
|
|
|
NORETURN void mp_raise_TypeError(mp_rom_error_text_t msg);
|
|
|
|
NORETURN void mp_raise_NotImplementedError(mp_rom_error_text_t msg);
|
2021-04-22 03:13:58 +01:00
|
|
|
#endif
|
|
|
|
|
2021-07-14 13:56:52 +01:00
|
|
|
NORETURN void mp_raise_type_arg(const mp_obj_type_t *exc_type, mp_obj_t arg);
|
2021-06-29 08:34:34 +01:00
|
|
|
NORETURN void mp_raise_StopIteration(mp_obj_t arg);
|
2023-05-25 01:57:08 +01:00
|
|
|
NORETURN void mp_raise_TypeError_int_conversion(mp_const_obj_t arg);
|
2016-10-07 03:31:59 +01:00
|
|
|
NORETURN void mp_raise_OSError(int errno_);
|
2022-09-19 01:35:12 +01:00
|
|
|
NORETURN void mp_raise_OSError_with_filename(int errno_, const char *filename);
|
2017-11-20 06:29:58 +00:00
|
|
|
NORETURN void mp_raise_recursion_depth(void);
|
2014-06-07 21:22:41 +01:00
|
|
|
|
2016-08-12 19:58:56 +01: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 22:06:11 +01:00
|
|
|
// helper functions for native/viper code
|
2019-03-08 23:16:09 +00:00
|
|
|
int mp_native_type_from_qstr(qstr qst);
|
2019-03-08 23:22:09 +00:00
|
|
|
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 23:47:59 +01:00
|
|
|
|
2023-06-05 07:52:29 +01:00
|
|
|
#if MICROPY_PY_SYS_PATH
|
|
|
|
#define mp_sys_path (MP_STATE_VM(sys_mutable[MP_SYS_MUTABLE_PATH]))
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if MICROPY_PY_SYS_ARGV
|
2015-11-27 17:01:44 +00:00
|
|
|
#define mp_sys_argv (MP_OBJ_FROM_PTR(&MP_STATE_VM(mp_sys_argv_obj)))
|
2023-06-05 07:52:29 +01:00
|
|
|
#endif
|
2014-12-29 01:02:19 +00:00
|
|
|
|
2015-01-01 07:29:28 +00:00
|
|
|
#if MICROPY_WARNINGS
|
2018-12-21 11:20:55 +00:00
|
|
|
#ifndef mp_warning
|
|
|
|
void mp_warning(const char *category, const char *msg, ...);
|
|
|
|
#endif
|
2015-01-01 07:29:28 +00:00
|
|
|
#else
|
2017-09-13 11:33:55 +01:00
|
|
|
#define mp_warning(...)
|
2015-01-01 07:29:28 +00: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 22:14:58 +01:00
|
|
|
#endif // MICROPY_INCLUDED_PY_RUNTIME_H
|