blob: 8d62403a7c086801b320d608b9cdc3d38ab85580 [file] [log] [blame]
Damien George04b91472014-05-03 23:27:38 +01001/*
2 * This file is part of the Micro Python project, http://micropython.org/
3 *
4 * The MIT License (MIT)
5 *
6 * Copyright (c) 2013, 2014 Damien P. George
7 *
8 * Permission is hereby granted, free of charge, to any person obtaining a copy
9 * of this software and associated documentation files (the "Software"), to deal
10 * in the Software without restriction, including without limitation the rights
11 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 * copies of the Software, and to permit persons to whom the Software is
13 * furnished to do so, subject to the following conditions:
14 *
15 * The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24 * THE SOFTWARE.
25 */
Paul Sokolovsky8ab6f902014-12-25 23:29:19 +020026#ifndef __MICROPY_INCLUDED_PY_RUNTIME0_H__
27#define __MICROPY_INCLUDED_PY_RUNTIME0_H__
Damien George04b91472014-05-03 23:27:38 +010028
Damien George78035b92014-04-09 12:27:39 +010029// These must fit in 8 bits; see scope.h
Damien George7f70b602015-08-17 22:39:03 +010030#define MP_SCOPE_FLAG_VARARGS (0x01)
31#define MP_SCOPE_FLAG_VARKEYWORDS (0x02)
32#define MP_SCOPE_FLAG_GENERATOR (0x04)
Damien George3a3db4d2015-10-22 23:45:37 +010033#define MP_SCOPE_FLAG_DEFKWARGS (0x08)
Damien George8725f8f2014-02-15 19:33:11 +000034
Damien George2ac4af62014-08-15 16:45:41 +010035// types for native (viper) function signature
36#define MP_NATIVE_TYPE_OBJ (0x00)
37#define MP_NATIVE_TYPE_BOOL (0x01)
38#define MP_NATIVE_TYPE_INT (0x02)
39#define MP_NATIVE_TYPE_UINT (0x03)
Damien George5f3e0052016-02-02 23:16:05 +000040#define MP_NATIVE_TYPE_PTR (0x04)
41#define MP_NATIVE_TYPE_PTR8 (0x05)
42#define MP_NATIVE_TYPE_PTR16 (0x06)
43#define MP_NATIVE_TYPE_PTR32 (0x07)
Damien George2ac4af62014-08-15 16:45:41 +010044
Damiend99b0522013-12-21 18:17:45 +000045typedef enum {
Damien Georged17926d2014-03-30 13:35:08 +010046 MP_UNARY_OP_BOOL, // __bool__
47 MP_UNARY_OP_LEN, // __len__
Damien Georgec2a4e4e2015-05-11 12:25:19 +000048 MP_UNARY_OP_HASH, // __hash__; must return a small int
Damien Georged17926d2014-03-30 13:35:08 +010049 MP_UNARY_OP_POSITIVE,
50 MP_UNARY_OP_NEGATIVE,
51 MP_UNARY_OP_INVERT,
Damien Georged17926d2014-03-30 13:35:08 +010052 MP_UNARY_OP_NOT,
53} mp_unary_op_t;
Damiend99b0522013-12-21 18:17:45 +000054
55typedef enum {
Damien Georged17926d2014-03-30 13:35:08 +010056 MP_BINARY_OP_OR,
57 MP_BINARY_OP_XOR,
58 MP_BINARY_OP_AND,
59 MP_BINARY_OP_LSHIFT,
60 MP_BINARY_OP_RSHIFT,
Paul Sokolovsky070c78a2014-05-10 04:24:22 +030061
Damien Georged17926d2014-03-30 13:35:08 +010062 MP_BINARY_OP_ADD,
63 MP_BINARY_OP_SUBTRACT,
64 MP_BINARY_OP_MULTIPLY,
65 MP_BINARY_OP_FLOOR_DIVIDE,
66 MP_BINARY_OP_TRUE_DIVIDE,
Paul Sokolovsky070c78a2014-05-10 04:24:22 +030067
Damien Georged17926d2014-03-30 13:35:08 +010068 MP_BINARY_OP_MODULO,
69 MP_BINARY_OP_POWER,
Damien Georgec5029bc2015-06-13 22:00:10 +010070 MP_BINARY_OP_DIVMOD, // not emitted by the compiler but supported by the runtime
Damien Georged17926d2014-03-30 13:35:08 +010071 MP_BINARY_OP_INPLACE_OR,
72 MP_BINARY_OP_INPLACE_XOR,
Paul Sokolovsky070c78a2014-05-10 04:24:22 +030073
Damien Georgec5029bc2015-06-13 22:00:10 +010074 MP_BINARY_OP_INPLACE_AND,
Damien Georged17926d2014-03-30 13:35:08 +010075 MP_BINARY_OP_INPLACE_LSHIFT,
76 MP_BINARY_OP_INPLACE_RSHIFT,
77 MP_BINARY_OP_INPLACE_ADD,
78 MP_BINARY_OP_INPLACE_SUBTRACT,
Paul Sokolovsky070c78a2014-05-10 04:24:22 +030079
Damien Georgec5029bc2015-06-13 22:00:10 +010080 MP_BINARY_OP_INPLACE_MULTIPLY,
Damien Georged17926d2014-03-30 13:35:08 +010081 MP_BINARY_OP_INPLACE_FLOOR_DIVIDE,
82 MP_BINARY_OP_INPLACE_TRUE_DIVIDE,
83 MP_BINARY_OP_INPLACE_MODULO,
84 MP_BINARY_OP_INPLACE_POWER,
Damien Georgec5029bc2015-06-13 22:00:10 +010085
Damien George9aa2a522014-02-01 23:04:09 +000086 // these should return a bool
Damien Georged17926d2014-03-30 13:35:08 +010087 MP_BINARY_OP_LESS,
88 MP_BINARY_OP_MORE,
89 MP_BINARY_OP_EQUAL,
90 MP_BINARY_OP_LESS_EQUAL,
91 MP_BINARY_OP_MORE_EQUAL,
Paul Sokolovsky070c78a2014-05-10 04:24:22 +030092
Damien Georgec5029bc2015-06-13 22:00:10 +010093 MP_BINARY_OP_NOT_EQUAL,
Damien Georged17926d2014-03-30 13:35:08 +010094 MP_BINARY_OP_IN,
95 MP_BINARY_OP_IS,
96 MP_BINARY_OP_EXCEPTION_MATCH,
Damien George9aa2a522014-02-01 23:04:09 +000097 // these are not supported by the runtime and must be synthesised by the emitter
Damien Georged17926d2014-03-30 13:35:08 +010098 MP_BINARY_OP_NOT_IN,
99 MP_BINARY_OP_IS_NOT,
100} mp_binary_op_t;
Damiend99b0522013-12-21 18:17:45 +0000101
102typedef enum {
Damien Georgee6c0dff2014-08-15 23:47:59 +0100103 MP_F_CONVERT_OBJ_TO_NATIVE = 0,
104 MP_F_CONVERT_NATIVE_TO_OBJ,
Damien Georged17926d2014-03-30 13:35:08 +0100105 MP_F_LOAD_NAME,
106 MP_F_LOAD_GLOBAL,
107 MP_F_LOAD_BUILD_CLASS,
108 MP_F_LOAD_ATTR,
109 MP_F_LOAD_METHOD,
110 MP_F_STORE_NAME,
Damien Georgee6c0dff2014-08-15 23:47:59 +0100111 MP_F_STORE_GLOBAL,
Damien Georged17926d2014-03-30 13:35:08 +0100112 MP_F_STORE_ATTR,
Damien George729f7b42014-04-17 22:10:53 +0100113 MP_F_OBJ_SUBSCR,
Damien Georged17926d2014-03-30 13:35:08 +0100114 MP_F_OBJ_IS_TRUE,
115 MP_F_UNARY_OP,
116 MP_F_BINARY_OP,
117 MP_F_BUILD_TUPLE,
118 MP_F_BUILD_LIST,
119 MP_F_LIST_APPEND,
120 MP_F_BUILD_MAP,
121 MP_F_STORE_MAP,
Damien George3ebd4d02014-06-01 13:46:47 +0100122#if MICROPY_PY_BUILTINS_SET
Damien Georged17926d2014-03-30 13:35:08 +0100123 MP_F_BUILD_SET,
124 MP_F_STORE_SET,
Damien George3ebd4d02014-06-01 13:46:47 +0100125#endif
Damien Georgedf8127a2014-04-13 11:04:33 +0100126 MP_F_MAKE_FUNCTION_FROM_RAW_CODE,
Damien George86de21b2014-08-16 22:06:11 +0100127 MP_F_NATIVE_CALL_FUNCTION_N_KW,
Damien Georged17926d2014-03-30 13:35:08 +0100128 MP_F_CALL_METHOD_N_KW,
Damien George78772ad2015-04-06 22:48:21 +0100129 MP_F_CALL_METHOD_N_KW_VAR,
Damien Georged17926d2014-03-30 13:35:08 +0100130 MP_F_GETITER,
131 MP_F_ITERNEXT,
Damien George7fe21912014-08-16 22:31:57 +0100132 MP_F_NLR_PUSH,
133 MP_F_NLR_POP,
Damien George86de21b2014-08-16 22:06:11 +0100134 MP_F_NATIVE_RAISE,
Damien Georgecdd96df2014-04-06 12:58:40 +0100135 MP_F_IMPORT_NAME,
Damien George7fe21912014-08-16 22:31:57 +0100136 MP_F_IMPORT_FROM,
Damien Georgecdd96df2014-04-06 12:58:40 +0100137 MP_F_IMPORT_ALL,
Damien Georgec49ddb92014-06-01 13:49:35 +0100138#if MICROPY_PY_BUILTINS_SLICE
Damien Georgecdd96df2014-04-06 12:58:40 +0100139 MP_F_NEW_SLICE,
Damien Georgec49ddb92014-06-01 13:49:35 +0100140#endif
Damien Georgecdd96df2014-04-06 12:58:40 +0100141 MP_F_UNPACK_SEQUENCE,
Damien Georgea32c1e42014-05-07 18:30:52 +0100142 MP_F_UNPACK_EX,
Damien Georgee6ce10a2014-09-06 18:38:20 +0100143 MP_F_DELETE_NAME,
144 MP_F_DELETE_GLOBAL,
Damien George4cd9ced2015-01-15 14:41:41 +0000145 MP_F_NEW_CELL,
146 MP_F_MAKE_CLOSURE_FROM_RAW_CODE,
Damien George99886182015-04-06 22:38:53 +0100147 MP_F_SETUP_CODE_STATE,
Damien Georged17926d2014-03-30 13:35:08 +0100148 MP_F_NUMBER_OF,
149} mp_fun_kind_t;
Damiend99b0522013-12-21 18:17:45 +0000150
Damien Georged17926d2014-03-30 13:35:08 +0100151extern void *const mp_fun_table[MP_F_NUMBER_OF];
Paul Sokolovsky8ab6f902014-12-25 23:29:19 +0200152
153#endif // __MICROPY_INCLUDED_PY_RUNTIME0_H__