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)
|
|
|
|
*
|
|
|
|
* 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 17:14:58 -04:00
|
|
|
#ifndef MICROPY_INCLUDED_PY_BUILTIN_H
|
|
|
|
#define MICROPY_INCLUDED_PY_BUILTIN_H
|
2015-01-01 15:27:54 -05:00
|
|
|
|
|
|
|
#include "py/obj.h"
|
2014-05-03 18:27:38 -04:00
|
|
|
|
2022-05-24 22:04:27 -04:00
|
|
|
typedef enum {
|
|
|
|
MP_IMPORT_STAT_NO_EXIST,
|
|
|
|
MP_IMPORT_STAT_DIR,
|
|
|
|
MP_IMPORT_STAT_FILE,
|
|
|
|
} mp_import_stat_t;
|
|
|
|
|
|
|
|
#if MICROPY_VFS
|
|
|
|
|
|
|
|
// Delegate to the VFS for import stat and builtin open.
|
|
|
|
|
|
|
|
#define mp_builtin_open_obj mp_vfs_open_obj
|
|
|
|
|
|
|
|
mp_import_stat_t mp_vfs_import_stat(const char *path);
|
|
|
|
mp_obj_t mp_vfs_open(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs);
|
|
|
|
|
|
|
|
MP_DECLARE_CONST_FUN_OBJ_KW(mp_vfs_open_obj);
|
|
|
|
|
|
|
|
static inline mp_import_stat_t mp_import_stat(const char *path) {
|
|
|
|
return mp_vfs_import_stat(path);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline mp_obj_t mp_builtin_open(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs) {
|
|
|
|
return mp_vfs_open(n_args, args, kwargs);
|
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
// A port can provide implementations of these functions.
|
|
|
|
mp_import_stat_t mp_import_stat(const char *path);
|
2016-01-03 09:21:40 -05:00
|
|
|
mp_obj_t mp_builtin_open(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs);
|
2022-05-24 22:04:27 -04:00
|
|
|
|
|
|
|
// A port can provide this object.
|
|
|
|
MP_DECLARE_CONST_FUN_OBJ_KW(mp_builtin_open_obj);
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2022-08-19 10:40:28 -04:00
|
|
|
// A port can provide its own import handler by defining mp_builtin___import__.
|
|
|
|
#ifndef mp_builtin___import__
|
|
|
|
#define mp_builtin___import__ mp_builtin___import___default
|
|
|
|
#endif
|
2022-05-24 22:04:27 -04:00
|
|
|
mp_obj_t mp_builtin___import__(size_t n_args, const mp_obj_t *args);
|
2022-08-19 10:40:28 -04:00
|
|
|
mp_obj_t mp_builtin___import___default(size_t n_args, const mp_obj_t *args);
|
|
|
|
|
2016-01-03 09:21:40 -05:00
|
|
|
mp_obj_t mp_micropython_mem_info(size_t n_args, const mp_obj_t *args);
|
2013-12-21 13:17:45 -05:00
|
|
|
|
2016-10-17 20:06:20 -04:00
|
|
|
MP_DECLARE_CONST_FUN_OBJ_VAR(mp_builtin___build_class___obj);
|
|
|
|
MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(mp_builtin___import___obj);
|
|
|
|
MP_DECLARE_CONST_FUN_OBJ_1(mp_builtin___repl_print___obj);
|
|
|
|
MP_DECLARE_CONST_FUN_OBJ_1(mp_builtin_abs_obj);
|
|
|
|
MP_DECLARE_CONST_FUN_OBJ_1(mp_builtin_all_obj);
|
|
|
|
MP_DECLARE_CONST_FUN_OBJ_1(mp_builtin_any_obj);
|
|
|
|
MP_DECLARE_CONST_FUN_OBJ_1(mp_builtin_bin_obj);
|
|
|
|
MP_DECLARE_CONST_FUN_OBJ_1(mp_builtin_callable_obj);
|
|
|
|
MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(mp_builtin_compile_obj);
|
|
|
|
MP_DECLARE_CONST_FUN_OBJ_1(mp_builtin_chr_obj);
|
2016-10-23 22:50:03 -04:00
|
|
|
MP_DECLARE_CONST_FUN_OBJ_2(mp_builtin_delattr_obj);
|
2016-10-17 20:06:20 -04:00
|
|
|
MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(mp_builtin_dir_obj);
|
|
|
|
MP_DECLARE_CONST_FUN_OBJ_2(mp_builtin_divmod_obj);
|
|
|
|
MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(mp_builtin_eval_obj);
|
|
|
|
MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(mp_builtin_exec_obj);
|
|
|
|
MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(mp_builtin_execfile_obj);
|
|
|
|
MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(mp_builtin_getattr_obj);
|
|
|
|
MP_DECLARE_CONST_FUN_OBJ_3(mp_builtin_setattr_obj);
|
|
|
|
MP_DECLARE_CONST_FUN_OBJ_0(mp_builtin_globals_obj);
|
|
|
|
MP_DECLARE_CONST_FUN_OBJ_2(mp_builtin_hasattr_obj);
|
|
|
|
MP_DECLARE_CONST_FUN_OBJ_1(mp_builtin_hash_obj);
|
2017-01-21 07:17:51 -05:00
|
|
|
MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(mp_builtin_help_obj);
|
2016-10-17 20:06:20 -04:00
|
|
|
MP_DECLARE_CONST_FUN_OBJ_1(mp_builtin_hex_obj);
|
|
|
|
MP_DECLARE_CONST_FUN_OBJ_1(mp_builtin_id_obj);
|
|
|
|
MP_DECLARE_CONST_FUN_OBJ_2(mp_builtin_isinstance_obj);
|
|
|
|
MP_DECLARE_CONST_FUN_OBJ_2(mp_builtin_issubclass_obj);
|
|
|
|
MP_DECLARE_CONST_FUN_OBJ_1(mp_builtin_iter_obj);
|
|
|
|
MP_DECLARE_CONST_FUN_OBJ_1(mp_builtin_len_obj);
|
|
|
|
MP_DECLARE_CONST_FUN_OBJ_0(mp_builtin_locals_obj);
|
|
|
|
MP_DECLARE_CONST_FUN_OBJ_KW(mp_builtin_max_obj);
|
|
|
|
MP_DECLARE_CONST_FUN_OBJ_KW(mp_builtin_min_obj);
|
2019-01-03 09:19:42 -05:00
|
|
|
#if MICROPY_PY_BUILTINS_NEXT2
|
|
|
|
MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(mp_builtin_next_obj);
|
|
|
|
#else
|
2016-10-17 20:06:20 -04:00
|
|
|
MP_DECLARE_CONST_FUN_OBJ_1(mp_builtin_next_obj);
|
2019-01-03 09:19:42 -05:00
|
|
|
#endif
|
2016-10-17 20:06:20 -04:00
|
|
|
MP_DECLARE_CONST_FUN_OBJ_1(mp_builtin_oct_obj);
|
|
|
|
MP_DECLARE_CONST_FUN_OBJ_1(mp_builtin_ord_obj);
|
|
|
|
MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(mp_builtin_pow_obj);
|
|
|
|
MP_DECLARE_CONST_FUN_OBJ_KW(mp_builtin_print_obj);
|
|
|
|
MP_DECLARE_CONST_FUN_OBJ_1(mp_builtin_repr_obj);
|
|
|
|
MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(mp_builtin_round_obj);
|
|
|
|
MP_DECLARE_CONST_FUN_OBJ_KW(mp_builtin_sorted_obj);
|
|
|
|
MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(mp_builtin_sum_obj);
|
|
|
|
MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(mp_builtin_input_obj);
|
2014-01-19 18:53:15 -05:00
|
|
|
|
2016-10-17 20:06:20 -04:00
|
|
|
MP_DECLARE_CONST_FUN_OBJ_2(mp_namedtuple_obj);
|
2014-02-27 15:22:04 -05:00
|
|
|
|
2016-10-17 20:06:20 -04:00
|
|
|
MP_DECLARE_CONST_FUN_OBJ_2(mp_op_contains_obj);
|
|
|
|
MP_DECLARE_CONST_FUN_OBJ_2(mp_op_getitem_obj);
|
|
|
|
MP_DECLARE_CONST_FUN_OBJ_3(mp_op_setitem_obj);
|
|
|
|
MP_DECLARE_CONST_FUN_OBJ_2(mp_op_delitem_obj);
|
2014-04-13 04:53:15 -04:00
|
|
|
|
2022-06-26 20:37:28 -04:00
|
|
|
// Modules needed by the runtime.
|
|
|
|
extern const mp_obj_dict_t mp_module_builtins_globals;
|
2014-04-04 13:08:21 -04:00
|
|
|
extern const mp_obj_module_t mp_module___main__;
|
2014-12-09 11:19:48 -05:00
|
|
|
extern const mp_obj_module_t mp_module_builtins;
|
2014-04-12 23:43:18 -04:00
|
|
|
extern const mp_obj_module_t mp_module_sys;
|
2014-12-09 11:19:48 -05:00
|
|
|
|
2022-06-26 20:37:28 -04:00
|
|
|
// Modules needed by the parser when MICROPY_COMP_MODULE_CONST is enabled.
|
2016-05-10 05:54:25 -04:00
|
|
|
extern const mp_obj_module_t mp_module_uerrno;
|
2014-06-27 20:03:47 -04:00
|
|
|
extern const mp_obj_module_t mp_module_uctypes;
|
2015-05-03 13:25:40 -04:00
|
|
|
extern const mp_obj_module_t mp_module_machine;
|
2015-01-01 15:27:54 -05:00
|
|
|
|
2017-09-12 02:03:52 -04:00
|
|
|
extern const char MICROPY_PY_BUILTINS_HELP_TEXT[];
|
2017-01-21 07:17:51 -05:00
|
|
|
|
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_BUILTIN_H
|