Skip to content

Commit 9d7b871

Browse files
committed
esp8266: Store frozen modules in FlashROM.
Requires special lexer to access their contents.
1 parent 2466cb6 commit 9d7b871

4 files changed

Lines changed: 73 additions & 0 deletions

File tree

esp8266/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ SRC_C = \
5555
main.c \
5656
esp_mphal.c \
5757
gccollect.c \
58+
lexerstr32.c \
5859
uart.c \
5960
modpyb.c \
6061
modpybpin.c \

esp8266/esp8266.ld

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,8 @@ SECTIONS
146146
*.o(.rodata.mp_type_*) /* catches type: mp_obj_type_t */
147147
*.o(.rodata.*_locals_dict*) /* catches types: mp_obj_dict_t, mp_map_elem_t */
148148
*.o(.rodata.mp_module_*) /* catches types: mp_obj_module_t, mp_obj_dict_t, mp_map_elem_t */
149+
*/frozen.o(.rodata.mp_frozen_sizes) /* frozen modules */
150+
*/frozen.o(.rodata.mp_frozen_content) /* frozen modules */
149151

150152
_irom0_text_end = ABSOLUTE(.);
151153
} >irom0_0_seg :irom0_0_phdr

esp8266/lexerstr32.c

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/*
2+
* This file is part of the MicroPython project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2013-2016 Damien P. George
7+
* Copyright (c) 2016 Paul Sokolovsky
8+
*
9+
* Permission is hereby granted, free of charge, to any person obtaining a copy
10+
* of this software and associated documentation files (the "Software"), to deal
11+
* in the Software without restriction, including without limitation the rights
12+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13+
* copies of the Software, and to permit persons to whom the Software is
14+
* furnished to do so, subject to the following conditions:
15+
*
16+
* The above copyright notice and this permission notice shall be included in
17+
* all copies or substantial portions of the Software.
18+
*
19+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25+
* THE SOFTWARE.
26+
*/
27+
28+
#include "py/lexer.h"
29+
30+
#if MICROPY_ENABLE_COMPILER
31+
32+
typedef struct _mp_lexer_str32_buf_t {
33+
const uint32_t *src_cur;
34+
uint32_t val;
35+
uint8_t byte_off;
36+
} mp_lexer_str32_buf_t;
37+
38+
STATIC mp_uint_t str32_buf_next_byte(mp_lexer_str32_buf_t *sb) {
39+
byte c = sb->val & 0xff;
40+
if (c == 0) {
41+
return MP_LEXER_EOF;
42+
}
43+
44+
if (++sb->byte_off > 3) {
45+
sb->byte_off = 0;
46+
sb->val = *sb->src_cur++;
47+
} else {
48+
sb->val >>= 8;
49+
}
50+
51+
return c;
52+
}
53+
54+
STATIC void str32_buf_free(mp_lexer_str32_buf_t *sb) {
55+
m_del_obj(mp_lexer_str32_buf_t, sb);
56+
}
57+
58+
mp_lexer_t *mp_lexer_new_from_str32(qstr src_name, const char *str, mp_uint_t len, mp_uint_t free_len) {
59+
mp_lexer_str32_buf_t *sb = m_new_obj_maybe(mp_lexer_str32_buf_t);
60+
if (sb == NULL) {
61+
return NULL;
62+
}
63+
sb->byte_off = (uint32_t)str & 3;
64+
sb->src_cur = (uint32_t*)(str - sb->byte_off);
65+
sb->val = *sb->src_cur++ >> sb->byte_off * 8;
66+
return mp_lexer_new(src_name, sb, (mp_lexer_stream_next_byte_t)str32_buf_next_byte, (mp_lexer_stream_close_t)str32_buf_free);
67+
}
68+
69+
#endif // MICROPY_ENABLE_COMPILER

esp8266/mpconfigport.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
#define MICROPY_FLOAT_IMPL (MICROPY_FLOAT_IMPL_FLOAT)
5252
#define MICROPY_ERROR_REPORTING (MICROPY_ERROR_REPORTING_TERSE)
5353
#define MICROPY_MODULE_FROZEN (1)
54+
#define MICROPY_MODULE_FROZEN_LEXER mp_lexer_new_from_str32
5455

5556
#define MICROPY_EVENT_POLL_HOOK {ets_event_poll();}
5657

0 commit comments

Comments
 (0)