Skip to content
This repository was archived by the owner on Apr 25, 2021. It is now read-only.

Commit 3a7269a

Browse files
committed
OpenPython v1.0 Ready
1 parent b444df3 commit 3a7269a

File tree

13 files changed

+133
-69
lines changed

13 files changed

+133
-69
lines changed

src/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ CFLAGS += -O2 -DNDEBUG
3636
endif
3737

3838

39-
LDFLAGS = -nostdlib -T openpie.ld -Map=$@.map --cref
39+
LDFLAGS = -nostdlib -T openpython.ld -Map=$@.map --cref
4040
LIBS = $(shell $(CC) $(CFLAGS) -print-libgcc-file-name)
4141

4242
# Remove uncalled code from the final image.
@@ -59,7 +59,7 @@ SRC_C = \
5959
modumsgpack.c \
6060
moduvalue.c \
6161
gccollect.c \
62-
openpie_vfs.c \
62+
openpython_vfs.c \
6363
msgpack.c \
6464
syscall.c \
6565

src/build.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
FOLDER = Path(__file__).parent
1616
BASE_FOLDER = FOLDER.parent
1717
OPMOD_PATH = BASE_FOLDER / "opmod"
18-
SOURCE_SYSCALL_TABLE: Path = OPMOD_PATH / "src/main/java/kr/pe/ecmaxp/openpie/arch/consts/OpenPieSystemCallTable.kt"
18+
SOURCE_SYSCALL_TABLE: Path = OPMOD_PATH / "src/main/java/kr/pe/ecmaxp/openpython/arch/consts/OpenPythonSystemCallTable.kt"
1919
TARGET_SYSCALL_TABLE: Path = FOLDER / "syscall_table.h"
20-
TARGET_FOLDER: Path = OPMOD_PATH / "src/main/resources/assets/openpie/firmwares/debug" # TODO: place version
20+
TARGET_FOLDER: Path = OPMOD_PATH / "src/main/resources/assets/openpython/firmwares/debug" # TODO: place version
2121

2222

2323
@dataclass

src/help.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include "py/builtin.h"
22

3-
const char openpie_help_text[] =
4-
"Welcome to MicroPython running under openpie!\n"
3+
const char openpython_help_text[] =
4+
"Welcome to MicroPython running under openpython!\n"
55
"\n"
66
"For further help on a specific object, type help(obj)\n"
77
#if MICROPY_PY_BUILTINS_HELP_MODULES

src/machine.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ void Reset_Handler(void) {
4545
}
4646
}
4747

48-
// OPENPIE_CONTROLLER->PENDING = (uint32_t) &MP_STATE_VM(mp_pending_exception);
49-
// OPENPIE_CONTROLLER->EXCEPTION = (uint32_t) &MP_STATE_VM(mp_kbd_exception);
50-
// OPENPIE_CONTROLLER->INTR_CHAR = (uint32_t) &mp_interrupt_char;
48+
// OPENPYTHON_CONTROLLER->PENDING = (uint32_t) &MP_STATE_VM(mp_pending_exception);
49+
// OPENPYTHON_CONTROLLER->EXCEPTION = (uint32_t) &MP_STATE_VM(mp_kbd_exception);
50+
// OPENPYTHON_CONTROLLER->INTR_CHAR = (uint32_t) &mp_interrupt_char;
5151

5252
// jump to board initialisation
5353
_start();

src/machine.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#ifndef OPENPIE_MACHINE_H
2-
#define OPENPIE_MACHINE_H
1+
#ifndef OPENPYTHON_MACHINE_H
2+
#define OPENPYTHON_MACHINE_H
33

44
#include "py/objexcept.h"
55

@@ -9,4 +9,4 @@ void _exit(int status);
99
void nlr_jump_fail(void *val);
1010
void NORETURN __fatal_error(const char *msg);
1111

12-
#endif // OPENPIE_MACHINE_H
12+
#endif // OPENPYTHON_MACHINE_H

src/modules/bios.py

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,70 @@ def bios():
99
crash("no bios found; install a configured EEPROM with Python")
1010

1111
eeprom = eeproms[0]
12+
if True:
13+
invoke(eeprom, 'setLabel', "EEPROM (micropython)")
14+
invoke(eeprom, 'set', b"""#!micropython
15+
16+
17+
def main():
18+
globals().pop('main')
19+
from ucomponent import invoke, get_list as get_components
20+
from ucomputer import crash, get_computer_address
21+
22+
def component(t):
23+
seq = get_components(t)
24+
return seq[0] if seq else None
25+
26+
def check_bootable(filesystems, address):
27+
return address in filesystems and invoke(address, 'exists', '/init.py')
28+
29+
eeprom = __path__
30+
filesystems = get_components("filesystem")
31+
32+
address = invoke(eeprom, 'getData').decode()
33+
if not check_bootable(filesystems, address):
34+
invoke(__path__, 'setData', b'')
35+
for address in filesystems:
36+
if check_bootable(filesystems, address):
37+
invoke(eeprom, 'setData', address.encode())
38+
break
39+
else:
40+
crash("no bootable medium found")
41+
42+
computer = get_computer_address()
43+
invoke(computer, 'beep', 1000, 0.2)
44+
45+
gpu = component("gpu")
46+
monitor = component("monitor")
47+
if gpu and monitor:
48+
invoke(gpu, "bind", monitor)
49+
50+
def load(address):
51+
handle = invoke(address, 'open', '/init.py', 'r')
52+
buffer = []
53+
54+
try:
55+
while True:
56+
buf = invoke(address, 'read', handle, 4096)
57+
if not buf: break
58+
buffer.append(buf)
59+
finally:
60+
invoke(address, 'close', handle)
61+
handle.dispose()
62+
63+
content = b"".join(buffer)
64+
return content.decode()
65+
66+
content = load(address)
67+
context = {'__name__': '__main__', '__path__': address}
68+
func = compile(content, '/init.py', "exec")
69+
exec(func, context)
70+
71+
72+
if __name__ == '__main__':
73+
main()
74+
""")
75+
1276
data = invoke(eeprom, 'get')
1377
context = {'__name__': '__main__', '__path__': eeprom}
1478

src/mpconfigport.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@
121121
#define MICROPY_PY_BUILTINS_MIN_MAX (1)
122122
#define MICROPY_PY_BUILTINS_POW3 (1)
123123
#define MICROPY_PY_BUILTINS_HELP (1)
124-
#define MICROPY_PY_BUILTINS_HELP_TEXT openpie_help_text
124+
#define MICROPY_PY_BUILTINS_HELP_TEXT openpython_help_text
125125
#define MICROPY_PY_BUILTINS_HELP_MODULES (1)
126126
#define MICROPY_PY___FILE__ (1)
127127
#define MICROPY_PY_MICROPYTHON_MEM_INFO (1)
@@ -203,9 +203,9 @@ extern const struct _mp_print_t debug_print;
203203
#define INT_FMT "%d"
204204

205205
// Machine settings
206-
#define MICROPY_HW_BOARD_NAME "OpenPie"
206+
#define MICROPY_HW_BOARD_NAME "OpenPython"
207207
#define MICROPY_HW_MCU_NAME "Cortex-M0"
208-
#define MICROPY_OPENPIE_VFS (1)
208+
#define MICROPY_OPENPYTHON_VFS (1)
209209

210210
#define MP_SSIZE_MAX (0x7fffffff)
211211
#define MP_NEED_LOG2 (1)
@@ -239,8 +239,8 @@ extern const struct _mp_obj_type_t mp_type_SystemError;
239239
mp_obj_t stderr_hook_obj; \
240240
mp_obj_t object_hook_obj; \
241241

242-
#define mp_type_fileio mp_type_vfs_openpie_fileio
243-
#define mp_type_textio mp_type_vfs_openpie_textio
242+
#define mp_type_fileio mp_type_vfs_openpython_fileio
243+
#define mp_type_textio mp_type_vfs_openpython_textio
244244

245245
#define mp_import_stat mp_vfs_import_stat
246246
#define mp_builtin_open mp_vfs_open

src/msgpack.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#ifndef OPENPIE_UMSGPACK_H
2-
#define OPENPIE_UMSGPACK_H
1+
#ifndef OPENPYTHON_UMSGPACK_H
2+
#define OPENPYTHON_UMSGPACK_H
33

44
#include "py/obj.h"
55
#include "lib/mpack/mpack.h"
@@ -19,4 +19,4 @@ void msgpack_dump_close(mpack_writer_t *writer);
1919
msgpack_result_t msgpack_dumps(mp_obj_t obj);
2020
msgpack_result_t msgpack_args_dumps(size_t n_args, const mp_obj_t *args);
2121

22-
#endif // OPENPIE_UMSGPACK_H
22+
#endif // OPENPYTHON_UMSGPACK_H

src/openpie.ld renamed to src/openpython.ld

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
GNU linker script for OPENPIE
2+
GNU linker script for OpenPython
33
*/
44

55
/* Specify the memory areas */

src/openpie_vfs.c renamed to src/openpython_vfs.c

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -32,35 +32,35 @@
3232
#include "py/runtime.h"
3333
#include "py/stream.h"
3434
#include "py/mperrno.h"
35-
#include "openpie_vfs.h"
36-
#include "openpie_vfs.h"
35+
#include "openpython_vfs.h"
36+
#include "openpython_vfs.h"
3737
#include "syscall.h"
3838

3939

40-
#if MICROPY_OPENPIE_VFS
40+
#if MICROPY_OPENPYTHON_VFS
4141

4242

43-
typedef struct _mp_obj_vfs_openpie_file_t {
43+
typedef struct _mp_obj_vfs_openpython_file_t {
4444
mp_obj_base_t base;
4545
int fd;
46-
} mp_obj_vfs_openpie_file_t;
46+
} mp_obj_vfs_openpython_file_t;
4747

48-
STATIC void check_fd_is_open(const mp_obj_vfs_openpie_file_t *o) {
48+
STATIC void check_fd_is_open(const mp_obj_vfs_openpython_file_t *o) {
4949
if (o->fd == -1) {
5050
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "I/O operation on closed file"));
5151
}
5252
}
5353

54-
STATIC void vfs_openpie_file_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
54+
STATIC void vfs_openpython_file_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
5555
// SVC_FUNCTION_START;
5656
(void) kind;
57-
mp_obj_vfs_openpie_file_t *self = MP_OBJ_TO_PTR(self_in);
57+
mp_obj_vfs_openpython_file_t *self = MP_OBJ_TO_PTR(self_in);
5858

5959
mp_printf(print, "<io.%s fd=%d>", mp_obj_get_type_str(self_in), self->fd);
6060
}
6161

62-
mp_obj_t mp_vfs_openpie_file_open(const mp_obj_type_t *type, mp_obj_t address_in, mp_obj_t path_in, mp_obj_t mode_in) {
63-
mp_obj_vfs_openpie_file_t *o = m_new_obj(mp_obj_vfs_openpie_file_t);
62+
mp_obj_t mp_vfs_openpython_file_open(const mp_obj_type_t *type, mp_obj_t address_in, mp_obj_t path_in, mp_obj_t mode_in) {
63+
mp_obj_vfs_openpython_file_t *o = m_new_obj(mp_obj_vfs_openpython_file_t);
6464
const char *address = mp_obj_str_get_str(address_in);
6565
const char *path = mp_obj_str_get_str(path_in);
6666
const char *mode = mp_obj_str_get_str(mode_in);
@@ -77,7 +77,7 @@ mp_obj_t mp_vfs_openpie_file_open(const mp_obj_type_t *type, mp_obj_t address_in
7777
return MP_OBJ_FROM_PTR(o);
7878
}
7979

80-
STATIC mp_obj_t vfs_openpie_file_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
80+
STATIC mp_obj_t vfs_openpython_file_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
8181
static const mp_arg_t allowed_args[] = {
8282
{MP_QSTR_address, MP_ARG_OBJ | MP_ARG_REQUIRED, {.u_rom_obj = MP_ROM_PTR(&mp_const_none_obj)}},
8383
{MP_QSTR_path, MP_ARG_OBJ | MP_ARG_REQUIRED, {.u_rom_obj = MP_ROM_PTR(&mp_const_none_obj)}},
@@ -86,26 +86,26 @@ STATIC mp_obj_t vfs_openpie_file_make_new(const mp_obj_type_t *type, size_t n_ar
8686

8787
mp_arg_val_t arg_vals[MP_ARRAY_SIZE(allowed_args)];
8888
mp_arg_parse_all_kw_array(n_args, n_kw, args, MP_ARRAY_SIZE(allowed_args), allowed_args, arg_vals);
89-
return mp_vfs_openpie_file_open(type, arg_vals[0].u_obj, arg_vals[1].u_obj, arg_vals[2].u_obj);
89+
return mp_vfs_openpython_file_open(type, arg_vals[0].u_obj, arg_vals[1].u_obj, arg_vals[2].u_obj);
9090
}
9191

92-
STATIC mp_obj_t vfs_openpie_file_fileno(mp_obj_t self_in) {
93-
mp_obj_vfs_openpie_file_t *self = MP_OBJ_TO_PTR(self_in);
92+
STATIC mp_obj_t vfs_openpython_file_fileno(mp_obj_t self_in) {
93+
mp_obj_vfs_openpython_file_t *self = MP_OBJ_TO_PTR(self_in);
9494
check_fd_is_open(self);
9595
return mp_obj_new_int(self->fd);
9696
}
9797

98-
STATIC MP_DEFINE_CONST_FUN_OBJ_1(vfs_openpie_file_fileno_obj, vfs_openpie_file_fileno);
98+
STATIC MP_DEFINE_CONST_FUN_OBJ_1(vfs_openpython_file_fileno_obj, vfs_openpython_file_fileno);
9999

100-
STATIC mp_obj_t vfs_openpie_file___exit__(size_t n_args, const mp_obj_t *args) {
100+
STATIC mp_obj_t vfs_openpython_file___exit__(size_t n_args, const mp_obj_t *args) {
101101
(void) n_args;
102102
return mp_stream_close(args[0]);
103103
}
104104

105-
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(vfs_openpie_file___exit___obj, 4, 4, vfs_openpie_file___exit__);
105+
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(vfs_openpython_file___exit___obj, 4, 4, vfs_openpython_file___exit__);
106106

107-
STATIC mp_uint_t vfs_openpie_file_read(mp_obj_t o_in, void *buf, mp_uint_t size, int *errcode) {
108-
mp_obj_vfs_openpie_file_t *o = MP_OBJ_TO_PTR(o_in);
107+
STATIC mp_uint_t vfs_openpython_file_read(mp_obj_t o_in, void *buf, mp_uint_t size, int *errcode) {
108+
mp_obj_vfs_openpython_file_t *o = MP_OBJ_TO_PTR(o_in);
109109
check_fd_is_open(o);
110110

111111
int count = 0;
@@ -117,8 +117,8 @@ STATIC mp_uint_t vfs_openpie_file_read(mp_obj_t o_in, void *buf, mp_uint_t size,
117117
return count;
118118
}
119119

120-
STATIC mp_uint_t vfs_openpie_file_write(mp_obj_t o_in, const void *buf, mp_uint_t size, int *errcode) {
121-
mp_obj_vfs_openpie_file_t *o = MP_OBJ_TO_PTR(o_in);
120+
STATIC mp_uint_t vfs_openpython_file_write(mp_obj_t o_in, const void *buf, mp_uint_t size, int *errcode) {
121+
mp_obj_vfs_openpython_file_t *o = MP_OBJ_TO_PTR(o_in);
122122
check_fd_is_open(o);
123123
#if MICROPY_PY_OS_DUPTERM
124124
if (o->flag & 1) {
@@ -150,8 +150,8 @@ STATIC mp_uint_t vfs_openpie_file_write(mp_obj_t o_in, const void *buf, mp_uint_
150150
return (mp_uint_t) written;
151151
}
152152

153-
STATIC mp_uint_t vfs_openpie_file_ioctl(mp_obj_t o_in, mp_uint_t request, uintptr_t arg, int *errcode) {
154-
mp_obj_vfs_openpie_file_t *o = MP_OBJ_TO_PTR(o_in);
153+
STATIC mp_uint_t vfs_openpython_file_ioctl(mp_obj_t o_in, mp_uint_t request, uintptr_t arg, int *errcode) {
154+
mp_obj_vfs_openpython_file_t *o = MP_OBJ_TO_PTR(o_in);
155155
check_fd_is_open(o);
156156
int errno;
157157
switch (request) {
@@ -188,7 +188,7 @@ STATIC mp_uint_t vfs_openpie_file_ioctl(mp_obj_t o_in, mp_uint_t request, uintpt
188188
}
189189

190190
STATIC const mp_rom_map_elem_t rawfile_locals_dict_table[] = {
191-
{MP_ROM_QSTR(MP_QSTR_fileno), MP_ROM_PTR(&vfs_openpie_file_fileno_obj)},
191+
{MP_ROM_QSTR(MP_QSTR_fileno), MP_ROM_PTR(&vfs_openpython_file_fileno_obj)},
192192
{MP_ROM_QSTR(MP_QSTR_read), MP_ROM_PTR(&mp_stream_read_obj)},
193193
{MP_ROM_QSTR(MP_QSTR_readinto), MP_ROM_PTR(&mp_stream_readinto_obj)},
194194
{MP_ROM_QSTR(MP_QSTR_readline), MP_ROM_PTR(&mp_stream_unbuffered_readline_obj)},
@@ -199,23 +199,23 @@ STATIC const mp_rom_map_elem_t rawfile_locals_dict_table[] = {
199199
{MP_ROM_QSTR(MP_QSTR_flush), MP_ROM_PTR(&mp_stream_flush_obj)},
200200
{MP_ROM_QSTR(MP_QSTR_close), MP_ROM_PTR(&mp_stream_close_obj)},
201201
{MP_ROM_QSTR(MP_QSTR___enter__), MP_ROM_PTR(&mp_identity_obj)},
202-
{MP_ROM_QSTR(MP_QSTR___exit__), MP_ROM_PTR(&vfs_openpie_file___exit___obj)},
202+
{MP_ROM_QSTR(MP_QSTR___exit__), MP_ROM_PTR(&vfs_openpython_file___exit___obj)},
203203
};
204204

205205
STATIC MP_DEFINE_CONST_DICT(rawfile_locals_dict, rawfile_locals_dict_table);
206206

207207
#if MICROPY_PY_IO_FILEIO
208208
STATIC const mp_stream_p_t fileio_stream_p = {
209-
.read = vfs_openpie_file_read,
210-
.write = vfs_openpie_file_write,
211-
.ioctl = vfs_openpie_file_ioctl,
209+
.read = vfs_openpython_file_read,
210+
.write = vfs_openpython_file_write,
211+
.ioctl = vfs_openpython_file_ioctl,
212212
};
213213

214-
const mp_obj_type_t mp_type_vfs_openpie_fileio = {
214+
const mp_obj_type_t mp_type_vfs_openpython_fileio = {
215215
{&mp_type_type},
216216
.name = MP_QSTR_FileIO,
217-
.print = vfs_openpie_file_print,
218-
.make_new = vfs_openpie_file_make_new,
217+
.print = vfs_openpython_file_print,
218+
.make_new = vfs_openpython_file_make_new,
219219
.getiter = mp_identity_getiter,
220220
.iternext = mp_stream_unbuffered_iter,
221221
.protocol = &fileio_stream_p,
@@ -224,21 +224,21 @@ const mp_obj_type_t mp_type_vfs_openpie_fileio = {
224224
#endif
225225

226226
STATIC const mp_stream_p_t textio_stream_p = {
227-
.read = vfs_openpie_file_read,
228-
.write = vfs_openpie_file_write,
229-
.ioctl = vfs_openpie_file_ioctl,
227+
.read = vfs_openpython_file_read,
228+
.write = vfs_openpython_file_write,
229+
.ioctl = vfs_openpython_file_ioctl,
230230
.is_text = true,
231231
};
232232

233-
const mp_obj_type_t mp_type_vfs_openpie_textio = {
233+
const mp_obj_type_t mp_type_vfs_openpython_textio = {
234234
{&mp_type_type},
235235
.name = MP_QSTR_TextIOWrapper,
236-
.print = vfs_openpie_file_print,
237-
.make_new = vfs_openpie_file_make_new,
236+
.print = vfs_openpython_file_print,
237+
.make_new = vfs_openpython_file_make_new,
238238
.getiter = mp_identity_getiter,
239239
.iternext = mp_stream_unbuffered_iter,
240240
.protocol = &textio_stream_p,
241241
.locals_dict = (mp_obj_dict_t *) &rawfile_locals_dict,
242242
};
243243

244-
#endif // MICROPY_OPENPIE_VFS
244+
#endif // MICROPY_OPENPYTHON_VFS

src/openpie_vfs.h renamed to src/openpython_vfs.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@
2323
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2424
* THE SOFTWARE.
2525
*/
26-
#ifndef MICROPY_INCLUDED_EXTMOD_VFS_OPENPIE_H
27-
#define MICROPY_INCLUDED_EXTMOD_VFS_OPENPIE_H
26+
#ifndef MICROPY_INCLUDED_EXTMOD_VFS_OPENPYTHON_H
27+
#define MICROPY_INCLUDED_EXTMOD_VFS_OPENPYTHON_H
2828

2929
#include "py/lexer.h"
3030
#include "py/obj.h"
3131

32-
extern const mp_obj_type_t mp_type_vfs_openpie_fileio;
33-
extern const mp_obj_type_t mp_type_vfs_openpie_textio;
32+
extern const mp_obj_type_t mp_type_vfs_openpython_fileio;
33+
extern const mp_obj_type_t mp_type_vfs_openpython_textio;
3434

35-
mp_obj_t mp_vfs_openpie_file_open(const mp_obj_type_t *type, mp_obj_t address_in, mp_obj_t path_in, mp_obj_t mode_in);
35+
mp_obj_t mp_vfs_openpython_file_open(const mp_obj_type_t *type, mp_obj_t address_in, mp_obj_t path_in, mp_obj_t mode_in);
3636

37-
#endif // MICROPY_INCLUDED_EXTMOD_VFS_OPENPIE_H
37+
#endif // MICROPY_INCLUDED_EXTMOD_VFS_OPENPYTHON_H

0 commit comments

Comments
 (0)