Akos Kiss 91e976f8c7 Move jerry-core API implementations and headers into dedicated subdirectories (#1793)
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 akiss@inf.u-szeged.hu
2017-05-04 15:28:24 +02:00

91 lines
2.5 KiB
C++

/* Copyright JS Foundation and other contributors, http://js.foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "mbed.h"
#include "rtos.h"
#include "jerry-core/include/jerryscript.h"
#include "jerryscript-mbed-event-loop/EventLoop.h"
#include "jerryscript-mbed-util/js_source.h"
#include "jerryscript-mbed-library-registry/registry.h"
#include "jerryscript-mbed-launcher/launcher.h"
#include "jerryscript-mbed-launcher/setup.h"
#include "jerry-targetjs.h"
DECLARE_JS_CODES;
/**
* load_javascript
*
* Parse and run javascript files specified in jerry-targetjs.h
*/
static int load_javascript() {
for (int src = 0; js_codes[src].source; src++) {
LOG_PRINT("running js file %s\r\n", js_codes[src].name);
const jerry_char_t* code = reinterpret_cast<const jerry_char_t*>(js_codes[src].source);
const size_t length = js_codes[src].length;
jerry_value_t parsed_code = jerry_parse(code, length, false);
if (jerry_value_has_error_flag(parsed_code)) {
LOG_PRINT_ALWAYS("jerry_parse failed [%s]\r\n", js_codes[src].name);
jsmbed_js_exit();
return -1;
}
jerry_value_t returned_value = jerry_run(parsed_code);
if (jerry_value_has_error_flag(returned_value)) {
LOG_PRINT_ALWAYS("jerry_run failed [%s]\r\n", js_codes[src].name);
jsmbed_js_exit();
return -1;
}
jerry_release_value(parsed_code);
jerry_release_value(returned_value);
}
return 0;
}
int jsmbed_js_init() {
jerry_init_flag_t flags = JERRY_INIT_EMPTY;
jerry_init(flags);
jsmbed_js_load_magic_strings();
mbed::js::LibraryRegistry::getInstance().register_all();
return 0;
}
void jsmbed_js_exit() {
jerry_cleanup();
}
void jsmbed_js_launch() {
jsmbed_js_init();
puts(" JerryScript in mbed\r\n");
puts(" build date: " __DATE__ " \r\n");
if (load_javascript() == 0) {
mbed::js::event_loop();
}
}