Skip to content

Commit d83035d

Browse files
committed
Fixed builtin file support.
1 parent b4e3565 commit d83035d

3 files changed

Lines changed: 50 additions & 5 deletions

File tree

‎frosted/mpconfigport.h‎

Lines changed: 47 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
*/
2626

2727
// options to control how Micro Python is built
28+
#define MICROPY_PY_IO_BUFFEREDWRITER (1)
2829

2930
#define MICROPY_ALLOC_QSTR_CHUNK_INIT (64)
3031
#define MICROPY_ALLOC_PARSE_RULE_INIT (8)
@@ -40,6 +41,8 @@
4041
#define MICROPY_MEM_STATS (0)
4142
#define MICROPY_DEBUG_PRINTERS (0)
4243
#define MICROPY_HELPER_REPL (1)
44+
#define MICROPY_REPL_EMACS_KEYS (1)
45+
#define MICROPY_REPL_AUTO_INDENT (1)
4346
#define MICROPY_HELPER_LEXER_UNIX (1)
4447
#define MICROPY_ENABLE_SOURCE_LINE (0)
4548
#define MICROPY_ERROR_REPORTING (MICROPY_ERROR_REPORTING_TERSE)
@@ -64,13 +67,13 @@
6467
#define MICROPY_PY_BUILTINS_STR_UNICODE (0)
6568
#define MICROPY_PY_BUILTINS_PROPERTY (0)
6669
#define MICROPY_PY_BUILTINS_MIN_MAX (0)
67-
#define MICROPY_PY___FILE__ (0)
70+
#define MICROPY_PY___FILE__ (1)
6871
#define MICROPY_PY_MICROPYTHON_MEM_INFO (0)
6972
#define MICROPY_READER_POSIX (1)
7073
#define MICROPY_PY_GC (0)
7174
#define MICROPY_PY_GC_COLLECT_RETVAL (0)
7275
#define MICROPY_PY_ARRAY (0)
73-
#define MICROPY_PY_COLLECTIONS (0)
76+
#define MICROPY_PY_COLLECTIONS (1)
7477
#define MICROPY_PY_MATH (0)
7578
#define MICROPY_PY_CMATH (0)
7679
#define MICROPY_PY_IO (1)
@@ -79,8 +82,8 @@
7982
#define MICROPY_PY_SYS (1)
8083
#define MICROPY_PY_SYS_EXIT (1)
8184
#define MICROPY_PY_SYS_PLATFORM "frosted"
82-
#define MICROPY_PY_SYS_MAXSIZE (0)
83-
#define MICROPY_PY_SYS_STDFILES (0)
85+
#define MICROPY_PY_SYS_MAXSIZE (1)
86+
#define MICROPY_PY_SYS_STDFILES (1)
8487
#define MICROPY_PY_CMATH (0)
8588
#define MICROPY_PY_UTIME (1)
8689
#define MICROPY_PY_UERRNO (1)
@@ -91,6 +94,8 @@
9194
#define MICROPY_PY_UHEAPQ (0)
9295
#define MICROPY_PY_UHASHLIB (0)
9396
#define MICROPY_PY_UBINASCII (0)
97+
#define MICROPY_PY_MACHINE (0)
98+
#define MICROPY_PY_MACHINE_PULSE (0)
9499

95100

96101
#define MICROPY_PORT_ROOT_POINTERS \
@@ -111,13 +116,19 @@
111116
#endif
112117

113118
extern const struct _mp_obj_module_t mp_module_os;
119+
extern const struct _mp_obj_module_t mp_module_uos_vfs;
114120
extern const struct _mp_obj_module_t mp_module_uselect;
115121
extern const struct _mp_obj_module_t mp_module_time;
116122
extern const struct _mp_obj_module_t mp_module_termios;
117123
extern const struct _mp_obj_module_t mp_module_socket;
118124
extern const struct _mp_obj_module_t mp_module_ffi;
119125
extern const struct _mp_obj_module_t mp_module_jni;
120126

127+
#if MICROPY_PY_UOS_VFS
128+
#define MICROPY_PY_UOS_VFS_DEF { MP_ROM_QSTR(MP_QSTR_uos_vfs), MP_ROM_PTR(&mp_module_uos_vfs) },
129+
#else
130+
#define MICROPY_PY_UOS_VFS_DEF
131+
#endif
121132
#if MICROPY_PY_FFI
122133
#define MICROPY_PY_FFI_DEF { MP_ROM_QSTR(MP_QSTR_ffi), MP_ROM_PTR(&mp_module_ffi) },
123134
#else
@@ -155,20 +166,24 @@ extern const struct _mp_obj_module_t mp_module_jni;
155166
MICROPY_PY_UTIME_DEF \
156167
MICROPY_PY_SOCKET_DEF \
157168
{ MP_ROM_QSTR(MP_QSTR_uos), MP_ROM_PTR(&mp_module_os) }, \
169+
MICROPY_PY_UOS_VFS_DEF \
158170
MICROPY_PY_USELECT_DEF \
159171
MICROPY_PY_TERMIOS_DEF \
160172

161173
// type definitions for the specific machine
162174

175+
// assume that if we already defined the obj repr then we also defined types
176+
#ifndef MICROPY_OBJ_REPR
163177
#ifdef __LP64__
164178
typedef long mp_int_t; // must be pointer size
165179
typedef unsigned long mp_uint_t; // must be pointer size
166180
#else
167181
// These are definitions for machines where sizeof(int) == sizeof(void*),
168-
// regardless for actual size.
182+
// regardless of actual size.
169183
typedef int mp_int_t; // must be pointer size
170184
typedef unsigned int mp_uint_t; // must be pointer size
171185
#endif
186+
#endif
172187

173188
#define BYTES_PER_WORD sizeof(mp_int_t)
174189

@@ -179,6 +194,33 @@ typedef long long mp_off_t;
179194
typedef long mp_off_t;
180195
#endif
181196

197+
void mp_unix_alloc_exec(mp_uint_t min_size, void** ptr, mp_uint_t *size);
198+
void mp_unix_free_exec(void *ptr, mp_uint_t size);
199+
void mp_unix_mark_exec(void);
200+
#define MP_PLAT_ALLOC_EXEC(min_size, ptr, size) mp_unix_alloc_exec(min_size, ptr, size)
201+
#define MP_PLAT_FREE_EXEC(ptr, size) mp_unix_free_exec(ptr, size)
202+
#ifndef MICROPY_FORCE_PLAT_ALLOC_EXEC
203+
// Use MP_PLAT_ALLOC_EXEC for any executable memory allocation, including for FFI
204+
// (overriding libffi own implementation)
205+
#define MICROPY_FORCE_PLAT_ALLOC_EXEC (1)
206+
#endif
207+
208+
#if MICROPY_PY_OS_DUPTERM
209+
#define MP_PLAT_PRINT_STRN(str, len) mp_hal_stdout_tx_strn_cooked(str, len)
210+
#else
211+
#include <unistd.h>
212+
#define MP_PLAT_PRINT_STRN(str, len) do { ssize_t ret = write(1, str, len); (void)ret; } while (0)
213+
#endif
214+
215+
216+
217+
218+
#define MICROPY_PORT_BUILTINS \
219+
{ MP_ROM_QSTR(MP_QSTR_input), MP_ROM_PTR(&mp_builtin_input_obj) }, \
220+
{ MP_ROM_QSTR(MP_QSTR_open), MP_ROM_PTR(&mp_builtin_open_obj) },
221+
222+
#define MP_STATE_PORT MP_STATE_VM
223+
182224
// We need to provide a declaration/definition of alloca()
183225
#ifdef __FreeBSD__
184226
#include <stdlib.h>

‎py/modio.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ STATIC mp_uint_t bufwriter_write(mp_obj_t self_in, const void *buf, mp_uint_t si
8484
}
8585
// TODO: try to recover from a case of non-blocking stream, e.g. move
8686
// remaining chunk to the beginning of buffer.
87+
(void)out_sz;
8788
assert(out_sz == self->alloc);
8889
self->len = 0;
8990
}
@@ -99,6 +100,7 @@ STATIC mp_obj_t bufwriter_flush(mp_obj_t self_in) {
99100
mp_uint_t out_sz = mp_stream_write_exactly(self->stream, self->buf, self->len, &err);
100101
// TODO: try to recover from a case of non-blocking stream, e.g. move
101102
// remaining chunk to the beginning of buffer.
103+
(void)out_sz;
102104
assert(out_sz == self->len);
103105
self->len = 0;
104106
if (err != 0) {

‎py/modsys.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include "py/objstr.h"
3333
#include "py/objint.h"
3434
#include "py/stream.h"
35+
#include <stdio.h>
3536

3637
#if MICROPY_PY_SYS
3738

0 commit comments

Comments
 (0)