pmp-p / micropython-ports-wasm

*experimental* wasm micropython port *not a fork* for Pythons Everywhere
http://pmp-p.github.io/layout.html
37 stars 1 forks source link

REPL #3

Open amirgon opened 5 years ago

amirgon commented 5 years ago

Hi, Nice work! Any chance for an online REPL, just to get the feel of it?

pmp-p commented 5 years ago

hi, the runtime stays alive so you can call Module._PyRun_SimpleString() whenever you want like this

~~function repl(str) { var cs = allocate(intArrayFromString(str), 'i8', ALLOC_STACK); Module._PyRun_SimpleString(cs) Module._free(cs) }~~

edit/ use PyRun_SimpleString(text), data will be put in shared memory and will get interpreted next screen refresh.

and you can redirect ouput with some logic in function term_impl(text) which defaults to :
stdout.value += text

non async-repl are not possible (yet) in wasm without dealing with emterpreting and pthreads which is not compatible with dynamic linking. async repl like i use for cpython need some more work in core cf https://github.com/micropython/micropython/issues/3217

pmp-p commented 5 years ago

REPL still have issues

so would need EMTERPRETER but it slows down everything.

The way i see it, raise a special exception SyncIOError from those commands.

Then delegate the offending code block to an async handler written for the REPL : so would just have to write "await sleep()" or "await input()" directly in the repl.

it can be solved as cpython 3.8 https://bugs.python.org/issue34616 or hacked https://github.com/pmp-p/aioprompt

pmp-p commented 4 years ago

issues with synchronous bytecode can be solved in wapy ( https://github.com/pmp-p/wapy demo: https://pmp-p.github.io/wapy/minide/ ), using generators and aio.suspend() to wrap blocking system calls but not with micropython/cpython vm.

There's also an issue left open about utf-8 https://github.com/micropython/micropython/issues/2789 that impact event driven repl too.

pmp-p commented 4 years ago

@amirgon , could the LittleVGL code for bidi input replace partially the repl input loop ?

amirgon commented 4 years ago

@amirgon , could the LittleVGL code for bidi input replace partially the repl input loop ?

Do you mean using the lvgl gui to replace the console? I don't think there is widget in lvgl which can give you the same features. Possibly with a text box and handling keyboard events for history, completion etc. Why do you need bidi input?

pmp-p commented 4 years ago

@amirgon there's a need for bidi+utf-8 input editing in the REPL, but actually micropython repl handler discards UTF-8 and only do LTR / ascii in simplified vt100 mode. I don't mean the GUI just the line-editing bidi unicode logic (which i expect to be small and optimized in LVGL).

web simulators and xterm.js + webserial connected to real boards would need that.

amirgon commented 4 years ago

I don't mean the GUI just the line-editing bidi unicode logic (which i expect to be small and optimized in LVGL).

lvgl has functions for processing utf8 and bidi characters, but I'm not sure this is what you are looking for. For example, _lv_bidi_process receives a logical utf8 string and returns its visual representation taking into account RTL, LTR, neutral characters etc. But this is not line editing, only string conversion.

For actual line editing (inserting text in the middle of a line, text selection, etc.) you would need to translate visual and logical positions _lv_bidi_get_logical_pos, _lv_bidi_get_visual_pos when drawing the text on the label, and I'm not sure this is how a terminal emulators work.

In fact, in lvgl we still have bugs and it still doesn't work correctly on multiline text and with text selection.

pmp-p commented 4 years ago

Thx for the pointers !

it still doesn't work correctly on multiline text and with text selection.

it would not matter much since repl is single line with no selection