kopia lustrzana https://github.com/micropython/micropython
webassembly: Use POSIX write for output and add stderr.
All output is now handled by Emscripten's stdio facility. Signed-off-by: Damien George <damien@micropython.org>pull/13583/head
rodzic
8e3b701dee
commit
ae6bcc9d23
|
@ -25,16 +25,6 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
mergeInto(LibraryManager.library, {
|
mergeInto(LibraryManager.library, {
|
||||||
mp_js_write: function(ptr, len) {
|
|
||||||
const buffer = HEAPU8.subarray(ptr, ptr + len)
|
|
||||||
if (ENVIRONMENT_IS_NODE) {
|
|
||||||
process.stdout.write(buffer);
|
|
||||||
} else {
|
|
||||||
const printEvent = new CustomEvent('micropython-print', { detail: buffer });
|
|
||||||
document.dispatchEvent(printEvent);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
// This string will be emitted directly into the output file by Emscripten.
|
// This string will be emitted directly into the output file by Emscripten.
|
||||||
mp_js_ticks_ms__postset: "var MP_JS_EPOCH = Date.now()",
|
mp_js_ticks_ms__postset: "var MP_JS_EPOCH = Date.now()",
|
||||||
|
|
||||||
|
|
|
@ -46,6 +46,7 @@
|
||||||
#define MICROPY_LONGINT_IMPL (MICROPY_LONGINT_IMPL_MPZ)
|
#define MICROPY_LONGINT_IMPL (MICROPY_LONGINT_IMPL_MPZ)
|
||||||
#define MICROPY_ENABLE_DOC_STRING (1)
|
#define MICROPY_ENABLE_DOC_STRING (1)
|
||||||
#define MICROPY_WARNINGS (1)
|
#define MICROPY_WARNINGS (1)
|
||||||
|
#define MICROPY_ERROR_PRINTER (&mp_stderr_print)
|
||||||
#define MICROPY_FLOAT_IMPL (MICROPY_FLOAT_IMPL_DOUBLE)
|
#define MICROPY_FLOAT_IMPL (MICROPY_FLOAT_IMPL_DOUBLE)
|
||||||
#define MICROPY_USE_INTERNAL_ERRNO (1)
|
#define MICROPY_USE_INTERNAL_ERRNO (1)
|
||||||
#define MICROPY_USE_INTERNAL_PRINTF (0)
|
#define MICROPY_USE_INTERNAL_PRINTF (0)
|
||||||
|
@ -60,7 +61,6 @@
|
||||||
#endif
|
#endif
|
||||||
#define MICROPY_VFS_POSIX (MICROPY_VFS)
|
#define MICROPY_VFS_POSIX (MICROPY_VFS)
|
||||||
#define MICROPY_PY_SYS_PLATFORM "webassembly"
|
#define MICROPY_PY_SYS_PLATFORM "webassembly"
|
||||||
#define MICROPY_PY_SYS_STDFILES (0)
|
|
||||||
|
|
||||||
#define MICROPY_EVENT_POLL_HOOK \
|
#define MICROPY_EVENT_POLL_HOOK \
|
||||||
do { \
|
do { \
|
||||||
|
@ -102,4 +102,6 @@ typedef long mp_off_t;
|
||||||
#define _GNU_SOURCE
|
#define _GNU_SOURCE
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
extern const struct _mp_print_t mp_stderr_print;
|
||||||
|
|
||||||
uint32_t mp_js_random_u32(void);
|
uint32_t mp_js_random_u32(void);
|
||||||
|
|
|
@ -24,12 +24,19 @@
|
||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <unistd.h>
|
||||||
#include "library.h"
|
#include "library.h"
|
||||||
#include "mphalport.h"
|
#include "mphalport.h"
|
||||||
|
|
||||||
|
static void stderr_print_strn(void *env, const char *str, size_t len) {
|
||||||
|
(void)env;
|
||||||
|
write(2, str, len);
|
||||||
|
}
|
||||||
|
|
||||||
|
const mp_print_t mp_stderr_print = {NULL, stderr_print_strn};
|
||||||
|
|
||||||
mp_uint_t mp_hal_stdout_tx_strn(const char *str, size_t len) {
|
mp_uint_t mp_hal_stdout_tx_strn(const char *str, size_t len) {
|
||||||
mp_js_write(str, len);
|
return write(1, str, len);
|
||||||
return len;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void mp_hal_delay_ms(mp_uint_t ms) {
|
void mp_hal_delay_ms(mp_uint_t ms) {
|
||||||
|
|
Ładowanie…
Reference in New Issue