-
-
Notifications
You must be signed in to change notification settings - Fork 1
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
Add class support and function wrappers #7
Conversation
Always abort on jerryscript exception (no point in calling exit) Enable assertions and messages in debug builds Emit log messages to flash
Eliminating use of raw C API provides some isolation from upstream changes
Natural integer storage in ECMA is limited: ECMA_INTEGER_NUMBER_MAX = 0x7ffffff = 134217727 ECMA_INTEGER_NUMBER_MIN = -0x7fffff = -8388607 With float64 disabled, standard integer numbers outside this range aren't represented accurately. Floating point generally seems broken without it as well.
@mikee47 Fantastic PR! I really enjoy your work! |
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.
@slaff Just some extra thoughts, in particular the VirtualMachine class seems un-necessary. Let me know what you think , can submit another PR if you agree?
@@ -4,29 +4,30 @@ | |||
* http://github.com/SmingHub/Sming | |||
* All files of the Sming Core are provided under the LGPL v3 license. | |||
* | |||
* Jsvm.h | |||
* VirtualMachine.h |
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.
I'm not sure we really need a VirtualMachine
class at all since it contains no state. We could instead place these methods as regular functions.
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.
Let me know what you think , can submit another PR if you agree?
.. We could instead place these methods as regular functions.
Ok, let's have it this way.
{ | ||
static const char* null_str = "\\u0000"; |
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.
I'm not sure why the original implementation of this bothered display NULL differently, can't think of any particular reason (other than debugging I guess). It complicated the code so just removed it.
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.
define BuildAndRun | ||
$(MAKE) snap-clean && MODULE="$1.$3" $(MAKE) JERRY_COMPACT_PROFILE=$2 SMING_RELEASE=$4 run | ||
endef | ||
|
||
.PHONY: execute | ||
execute: | ||
$(call BuildAndRun,minimal,1,debug,0) | ||
$(call BuildAndRun,minimal,1,release,1) | ||
$(call BuildAndRun,es.next,0,debug,0) | ||
$(call BuildAndRun,es.next,0,release,1) |
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.
Names don't appear correctly in appveyor! We just get 'minimal.debug' twice... Investigating...
/** | ||
* @brief Function to register event listeners | ||
* @code {.javascript} | ||
* | ||
* event = { | ||
* name => "TEMP_CHANGE", | ||
* params = { | ||
* }, | ||
* "origin" => "The\Creator\Of\The\Event" | ||
* }; | ||
* |
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.
The "origin" property sticks out a bit here. Weird value too! Purpose?
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.
There idea is the following: If you have two or more temperature sensors may be you would like to know which one sent the event. And the "origin" property can be used to provide that information. The value of the property is free text so it can be just temp1
or cpu/temp
and extern/temp1
.
jsVm.registerFunction("addEventListener", addEventListener); | ||
vm.registerFunction("addEventListener", addEventListener); |
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.
As above, this could translate into JS::global().registerFunction(...)
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.
Let's have it as suggested.
if(!jsVm.load(main_snap)) { | ||
if(!vm.load(main_snap)) { |
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.
JS::loadSnapshot(...)
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.
Agreed.
if(!jsVm.runFunction("init")) { | ||
if(!vm.runFunction("init")) { |
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.
JS::global().runFunction(...)
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.
Agreed too.
Add Jerryscript type classes and function support
C++ wrapper classes deal with object lifetime management
Simplifies code, try to make usage as easy and natural as possible
Avoid use of raw C API in applications provides some isolation from upstream changes.
Classes are inline (mostly) so should add little to no overhead to jerryscript API.
External functions can be implemented using classes.
This is enabled using macros to declare/define wrapper functions which check parameter count
and thunk raw jerryscript values into their class equivalents (with zero overhead).
Don't disable float64 support
Floating point numbers don't work at all and 32-bit integers aren't handled correctly.
This is because natural integer storage in ECMA is limited:
Larger values are stored as floating-point.
Sort out jerryscript debugging
Add test application
CI runs this with both minimal/es.next profiles and in debug/release builds.
Focus is on correct code operation and ensuring absence of memory leaks in jerryscript heap.