diff --git a/docs/03.API-EXAMPLE.md b/docs/03.API-EXAMPLE.md index c5feb2e3d5..bac532e62b 100644 --- a/docs/03.API-EXAMPLE.md +++ b/docs/03.API-EXAMPLE.md @@ -177,7 +177,7 @@ The following example function will output a JavaScript value: #include #include "jerryscript.h" -#include "jerry-port.h" +#include "jerryscript-port.h" static void print_value (const jerry_value_t value) @@ -247,7 +247,7 @@ Shell operation can be described with the following loop: #include #include "jerryscript.h" -#include "jerry-port.h" +#include "jerryscript-port.h" static void print_value (const jerry_value_t); diff --git a/docs/05.PORT-API.md b/docs/05.PORT-API.md index fe49f0c3f8..ead5276c42 100644 --- a/docs/05.PORT-API.md +++ b/docs/05.PORT-API.md @@ -116,7 +116,7 @@ This section describes a basic port implementation which was created for Unix ba ```c #include -#include "jerry-port.h" +#include "jerryscript-port.h" /** * Default implementation of jerry_port_fatal. @@ -131,7 +131,7 @@ void jerry_port_fatal (jerry_fatal_code_t code) ```c #include -#include "jerry-port.h" +#include "jerryscript-port.h" /** * Provide console message implementation for the engine. @@ -168,7 +168,7 @@ jerry_port_log (jerry_log_level_t level, /**< log level */ ```c #include -#include "jerry-port.h" +#include "jerryscript-port.h" /** * Default implementation of jerry_port_get_time_zone. diff --git a/jerry-core/CMakeLists.txt b/jerry-core/CMakeLists.txt index 498f62e836..4fdd2e6559 100644 --- a/jerry-core/CMakeLists.txt +++ b/jerry-core/CMakeLists.txt @@ -270,4 +270,4 @@ foreach(EXT_LIB ${EXTERNAL_LINK_LIBS}) endforeach() install(TARGETS ${JERRY_CORE_NAME} DESTINATION lib) -install(FILES jerry-api.h jerryscript.h jerry-port.h DESTINATION include) +install(FILES jerryscript.h jerryscript-port.h jerry-api.h jerry-port.h DESTINATION include) diff --git a/jerry-core/debugger/jerry-debugger-ws.c b/jerry-core/debugger/jerry-debugger-ws.c index efe433afdc..29e3603c4b 100644 --- a/jerry-core/debugger/jerry-debugger-ws.c +++ b/jerry-core/debugger/jerry-debugger-ws.c @@ -22,7 +22,7 @@ #include "jcontext.h" #include "jerry-debugger.h" -#include "jerry-port.h" +#include "jerryscript-port.h" /** * Debugger socket communication port. diff --git a/jerry-core/debugger/jerry-debugger.c b/jerry-core/debugger/jerry-debugger.c index 8d6d7bab30..36c10759c4 100644 --- a/jerry-core/debugger/jerry-debugger.c +++ b/jerry-core/debugger/jerry-debugger.c @@ -21,7 +21,7 @@ #include "ecma-objects.h" #include "jcontext.h" #include "jerry-debugger.h" -#include "jerry-port.h" +#include "jerryscript-port.h" /** * Type cast the debugger send buffer into a specific type. diff --git a/jerry-core/ecma/operations/ecma-jobqueue.c b/jerry-core/ecma/operations/ecma-jobqueue.c index 1d13457ae6..5189cd15e6 100644 --- a/jerry-core/ecma/operations/ecma-jobqueue.c +++ b/jerry-core/ecma/operations/ecma-jobqueue.c @@ -19,7 +19,7 @@ #include "ecma-jobqueue.h" #include "ecma-objects.h" #include "ecma-promise-object.h" -#include "jerry-port.h" +#include "jerryscript-port.h" #ifndef CONFIG_DISABLE_ES2015_PROMISE_BUILTIN diff --git a/jerry-core/jerry-port.h b/jerry-core/jerry-port.h index 466d04c7fe..fe6bc37d33 100644 --- a/jerry-core/jerry-port.h +++ b/jerry-core/jerry-port.h @@ -16,145 +16,8 @@ #ifndef JERRY_PORT_H #define JERRY_PORT_H -#include -#include -#include +#pragma message ("using jerry-port.h directly is deprecated, please use jerryscript-port.h") -#ifdef __cplusplus -extern "C" -{ -#endif /* __cplusplus */ +#include "jerryscript-port.h" -/** \addtogroup jerry_port Jerry engine port - * @{ - */ - -/* - * Termination Port API - * - * Note: - * It is questionable whether a library should be able to terminate an - * application. However, as of now, we only have the concept of completion - * code around jerry_parse and jerry_run. Most of the other API functions - * have no way of signaling an error. So, we keep the termination approach - * with this port function. - */ - -/** - * Error codes - */ -typedef enum -{ - ERR_OUT_OF_MEMORY = 10, - ERR_SYSCALL = 11, - ERR_REF_COUNT_LIMIT = 12, - ERR_FAILED_INTERNAL_ASSERTION = 120 -} jerry_fatal_code_t; - -/** - * Signal the port that jerry experienced a fatal failure from which it cannot - * recover. - * - * @param code gives the cause of the error. - * - * Note: - * Jerry expects the function not to return. - * - * Example: a libc-based port may implement this with exit() or abort(), or both. - */ -void jerry_port_fatal (jerry_fatal_code_t code); - -/* - * I/O Port API - */ - -/** - * Print a string to the console. The function should implement a printf-like - * interface, where the first argument specifies a format string on how to - * stringify the rest of the parameter list. - * - * This function is only called with strings coming from the executed ECMAScript - * wanting to print something as the result of its normal operation. - * - * It should be the port that decides what a "console" is. - * - * Example: a libc-based port may implement this with vprintf(). - */ -void jerry_port_console (const char *format, ...) __attribute__ ((format (printf, 1, 2))); - -/** - * Jerry log levels. The levels are in severity order - * where the most serious levels come first. - */ -typedef enum -{ - JERRY_LOG_LEVEL_ERROR, /**< the engine will terminate after the message is printed */ - JERRY_LOG_LEVEL_WARNING, /**< a request is aborted, but the engine continues its operation */ - JERRY_LOG_LEVEL_DEBUG, /**< debug messages from the engine, low volume */ - JERRY_LOG_LEVEL_TRACE /**< detailed info about engine internals, potentially high volume */ -} jerry_log_level_t; - -/** - * Display or log a debug/error message. The function should implement a printf-like - * interface, where the first argument specifies the log level - * and the second argument specifies a format string on how to stringify the rest - * of the parameter list. - * - * This function is only called with messages coming from the jerry engine as - * the result of some abnormal operation or describing its internal operations - * (e.g., data structure dumps or tracing info). - * - * It should be the port that decides whether error and debug messages are logged to - * the console, or saved to a database or to a file. - * - * Example: a libc-based port may implement this with vfprintf(stderr) or - * vfprintf(logfile), or both, depending on log level. - */ -void jerry_port_log (jerry_log_level_t level, const char *format, ...) __attribute__ ((format (printf, 2, 3))); - -/* - * Date Port API - */ - -/** - * Jerry time zone structure - */ -typedef struct -{ - int offset; /**< minutes from west */ - int daylight_saving_time; /**< daylight saving time (1 - DST applies, 0 - not on DST) */ -} jerry_time_zone_t; - -/** - * Get timezone and daylight saving data - * - * @return true - if success - * false - otherwise - */ -bool jerry_port_get_time_zone (jerry_time_zone_t *tz_p); - -/** - * Get system time - * - * @return milliseconds since Unix epoch - */ -double jerry_port_get_current_time (void); - -#ifndef CONFIG_DISABLE_ES2015_PROMISE_BUILTIN - -#define JERRY_PORT_ENABLE_JOBQUEUE - -typedef uint32_t (*jerry_job_handler_t) (void *); - -void jerry_port_jobqueue_enqueue (jerry_job_handler_t handler, void *job_p); - -#endif /* !CONFIG_DISABLE_ES2015_PROMISE_BUILTIN */ - -/** - * @} - */ - -#ifdef __cplusplus -} -#endif /* __cplusplus */ #endif /* !JERRY_PORT_H */ diff --git a/jerry-core/jerryscript-port.h b/jerry-core/jerryscript-port.h new file mode 100644 index 0000000000..89152a6c35 --- /dev/null +++ b/jerry-core/jerryscript-port.h @@ -0,0 +1,160 @@ +/* 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. + */ + +#ifndef JERRYSCRIPT_PORT_H +#define JERRYSCRIPT_PORT_H + +#include +#include +#include + +#ifdef __cplusplus +extern "C" +{ +#endif /* __cplusplus */ + +/** \addtogroup jerry_port Jerry engine port + * @{ + */ + +/* + * Termination Port API + * + * Note: + * It is questionable whether a library should be able to terminate an + * application. However, as of now, we only have the concept of completion + * code around jerry_parse and jerry_run. Most of the other API functions + * have no way of signaling an error. So, we keep the termination approach + * with this port function. + */ + +/** + * Error codes + */ +typedef enum +{ + ERR_OUT_OF_MEMORY = 10, + ERR_SYSCALL = 11, + ERR_REF_COUNT_LIMIT = 12, + ERR_FAILED_INTERNAL_ASSERTION = 120 +} jerry_fatal_code_t; + +/** + * Signal the port that jerry experienced a fatal failure from which it cannot + * recover. + * + * @param code gives the cause of the error. + * + * Note: + * Jerry expects the function not to return. + * + * Example: a libc-based port may implement this with exit() or abort(), or both. + */ +void jerry_port_fatal (jerry_fatal_code_t code); + +/* + * I/O Port API + */ + +/** + * Print a string to the console. The function should implement a printf-like + * interface, where the first argument specifies a format string on how to + * stringify the rest of the parameter list. + * + * This function is only called with strings coming from the executed ECMAScript + * wanting to print something as the result of its normal operation. + * + * It should be the port that decides what a "console" is. + * + * Example: a libc-based port may implement this with vprintf(). + */ +void jerry_port_console (const char *format, ...) __attribute__ ((format (printf, 1, 2))); + +/** + * Jerry log levels. The levels are in severity order + * where the most serious levels come first. + */ +typedef enum +{ + JERRY_LOG_LEVEL_ERROR, /**< the engine will terminate after the message is printed */ + JERRY_LOG_LEVEL_WARNING, /**< a request is aborted, but the engine continues its operation */ + JERRY_LOG_LEVEL_DEBUG, /**< debug messages from the engine, low volume */ + JERRY_LOG_LEVEL_TRACE /**< detailed info about engine internals, potentially high volume */ +} jerry_log_level_t; + +/** + * Display or log a debug/error message. The function should implement a printf-like + * interface, where the first argument specifies the log level + * and the second argument specifies a format string on how to stringify the rest + * of the parameter list. + * + * This function is only called with messages coming from the jerry engine as + * the result of some abnormal operation or describing its internal operations + * (e.g., data structure dumps or tracing info). + * + * It should be the port that decides whether error and debug messages are logged to + * the console, or saved to a database or to a file. + * + * Example: a libc-based port may implement this with vfprintf(stderr) or + * vfprintf(logfile), or both, depending on log level. + */ +void jerry_port_log (jerry_log_level_t level, const char *format, ...) __attribute__ ((format (printf, 2, 3))); + +/* + * Date Port API + */ + +/** + * Jerry time zone structure + */ +typedef struct +{ + int offset; /**< minutes from west */ + int daylight_saving_time; /**< daylight saving time (1 - DST applies, 0 - not on DST) */ +} jerry_time_zone_t; + +/** + * Get timezone and daylight saving data + * + * @return true - if success + * false - otherwise + */ +bool jerry_port_get_time_zone (jerry_time_zone_t *tz_p); + +/** + * Get system time + * + * @return milliseconds since Unix epoch + */ +double jerry_port_get_current_time (void); + +#ifndef CONFIG_DISABLE_ES2015_PROMISE_BUILTIN + +#define JERRY_PORT_ENABLE_JOBQUEUE + +typedef uint32_t (*jerry_job_handler_t) (void *); + +void jerry_port_jobqueue_enqueue (jerry_job_handler_t handler, void *job_p); + +#endif /* !CONFIG_DISABLE_ES2015_PROMISE_BUILTIN */ + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif /* __cplusplus */ +#endif /* !JERRYSCRIPT_PORT_H */ diff --git a/jerry-core/jrt/jrt.h b/jerry-core/jrt/jrt.h index d5181aa0cb..c667a0dc43 100644 --- a/jerry-core/jrt/jrt.h +++ b/jerry-core/jrt/jrt.h @@ -20,7 +20,7 @@ #include #include "jerryscript.h" -#include "jerry-port.h" +#include "jerryscript-port.h" #include "jrt-types.h" /* diff --git a/jerry-main/main-unix-minimal.c b/jerry-main/main-unix-minimal.c index abe233b2c2..fc6409607a 100644 --- a/jerry-main/main-unix-minimal.c +++ b/jerry-main/main-unix-minimal.c @@ -16,7 +16,7 @@ #include #include "jerryscript.h" -#include "jerry-port-default.h" +#include "jerryscript-port.h" /** * Maximum size of source code / snapshots buffer diff --git a/jerry-main/main-unix.c b/jerry-main/main-unix.c index c3555f8b2f..160ae29078 100644 --- a/jerry-main/main-unix.c +++ b/jerry-main/main-unix.c @@ -19,8 +19,8 @@ #include #include "jerryscript.h" -#include "jerry-port.h" -#include "jerry-port-default.h" +#include "jerryscript-port.h" +#include "jerryscript-port-default.h" /** * Maximum command line arguments number diff --git a/targets/curie_bsp/jerry_app/quark/main.c b/targets/curie_bsp/jerry_app/quark/main.c index 25ed481395..ee5a08fa1d 100644 --- a/targets/curie_bsp/jerry_app/quark/main.c +++ b/targets/curie_bsp/jerry_app/quark/main.c @@ -30,8 +30,8 @@ #include "infra/wdt_helper.h" #include "jerryscript.h" +#include "jerryscript-port.h" #include "string.h" -#include "jerry-port.h" #include "zephyr.h" #include "microkernel/task.h" diff --git a/targets/curie_bsp/source/curie-bsp-port.c b/targets/curie_bsp/source/curie-bsp-port.c index 3719d201e0..0a52d9d27a 100644 --- a/targets/curie_bsp/source/curie-bsp-port.c +++ b/targets/curie_bsp/source/curie-bsp-port.c @@ -18,7 +18,7 @@ #include #include #include -#include "jerry-port.h" +#include "jerryscript-port.h" /** * Provide console message implementation for the engine. diff --git a/targets/default/jerry-port-default-date.c b/targets/default/jerry-port-default-date.c index 72b785ab2a..6bdf768741 100644 --- a/targets/default/jerry-port-default-date.c +++ b/targets/default/jerry-port-default-date.c @@ -17,8 +17,8 @@ #include #endif -#include "jerry-port.h" -#include "jerry-port-default.h" +#include "jerryscript-port.h" +#include "jerryscript-port-default.h" /** * Default implementation of jerry_port_get_time_zone. diff --git a/targets/default/jerry-port-default-fatal.c b/targets/default/jerry-port-default-fatal.c index ae25e785e5..cce8e94db6 100644 --- a/targets/default/jerry-port-default-fatal.c +++ b/targets/default/jerry-port-default-fatal.c @@ -15,8 +15,8 @@ #include -#include "jerry-port.h" -#include "jerry-port-default.h" +#include "jerryscript-port.h" +#include "jerryscript-port-default.h" static bool abort_on_fail = false; diff --git a/targets/default/jerry-port-default-io.c b/targets/default/jerry-port-default-io.c index c3b5062c68..dfd7f1d7e7 100644 --- a/targets/default/jerry-port-default-io.c +++ b/targets/default/jerry-port-default-io.c @@ -15,8 +15,8 @@ #include -#include "jerry-port.h" -#include "jerry-port-default.h" +#include "jerryscript-port.h" +#include "jerryscript-port-default.h" /** * Actual log level diff --git a/targets/default/jerry-port-default-jobqueue.c b/targets/default/jerry-port-default-jobqueue.c index 183239177b..d5a577858c 100644 --- a/targets/default/jerry-port-default-jobqueue.c +++ b/targets/default/jerry-port-default-jobqueue.c @@ -14,8 +14,8 @@ */ #include "jerryscript.h" -#include "jerry-port.h" -#include "jerry-port-default.h" +#include "jerryscript-port.h" +#include "jerryscript-port-default.h" #include "jmem.h" #include "jrt.h" diff --git a/targets/default/jerry-port-default.h b/targets/default/jerryscript-port-default.h similarity index 90% rename from targets/default/jerry-port-default.h rename to targets/default/jerryscript-port-default.h index e614c5c69c..1e8bb02632 100644 --- a/targets/default/jerry-port-default.h +++ b/targets/default/jerryscript-port-default.h @@ -13,11 +13,11 @@ * limitations under the License. */ -#ifndef JERRY_PORT_DEFAULT_H -#define JERRY_PORT_DEFAULT_H +#ifndef JERRYSCRIPT_PORT_DEFAULT_H +#define JERRYSCRIPT_PORT_DEFAULT_H #include "jerryscript.h" -#include "jerry-port.h" +#include "jerryscript-port.h" #include @@ -49,4 +49,4 @@ jerry_value_t jerry_port_jobqueue_run (void); #ifdef __cplusplus } #endif /* __cplusplus */ -#endif /* !JERRY_PORT_DEFAULT_H */ +#endif /* !JERRYSCRIPT_PORT_DEFAULT_H */ diff --git a/targets/esp8266/user/jerry_port.c b/targets/esp8266/user/jerry_port.c index e6e48f341a..f64e339cc7 100644 --- a/targets/esp8266/user/jerry_port.c +++ b/targets/esp8266/user/jerry_port.c @@ -17,7 +17,7 @@ #include #include -#include "jerry-core/jerry-port.h" +#include "jerry-core/jerryscript-port.h" int ets_putc (int); /** diff --git a/targets/mbed/source/port/jerry_port.c b/targets/mbed/source/port/jerry_port.c index 18c163a05e..1261156d35 100644 --- a/targets/mbed/source/port/jerry_port.c +++ b/targets/mbed/source/port/jerry_port.c @@ -18,7 +18,7 @@ #include #include -#include "jerry-core/jerry-port.h" +#include "jerry-core/jerryscript-port.h" #include "mbed-hal/us_ticker_api.h" diff --git a/targets/mbedos5/source/jerry_port_mbed.c b/targets/mbedos5/source/jerry_port_mbed.c index 62b7794249..c7c10372a5 100644 --- a/targets/mbedos5/source/jerry_port_mbed.c +++ b/targets/mbedos5/source/jerry_port_mbed.c @@ -18,7 +18,7 @@ #include #include -#include "jerry-core/jerry-port.h" +#include "jerry-core/jerryscript-port.h" #include "us_ticker_api.h" diff --git a/targets/nuttx-stm32f4/jerry_main.c b/targets/nuttx-stm32f4/jerry_main.c index fa7cc54ba7..f37bc23cc3 100644 --- a/targets/nuttx-stm32f4/jerry_main.c +++ b/targets/nuttx-stm32f4/jerry_main.c @@ -19,7 +19,7 @@ #include #include "jerryscript.h" -#include "jerry-port.h" +#include "jerryscript-port.h" #include "jmem.h" /** diff --git a/targets/zephyr/src/jerry-port.c b/targets/zephyr/src/jerry-port.c index bba6a6cd17..3ffe1806d8 100644 --- a/targets/zephyr/src/jerry-port.c +++ b/targets/zephyr/src/jerry-port.c @@ -17,7 +17,7 @@ #include -#include "jerry-port.h" +#include "jerryscript-port.h" /** * Provide console message implementation for the engine.