Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
micropython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
xpstem
micropython
Commits
d92898a3
Commit
d92898a3
authored
Jun 01, 2017
by
Damien George
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
unix: Convert to use core-provided version of built-in import().
parent
6ff0ecff
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
16 additions
and
42 deletions
+16
-42
unix/input.c
unix/input.c
+2
-41
unix/mpconfigport.h
unix/mpconfigport.h
+1
-1
unix/mphalport.h
unix/mphalport.h
+13
-0
No files found.
unix/input.c
View file @
d92898a3
...
...
@@ -37,32 +37,8 @@
#include "lib/mp-readline/readline.h"
#endif
#if MICROPY_USE_READLINE == 0
char
*
prompt
(
char
*
p
)
{
#if MICROPY_USE_READLINE == 1
// MicroPython supplied readline
vstr_t
vstr
;
vstr_init
(
&
vstr
,
16
);
mp_hal_stdio_mode_raw
();
int
ret
=
readline
(
&
vstr
,
p
);
mp_hal_stdio_mode_orig
();
if
(
ret
!=
0
)
{
vstr_clear
(
&
vstr
);
if
(
ret
==
CHAR_CTRL_D
)
{
// EOF
printf
(
"
\n
"
);
return
NULL
;
}
else
{
printf
(
"
\n
"
);
char
*
line
=
malloc
(
1
);
line
[
0
]
=
'\0'
;
return
line
;
}
}
vstr_null_terminated_str
(
&
vstr
);
char
*
line
=
malloc
(
vstr
.
len
+
1
);
memcpy
(
line
,
vstr
.
buf
,
vstr
.
len
+
1
);
vstr_clear
(
&
vstr
);
#else
// simple read string
static
char
buf
[
256
];
fputs
(
p
,
stdout
);
...
...
@@ -78,9 +54,9 @@ char *prompt(char *p) {
}
char
*
line
=
malloc
(
l
);
memcpy
(
line
,
buf
,
l
);
#endif
return
line
;
}
#endif
void
prompt_read_history
(
void
)
{
#if MICROPY_USE_READLINE_HISTORY
...
...
@@ -143,18 +119,3 @@ void prompt_write_history(void) {
#endif
#endif
}
STATIC
mp_obj_t
mp_builtin_input
(
size_t
n_args
,
const
mp_obj_t
*
args
)
{
if
(
n_args
==
1
)
{
mp_obj_print
(
args
[
0
],
PRINT_STR
);
}
char
*
line
=
prompt
(
""
);
if
(
line
==
NULL
)
{
nlr_raise
(
mp_obj_new_exception
(
&
mp_type_EOFError
));
}
mp_obj_t
o
=
mp_obj_new_str
(
line
,
strlen
(
line
),
false
);
free
(
line
);
return
o
;
}
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN
(
mp_builtin_input_obj
,
0
,
1
,
mp_builtin_input
);
unix/mpconfigport.h
View file @
d92898a3
...
...
@@ -81,6 +81,7 @@
#define MICROPY_PY_BUILTINS_FROZENSET (1)
#define MICROPY_PY_BUILTINS_COMPILE (1)
#define MICROPY_PY_BUILTINS_NOTIMPLEMENTED (1)
#define MICROPY_PY_BUILTINS_INPUT (1)
#define MICROPY_PY_BUILTINS_POW3 (1)
#define MICROPY_PY_MICROPYTHON_MEM_INFO (1)
#define MICROPY_PY_ALL_SPECIAL_METHODS (1)
...
...
@@ -279,7 +280,6 @@ void mp_unix_mark_exec(void);
#endif
#define MICROPY_PORT_BUILTINS \
{ MP_ROM_QSTR(MP_QSTR_input), MP_ROM_PTR(&mp_builtin_input_obj) }, \
{ MP_ROM_QSTR(MP_QSTR_open), MP_ROM_PTR(&mp_builtin_open_obj) },
#define MP_STATE_PORT MP_STATE_VM
...
...
unix/mphalport.h
View file @
d92898a3
...
...
@@ -34,6 +34,19 @@ void mp_hal_set_interrupt_char(char c);
void
mp_hal_stdio_mode_raw
(
void
);
void
mp_hal_stdio_mode_orig
(
void
);
#if MICROPY_USE_READLINE == 1 && MICROPY_PY_BUILTINS_INPUT
#include "py/misc.h"
#include "lib/mp-readline/readline.h"
// For built-in input() we need to wrap the standard readline() to enable raw mode
#define mp_hal_readline mp_hal_readline
static
inline
int
mp_hal_readline
(
vstr_t
*
vstr
,
const
char
*
p
)
{
mp_hal_stdio_mode_raw
();
int
ret
=
readline
(
vstr
,
p
);
mp_hal_stdio_mode_orig
();
return
ret
;
}
#endif
// TODO: POSIX et al. define usleep() as guaranteedly capable only of 1s sleep:
// "The useconds argument shall be less than one million."
static
inline
void
mp_hal_delay_ms
(
mp_uint_t
ms
)
{
usleep
((
ms
)
*
1000
);
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment