-
Notifications
You must be signed in to change notification settings - Fork 683
Move jerry-core API implementations and headers into dedicated subdirectories #1793
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
Move jerry-core API implementations and headers into dedicated subdirectories #1793
Conversation
On top of the main commit, the PR contains an extra patch to speculatively adapt all |
@akosthekiss I am thinking slightly differently about
Or
|
jerry-core/include/jerryscript.h
Outdated
bool jerry_debugger_is_connected (void); | ||
void jerry_debugger_stop (void); | ||
void jerry_debugger_continue (void); | ||
void jerry_debugger_stop_at_breakpoint (bool enable_stop_at_breakpoint); |
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 don't like this change. Why did you removed jerryscript-debugger.h
?
I don't like merging debugger api to main api as well. Debugger is an extension, although it is so tightly coupled to the core it is not in a separate directory, but it is still an extension. |
@@ -16,7 +16,7 @@ | |||
#include <stdlib.h> | |||
#include <stdio.h> | |||
|
|||
#include "jerry-core/jerryscript.h" | |||
#include "jerry-core/include/jerryscript.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.
This is so deep. What about creating a jerry-include top level directory and put the public api there.
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 "user error". The build system of ESP8266 should add "jerry-core/include" to the include path and then #include "jerryscript.h"
only. Actually, even before this PR, the ESP8266 build system should have added "jerry-core" to the include path and never ever have anything like #include "jerry-core/xxxxx"
in the code. But I did not want to go into rewriting the build systems of any of targets. (Where the build system was correctly written, no changes in the code was necessary -- see particle, riot-stm32f4, zephyr.)
Come to think of it, jerry debugger api could be an extension to jerry! Yes, the key functions are in the trunk but the whole concept of the debugger is an extension. Promise (#1796) could be an extension as well. @jiangzidong what do you think of that? |
I think Promise should be in the same position as string/number/boolean, because they are all JS builtin object. Do you mean to put every builtin-object related APIs into jerry-ext? |
Good point. Ok, keep promise in top level. |
@glistening I've two arguments against conditionalizing the debugger-related functions:
This is very much aligned with other optional features. E.g., all snapshot-related API functions work this way. They are always part of the API, but if the built library does not support snapshots, they don't do anything. @zherczeg @LaszloLango My motivation for merging jerryscript-debugger.h into jerryscript.h was the above-mentioned analogy with snapshots. The debugger functions are always present API functions, only their implementation depends on the availability of a feature. That sounds very core to me. (Changing perspective: if debugger API function declarations should be in a separate header, should snapshot-related functions also be in a separate header?) |
@akosthekiss I agree that not using the conditional guards in public header is better. Then, what about keep the |
To myself, it is unlikely to help to reduce the binary or runtime memory usage by getting rid of @akosthekiss What do you mean by
Anyway, although I am personally not familiar with declarations in public header that have no definitions in library itself. However, if it is accepted convention, I will accept this convention. |
@akosthekiss following that logic everything is core, since everything depends on the internals of JerryScript. Functions in jerryscript-debugger.h are debug specific functions, and there is no reason for them to be available in the main API. |
Sorry, that was ambiguous. What I meant was that bool
jerry_debugger_is_connected (void)
{
#ifdef JERRY_DEBUGGER
return JERRY_CONTEXT (debugger_flags) & JERRY_DEBUGGER_CONNECTED;
#else
return false;
#endif /* JERRY_DEBUGGER */
} /* jerry_debugger_is_connected */ This is how So, no jerry-core API function is ever missing. Even if some features are disabled in a build, all API functions are callable -- but not necessarily do anything meaningful. This ensures that linking always succeeds. And it is possible to check during execution whether a feature is available or not (via |
@akosthekiss Thank you for clear explanation. |
Please, elaborate. I'm not sure I know what "everything" means here. Right now, the engine (the jerry-core library) has 3 public headers:
My point is, that I see no difference between jerryscript.h and jerryscript-debugger.h because both headers declare API of the engine. The debugger support is not just an extension of the engine, at least not in the sense of the jerry-ext library, because it is not possible to implement its functionality outside / on top of the engine. That's why I've brought up the snapshot analogy: snapshot saving/execution is not a mandatory part of the engine, you can opt in or out; but it is impossible to implement snapshot saving/execution outside of the engine (outside of jerry-core). IMHO:
|
@akosthekiss Here is my understanding: If it is impossible to implement some feature outside of jerry-core, it will be part of jerry-core even when it is optional feature. ( Hereafter I will call this feature core-extension to distinguish other extension (user-extension). in this comment. ) Here are my opinions on core-extensions
|
Actually, any approach can work with me if we apply that approach consistently. Where I disagreed with fellow reviewers was that right now the debugger API/header was treated differently than the rest, although I could not find the reason for that (analysis above). There are several options to chose from:
Any of the above works with me, just let's keep things consistent. Or convince me that we shouldn't ( @zherczeg @LaszloLango :) ) Note to self (and to all interested parties): option 2, when applied consistently (i.e., splitting out snapshot-related function declarations), is a breaking change, as library users will have to add an extra
I wouldn't plan function removal for this patch, although I agree that because of the goals of jerryscript, we should aim at zero overhead. Note 1: not including those functions with dummy implementation is a breaking change (users who could link before may not link afterwards). Note 2 (or a question): "removed by using macro like assert statement", I'll have to ask for some explanation this, I'm not sure how this would look like. |
It is hard to judge the effect of choices. I would prefer the 1st option if the size of the header will not grow too large. But if it is, I would prefer the 3rd. |
I've added a commit that implements option 3 so that we can compare it against option 1. So, the question is, which variant to keep? |
@akosthekiss you convinced me. The first was better. :) I agree with @zherczeg
I think it isn't too big if we merge and it is easier for Jerry users to use only one header. |
Another idea: what about making multiple headers, and jerryscript,h includes them all (it has no other code than including the other headers). So people need to include only one file, but we can separate type declarations, functions prototypes better. |
@zherczeg we may consider that too, but I think that could be done in a follow-up work. |
It has already done in this patch. |
@zherczeg sure. My bad. Too many open PRs :) |
@zherczeg Sorry, I'm a bit confused now. The current status of this PR (all 3 commits together) implement option 3 (see above; non-optional jerry-core API in jerryscript.h, feature-dependent APIs in jerryscript-FEATURE.h). But two recent comments seem to conflict with this and with each other: "what about making multiple headers, and jerryscript,h includes them all (it has no other code than including the other headers)" vs "It has already done in this patch". Note (for option 3, and similar variants): if feature APIs are split out into separate headers which are included by jerryscript.h, then either they cannot be used directly (i.e., user must not include jerryscript-snapshot.h directly) or these feature headers must include jerryscript.h, too (because API function declarations may need types defined in jerryscript.h; that's how jerryscript-snapshot.h looks right now; works, but it's not nice, IMHO). |
Yes, users can only include jerryscript.h. The current API would be moved to jerryscript-api.h, which would be the first file in the include list of jerryscript.h. The rest is already in the patch, so this is little work. |
I've updated the PR according to the latest comments (added a 4th commit that splits out the main API into a new header). |
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.
LGTM
jerry-core/include/jerryscript.h
Outdated
|
||
#include "jerryscript-api.h" | ||
#include "jerryscript-snapshot.h" | ||
#include "jerryscript-debugger.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.
Btw should be in alphabetic order.
@akosthekiss @zherczeg, |
@LaszloLango both -api.h and -core.h are OK with me. (-common.h looks a bit strange to me) |
I like the -core postfix. or -base. |
…ectories Moved all public API headers under the `jerry-core/include` directory. This makes installing all the public headers easier. Also, should we have new public headers in the future, their installation will be automatic, there will be no need to update the build files. Moreover, this aligns better with the structure of other libraries in the project (in those cases, public headers always reside in `<library>/include`). Moved all public API implementations under the `jerry-core/api` directory. This cleans up the root directory of `jerry-core`, moving all implementation code under "modules", i.e., subdirectories. This also makes the future splitting of the big and monolithic `jerry.c` along features easier, if needed. (Debugger and snapshot-related functions are already in separate sources.) Notes: * `jerryscript.h` is split up to separate header files along feature boundaries. These new headers are included by `jerryscript.h`, so this is not a breaking change but header modularization only. * `jerry-snapshot.h` is still under `jerry-core/api`, keeping it as a non-public header. * This commit also adapts all targets to the include path change. JerryScript-DCO-1.0-Signed-off-by: Akos Kiss [email protected]
I've changed jerryscript-api.h to -core.h and squashed all commits. |
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.
LGTM
Merged debugger-related public API declarations from
jerryscript-debugger.h
tojerryscript.h
. It's part of theengine's public API, there is no need to force the users of the
library to include yet another header.
Moved all public API headers under the
jerry-core/include
directory. This makes installing all the public headers easier.
Also, should we have new public headers in the future (not probable
but possible), their installation will be automatic, there will be
no need to update the build files. Moreover, this aligns better
with the structure of other libraries in the project (in those
cases, public headers always reside in
<library>/include
).Moved all public API implementations under the
jerry-core/api
directory. This cleans up the root directory of
jerry-core
,moving all implementation code under "modules", i.e.,
subdirectories. This also makes the future splitting of the big and
monolithic
jerry.c
along features easier, if needed. (Debuggerand snapshot-related functions are already in separate sources.)
Note:
jerry-snapshot.h
is still underjerry-core/api
, keepingit as a non-public header.
JerryScript-DCO-1.0-Signed-off-by: Akos Kiss [email protected]