mirror of
https://github.com/jerryscript-project/jerryscript.git
synced 2025-12-15 16:29:21 +00:00
targets: zephyr: Reinstate "print" function and error printing. (#1851)
Re-add "print" function following resent refactors when it was moved from jerry-core to jerry-ext. This is done in particular to keep detailed messages on errors. JerryScript-DCO-1.0-Signed-off-by: Paul Sokolovsky paul.sokolovsky@linaro.org
This commit is contained in:
parent
557fa5006c
commit
b51b6824bb
@ -34,7 +34,7 @@ ZEPHYRLIB = $(ZEPHYR_BASE)/lib
|
|||||||
TARGET_ZEPHYR ?= ./targets/zephyr
|
TARGET_ZEPHYR ?= ./targets/zephyr
|
||||||
SOURCE_DIR = $(TARGET_ZEPHYR)/src
|
SOURCE_DIR = $(TARGET_ZEPHYR)/src
|
||||||
|
|
||||||
export JERRY_INCLUDE = $(CURDIR)/jerry-core/include
|
export JERRY_INCLUDE = -I$(CURDIR)/jerry-core/include -I$(CURDIR)/jerry-ext/include
|
||||||
|
|
||||||
MDEF_FILE = $(realpath $(SOURCE_DIR)/../prj.mdef)
|
MDEF_FILE = $(realpath $(SOURCE_DIR)/../prj.mdef)
|
||||||
CONF_FILE = $(realpath $(SOURCE_DIR)/../prj.conf)
|
CONF_FILE = $(realpath $(SOURCE_DIR)/../prj.conf)
|
||||||
|
|||||||
@ -24,7 +24,7 @@ export BOARD
|
|||||||
TARGET_ZEPHYR ?= ./targets/zephyr
|
TARGET_ZEPHYR ?= ./targets/zephyr
|
||||||
TARGET_ZEPHYR_SRC_DIR = $(TARGET_ZEPHYR)/src
|
TARGET_ZEPHYR_SRC_DIR = $(TARGET_ZEPHYR)/src
|
||||||
|
|
||||||
TYPE ?= jerry-core
|
COMPONENTS ?= jerry-core jerry-ext
|
||||||
JERRYHEAP ?= 16
|
JERRYHEAP ?= 16
|
||||||
JERRYPROFILE ?= minimal
|
JERRYPROFILE ?= minimal
|
||||||
|
|
||||||
@ -61,9 +61,9 @@ EXT_CFLAGS += -D_XOPEN_SOURCE=700
|
|||||||
|
|
||||||
EXT_CFLAGS += -Wno-error=conversion
|
EXT_CFLAGS += -Wno-error=conversion
|
||||||
|
|
||||||
EXTERNAL_LIB = $(INTERM)/lib/libjerry-core.a
|
EXTERNAL_LIB = $(INTERM)/lib/libjerry-core.a $(INTERM)/lib/libjerry-ext.a
|
||||||
|
|
||||||
LIBS = jerry-core
|
LIBS = jerry-core jerry-ext
|
||||||
|
|
||||||
BUILD_CONFIG = O="$(OUTPUT)" V=$(V) USER_LIBS="$(LIBS)" USER_LIB_INCLUDE_DIR="-L $(CURDIR)/$(INTERM)/lib" TARGET_ZEPHYR=$(TARGET_ZEPHYR)
|
BUILD_CONFIG = O="$(OUTPUT)" V=$(V) USER_LIBS="$(LIBS)" USER_LIB_INCLUDE_DIR="-L $(CURDIR)/$(INTERM)/lib" TARGET_ZEPHYR=$(TARGET_ZEPHYR)
|
||||||
|
|
||||||
@ -94,7 +94,7 @@ endif
|
|||||||
-DJERRY_LIBC=OFF \
|
-DJERRY_LIBC=OFF \
|
||||||
$(EXT_JERRY_FLAGS)
|
$(EXT_JERRY_FLAGS)
|
||||||
|
|
||||||
make -C $(INTERM) $(TYPE)$(VARIETY) V=1
|
make -C $(INTERM) $(COMPONENTS) V=1
|
||||||
|
|
||||||
$(OUTPUT)/Makefile.export: $(OUTPUT)/include/config/auto.conf
|
$(OUTPUT)/Makefile.export: $(OUTPUT)/include/config/auto.conf
|
||||||
make -f $(TARGET_ZEPHYR)/Makefile $(BUILD_CONFIG) outputexports
|
make -f $(TARGET_ZEPHYR)/Makefile $(BUILD_CONFIG) outputexports
|
||||||
|
|||||||
@ -17,6 +17,6 @@ $(info Compiling application)
|
|||||||
endif
|
endif
|
||||||
|
|
||||||
# Adding path for jerry script APIs
|
# Adding path for jerry script APIs
|
||||||
ZEPHYRINCLUDE += -I$(JERRY_INCLUDE)
|
ZEPHYRINCLUDE += $(JERRY_INCLUDE)
|
||||||
|
|
||||||
obj-y += main-zephyr.o getline-zephyr.o jerry-port.o
|
obj-y += main-zephyr.o getline-zephyr.o jerry-port.o
|
||||||
|
|||||||
@ -72,3 +72,13 @@ jerry_port_get_time_zone (jerry_time_zone_t *tz_p)
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
} /* jerry_port_get_time_zone */
|
} /* jerry_port_get_time_zone */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provide the implementation of jerryx_port_handler_print_char.
|
||||||
|
* Uses 'printf' to print a single character to standard output.
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
jerryx_port_handler_print_char (char c) /**< the character to print */
|
||||||
|
{
|
||||||
|
printf ("%c", c);
|
||||||
|
} /* jerryx_port_handler_print_char */
|
||||||
|
|||||||
@ -22,9 +22,28 @@
|
|||||||
#include "getline-zephyr.h"
|
#include "getline-zephyr.h"
|
||||||
|
|
||||||
#include "jerryscript.h"
|
#include "jerryscript.h"
|
||||||
|
#include "jerryscript-port.h"
|
||||||
|
#include "jerryscript-ext/handler.h"
|
||||||
|
|
||||||
static jerry_value_t print_function;
|
static jerry_value_t print_function;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Register a JavaScript function in the global object.
|
||||||
|
*/
|
||||||
|
static void
|
||||||
|
register_js_function (const char *name_p, /**< name of the function */
|
||||||
|
jerry_external_handler_t handler_p) /**< function callback */
|
||||||
|
{
|
||||||
|
jerry_value_t result_val = jerryx_handler_register_global ((const jerry_char_t *) name_p, handler_p);
|
||||||
|
|
||||||
|
if (jerry_value_has_error_flag (result_val))
|
||||||
|
{
|
||||||
|
jerry_port_log (JERRY_LOG_LEVEL_WARNING, "Warning: failed to register '%s' method.", name_p);
|
||||||
|
}
|
||||||
|
|
||||||
|
jerry_release_value (result_val);
|
||||||
|
} /* register_js_function */
|
||||||
|
|
||||||
static int shell_cmd_handler (char *source_buffer)
|
static int shell_cmd_handler (char *source_buffer)
|
||||||
{
|
{
|
||||||
jerry_value_t ret_val;
|
jerry_value_t ret_val;
|
||||||
@ -69,6 +88,7 @@ void main (void)
|
|||||||
|
|
||||||
zephyr_getline_init ();
|
zephyr_getline_init ();
|
||||||
jerry_init (JERRY_INIT_EMPTY);
|
jerry_init (JERRY_INIT_EMPTY);
|
||||||
|
register_js_function ("print", jerryx_handler_print);
|
||||||
jerry_value_t global_obj_val = jerry_get_global_object ();
|
jerry_value_t global_obj_val = jerry_get_global_object ();
|
||||||
|
|
||||||
jerry_value_t print_func_name_val = jerry_create_string ((jerry_char_t *) "print");
|
jerry_value_t print_func_name_val = jerry_create_string ((jerry_char_t *) "print");
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user