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_RUNTIME0_H
|
|
|
|
#define MICROPY_INCLUDED_PY_RUNTIME0_H
|
2014-05-03 18:27:38 -04:00
|
|
|
|
2016-11-03 18:50:59 -04:00
|
|
|
#include "mpconfig.h"
|
|
|
|
|
2014-04-09 07:27:39 -04:00
|
|
|
// These must fit in 8 bits; see scope.h
|
2015-08-17 17:39:03 -04:00
|
|
|
#define MP_SCOPE_FLAG_VARARGS (0x01)
|
|
|
|
#define MP_SCOPE_FLAG_VARKEYWORDS (0x02)
|
|
|
|
#define MP_SCOPE_FLAG_GENERATOR (0x04)
|
2015-10-22 18:45:37 -04:00
|
|
|
#define MP_SCOPE_FLAG_DEFKWARGS (0x08)
|
2020-07-21 03:01:22 -04:00
|
|
|
#define MP_SCOPE_FLAG_ASYNC (0x10)
|
2014-02-15 14:33:11 -05:00
|
|
|
|
2014-08-15 11:45:41 -04:00
|
|
|
// types for native (viper) function signature
|
|
|
|
#define MP_NATIVE_TYPE_OBJ (0x00)
|
|
|
|
#define MP_NATIVE_TYPE_BOOL (0x01)
|
|
|
|
#define MP_NATIVE_TYPE_INT (0x02)
|
|
|
|
#define MP_NATIVE_TYPE_UINT (0x03)
|
2016-02-02 18:16:05 -05:00
|
|
|
#define MP_NATIVE_TYPE_PTR (0x04)
|
|
|
|
#define MP_NATIVE_TYPE_PTR8 (0x05)
|
|
|
|
#define MP_NATIVE_TYPE_PTR16 (0x06)
|
|
|
|
#define MP_NATIVE_TYPE_PTR32 (0x07)
|
2014-08-15 11:45:41 -04:00
|
|
|
|
2013-12-21 13:17:45 -05:00
|
|
|
typedef enum {
|
2017-09-25 19:35:19 -04:00
|
|
|
// These ops may appear in the bytecode. Changing this group
|
|
|
|
// in any way requires changing the bytecode version.
|
2014-03-30 08:35:08 -04:00
|
|
|
MP_UNARY_OP_POSITIVE,
|
|
|
|
MP_UNARY_OP_NEGATIVE,
|
|
|
|
MP_UNARY_OP_INVERT,
|
|
|
|
MP_UNARY_OP_NOT,
|
2017-09-25 19:35:19 -04:00
|
|
|
|
|
|
|
// Following ops cannot appear in the bytecode
|
2017-10-03 08:34:28 -04:00
|
|
|
MP_UNARY_OP_NUM_BYTECODE,
|
2017-09-25 19:35:19 -04:00
|
|
|
|
2017-10-03 08:34:28 -04:00
|
|
|
MP_UNARY_OP_BOOL = MP_UNARY_OP_NUM_BYTECODE, // __bool__
|
2017-09-25 19:35:19 -04:00
|
|
|
MP_UNARY_OP_LEN, // __len__
|
|
|
|
MP_UNARY_OP_HASH, // __hash__; must return a small int
|
2017-09-17 17:06:43 -04:00
|
|
|
MP_UNARY_OP_ABS, // __abs__
|
2017-08-11 02:42:39 -04:00
|
|
|
MP_UNARY_OP_SIZEOF, // for sys.getsizeof()
|
2017-10-03 08:34:28 -04:00
|
|
|
|
|
|
|
MP_UNARY_OP_NUM_RUNTIME,
|
2014-03-30 08:35:08 -04:00
|
|
|
} mp_unary_op_t;
|
2013-12-21 13:17:45 -05:00
|
|
|
|
2017-10-03 08:34:28 -04:00
|
|
|
// Note: the first 9+12+12 of these are used in bytecode and changing
|
2017-09-21 21:54:08 -04:00
|
|
|
// them requires changing the bytecode version.
|
2013-12-21 13:17:45 -05:00
|
|
|
typedef enum {
|
2017-10-03 08:34:28 -04:00
|
|
|
// 9 relational operations, should return a bool
|
2017-09-07 03:55:43 -04:00
|
|
|
MP_BINARY_OP_LESS,
|
|
|
|
MP_BINARY_OP_MORE,
|
|
|
|
MP_BINARY_OP_EQUAL,
|
|
|
|
MP_BINARY_OP_LESS_EQUAL,
|
|
|
|
MP_BINARY_OP_MORE_EQUAL,
|
|
|
|
MP_BINARY_OP_NOT_EQUAL,
|
|
|
|
MP_BINARY_OP_IN,
|
|
|
|
MP_BINARY_OP_IS,
|
|
|
|
MP_BINARY_OP_EXCEPTION_MATCH,
|
2014-05-09 21:24:22 -04:00
|
|
|
|
2017-10-03 08:34:28 -04:00
|
|
|
// 12 inplace arithmetic operations
|
2014-03-30 08:35:08 -04:00
|
|
|
MP_BINARY_OP_INPLACE_OR,
|
|
|
|
MP_BINARY_OP_INPLACE_XOR,
|
2015-06-13 17:00:10 -04:00
|
|
|
MP_BINARY_OP_INPLACE_AND,
|
2014-03-30 08:35:08 -04:00
|
|
|
MP_BINARY_OP_INPLACE_LSHIFT,
|
|
|
|
MP_BINARY_OP_INPLACE_RSHIFT,
|
|
|
|
MP_BINARY_OP_INPLACE_ADD,
|
2017-09-07 06:37:33 -04:00
|
|
|
MP_BINARY_OP_INPLACE_SUBTRACT,
|
2015-06-13 17:00:10 -04:00
|
|
|
MP_BINARY_OP_INPLACE_MULTIPLY,
|
2014-03-30 08:35:08 -04:00
|
|
|
MP_BINARY_OP_INPLACE_FLOOR_DIVIDE,
|
|
|
|
MP_BINARY_OP_INPLACE_TRUE_DIVIDE,
|
|
|
|
MP_BINARY_OP_INPLACE_MODULO,
|
|
|
|
MP_BINARY_OP_INPLACE_POWER,
|
2015-06-13 17:00:10 -04:00
|
|
|
|
2017-10-03 08:34:28 -04:00
|
|
|
// 12 normal arithmetic operations
|
2017-09-07 17:10:10 -04:00
|
|
|
MP_BINARY_OP_OR,
|
|
|
|
MP_BINARY_OP_XOR,
|
|
|
|
MP_BINARY_OP_AND,
|
|
|
|
MP_BINARY_OP_LSHIFT,
|
|
|
|
MP_BINARY_OP_RSHIFT,
|
|
|
|
MP_BINARY_OP_ADD,
|
|
|
|
MP_BINARY_OP_SUBTRACT,
|
|
|
|
MP_BINARY_OP_MULTIPLY,
|
|
|
|
MP_BINARY_OP_FLOOR_DIVIDE,
|
|
|
|
MP_BINARY_OP_TRUE_DIVIDE,
|
|
|
|
MP_BINARY_OP_MODULO,
|
|
|
|
MP_BINARY_OP_POWER,
|
|
|
|
|
2017-09-07 04:26:42 -04:00
|
|
|
// Operations below this line don't appear in bytecode, they
|
|
|
|
// just identify special methods.
|
2017-10-03 08:34:28 -04:00
|
|
|
MP_BINARY_OP_NUM_BYTECODE,
|
2017-09-07 04:26:42 -04:00
|
|
|
|
2017-09-10 10:05:20 -04:00
|
|
|
// MP_BINARY_OP_REVERSE_* must follow immediately after MP_BINARY_OP_*
|
2021-03-15 09:57:36 -04:00
|
|
|
#if MICROPY_PY_REVERSE_SPECIAL_METHODS
|
2017-10-03 08:34:28 -04:00
|
|
|
MP_BINARY_OP_REVERSE_OR = MP_BINARY_OP_NUM_BYTECODE,
|
2017-09-10 10:05:20 -04:00
|
|
|
MP_BINARY_OP_REVERSE_XOR,
|
|
|
|
MP_BINARY_OP_REVERSE_AND,
|
|
|
|
MP_BINARY_OP_REVERSE_LSHIFT,
|
|
|
|
MP_BINARY_OP_REVERSE_RSHIFT,
|
|
|
|
MP_BINARY_OP_REVERSE_ADD,
|
|
|
|
MP_BINARY_OP_REVERSE_SUBTRACT,
|
|
|
|
MP_BINARY_OP_REVERSE_MULTIPLY,
|
|
|
|
MP_BINARY_OP_REVERSE_FLOOR_DIVIDE,
|
|
|
|
MP_BINARY_OP_REVERSE_TRUE_DIVIDE,
|
|
|
|
MP_BINARY_OP_REVERSE_MODULO,
|
|
|
|
MP_BINARY_OP_REVERSE_POWER,
|
2021-03-15 09:57:36 -04:00
|
|
|
#endif
|
2017-09-10 10:05:20 -04:00
|
|
|
|
2017-10-03 08:34:28 -04:00
|
|
|
// This is not emitted by the compiler but is supported by the runtime
|
|
|
|
MP_BINARY_OP_DIVMOD
|
2021-03-15 09:57:36 -04:00
|
|
|
#if !MICROPY_PY_REVERSE_SPECIAL_METHODS
|
2017-10-03 08:34:28 -04:00
|
|
|
= MP_BINARY_OP_NUM_BYTECODE
|
2021-03-15 09:57:36 -04:00
|
|
|
#endif
|
2017-10-03 08:34:28 -04:00
|
|
|
,
|
|
|
|
|
2017-11-23 21:04:24 -05:00
|
|
|
// The runtime will convert MP_BINARY_OP_IN to this operator with swapped args.
|
|
|
|
// A type should implement this containment operator instead of MP_BINARY_OP_IN.
|
|
|
|
MP_BINARY_OP_CONTAINS,
|
|
|
|
|
2017-10-03 08:34:28 -04:00
|
|
|
MP_BINARY_OP_NUM_RUNTIME,
|
2017-09-07 05:54:58 -04:00
|
|
|
|
2017-10-03 08:34:28 -04:00
|
|
|
// These 2 are not supported by the runtime and must be synthesised by the emitter
|
|
|
|
MP_BINARY_OP_NOT_IN,
|
|
|
|
MP_BINARY_OP_IS_NOT,
|
2014-03-30 08:35:08 -04:00
|
|
|
} mp_binary_op_t;
|
2013-12-21 13:17:45 -05:00
|
|
|
|
|
|
|
typedef enum {
|
2014-08-15 18:47:59 -04:00
|
|
|
MP_F_CONVERT_OBJ_TO_NATIVE = 0,
|
|
|
|
MP_F_CONVERT_NATIVE_TO_OBJ,
|
2014-03-30 08:35:08 -04:00
|
|
|
MP_F_LOAD_NAME,
|
|
|
|
MP_F_LOAD_GLOBAL,
|
|
|
|
MP_F_LOAD_BUILD_CLASS,
|
|
|
|
MP_F_LOAD_ATTR,
|
|
|
|
MP_F_LOAD_METHOD,
|
2017-04-18 19:45:59 -04:00
|
|
|
MP_F_LOAD_SUPER_METHOD,
|
2014-03-30 08:35:08 -04:00
|
|
|
MP_F_STORE_NAME,
|
2014-08-15 18:47:59 -04:00
|
|
|
MP_F_STORE_GLOBAL,
|
2014-03-30 08:35:08 -04:00
|
|
|
MP_F_STORE_ATTR,
|
2014-04-17 17:10:53 -04:00
|
|
|
MP_F_OBJ_SUBSCR,
|
2014-03-30 08:35:08 -04:00
|
|
|
MP_F_OBJ_IS_TRUE,
|
|
|
|
MP_F_UNARY_OP,
|
|
|
|
MP_F_BINARY_OP,
|
|
|
|
MP_F_BUILD_TUPLE,
|
|
|
|
MP_F_BUILD_LIST,
|
|
|
|
MP_F_LIST_APPEND,
|
|
|
|
MP_F_BUILD_MAP,
|
|
|
|
MP_F_STORE_MAP,
|
2021-03-15 09:57:36 -04:00
|
|
|
#if MICROPY_PY_BUILTINS_SET
|
2014-03-30 08:35:08 -04:00
|
|
|
MP_F_STORE_SET,
|
2018-05-22 08:18:42 -04:00
|
|
|
MP_F_BUILD_SET,
|
2021-03-15 09:57:36 -04:00
|
|
|
#endif
|
2014-04-13 06:04:33 -04:00
|
|
|
MP_F_MAKE_FUNCTION_FROM_RAW_CODE,
|
2014-08-16 17:06:11 -04:00
|
|
|
MP_F_NATIVE_CALL_FUNCTION_N_KW,
|
2014-03-30 08:35:08 -04:00
|
|
|
MP_F_CALL_METHOD_N_KW,
|
2015-04-06 17:48:21 -04:00
|
|
|
MP_F_CALL_METHOD_N_KW_VAR,
|
2017-01-16 23:27:37 -05:00
|
|
|
MP_F_NATIVE_GETITER,
|
|
|
|
MP_F_NATIVE_ITERNEXT,
|
2014-08-16 17:31:57 -04:00
|
|
|
MP_F_NLR_PUSH,
|
|
|
|
MP_F_NLR_POP,
|
2014-08-16 17:06:11 -04:00
|
|
|
MP_F_NATIVE_RAISE,
|
2014-04-06 07:58:40 -04:00
|
|
|
MP_F_IMPORT_NAME,
|
2014-08-16 17:31:57 -04:00
|
|
|
MP_F_IMPORT_FROM,
|
2014-04-06 07:58:40 -04:00
|
|
|
MP_F_IMPORT_ALL,
|
2021-03-15 09:57:36 -04:00
|
|
|
#if MICROPY_PY_BUILTINS_SLICE
|
2014-04-06 07:58:40 -04:00
|
|
|
MP_F_NEW_SLICE,
|
2021-03-15 09:57:36 -04:00
|
|
|
#endif
|
2014-04-06 07:58:40 -04:00
|
|
|
MP_F_UNPACK_SEQUENCE,
|
2014-05-07 13:30:52 -04:00
|
|
|
MP_F_UNPACK_EX,
|
2014-09-06 13:38:20 -04:00
|
|
|
MP_F_DELETE_NAME,
|
|
|
|
MP_F_DELETE_GLOBAL,
|
2015-01-15 09:41:41 -05:00
|
|
|
MP_F_NEW_CELL,
|
|
|
|
MP_F_MAKE_CLOSURE_FROM_RAW_CODE,
|
2015-04-06 17:38:53 -04:00
|
|
|
MP_F_SETUP_CODE_STATE,
|
2017-10-11 03:54:34 -04:00
|
|
|
MP_F_SMALL_INT_FLOOR_DIVIDE,
|
|
|
|
MP_F_SMALL_INT_MODULO,
|
2014-03-30 08:35:08 -04:00
|
|
|
MP_F_NUMBER_OF,
|
|
|
|
} mp_fun_kind_t;
|
2013-12-21 13:17:45 -05:00
|
|
|
|
2014-03-30 08:35:08 -04:00
|
|
|
extern void *const mp_fun_table[MP_F_NUMBER_OF];
|
2014-12-25 16:29:19 -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_RUNTIME0_H
|