-
Notifications
You must be signed in to change notification settings - Fork 2.1k
sys/js: initial support of RIOT <-> javascript API mapping #7796
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
Conversation
|
needs #6000 |
| @@ -1 +1,12 @@ | |||
| print("Hello from JerryScript!"); | |||
| print("Hello from JerryScript!!!!"); | |||
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.
Real important change ^^!!!!
|
Let me know if this isn't WIP anymore. |
Actually, this is more "Request for comments". I don't know enough javascript to say if the API makes sense (from a javascript conventions perspective)... |
|
|
||
| js_xtimer_t *js_xtimer = (js_xtimer_t *) native_p; | ||
| xtimer_remove(&js_xtimer->xtimer); | ||
| free(js_xtimer); |
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.
@kaspar030 isn't jerryscript freeing this js_xtimer block?
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.
Well, jerryscript garbage-collects the javascript timer object. If that happens to be a "native" object, it calls that native object's free_cb, which happens to be this function.
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.
yeah, I see. But why is it required to call free()? Shouldn't the js memory manager free the whole block?
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.
No, when the native timer object is created (using js_object_native_create()), the js_xtimer_t is malloc'ed outside jerryscript's heap (so we still have control over it). Thus our binding code both allocateds and frees the object.
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.
ok, I see ;)
|
Very nice! I like it.
On the other side, at some point could be nice to have a tiny RIOT-JS framework focused in IoT scenarios. But for now, I think the idea is ok and would be nice to have it merged. After that, it's easier to work in the a better API. |
|
Thanks a lot for the feedback!
Sure! It was just very convenient to write lib.js in Javascript. :)
Difficult. Jerryscript uses non-trivial pointer compression in order to keep memory usage down, so this is not a matter of just mapping "js_malloc" to "tlsf_malloc", and might turn out counter-productive. (TLSF also eats >3kB just for house keeping in its default configuration). |
I will give it a try and let you know ;)
I see |
|
@kaspar030 if you like the idea in #8533, there could be a |
|
just noticed something weird in native: There's is a Script Error here. |
|
@kaspar030 have you checked JERRY_SYSTEM_ALLOCATOR? It forces js to use system's malloc, as seen here |
|
|
||
| static void js_callback_cleanup(js_callback_t *js_callback) | ||
| { | ||
| DEBUG("release %lu\n", callback); |
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.
sed 's/callback/js_callback'
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.
(and add ->callback.object?)
|
what is WIP here? |
|
@emmanuelsearch It looks like there are changes requested. Needs resolution, I suppose. |
|
|
||
| led.write(1); | ||
|
|
||
| button.on_threshold(0, function(){led.write(0); return true;}, saul.op.EQ); |
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.
@kaspar030 how about showing some timer function too, for documentation purposes ;)
Something more or less like below, i.e. blink if you press the button?
blink = function () {
while (1) {
value += 1 % 2;
this.led.write(value);
t = timer.setTimeout(this.blink, 500000);
}
}
button.on_threshold(0, this.blink}, saul.op.EQ);
|
@kaspar030 may I open a rework of the event handler part, and then gradually add the remaining parts of the lib.js file? |
ping @kaspar030 |
Sure. What's wrong with this? |
Nothing wrong. Just add Doxygen labels, patch pointed out errors and reduce the scope to speed up the merge. What do you think? |
|
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you want me to ignore this issue, please mark it with the "State: don't stale" label. Thank you for your contributions. |
|
@kaspar030 any plans to work on this in the near future? |
|
I won't work on this anymore. |
This pull requests adds the foundation for accessing RIOT's API through javascript.
Currently available are timers and saul.
It uses the event system introduced in #6000 in order to asynchronously pass e.g., interrupts into javascript (whose state cannot be modified while it is running).
This is WIP as we need to agree on the concept, and licenses and documentation still missing.
Waiting for #7794, #6000.