target: mbedos5: use jerry-ext (#1889)

Update target mbedos5 to use external function handlers: `assert`, `gc` and `print` from jerry-ext.

JerryScript-DCO-1.0-Signed-off-by: Marko Fabo mfabo@inf.u-szeged.hu
This commit is contained in:
fbmrk
2017-06-16 20:25:00 +02:00
committed by László Langó
parent 70b078faa4
commit 7cc9d65c09
8 changed files with 7 additions and 169 deletions
@@ -1,23 +0,0 @@
/* 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_MBED_DRIVERS_ASSERT_H
#define _JERRYSCRIPT_MBED_DRIVERS_ASSERT_H
#include "jerryscript-mbed-library-registry/wrap_tools.h"
#include "jerryscript-mbed-util/logging.h"
DECLARE_GLOBAL_FUNCTION(assert);
#endif // _JERRYSCRIPT_MBED_DRIVERS_ASSERT_H
@@ -1,23 +0,0 @@
/* 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_MBED_DRIVERS_GC_H
#define _JERRYSCRIPT_MBED_DRIVERS_GC_H
#include "jerryscript-mbed-library-registry/wrap_tools.h"
#include "jerryscript-mbed-util/logging.h"
DECLARE_GLOBAL_FUNCTION(gc);
#endif // _JERRYSCRIPT_MBED_DRIVERS_GC_H
@@ -15,25 +15,23 @@
#ifndef _JERRYSCRIPT_MBED_DRIVERS_LIB_DRIVERS_H #ifndef _JERRYSCRIPT_MBED_DRIVERS_LIB_DRIVERS_H
#define _JERRYSCRIPT_MBED_DRIVERS_LIB_DRIVERS_H #define _JERRYSCRIPT_MBED_DRIVERS_LIB_DRIVERS_H
#include "jerryscript-ext/handler.h"
#include "jerryscript-mbed-drivers/InterruptIn-js.h" #include "jerryscript-mbed-drivers/InterruptIn-js.h"
#include "jerryscript-mbed-drivers/DigitalOut-js.h" #include "jerryscript-mbed-drivers/DigitalOut-js.h"
#include "jerryscript-mbed-drivers/setInterval-js.h" #include "jerryscript-mbed-drivers/setInterval-js.h"
#include "jerryscript-mbed-drivers/setTimeout-js.h" #include "jerryscript-mbed-drivers/setTimeout-js.h"
#include "jerryscript-mbed-drivers/print-js.h"
#include "jerryscript-mbed-drivers/assert-js.h"
#include "jerryscript-mbed-drivers/I2C-js.h" #include "jerryscript-mbed-drivers/I2C-js.h"
#include "jerryscript-mbed-drivers/gc-js.h"
#include "jerryscript-mbed-drivers/AnalogIn-js.h" #include "jerryscript-mbed-drivers/AnalogIn-js.h"
#include "jerryscript-mbed-drivers/PwmOut-js.h" #include "jerryscript-mbed-drivers/PwmOut-js.h"
DECLARE_JS_WRAPPER_REGISTRATION (base) { DECLARE_JS_WRAPPER_REGISTRATION (base) {
REGISTER_GLOBAL_FUNCTION(assert); REGISTER_GLOBAL_FUNCTION_WITH_HANDLER(assert, jerryx_handler_assert);
REGISTER_GLOBAL_FUNCTION(gc); REGISTER_GLOBAL_FUNCTION_WITH_HANDLER(gc, jerryx_handler_gc);
REGISTER_GLOBAL_FUNCTION_WITH_HANDLER(print, jerryx_handler_print);
REGISTER_GLOBAL_FUNCTION(setInterval); REGISTER_GLOBAL_FUNCTION(setInterval);
REGISTER_GLOBAL_FUNCTION(setTimeout); REGISTER_GLOBAL_FUNCTION(setTimeout);
REGISTER_GLOBAL_FUNCTION(clearInterval); REGISTER_GLOBAL_FUNCTION(clearInterval);
REGISTER_GLOBAL_FUNCTION(clearTimeout); REGISTER_GLOBAL_FUNCTION(clearTimeout);
REGISTER_GLOBAL_FUNCTION(print);
REGISTER_CLASS_CONSTRUCTOR(DigitalOut); REGISTER_CLASS_CONSTRUCTOR(DigitalOut);
REGISTER_CLASS_CONSTRUCTOR(I2C); REGISTER_CLASS_CONSTRUCTOR(I2C);
REGISTER_CLASS_CONSTRUCTOR(InterruptIn); REGISTER_CLASS_CONSTRUCTOR(InterruptIn);
@@ -1,22 +0,0 @@
/* 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_MBED_DRIVERS_PRINT_H
#define _JERRYSCRIPT_MBED_DRIVERS_PRINT_H
#include "jerryscript-mbed-library-registry/wrap_tools.h"
DECLARE_GLOBAL_FUNCTION(print);
#endif // _JERRYSCRIPT_MBED_DRIVERS_PRINT_H
@@ -1,34 +0,0 @@
/* 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 "jerryscript-mbed-drivers/assert-js.h"
/**
* assert (native JavaScript function)
*
* @param condition The condition to assert to be true
* @returns undefined if the assertion passes, returns an error if the assertion
* fails.
*/
DECLARE_GLOBAL_FUNCTION(assert) {
CHECK_ARGUMENT_COUNT(global, assert, (args_count == 1));
CHECK_ARGUMENT_TYPE_ALWAYS(global, assert, 0, boolean);
if (!jerry_get_boolean_value(args[0])) {
const char* error_msg = "Assertion failed";
return jerry_create_error(JERRY_ERROR_TYPE, reinterpret_cast<const jerry_char_t*>(error_msg));
}
return jerry_create_undefined();
}
@@ -1,25 +0,0 @@
/* 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 "jerryscript-mbed-drivers/gc-js.h"
/**
* gc (native JavaScript function)
*
* Manually cause JerryScript to run garbage collection.
*/
DECLARE_GLOBAL_FUNCTION(gc) {
jerry_gc();
return jerry_create_undefined();
}
@@ -1,36 +0,0 @@
/* 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 "jerryscript-mbed-drivers/print-js.h"
/**
* print (native JavaScript function)
*
* Print a string over serial (baud rate 115,200)
*
* @param string String to print
*/
DECLARE_GLOBAL_FUNCTION(print) {
CHECK_ARGUMENT_COUNT(global, print, (args_count == 1));
CHECK_ARGUMENT_TYPE_ALWAYS(global, print, 0, string);
jerry_size_t szArg0 = jerry_get_string_size(args[0]);
jerry_char_t *sArg0 = (jerry_char_t*) calloc(szArg0 + 1, sizeof(jerry_char_t));
jerry_string_to_char_buffer(args[0], sArg0, szArg0);
printf("%s\n", (const char*)sArg0);
return jerry_create_undefined();
}
@@ -37,6 +37,9 @@ NAME_FOR_GLOBAL_FUNCTION(NAME) (const jerry_value_t function_obj_p, \
#define REGISTER_GLOBAL_FUNCTION(NAME) \ #define REGISTER_GLOBAL_FUNCTION(NAME) \
jsmbed_wrap_register_global_function ( # NAME, NAME_FOR_GLOBAL_FUNCTION(NAME) ) jsmbed_wrap_register_global_function ( # NAME, NAME_FOR_GLOBAL_FUNCTION(NAME) )
#define REGISTER_GLOBAL_FUNCTION_WITH_HANDLER(NAME, HANDLER) \
jsmbed_wrap_register_global_function ( # NAME, HANDLER )
// Class constructors // Class constructors
#define DECLARE_CLASS_CONSTRUCTOR(CLASS) \ #define DECLARE_CLASS_CONSTRUCTOR(CLASS) \
jerry_value_t \ jerry_value_t \