mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-19 00:37:25 +01:00
[python] Adding mp_hal_input
This commit is contained in:
committed by
EmilieNumworks
parent
1b6d798eef
commit
651d5715e4
@@ -184,7 +184,7 @@ python/src/extmod/modurandom.o: SFLAGS += -DMP_QSTR_urandom="MP_QSTR_random"
|
||||
|
||||
port_objs += $(addprefix python/port/,\
|
||||
port.o \
|
||||
import_helper.o\
|
||||
builtins.o\
|
||||
interrupt_helper.o \
|
||||
modkandinsky.o \
|
||||
modkandinsky_impl.o \
|
||||
|
||||
28
python/port/builtins.c
Normal file
28
python/port/builtins.c
Normal file
@@ -0,0 +1,28 @@
|
||||
#include "py/builtin.h"
|
||||
#include "py/obj.h"
|
||||
#include <string.h>
|
||||
#include "mphalport.h"
|
||||
|
||||
mp_obj_t mp_builtin_open(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs) {
|
||||
return mp_const_none;
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_KW(mp_builtin_open_obj, 1, mp_builtin_open);
|
||||
|
||||
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);
|
||||
}
|
||||
/*vstr_t line;
|
||||
vstr_init(&line, 16);
|
||||
int ret = mp_hal_readline(&line, "");
|
||||
if (ret == CHAR_CTRL_C) {
|
||||
nlr_raise(mp_obj_new_exception(&mp_type_KeyboardInterrupt));
|
||||
}
|
||||
if (line.len == 0 && ret == CHAR_CTRL_D) {
|
||||
nlr_raise(mp_obj_new_exception(&mp_type_EOFError));
|
||||
}
|
||||
*/
|
||||
const char * input = mp_hal_input();
|
||||
return mp_obj_new_str(input, strlen(input), false);
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_builtin_input_obj, 0, 1, mp_builtin_input);
|
||||
@@ -176,6 +176,7 @@ Q(hex)
|
||||
Q(id)
|
||||
Q(imag)
|
||||
Q(index)
|
||||
Q(input)
|
||||
Q(insert)
|
||||
Q(int)
|
||||
Q(isalpha)
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
#include "py/builtin.h"
|
||||
#include "py/obj.h"
|
||||
|
||||
mp_obj_t mp_builtin_open(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs) {
|
||||
return mp_const_none;
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_KW(mp_builtin_open_obj, 1, mp_builtin_open);
|
||||
@@ -76,7 +76,8 @@ typedef long mp_off_t;
|
||||
|
||||
// extra built in names to add to the global namespace
|
||||
#define MICROPY_PORT_BUILTINS \
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_open), (mp_obj_t)&mp_builtin_open_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_open), (mp_obj_t)&mp_builtin_open_obj }, \
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_input), (mp_obj_t)&mp_builtin_input_obj },
|
||||
|
||||
// We need to provide a declaration/definition of alloca()
|
||||
#include <alloca.h>
|
||||
|
||||
@@ -4,5 +4,6 @@
|
||||
extern int mp_interrupt_char;
|
||||
void mp_hal_set_interrupt_char(int c);
|
||||
void mp_keyboard_interrupt(void);
|
||||
const char * mp_hal_input(void);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -170,3 +170,8 @@ void mp_hal_stdout_tx_strn_cooked(const char * str, size_t len) {
|
||||
assert(sCurrentExecutionEnvironment != nullptr);
|
||||
sCurrentExecutionEnvironment->printText(str, len);
|
||||
}
|
||||
|
||||
const char * mp_hal_input() {
|
||||
assert(sCurrentExecutionEnvironment != nullptr);
|
||||
return sCurrentExecutionEnvironment->input();
|
||||
}
|
||||
|
||||
@@ -13,6 +13,9 @@ public:
|
||||
ExecutionEnvironment();
|
||||
static ExecutionEnvironment * currentExecutionEnvironment();
|
||||
void runCode(const char * );
|
||||
virtual const char * input() {
|
||||
return nullptr;
|
||||
}
|
||||
virtual void displaySandbox() {
|
||||
}
|
||||
virtual void printText(const char * text, size_t length) {
|
||||
@@ -31,5 +34,6 @@ void registerScriptProvider(ScriptProvider * s);
|
||||
// mp_lexer_new_from_file -> Ask the context about a file
|
||||
// mp_import_stat
|
||||
// mp_hal_stdout_tx_strn_cooked -> Tell the context Python printed text
|
||||
// mp_hal_input
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user