Skip to content

Commit 0e5a2e2

Browse files
author
Levente Orban
committed
Follow the API & build system update in mbed targets
- Update the API changes in mbed targets - Build fix for mbed target after the build system patch. JerryScript-DCO-1.0-Signed-off-by: Levente Orban [email protected]
1 parent 76d42b5 commit 0e5a2e2

File tree

5 files changed

+146
-144
lines changed

5 files changed

+146
-144
lines changed

targets/mbed/Makefile.mbed

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515

1616
# use TAB-8
1717

18-
TYPE = release
1918
TARGET_LIST = k64f stm32f4 stm32f429i nucleo
2019
JERRYHEAP ?= 16
2120

@@ -33,10 +32,9 @@ else ifeq ($(TARGET), nucleo)
3332
TARGET_DIR ?= /media/$(USER)/NODE_F401RE
3433
endif
3534

36-
UPPERC_TARGET = $(shell echo $(TARGET) | tr a-z A-Z)
37-
INTERM = build/obj-mbed-$(TARGET)
38-
OUTPUT = build/bin/$(TYPE).mbed$(TARGET)
39-
COPYTARGET = targets/mbed/libjerry
35+
BUILD_DIR ?= build/mbed
36+
UPPERC_TARGET ?= $(shell echo $(TARGET) | tr a-z A-Z)
37+
COPYTARGET ?= targets/mbed/libjerry
4038

4139
else
4240
$(error This board ($(board)) is not supported!)
@@ -53,25 +51,26 @@ EXT_PORT_DIR := ""
5351
all: jerry js2c yotta
5452

5553
jerry:
56-
mkdir -p $(INTERM)
57-
mkdir -p $(OUTPUT)
5854
mkdir -p $(COPYTARGET)
59-
cmake -B$(INTERM) -H./ \
55+
mkdir -p $(BUILD_DIR)
56+
cmake -B$(BUILD_DIR) -H./ \
6057
-DENABLE_LTO=OFF \
61-
-DENABLE_VALGRIND=OFF \
62-
-DCMAKE_TOOLCHAIN_FILE=build/configs/toolchain_external.cmake \
58+
-DFEATURE_VALGRIND=OFF \
59+
-DCMAKE_TOOLCHAIN_FILE=cmake/toolchain_external.cmake \
60+
-DJERRY_LIBC=OFF \
61+
-DJERRY_CMDLINE=OFF \
6362
-DCOMPILER_DEFAULT_LIBC=ON \
64-
-DEXTERNAL_CMAKE_SYSTEM_PROCESSOR=arm7-m \
63+
-DENABLE_ALL_IN_ONE=OFF \
64+
-DEXTERNAL_CMAKE_SYSTEM_PROCESSOR=armv7l-hf \
6565
-DEXTERNAL_CMAKE_C_COMPILER=arm-none-eabi-gcc \
6666
-DEXTERNAL_CMAKE_C_COMPILER_ID=GNU \
6767
-DEXTERNAL_COMPILE_FLAGS="$(EXT_CFLAGS)" \
68-
-DEXTERNAL_MEM_HEAP_SIZE_KB=$(JERRYHEAP) \
69-
-DEXTERNAL_PORT_DIR=$(EXT_PORT_DIR)
68+
-DMEM_HEAP_SIZE_KB=$(JERRYHEAP) \
7069

71-
make -C $(INTERM) $(TYPE).external
72-
cp `cat $(INTERM)/$(TYPE).external/list` $(OUTPUT)/.
73-
cp $(OUTPUT)/lib$(TYPE).jerry-core.a $(COPYTARGET)/libjerrycore.a
74-
cp $(OUTPUT)/lib$(TYPE).jerry-libm.lib.a $(COPYTARGET)/libjerrylibm.a
70+
make -C$(BUILD_DIR) jerry-core
71+
make -C$(BUILD_DIR) jerry-libm
72+
cp $(BUILD_DIR)/lib/libjerry-core.a $(COPYTARGET)/libjerrycore.a
73+
cp $(BUILD_DIR)/lib/libjerry-libm.a $(COPYTARGET)/libjerrylibm.a
7574

7675
js2c:
7776
cd targets/mbed; ../tools/js2c.py;
@@ -83,7 +82,7 @@ yotta:
8382

8483
flash:
8584
ifndef TARGET_DIR
86-
st-flash write targets/mbed/build/$(YOTTA_TARGET)/source/jerry.bin 0x08000000
85+
st-flash write targets/mbed/build/$(YOTTA_TARGET)/source/jerry.bin 0x08000000
8786
else
8887
@if [ ! -d "${TARGET_DIR}" ] ; then \
8988
echo "The board not mounted at ${TARGET_DIR}"; \
@@ -95,6 +94,6 @@ flash:
9594
@echo "Wait till LED flashing stops..."
9695

9796
clean:
98-
rm -rf $(INTERM)
97+
rm -rf $(COPYTARGET)
9998
rm -rf $(OUTPUT)
10099
rm -rf targets/mbed/build

targets/mbed/source/jerry_extapi.cpp

Lines changed: 61 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/* Copyright 2014-2015 Samsung Electronics Co., Ltd.
2+
* Copyright 2016 University of Szeged.
23
*
34
* Licensed under the Apache License, Version 2.0 (the "License");
45
* you may not use this file except in compliance with the License.
@@ -16,9 +17,9 @@
1617
#include <stdlib.h>
1718
#include <stdio.h>
1819

19-
#include "jerry-core/jerry.h"
20+
#include "jerry-core/jerry-api.h"
2021
#include "jerry_extapi.h"
21-
22+
2223
#include "native_mbed.h"
2324

2425
#ifndef MIN
@@ -30,12 +31,11 @@
3031
#define __UNSED__ __attribute__((unused))
3132

3233
#define DECLARE_HANDLER(NAME) \
33-
static bool \
34-
NAME ## _handler (const jerry_api_object_t * function_obj_p __UNSED__, \
35-
const jerry_api_value_t * this_p __UNSED__, \
36-
jerry_api_value_t * ret_val_p __UNSED__, \
37-
const jerry_api_value_t args_p[], \
38-
const jerry_api_length_t args_cnt)
34+
static jerry_value_t \
35+
NAME ## _handler (const jerry_value_t func_value __UNSED__, \
36+
const jerry_value_t this_value __UNSED__, \
37+
const jerry_value_t args[], \
38+
const jerry_length_t args_cnt )
3939

4040
#define REGISTER_HANDLER(NAME) \
4141
register_native_function ( # NAME, NAME ## _handler)
@@ -45,39 +45,50 @@ NAME ## _handler (const jerry_api_object_t * function_obj_p __UNSED__, \
4545
DECLARE_HANDLER(assert)
4646
{
4747
if (args_cnt == 1
48-
&& args_p[0].type == JERRY_API_DATA_TYPE_BOOLEAN
49-
&& args_p[0].u.v_bool == true)
48+
&& jerry_value_is_boolean (args[0])
49+
&& jerry_get_boolean_value (args[0]))
5050
{
5151
printf (">> Jerry assert true\r\n");
52-
return true;
52+
return jerry_create_boolean (true);
5353
}
5454
printf ("ERROR: Script assertion failed\n");
5555
exit (JERRY_STANDALONE_EXIT_CODE_FAIL);
56-
return false;
56+
return jerry_create_boolean (false);
5757
}
5858

5959
DECLARE_HANDLER(led)
6060
{
61+
jerry_value_t ret_val;
62+
6163
if (args_cnt < 2)
6264
{
63-
return false;
65+
ret_val = jerry_create_boolean (false);
66+
printf ("Error: invalid arguments number!\r\n");
67+
return ret_val;
68+
}
69+
70+
if (!(jerry_value_is_number(args[0])
71+
&& jerry_value_is_number(args[1])))
72+
{
73+
ret_val = jerry_create_boolean (false);
74+
printf ("Error: arguments must be numbers!\r\n");
75+
return ret_val;
6476
}
6577

6678
int port, value;
67-
port = (int)JS_VALUE_TO_NUMBER (&args_p[0]);
68-
value = (int)JS_VALUE_TO_NUMBER (&args_p[1]);
79+
port = (int) jerry_get_number_value (args[0]);
80+
value = (int) jerry_get_number_value (args[1]);
6981

70-
ret_val_p->type = JERRY_API_DATA_TYPE_BOOLEAN;
7182
if (port >=0 && port <= 3)
7283
{
73-
native_led(port, value);
74-
ret_val_p->u.v_bool = true;
84+
native_led (port, value);
85+
ret_val = jerry_create_boolean (true);
7586
}
7687
else
7788
{
78-
ret_val_p->u.v_bool = false;
89+
ret_val = jerry_create_boolean (false);
7990
}
80-
return true;
91+
return ret_val;
8192
}
8293

8394
//-----------------------------------------------------------------------------
@@ -86,41 +97,49 @@ static bool
8697
register_native_function (const char* name,
8798
jerry_external_handler_t handler)
8899
{
89-
jerry_api_object_t *global_obj_p;
90-
jerry_api_object_t *reg_func_p;
91-
jerry_api_value_t reg_value;
92-
bool bok;
100+
jerry_value_t global_object_val = jerry_get_global_object ();
101+
jerry_value_t reg_function = jerry_create_external_function (handler);
93102

94-
global_obj_p = jerry_api_get_global ();
95-
reg_func_p = jerry_api_create_external_function (handler);
103+
bool is_ok = true;
96104

97-
if (!(reg_func_p != NULL
98-
&& jerry_api_is_function (reg_func_p)
99-
&& jerry_api_is_constructor (reg_func_p)))
105+
if (!(jerry_value_is_function (reg_function)
106+
&& jerry_value_is_constructor (reg_function)))
100107
{
108+
is_ok = false;
101109
printf ("Error: create_external_function failed !!!\r\n");
102-
jerry_api_release_object (global_obj_p);
103-
return false;
110+
jerry_release_value (global_object_val);
111+
jerry_release_value (reg_function);
112+
return is_ok;
104113
}
105114

106-
jerry_api_acquire_object (reg_func_p);
107-
reg_value.type = JERRY_API_DATA_TYPE_OBJECT;
108-
reg_value.u.v_object = reg_func_p;
115+
if (jerry_value_has_error_flag (reg_function))
116+
{
117+
is_ok = false;
118+
printf ("Error: create_external_function has error flag! \n\r");
119+
jerry_release_value (global_object_val);
120+
jerry_release_value (reg_function);
121+
return is_ok;
122+
}
109123

110-
bok = jerry_api_set_object_field_value (global_obj_p,
111-
(jerry_api_char_t *) name,
112-
&reg_value);
124+
jerry_value_t jerry_name = jerry_create_string((jerry_char_t *) name);
113125

114-
jerry_api_release_value (&reg_value);
115-
jerry_api_release_object (reg_func_p);
116-
jerry_api_release_object (global_obj_p);
126+
jerry_value_t set_result = jerry_set_property (global_object_val,
127+
jerry_name,
128+
reg_function);
117129

118-
if (!bok)
130+
131+
if (jerry_value_has_error_flag (set_result))
119132
{
133+
is_ok = false;
120134
printf ("Error: register_native_function failed: [%s]\r\n", name);
121135
}
122136

123-
return bok;
137+
jerry_release_value (jerry_name);
138+
jerry_release_value (global_object_val);
139+
jerry_release_value (reg_function);
140+
jerry_release_value (set_result);
141+
142+
return is_ok;
124143
}
125144

126145
void js_register_functions (void)

targets/mbed/source/jerry_extapi.h

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,6 @@
1919
#define JERRY_STANDALONE_EXIT_CODE_OK (0)
2020
#define JERRY_STANDALONE_EXIT_CODE_FAIL (1)
2121

22-
#define API_DATA_IS_OBJECT(val_p) \
23-
((val_p)->type == JERRY_API_DATA_TYPE_OBJECT)
24-
25-
#define API_DATA_IS_FUNCTION(val_p) \
26-
(API_DATA_IS_OBJECT (val_p) && \
27-
jerry_api_is_function ((val_p)->u.v_object))
28-
29-
#define JS_VALUE_TO_NUMBER(val_p) \
30-
((val_p)->type == JERRY_API_DATA_TYPE_FLOAT32 ? \
31-
static_cast<double>((val_p)->u.v_float32) : \
32-
(val_p)->type == JERRY_API_DATA_TYPE_FLOAT64 ? \
33-
static_cast<double>((val_p)->u.v_float64) : \
34-
static_cast<double>((val_p)->u.v_uint32))
35-
3622
void js_register_functions (void);
3723

3824
#endif

0 commit comments

Comments
 (0)