-
-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Javascript Port #3575
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Javascript Port #3575
Conversation
When I tried to build from this branch, clang kept getting confused and trying to use different versions of header files installed on my system. To get around this I had to make this change to the branch: talljosh@b5d894d |
After an apparently successful build, I get this error when attempting to run it:
|
Now that you mention it I've never tried building the port on another computer. I'll give it a crack when I'm free. |
@talljosh I just successfully built and ran the program on macOS High Sierra without problems. The original work was completed on an Arch Linux system. |
I was building on Ubuntu 16.04 LTS using emsdk-portable from the page you linked. The issue seemed to be that (emsdk's) clang was looking at my system header files ahead of the emsdk header files. The patch I linked fixed this issue. I'm travelling at the moment and not on a machine where I can test this, but I can run it again next week when I'm home, and copy and paste the exact output for you. |
I also had to use the change @talljosh made to get it to compile using the latest trzeci/emscripten docker image. |
This is what I see when I try to build from this branch on Ubuntu 16.04 using the latest emsdk-portable without my change.
|
INC += -I$(TOP) | ||
INC += -I$(BUILD) | ||
|
||
CPP = clang -E |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Question: why not emcc -E
?
@talljosh I'm now getting similar error [stdbool.h not found] which is fixed by your patch. Maybe it's caused by an update? |
@flowergrass If the generated build's working for you I'd put it down to something wrong with my Node setup. I don't regularly use Node, and I didn't check to make sure I wasn't running some outdated Node installation. If it works for someone else, feel free to ignore my report on that. But the build issues will need fixing. |
@flowergrass Yes, the micropython.js file appeared to be functional. I can't say that I tested it much more than making sure the REPL came up and I could print hello world. |
I have some questions: Is there somewhere a demo page? |
void mp_hal_delay_ms(mp_uint_t ms) { | ||
uint32_t start = mp_hal_ticks_ms(); | ||
while (mp_hal_ticks_ms() - start < ms) { | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a busy wait, correct?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is correct. Javascript in most (all?) web browsers does not implement sleep. There are a couple solutions. The simplest is to busy-wait, at the expense of CPU time. If the code is in a web worker, you can launch a synchronous get request against something that will never return a result, with a timeout. Strictly speaking, you can do the same in the main thread too, but that behaviour is deprecated and may not work everywhere forever. Then again, sleeping in the main thread is frowned upon anyway.
The most proper solution is to set a timer to resume, then suspend the VM. Javascript closures make it relatively simple to do, but the rest of the code needs to support it via CPS or similar.
I just found this old entry: https://stackoverflow.com/a/47739532 and there is:
That's small, isn't it? Any news here? |
This was merged in 7d675f3. Sorry it took so long. |
It would be good to make a demo page. If someone wants to attempt it it can be hosted at micropython.org. |
I make an attempt to integrate this port to CommonJS (Node.JS module system) and Webpack. Feel free to give a feedback/PR https://www.npmjs.com/package/micropython |
@rafi16jan you may reach more people if you post about that at https://forum.micropython.org |
@jedie not anything formal, but @embeddedt created a simple proof-of-concept for Micropython (+LittlevGL binding) on https://embeddedt.github.io/lv_micropython/ports/javascript/lvgl.html |
It's still a work in progress. The REPL could use some work (i.e. autocompletion) and it does seem a bit slow compared to pure LittlevGL in the browser. Eventually we're hoping this can be used for prototyping Python GUI applications using LittlevGL. |
MicroPython transmuted into Javascript by Emscripten.