Skip to content

Commit e5ef15a

Browse files
committed
py/lexer: Provide generic mp_lexer_new_from_file based on mp_reader.
If a port defines MICROPY_READER_POSIX or MICROPY_READER_FATFS then lexer.c now provides an implementation of mp_lexer_new_from_file using the mp_reader_new_file function.
1 parent 511c083 commit e5ef15a

10 files changed

Lines changed: 16 additions & 151 deletions

File tree

cc3200/application.mk

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,6 @@ APP_STM_SRC_C = $(addprefix stmhal/,\
162162
import.c \
163163
input.c \
164164
irq.c \
165-
lexerfatfs.c \
166165
moduselect.c \
167166
pybstdio.c \
168167
)

esp8266/main.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -109,17 +109,13 @@ void user_init(void) {
109109
system_init_done_cb(init_done);
110110
}
111111

112-
mp_lexer_t *fat_vfs_lexer_new_from_file(const char *filename);
113112
mp_import_stat_t fat_vfs_import_stat(const char *path);
114113

114+
#if !MICROPY_VFS_FAT
115115
mp_lexer_t *mp_lexer_new_from_file(const char *filename) {
116-
#if MICROPY_VFS_FAT
117-
return fat_vfs_lexer_new_from_file(filename);
118-
#else
119-
(void)filename;
120116
return NULL;
121-
#endif
122117
}
118+
#endif
123119

124120
mp_import_stat_t mp_import_stat(const char *path) {
125121
#if MICROPY_VFS_FAT

esp8266/mpconfigport.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
#define MICROPY_MEM_STATS (0)
1717
#define MICROPY_DEBUG_PRINTERS (1)
1818
#define MICROPY_DEBUG_PRINTER_DEST mp_debug_print
19-
#define MICROPY_READER_FATFS (1)
19+
#define MICROPY_READER_FATFS (MICROPY_VFS_FAT)
2020
#define MICROPY_ENABLE_GC (1)
2121
#define MICROPY_STACK_CHECK (1)
2222
#define MICROPY_ENABLE_EMERGENCY_EXCEPTION_BUF (1)

extmod/vfs_fat_lexer.c

Lines changed: 0 additions & 83 deletions
This file was deleted.

py/lexer.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -759,6 +759,19 @@ mp_lexer_t *mp_lexer_new_from_str_len(qstr src_name, const char *str, mp_uint_t
759759
return mp_lexer_new(src_name, reader.data, (mp_lexer_stream_next_byte_t)reader.readbyte, (mp_lexer_stream_close_t)reader.close);
760760
}
761761

762+
#if MICROPY_READER_POSIX || MICROPY_READER_FATFS
763+
764+
mp_lexer_t *mp_lexer_new_from_file(const char *filename) {
765+
mp_reader_t reader;
766+
int ret = mp_reader_new_file(&reader, filename);
767+
if (ret != 0) {
768+
return NULL;
769+
}
770+
return mp_lexer_new(qstr_from_str(filename), reader.data, (mp_lexer_stream_next_byte_t)reader.readbyte, (mp_lexer_stream_close_t)reader.close);
771+
}
772+
773+
#endif
774+
762775
void mp_lexer_free(mp_lexer_t *lex) {
763776
if (lex) {
764777
if (lex->stream_close) {

py/lexerunix.c

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,4 @@ mp_lexer_t *mp_lexer_new_from_fd(qstr filename, int fd, bool close_fd) {
8585
return mp_lexer_new(filename, fb, (mp_lexer_stream_next_byte_t)file_buf_next_byte, (mp_lexer_stream_close_t)file_buf_close);
8686
}
8787

88-
mp_lexer_t *mp_lexer_new_from_file(const char *filename) {
89-
int fd = open(filename, O_RDONLY);
90-
if (fd < 0) {
91-
return NULL;
92-
}
93-
return mp_lexer_new_from_fd(qstr_from_str(filename), fd, true);
94-
}
95-
9688
#endif // MICROPY_HELPER_LEXER_UNIX

py/py.mk

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,6 @@ PY_O_BASENAME = \
229229
../extmod/vfs_fat_diskio.o \
230230
../extmod/vfs_fat_file.o \
231231
../extmod/vfs_fat_reader.o \
232-
../extmod/vfs_fat_lexer.o \
233232
../extmod/vfs_fat_misc.o \
234233
../extmod/utime_mphal.o \
235234
../extmod/uos_dupterm.o \

stmhal/Makefile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,6 @@ SRC_C = \
154154
modusocket.c \
155155
modnetwork.c \
156156
import.c \
157-
lexerfatfs.c \
158157
extint.c \
159158
usrsw.c \
160159
rng.c \

stmhal/lexerfatfs.c

Lines changed: 0 additions & 35 deletions
This file was deleted.

teensy/lexerfatfs.c

Lines changed: 0 additions & 15 deletions
This file was deleted.

0 commit comments

Comments
 (0)