Skip to content

Commit e103e00

Browse files
committed
[update] lib/utils
1 parent 35a4f3a commit e103e00

File tree

8 files changed

+192
-7
lines changed

8 files changed

+192
-7
lines changed

lib/utils/gchelper.h

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* This file is part of the MicroPython project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2019 Damien P. George
7+
*
8+
* Permission is hereby granted, free of charge, to any person obtaining a copy
9+
* of this software and associated documentation files (the "Software"), to deal
10+
* in the Software without restriction, including without limitation the rights
11+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
* copies of the Software, and to permit persons to whom the Software is
13+
* furnished to do so, subject to the following conditions:
14+
*
15+
* The above copyright notice and this permission notice shall be included in
16+
* all copies or substantial portions of the Software.
17+
*
18+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24+
* THE SOFTWARE.
25+
*/
26+
#ifndef MICROPY_INCLUDED_LIB_UTILS_GCHELPER_H
27+
#define MICROPY_INCLUDED_LIB_UTILS_GCHELPER_H
28+
29+
#include <stdint.h>
30+
31+
uintptr_t gc_helper_get_sp(void);
32+
uintptr_t gc_helper_get_regs_and_sp(uintptr_t *regs);
33+
34+
#endif // MICROPY_INCLUDED_LIB_UTILS_GCHELPER_H

lib/utils/gchelper_m0.s

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
* This file is part of the MicroPython project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2018 Damien P. George
7+
*
8+
* Permission is hereby granted, free of charge, to any person obtaining a copy
9+
* of this software and associated documentation files (the "Software"), to deal
10+
* in the Software without restriction, including without limitation the rights
11+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
* copies of the Software, and to permit persons to whom the Software is
13+
* furnished to do so, subject to the following conditions:
14+
*
15+
* The above copyright notice and this permission notice shall be included in
16+
* all copies or substantial portions of the Software.
17+
*
18+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24+
* THE SOFTWARE.
25+
*/
26+
27+
.syntax unified
28+
.cpu cortex-m0
29+
.thumb
30+
31+
.section .text
32+
.align 2
33+
34+
.global gc_helper_get_regs_and_sp
35+
.type gc_helper_get_regs_and_sp, %function
36+
37+
@ uint gc_helper_get_regs_and_sp(r0=uint regs[10])
38+
gc_helper_get_regs_and_sp:
39+
@ store registers into given array
40+
str r4, [r0, #0]
41+
str r5, [r0, #4]
42+
str r6, [r0, #8]
43+
str r7, [r0, #12]
44+
mov r1, r8
45+
str r1, [r0, #16]
46+
mov r1, r9
47+
str r1, [r0, #20]
48+
mov r1, r10
49+
str r1, [r0, #24]
50+
mov r1, r11
51+
str r1, [r0, #28]
52+
mov r1, r12
53+
str r1, [r0, #32]
54+
mov r1, r13
55+
str r1, [r0, #36]
56+
57+
@ return the sp
58+
mov r0, sp
59+
bx lr
60+
61+
.size gc_helper_get_regs_and_sp, .-gc_helper_get_regs_and_sp

lib/utils/gchelper_m3.s

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*
2+
* This file is part of the MicroPython project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2013-2014 Damien P. George
7+
*
8+
* Permission is hereby granted, free of charge, to any person obtaining a copy
9+
* of this software and associated documentation files (the "Software"), to deal
10+
* in the Software without restriction, including without limitation the rights
11+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
* copies of the Software, and to permit persons to whom the Software is
13+
* furnished to do so, subject to the following conditions:
14+
*
15+
* The above copyright notice and this permission notice shall be included in
16+
* all copies or substantial portions of the Software.
17+
*
18+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24+
* THE SOFTWARE.
25+
*/
26+
27+
.syntax unified
28+
.cpu cortex-m3
29+
.thumb
30+
31+
.section .text
32+
.align 2
33+
34+
.global gc_helper_get_sp
35+
.type gc_helper_get_sp, %function
36+
37+
@ uint gc_helper_get_sp(void)
38+
gc_helper_get_sp:
39+
@ return the sp
40+
mov r0, sp
41+
bx lr
42+
43+
.size gc_helper_get_sp, .-gc_helper_get_sp
44+
45+
46+
.global gc_helper_get_regs_and_sp
47+
.type gc_helper_get_regs_and_sp, %function
48+
49+
@ uint gc_helper_get_regs_and_sp(r0=uint regs[10])
50+
gc_helper_get_regs_and_sp:
51+
@ store registers into given array
52+
str r4, [r0], #4
53+
str r5, [r0], #4
54+
str r6, [r0], #4
55+
str r7, [r0], #4
56+
str r8, [r0], #4
57+
str r9, [r0], #4
58+
str r10, [r0], #4
59+
str r11, [r0], #4
60+
str r12, [r0], #4
61+
str r13, [r0], #4
62+
63+
@ return the sp
64+
mov r0, sp
65+
bx lr
66+
67+
.size gc_helper_get_regs_and_sp, .-gc_helper_get_regs_and_sp

lib/utils/interrupt_char.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
#if MICROPY_KBD_EXCEPTION
3131

32-
int mp_interrupt_char;
32+
int mp_interrupt_char = -1;
3333

3434
void mp_hal_set_interrupt_char(int c) {
3535
if (c != -1) {

lib/utils/mpirq.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,8 @@ void mp_irq_handler(mp_irq_obj_t *self) {
7878
}
7979
gc_unlock();
8080
} else {
81-
#if MICROPY_ENABLE_SCHEDULER
8281
// Schedule call to user function
8382
mp_sched_schedule(self->handler, self->parent);
84-
#endif
8583
}
8684
}
8785
}

lib/utils/pyexec.c

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ STATIC int parse_compile_execute(const void *source, mp_parse_input_kind_t input
8989
// source is a lexer, parse and compile the script
9090
qstr source_name = lex->source_name;
9191
mp_parse_tree_t parse_tree = mp_parse(lex, input_kind);
92-
module_fun = mp_compile(&parse_tree, source_name, MP_EMIT_OPT_NONE, exec_flags & EXEC_FLAG_IS_REPL);
92+
module_fun = mp_compile(&parse_tree, source_name, exec_flags & EXEC_FLAG_IS_REPL);
9393
#else
9494
mp_raise_msg(&mp_type_RuntimeError, "script compilation not supported");
9595
#endif
@@ -482,8 +482,7 @@ int pyexec_friendly_repl(void) {
482482
} else if (ret == CHAR_CTRL_D) {
483483
// exit for a soft reset
484484
mp_hal_stdout_tx_str("\r\n");
485-
//TODO it will occur assert on RT-Thread platform, so comment it
486-
// vstr_clear(&line);
485+
vstr_clear(&line);
487486
return PYEXEC_FORCED_EXIT;
488487
} else if (ret == CHAR_CTRL_E) {
489488
// paste mode
@@ -542,6 +541,18 @@ int pyexec_file(const char *filename) {
542541
return parse_compile_execute(filename, MP_PARSE_FILE_INPUT, EXEC_FLAG_SOURCE_IS_FILENAME);
543542
}
544543

544+
int pyexec_file_if_exists(const char *filename) {
545+
#if MICROPY_MODULE_FROZEN
546+
if (mp_frozen_stat(filename) == MP_IMPORT_STAT_FILE) {
547+
return pyexec_frozen_module(filename);
548+
}
549+
#endif
550+
if (mp_import_stat(filename) != MP_IMPORT_STAT_FILE) {
551+
return 1; // success (no file is the same as an empty file executing without fail)
552+
}
553+
return pyexec_file(filename);
554+
}
555+
545556
#if MICROPY_MODULE_FROZEN
546557
int pyexec_frozen_module(const char *name) {
547558
void *frozen_data;

lib/utils/pyexec.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ extern int pyexec_system_exit;
4646
int pyexec_raw_repl(void);
4747
int pyexec_friendly_repl(void);
4848
int pyexec_file(const char *filename);
49+
int pyexec_file_if_exists(const char *filename);
4950
int pyexec_frozen_module(const char *name);
5051
void pyexec_event_repl_init(void);
5152
int pyexec_event_repl_process_char(int c);

lib/utils/sys_stdio_mphal.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* The MIT License (MIT)
55
*
6-
* Copyright (c) 2013-2017 Damien P. George
6+
* Copyright (c) 2013-2019 Damien P. George
77
*
88
* Permission is hereby granted, free of charge, to any person obtaining a copy
99
* of this software and associated documentation files (the "Software"), to deal
@@ -85,6 +85,17 @@ STATIC mp_uint_t stdio_write(mp_obj_t self_in, const void *buf, mp_uint_t size,
8585
}
8686
}
8787

88+
// TODO NOT IMPLEMENT STDIO_IOCTL ON RT-THREAD YET
89+
// STATIC mp_uint_t stdio_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_t arg, int *errcode) {
90+
// (void)self_in;
91+
// if (request == MP_STREAM_POLL) {
92+
// return mp_hal_stdio_poll(arg);
93+
// } else {
94+
// *errcode = MP_EINVAL;
95+
// return MP_STREAM_ERROR;
96+
// }
97+
// }
98+
8899
STATIC mp_obj_t stdio_obj___exit__(size_t n_args, const mp_obj_t *args) {
89100
return mp_const_none;
90101
}
@@ -112,6 +123,7 @@ STATIC MP_DEFINE_CONST_DICT(stdio_locals_dict, stdio_locals_dict_table);
112123
STATIC const mp_stream_p_t stdio_obj_stream_p = {
113124
.read = stdio_read,
114125
.write = stdio_write,
126+
// .ioctl = stdio_ioctl,
115127
.is_text = true,
116128
};
117129

@@ -146,6 +158,7 @@ STATIC mp_uint_t stdio_buffer_write(mp_obj_t self_in, const void *buf, mp_uint_t
146158
STATIC const mp_stream_p_t stdio_buffer_obj_stream_p = {
147159
.read = stdio_buffer_read,
148160
.write = stdio_buffer_write,
161+
// .ioctl = stdio_ioctl,
149162
.is_text = false,
150163
};
151164

0 commit comments

Comments
 (0)