Update jerry-port and jerry-ext (#4907)

Notable changes:
  - Updated and the port API interface, new functions have been added
    and some have been changed. The port library is now cleaned up to
    not have any dependency on jerry-core, as it should be. The port library
    is now strictly a collection of functions that implement
    embedding/platform specific behavior.
  - The default port implementation has been split for windows and unix.
    Implemented port functions have been categorized and reorganized,
    and marked with attribute((weak)) for better reusability.
  - External context allocation has been moved to the port API instead
    of a core API callback. The iterface has also been extended with a
    function to free the allocated context. When external context is
    enabled, jerry_init now automatically calls the port implementation
    to allocate the context and jerry_cleanup automatically calls the port
    to free the context.
  - jerry_port_log has been changed to no longer require formatting to
    be implemented by the port. The reason beind this is that it was vague what
    format specifiers were used by the engine, and in what manner. The port
    function now takes a zero-terminated string, and should only implement
    how the string should be logged.
  - Logging and log message formatting is now handled by the core jerry library
    where it can be implemented as necessary. Logging can be done through a new
    core API function, which uses the port to output the final log message.
  - Log level has been moved into jerry-core, and an API function has
    been added to set the log level. It should be the library that
    filters log messages based on the requested log level, instead of
    logging everything and requiring the user to do so.
  - Module resolving logic has been moved into jerry-core. There's no
    reason to have it in the port library and requiring embedders to
    duplicate the code. It also added an unnecessary dependency on
    jerry-core to the port. Platform specific behavior is still used through
    the port API, like resolving module specifiers, and reading source file
    contents. If necessary, the resolving logic can still be overridden as
    previously.
  - The jerry-ext library has also been cleaned up, and many utility
    functions have been added that previously were implemented in
    jerry-main. This allows easier reusability for some common operations,
    like printing unhandled exceptions or providing a repl console.
  - Debugger interaction with logged/printed messages has been fixed, so
    that it's no longer the port implementations responsibility to send
    the output to the debugger, as the port should have no notion of what a
    debugger is.  The printing and logging functions will now pass the
    result message to the debugger, if connected.
  - Cleaned up TZA handling in the date port implementation, and simplified
    the API function prototype.
  - Moved property access helper functions that use ASCII strings as
    keys from jerry-ext to the core API.

JerryScript-DCO-1.0-Signed-off-by: Dániel Bátyai dbatyai@inf.u-szeged.hu
This commit is contained in:
Dániel Bátyai
2022-01-20 13:53:47 +01:00
committed by GitHub
parent 79fd540ec9
commit ac1c48eeff
170 changed files with 4201 additions and 5698 deletions
+26 -50
View File
@@ -13,55 +13,37 @@
* limitations under the License.
*/
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "jerryscript.h"
#include "jerryscript-port.h"
#include "mbed.h"
/**
* JerryScript log level.
*/
static jerry_log_level_t jerry_log_level = JERRY_LOG_LEVEL_ERROR;
/**
* Sets log level.
*/
void set_log_level (jerry_log_level_t level)
{
jerry_log_level = level;
} /* set_log_level */
/**
* Aborts the program.
*/
void jerry_port_fatal (jerry_fatal_code_t code)
void
jerry_port_fatal (jerry_fatal_code_t code)
{
exit (1);
exit ((int) code);
} /* jerry_port_fatal */
/**
* Provide log message implementation for the engine.
*/
void
jerry_port_log (jerry_log_level_t level, /**< log level */
const char *format, /**< format string */
...) /**< parameters */
jerry_port_log (const char *message_p) /**< message */
{
(void) level; /* ignore log level */
va_list args;
va_start (args, format);
vfprintf (stderr, format, args);
va_end (args);
if (strlen (format) == 1 && format[0] == 0x0a) /* line feed (\n) */
while (*message_p != '\0')
{
printf ("\r"); /* add CR for proper display in serial monitors */
if (*message_p == '\n')
{
/* add CR for proper display in serial monitors */
fputc ('\r', stderr);
}
fputc (*message_p++, stderr);
}
} /* jerry_port_log */
@@ -70,27 +52,28 @@ jerry_port_log (jerry_log_level_t level, /**< log level */
*
* @return 0
*/
double
jerry_port_get_local_time_zone_adjustment (double unix_ms, bool is_utc)
int32_t
jerry_port_local_tza (double unix_ms)
{
/* We live in UTC. */
(void) unix_ms;
return 0;
} /* jerry_port_get_local_time_zone_adjustment */
} /* jerry_port_local_tza */
/**
* Implementation of jerry_port_get_current_time.
* Implementation of jerry_port_current_time.
*
* @return current timer's counter value in milliseconds
*/
double
jerry_port_get_current_time (void)
jerry_port_current_time (void)
{
static uint64_t last_tick = 0;
static time_t last_time = 0;
static uint32_t skew = 0;
uint64_t curr_tick = us_ticker_read (); /* The value is in microseconds. */
time_t curr_time = time(NULL); /* The value is in seconds. */
time_t curr_time = time (NULL); /* The value is in seconds. */
double result = curr_time * 1000;
/* The us_ticker_read () has an overflow for each UINT_MAX microseconds
@@ -100,9 +83,12 @@ jerry_port_get_current_time (void)
* are within the mentioned 71 mins. Above that interval we can assume
* that the milliseconds part of the time is negligibe.
*/
if (curr_time - last_time > (time_t) (((uint32_t) - 1) / 1000000)) {
if (curr_time - last_time > (time_t) (((uint32_t) -1) / 1000000))
{
skew = 0;
} else if (last_tick > curr_tick) {
}
else if (last_tick > curr_tick)
{
skew = (skew + 33) % 1000;
}
result += (curr_tick / 1000 - skew) % 1000;
@@ -110,14 +96,4 @@ jerry_port_get_current_time (void)
last_tick = curr_tick;
last_time = curr_time;
return result;
} /* jerry_port_get_current_time */
/**
* Provide the implementation of jerry_port_print_char.
* Uses 'printf' to print a single character to standard output.
*/
void
jerry_port_print_char (char c) /**< the character to print */
{
printf ("%c", c);
} /* jerry_port_print_char */
} /* jerry_port_current_time */