Skip to content

Commit d99b052

Browse files
committed
Change object representation from 1 big union to individual structs.
A big change. Micro Python objects are allocated as individual structs with the first element being a pointer to the type information (which is itself an object). This scheme follows CPython. Much more flexible, not necessarily slower, uses same heap memory, and can allocate objects statically. Also change name prefix, from py_ to mp_ (mp for Micro Python).
1 parent e2880aa commit d99b052

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+4805
-3665
lines changed

py/asmthumb.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#include <string.h>
55

66
#include "misc.h"
7-
#include "mpyconfig.h"
7+
#include "mpconfig.h"
88
#include "asmthumb.h"
99

1010
#define UNSIGNED_FIT8(x) (((x) & 0xffffff00) == 0)

py/bc.h

Lines changed: 2 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -1,101 +1,2 @@
1-
#define PYBC_LOAD_CONST_FALSE (0x10)
2-
#define PYBC_LOAD_CONST_NONE (0x11)
3-
#define PYBC_LOAD_CONST_TRUE (0x12)
4-
#define PYBC_LOAD_CONST_SMALL_INT (0x13) // 24-bit, in excess
5-
#define PYBC_LOAD_CONST_INT (0x14) // qstr
6-
#define PYBC_LOAD_CONST_DEC (0x15) // qstr
7-
#define PYBC_LOAD_CONST_ID (0x16) // qstr
8-
#define PYBC_LOAD_CONST_BYTES (0x17) // qstr
9-
#define PYBC_LOAD_CONST_STRING (0x18) // qstr
10-
11-
#define PYBC_LOAD_FAST_0 (0x20)
12-
#define PYBC_LOAD_FAST_1 (0x21)
13-
#define PYBC_LOAD_FAST_2 (0x22)
14-
#define PYBC_LOAD_FAST_N (0x23) // uint
15-
#define PYBC_LOAD_DEREF (0x24) // uint
16-
#define PYBC_LOAD_CLOSURE (0x25) // uint
17-
#define PYBC_LOAD_NAME (0x26) // qstr
18-
#define PYBC_LOAD_GLOBAL (0x27) // qstr
19-
#define PYBC_LOAD_ATTR (0x28) // qstr
20-
#define PYBC_LOAD_METHOD (0x29) // qstr
21-
#define PYBC_LOAD_BUILD_CLASS (0x2a)
22-
23-
#define PYBC_STORE_FAST_0 (0x30)
24-
#define PYBC_STORE_FAST_1 (0x31)
25-
#define PYBC_STORE_FAST_2 (0x32)
26-
#define PYBC_STORE_FAST_N (0x33) // uint
27-
#define PYBC_STORE_DEREF (0x34) // uint
28-
#define PYBC_STORE_NAME (0x35) // qstr
29-
#define PYBC_STORE_GLOBAL (0x36) // qstr
30-
#define PYBC_STORE_ATTR (0x37) // qstr
31-
#define PYBC_STORE_SUBSCR (0x38)
32-
33-
#define PYBC_DELETE_FAST_N (0x39) // uint
34-
#define PYBC_DELETE_DEREF (0x3a) // uint
35-
#define PYBC_DELETE_NAME (0x3b) // qstr
36-
#define PYBC_DELETE_GLOBAL (0x3c) // qstr
37-
#define PYBC_DELETE_ATTR (0x3d) // qstr
38-
#define PYBC_DELETE_SUBSCR (0x3e)
39-
40-
#define PYBC_DUP_TOP (0x40)
41-
#define PYBC_DUP_TOP_TWO (0x41)
42-
#define PYBC_POP_TOP (0x42)
43-
#define PYBC_ROT_TWO (0x43)
44-
#define PYBC_ROT_THREE (0x44)
45-
46-
#define PYBC_JUMP (0x45) // rel byte code offset, 16-bit signed, in excess
47-
#define PYBC_POP_JUMP_IF_TRUE (0x46) // rel byte code offset, 16-bit signed, in excess
48-
#define PYBC_POP_JUMP_IF_FALSE (0x47) // rel byte code offset, 16-bit signed, in excess
49-
#define PYBC_JUMP_IF_TRUE_OR_POP (0x48) // rel byte code offset, 16-bit signed, in excess
50-
#define PYBC_JUMP_IF_FALSE_OR_POP (0x49) // rel byte code offset, 16-bit signed, in excess
51-
#define PYBC_SETUP_LOOP (0x4a) // rel byte code offset, 16-bit unsigned
52-
#define PYBC_BREAK_LOOP (0x4b) // rel byte code offset, 16-bit unsigned
53-
#define PYBC_CONTINUE_LOOP (0x4c) // rel byte code offset, 16-bit unsigned
54-
#define PYBC_SETUP_WITH (0x4d) // rel byte code offset, 16-bit unsigned
55-
#define PYBC_WITH_CLEANUP (0x4e)
56-
#define PYBC_SETUP_EXCEPT (0x4f) // rel byte code offset, 16-bit unsigned
57-
#define PYBC_SETUP_FINALLY (0x50) // rel byte code offset, 16-bit unsigned
58-
#define PYBC_END_FINALLY (0x51)
59-
#define PYBC_GET_ITER (0x52)
60-
#define PYBC_FOR_ITER (0x53) // rel byte code offset, 16-bit unsigned
61-
#define PYBC_POP_BLOCK (0x54)
62-
#define PYBC_POP_EXCEPT (0x55)
63-
64-
#define PYBC_UNARY_OP (0x60) // byte
65-
#define PYBC_BINARY_OP (0x61) // byte
66-
#define PYBC_COMPARE_OP (0x62) // byte
67-
68-
#define PYBC_BUILD_TUPLE (0x70) // uint
69-
#define PYBC_BUILD_LIST (0x71) // uint
70-
#define PYBC_LIST_APPEND (0x72) // uint
71-
#define PYBC_BUILD_MAP (0x73) // uint
72-
#define PYBC_STORE_MAP (0x74)
73-
#define PYBC_MAP_ADD (0x75) // uint
74-
#define PYBC_BUILD_SET (0x76) // uint
75-
#define PYBC_SET_ADD (0x77) // uint
76-
#define PYBC_BUILD_SLICE (0x78) // uint
77-
#define PYBC_UNPACK_SEQUENCE (0x79) // uint
78-
#define PYBC_UNPACK_EX (0x7a) // uint
79-
80-
#define PYBC_RETURN_VALUE (0x80)
81-
#define PYBC_RAISE_VARARGS (0x81) // uint
82-
#define PYBC_YIELD_VALUE (0x82)
83-
#define PYBC_YIELD_FROM (0x83)
84-
85-
#define PYBC_MAKE_FUNCTION (0x90) // uint
86-
#define PYBC_MAKE_CLOSURE (0x91) // uint
87-
#define PYBC_CALL_FUNCTION (0x92) // uint
88-
#define PYBC_CALL_FUNCTION_VAR (0x93) // uint
89-
#define PYBC_CALL_FUNCTION_KW (0x94) // uint
90-
#define PYBC_CALL_FUNCTION_VAR_KW (0x95) // uint
91-
#define PYBC_CALL_METHOD (0x96) // uint
92-
#define PYBC_CALL_METHOD_VAR (0x97) // uint
93-
#define PYBC_CALL_METHOD_KW (0x98) // uint
94-
#define PYBC_CALL_METHOD_VAR_KW (0x99) // uint
95-
96-
#define PYBC_IMPORT_NAME (0xe0) // qstr
97-
#define PYBC_IMPORT_FROM (0xe1) // qstr
98-
#define PYBC_IMPORT_STAR (0xe2)
99-
100-
py_obj_t py_execute_byte_code(const byte *code, const py_obj_t *args, uint n_args, uint n_state);
101-
bool py_execute_byte_code_2(const byte **ip_in_out, py_obj_t *fastn, py_obj_t **sp_in_out);
1+
mp_obj_t mp_execute_byte_code(const byte *code, const mp_obj_t *args, uint n_args, uint n_state);
2+
bool mp_execute_byte_code_2(const byte **ip_in_out, mp_obj_t *fastn, mp_obj_t **sp_in_out);

py/bc0.h

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
#define MP_BC_LOAD_CONST_FALSE (0x10)
2+
#define MP_BC_LOAD_CONST_NONE (0x11)
3+
#define MP_BC_LOAD_CONST_TRUE (0x12)
4+
#define MP_BC_LOAD_CONST_SMALL_INT (0x13) // 24-bit, in excess
5+
#define MP_BC_LOAD_CONST_INT (0x14) // qstr
6+
#define MP_BC_LOAD_CONST_DEC (0x15) // qstr
7+
#define MP_BC_LOAD_CONST_ID (0x16) // qstr
8+
#define MP_BC_LOAD_CONST_BYTES (0x17) // qstr
9+
#define MP_BC_LOAD_CONST_STRING (0x18) // qstr
10+
11+
#define MP_BC_LOAD_FAST_0 (0x20)
12+
#define MP_BC_LOAD_FAST_1 (0x21)
13+
#define MP_BC_LOAD_FAST_2 (0x22)
14+
#define MP_BC_LOAD_FAST_N (0x23) // uint
15+
#define MP_BC_LOAD_DEREF (0x24) // uint
16+
#define MP_BC_LOAD_CLOSURE (0x25) // uint
17+
#define MP_BC_LOAD_NAME (0x26) // qstr
18+
#define MP_BC_LOAD_GLOBAL (0x27) // qstr
19+
#define MP_BC_LOAD_ATTR (0x28) // qstr
20+
#define MP_BC_LOAD_METHOD (0x29) // qstr
21+
#define MP_BC_LOAD_BUILD_CLASS (0x2a)
22+
23+
#define MP_BC_STORE_FAST_0 (0x30)
24+
#define MP_BC_STORE_FAST_1 (0x31)
25+
#define MP_BC_STORE_FAST_2 (0x32)
26+
#define MP_BC_STORE_FAST_N (0x33) // uint
27+
#define MP_BC_STORE_DEREF (0x34) // uint
28+
#define MP_BC_STORE_NAME (0x35) // qstr
29+
#define MP_BC_STORE_GLOBAL (0x36) // qstr
30+
#define MP_BC_STORE_ATTR (0x37) // qstr
31+
#define MP_BC_STORE_SUBSCR (0x38)
32+
33+
#define MP_BC_DELETE_FAST_N (0x39) // uint
34+
#define MP_BC_DELETE_DEREF (0x3a) // uint
35+
#define MP_BC_DELETE_NAME (0x3b) // qstr
36+
#define MP_BC_DELETE_GLOBAL (0x3c) // qstr
37+
#define MP_BC_DELETE_ATTR (0x3d) // qstr
38+
#define MP_BC_DELETE_SUBSCR (0x3e)
39+
40+
#define MP_BC_DUP_TOP (0x40)
41+
#define MP_BC_DUP_TOP_TWO (0x41)
42+
#define MP_BC_POP_TOP (0x42)
43+
#define MP_BC_ROT_TWO (0x43)
44+
#define MP_BC_ROT_THREE (0x44)
45+
46+
#define MP_BC_JUMP (0x45) // rel byte code offset, 16-bit signed, in excess
47+
#define MP_BC_POP_JUMP_IF_TRUE (0x46) // rel byte code offset, 16-bit signed, in excess
48+
#define MP_BC_POP_JUMP_IF_FALSE (0x47) // rel byte code offset, 16-bit signed, in excess
49+
#define MP_BC_JUMP_IF_TRUE_OR_POP (0x48) // rel byte code offset, 16-bit signed, in excess
50+
#define MP_BC_JUMP_IF_FALSE_OR_POP (0x49) // rel byte code offset, 16-bit signed, in excess
51+
#define MP_BC_SETUP_LOOP (0x4a) // rel byte code offset, 16-bit unsigned
52+
#define MP_BC_BREAK_LOOP (0x4b) // rel byte code offset, 16-bit unsigned
53+
#define MP_BC_CONTINUE_LOOP (0x4c) // rel byte code offset, 16-bit unsigned
54+
#define MP_BC_SETUP_WITH (0x4d) // rel byte code offset, 16-bit unsigned
55+
#define MP_BC_WITH_CLEANUP (0x4e)
56+
#define MP_BC_SETUP_EXCEPT (0x4f) // rel byte code offset, 16-bit unsigned
57+
#define MP_BC_SETUP_FINALLY (0x50) // rel byte code offset, 16-bit unsigned
58+
#define MP_BC_END_FINALLY (0x51)
59+
#define MP_BC_GET_ITER (0x52)
60+
#define MP_BC_FOR_ITER (0x53) // rel byte code offset, 16-bit unsigned
61+
#define MP_BC_POP_BLOCK (0x54)
62+
#define MP_BC_POP_EXCEPT (0x55)
63+
64+
#define MP_BC_UNARY_OP (0x60) // byte
65+
#define MP_BC_BINARY_OP (0x61) // byte
66+
#define MP_BC_COMPARE_OP (0x62) // byte
67+
68+
#define MP_BC_BUILD_TUPLE (0x70) // uint
69+
#define MP_BC_BUILD_LIST (0x71) // uint
70+
#define MP_BC_LIST_APPEND (0x72) // uint
71+
#define MP_BC_BUILD_MAP (0x73) // uint
72+
#define MP_BC_STORE_MAP (0x74)
73+
#define MP_BC_MAP_ADD (0x75) // uint
74+
#define MP_BC_BUILD_SET (0x76) // uint
75+
#define MP_BC_SET_ADD (0x77) // uint
76+
#define MP_BC_BUILD_SLICE (0x78) // uint
77+
#define MP_BC_UNPACK_SEQUENCE (0x79) // uint
78+
#define MP_BC_UNPACK_EX (0x7a) // uint
79+
80+
#define MP_BC_RETURN_VALUE (0x80)
81+
#define MP_BC_RAISE_VARARGS (0x81) // uint
82+
#define MP_BC_YIELD_VALUE (0x82)
83+
#define MP_BC_YIELD_FROM (0x83)
84+
85+
#define MP_BC_MAKE_FUNCTION (0x90) // uint
86+
#define MP_BC_MAKE_CLOSURE (0x91) // uint
87+
#define MP_BC_CALL_FUNCTION (0x92) // uint
88+
#define MP_BC_CALL_FUNCTION_VAR (0x93) // uint
89+
#define MP_BC_CALL_FUNCTION_KW (0x94) // uint
90+
#define MP_BC_CALL_FUNCTION_VAR_KW (0x95) // uint
91+
#define MP_BC_CALL_METHOD (0x96) // uint
92+
#define MP_BC_CALL_METHOD_VAR (0x97) // uint
93+
#define MP_BC_CALL_METHOD_KW (0x98) // uint
94+
#define MP_BC_CALL_METHOD_VAR_KW (0x99) // uint
95+
96+
#define MP_BC_IMPORT_NAME (0xe0) // qstr
97+
#define MP_BC_IMPORT_FROM (0xe1) // qstr
98+
#define MP_BC_IMPORT_STAR (0xe2)

0 commit comments

Comments
 (0)