runtime0.h 4.67 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
/*
 * This file is part of the Micro Python project, http://micropython.org/
 *
 * 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.
 */
26
27
#ifndef __MICROPY_INCLUDED_PY_RUNTIME0_H__
#define __MICROPY_INCLUDED_PY_RUNTIME0_H__
28

29
// taken from python source, Include/code.h
30
// These must fit in 8 bits; see scope.h
31
32
33
34
35
36
37
38
39
40
41
42
43
#define MP_SCOPE_FLAG_OPTIMISED    0x01
#define MP_SCOPE_FLAG_NEWLOCALS    0x02
#define MP_SCOPE_FLAG_VARARGS      0x04
#define MP_SCOPE_FLAG_VARKEYWORDS  0x08
#define MP_SCOPE_FLAG_NESTED       0x10
#define MP_SCOPE_FLAG_GENERATOR    0x20
/* The MP_SCOPE_FLAG_NOFREE flag is set if there are no free or cell variables.
   This information is redundant, but it allows a single flag test
   to determine whether there is any extra work to be done when the
   call frame is setup.
*/
#define MP_SCOPE_FLAG_NOFREE       0x40

44
45
46
47
48
49
// 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)

50
typedef enum {
Damien George's avatar
Damien George committed
51
52
53
54
55
    MP_UNARY_OP_BOOL, // __bool__
    MP_UNARY_OP_LEN, // __len__
    MP_UNARY_OP_POSITIVE,
    MP_UNARY_OP_NEGATIVE,
    MP_UNARY_OP_INVERT,
56
57
    // The NOT op is only implemented by bool.  The emitter must synthesise NOT
    // for other types by calling BOOL then inverting (eg by then calling NOT).
Damien George's avatar
Damien George committed
58
59
    MP_UNARY_OP_NOT,
} mp_unary_op_t;
60
61

typedef enum {
Damien George's avatar
Damien George committed
62
63
64
65
66
    MP_BINARY_OP_OR,
    MP_BINARY_OP_XOR,
    MP_BINARY_OP_AND,
    MP_BINARY_OP_LSHIFT,
    MP_BINARY_OP_RSHIFT,
67

Damien George's avatar
Damien George committed
68
69
70
71
72
    MP_BINARY_OP_ADD,
    MP_BINARY_OP_SUBTRACT,
    MP_BINARY_OP_MULTIPLY,
    MP_BINARY_OP_FLOOR_DIVIDE,
    MP_BINARY_OP_TRUE_DIVIDE,
73

Damien George's avatar
Damien George committed
74
75
76
77
78
    MP_BINARY_OP_MODULO,
    MP_BINARY_OP_POWER,
    MP_BINARY_OP_INPLACE_OR,
    MP_BINARY_OP_INPLACE_XOR,
    MP_BINARY_OP_INPLACE_AND,
79

Damien George's avatar
Damien George committed
80
81
82
83
84
    MP_BINARY_OP_INPLACE_LSHIFT,
    MP_BINARY_OP_INPLACE_RSHIFT,
    MP_BINARY_OP_INPLACE_ADD,
    MP_BINARY_OP_INPLACE_SUBTRACT,
    MP_BINARY_OP_INPLACE_MULTIPLY,
85

Damien George's avatar
Damien George committed
86
87
88
89
    MP_BINARY_OP_INPLACE_FLOOR_DIVIDE,
    MP_BINARY_OP_INPLACE_TRUE_DIVIDE,
    MP_BINARY_OP_INPLACE_MODULO,
    MP_BINARY_OP_INPLACE_POWER,
90
    // these should return a bool
Damien George's avatar
Damien George committed
91
    MP_BINARY_OP_LESS,
92

Damien George's avatar
Damien George committed
93
94
95
96
97
    MP_BINARY_OP_MORE,
    MP_BINARY_OP_EQUAL,
    MP_BINARY_OP_LESS_EQUAL,
    MP_BINARY_OP_MORE_EQUAL,
    MP_BINARY_OP_NOT_EQUAL,
98

Damien George's avatar
Damien George committed
99
100
101
    MP_BINARY_OP_IN,
    MP_BINARY_OP_IS,
    MP_BINARY_OP_EXCEPTION_MATCH,
102
    // these are not supported by the runtime and must be synthesised by the emitter
Damien George's avatar
Damien George committed
103
104
105
    MP_BINARY_OP_NOT_IN,
    MP_BINARY_OP_IS_NOT,
} mp_binary_op_t;
106
107

typedef enum {
108
109
    MP_F_CONVERT_OBJ_TO_NATIVE = 0,
    MP_F_CONVERT_NATIVE_TO_OBJ,
Damien George's avatar
Damien George committed
110
    MP_F_LOAD_CONST_STR,
111
    MP_F_LOAD_CONST_BYTES,
Damien George's avatar
Damien George committed
112
113
114
115
116
117
    MP_F_LOAD_NAME,
    MP_F_LOAD_GLOBAL,
    MP_F_LOAD_BUILD_CLASS,
    MP_F_LOAD_ATTR,
    MP_F_LOAD_METHOD,
    MP_F_STORE_NAME,
118
    MP_F_STORE_GLOBAL,
Damien George's avatar
Damien George committed
119
    MP_F_STORE_ATTR,
120
    MP_F_OBJ_SUBSCR,
Damien George's avatar
Damien George committed
121
122
123
124
125
126
127
128
    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,
129
#if MICROPY_PY_BUILTINS_SET
Damien George's avatar
Damien George committed
130
131
    MP_F_BUILD_SET,
    MP_F_STORE_SET,
132
#endif
133
    MP_F_MAKE_FUNCTION_FROM_RAW_CODE,
134
    MP_F_NATIVE_CALL_FUNCTION_N_KW,
Damien George's avatar
Damien George committed
135
136
137
    MP_F_CALL_METHOD_N_KW,
    MP_F_GETITER,
    MP_F_ITERNEXT,
138
139
    MP_F_NLR_PUSH,
    MP_F_NLR_POP,
140
    MP_F_NATIVE_RAISE,
141
    MP_F_IMPORT_NAME,
142
    MP_F_IMPORT_FROM,
143
    MP_F_IMPORT_ALL,
144
#if MICROPY_PY_BUILTINS_SLICE
145
    MP_F_NEW_SLICE,
146
#endif
147
    MP_F_UNPACK_SEQUENCE,
148
    MP_F_UNPACK_EX,
149
150
    MP_F_DELETE_NAME,
    MP_F_DELETE_GLOBAL,
151
152
    MP_F_NEW_CELL,
    MP_F_MAKE_CLOSURE_FROM_RAW_CODE,
Damien George's avatar
Damien George committed
153
154
    MP_F_NUMBER_OF,
} mp_fun_kind_t;
155

Damien George's avatar
Damien George committed
156
extern void *const mp_fun_table[MP_F_NUMBER_OF];
157
158

#endif // __MICROPY_INCLUDED_PY_RUNTIME0_H__