diff --git a/.gitignore b/.gitignore index 1ea9c8e36d..f3b0646c3a 100644 --- a/.gitignore +++ b/.gitignore @@ -6,8 +6,4 @@ yarn-error.log .env dist/ games/metadata.json -public/*.json -firmware/spade/src/rpi/jerry/lib/*.a -firmware/spade/src/rpi/jerry/lib/libjerry-core.a -firmware/spade/src/rpi/jerry/lib/libjerry-ext.a -firmware/spade/src/rpi/jerry/lib/libjerry-port-default.a \ No newline at end of file +public/*.json \ No newline at end of file diff --git a/firmware/spade/.gitignore b/firmware/spade/.gitignore index 5f4519d558..fee0b66dbf 100644 --- a/firmware/spade/.gitignore +++ b/firmware/spade/.gitignore @@ -5,6 +5,8 @@ rpi_build/ .DS_Store src/pc/jerry/include src/pc/jerry/lib +src/rpi/jerry/include +src/rpi/jerry/lib CMakeFiles/ Makefile cmake_install.cmake diff --git a/firmware/spade/docker/dockerfile b/firmware/spade/docker/dockerfile index 11f63e3dbe..891a9e1829 100644 --- a/firmware/spade/docker/dockerfile +++ b/firmware/spade/docker/dockerfile @@ -1,6 +1,6 @@ FROM alpine:3.19 -RUN apk add git python3 clang make cmake entr uglify-js gcc-arm-none-eabi g++-arm-none-eabi gdb-multiarch +RUN apk add git python3 clang make cmake entr uglify-js gcc-arm-none-eabi g++-arm-none-eabi gdb-multiarch gcc COPY ./importBuildRepos.sh /opt/importBuildRepos.sh diff --git a/firmware/spade/src/pc/main.c b/firmware/spade/src/pc/main.c index c5a469be80..d284c60756 100644 --- a/firmware/spade/src/pc/main.c +++ b/firmware/spade/src/pc/main.c @@ -224,8 +224,7 @@ static void js_init(char *file, int file_size) { strcpy(combined, engine_script); strcpy(combined + sizeof(engine_script) - 1, file); - const jerry_length_t combined_size = sizeof (engine_script) - 1 + file_size; - js_run(combined, combined_size); + js_run(combined, 0); } /** diff --git a/firmware/spade/src/rpi/jerry/include/jerryscript-compiler.h b/firmware/spade/src/rpi/jerry/include/jerryscript-compiler.h deleted file mode 100644 index 01c3accdc5..0000000000 --- a/firmware/spade/src/rpi/jerry/include/jerryscript-compiler.h +++ /dev/null @@ -1,175 +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_COMPILER_H -#define JERRYSCRIPT_COMPILER_H - -#ifdef __cplusplus -extern "C" -{ -#endif /* __cplusplus */ - -/** \addtogroup jerry-compiler Jerry compiler compatibility components - * @{ - */ - -#ifdef __GNUC__ - -/* - * Compiler-specific macros relevant for GCC. - */ -#define JERRY_ATTR_ALIGNED(ALIGNMENT) __attribute__((aligned(ALIGNMENT))) -#define JERRY_ATTR_ALWAYS_INLINE __attribute__((always_inline)) -#define JERRY_ATTR_CONST __attribute__((const)) -#define JERRY_ATTR_DEPRECATED __attribute__((deprecated)) -#define JERRY_ATTR_FORMAT(...) __attribute__((format(__VA_ARGS__))) -#define JERRY_ATTR_HOT __attribute__((hot)) -#define JERRY_ATTR_NOINLINE __attribute__((noinline)) -#define JERRY_ATTR_NORETURN __attribute__((noreturn)) -#define JERRY_ATTR_PURE __attribute__((pure)) -#define JERRY_ATTR_WARN_UNUSED_RESULT __attribute__((warn_unused_result)) - -#define JERRY_LIKELY(x) __builtin_expect(!!(x), 1) -#define JERRY_UNLIKELY(x) __builtin_expect(!!(x), 0) - -#endif /* __GNUC__ */ - -#ifdef _MSC_VER - -/* - * Compiler-specific macros relevant for Microsoft Visual C/C++ Compiler. - */ -#define JERRY_ATTR_DEPRECATED __declspec(deprecated) -#define JERRY_ATTR_NOINLINE __declspec(noinline) -#define JERRY_ATTR_NORETURN __declspec(noreturn) - -/* - * Microsoft Visual C/C++ Compiler doesn't support for VLA, using _alloca - * instead. - */ -void * __cdecl _alloca (size_t _Size); -#define JERRY_VLA(type, name, size) type *name = (type *) (_alloca (sizeof (type) * size)) - -#endif /* _MSC_VER */ - -/* - * Default empty definitions for all compiler-specific macros. Define any of - * these in a guarded block above (e.g., as for GCC) to fine tune compilation - * for your own compiler. */ - -/** - * Function attribute to align function to given number of bytes. - */ -#ifndef JERRY_ATTR_ALIGNED -#define JERRY_ATTR_ALIGNED(ALIGNMENT) -#endif /* !JERRY_ATTR_ALIGNED */ - -/** - * Function attribute to inline function to all call sites. - */ -#ifndef JERRY_ATTR_ALWAYS_INLINE -#define JERRY_ATTR_ALWAYS_INLINE -#endif /* !JERRY_ATTR_ALWAYS_INLINE */ - -/** - * Function attribute to declare that function has no effect except the return - * value and it only depends on parameters. - */ -#ifndef JERRY_ATTR_CONST -#define JERRY_ATTR_CONST -#endif /* !JERRY_ATTR_CONST */ - -/** - * Function attribute to trigger warning if deprecated function is called. - */ -#ifndef JERRY_ATTR_DEPRECATED -#define JERRY_ATTR_DEPRECATED -#endif /* !JERRY_ATTR_DEPRECATED */ - -/** - * Function attribute to declare that function is variadic and takes a format - * string and some arguments as parameters. - */ -#ifndef JERRY_ATTR_FORMAT -#define JERRY_ATTR_FORMAT(...) -#endif /* !JERRY_ATTR_FORMAT */ - -/** - * Function attribute to predict that function is a hot spot, and therefore - * should be optimized aggressively. - */ -#ifndef JERRY_ATTR_HOT -#define JERRY_ATTR_HOT -#endif /* !JERRY_ATTR_HOT */ - -/** - * Function attribute not to inline function ever. - */ -#ifndef JERRY_ATTR_NOINLINE -#define JERRY_ATTR_NOINLINE -#endif /* !JERRY_ATTR_NOINLINE */ - -/** - * Function attribute to declare that function never returns. - */ -#ifndef JERRY_ATTR_NORETURN -#define JERRY_ATTR_NORETURN -#endif /* !JERRY_ATTR_NORETURN */ - -/** - * Function attribute to declare that function has no effect except the return - * value and it only depends on parameters and global variables. - */ -#ifndef JERRY_ATTR_PURE -#define JERRY_ATTR_PURE -#endif /* !JERRY_ATTR_PURE */ - -/** - * Function attribute to trigger warning if function's caller doesn't use (e.g., - * check) the return value. - */ -#ifndef JERRY_ATTR_WARN_UNUSED_RESULT -#define JERRY_ATTR_WARN_UNUSED_RESULT -#endif /* !JERRY_ATTR_WARN_UNUSED_RESULT */ - -/** - * Helper to predict that a condition is likely. - */ -#ifndef JERRY_LIKELY -#define JERRY_LIKELY(x) (x) -#endif /* !JERRY_LIKELY */ - -/** - * Helper to predict that a condition is unlikely. - */ -#ifndef JERRY_UNLIKELY -#define JERRY_UNLIKELY(x) (x) -#endif /* !JERRY_UNLIKELY */ - -/** - * Helper to declare (or mimic) a C99 variable-length array. - */ -#ifndef JERRY_VLA -#define JERRY_VLA(type, name, size) type name[size] -#endif /* !JERRY_VLA */ - -/** - * @} - */ - -#ifdef __cplusplus -} -#endif /* __cplusplus */ -#endif /* !JERRYSCRIPT_COMPILER_H */ diff --git a/firmware/spade/src/rpi/jerry/include/jerryscript-config.h b/firmware/spade/src/rpi/jerry/include/jerryscript-config.h deleted file mode 100644 index 8be977a760..0000000000 --- a/firmware/spade/src/rpi/jerry/include/jerryscript-config.h +++ /dev/null @@ -1,734 +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_CONFIG_H -#define JERRYSCRIPT_CONFIG_H - -// Generated differences from default by CMake based on build options: -#define JERRY_ERROR_MESSAGES 1 -#define JERRY_GLOBAL_HEAP_SIZE 190 -#define JERRY_GC_LIMIT (0) -#define JERRY_LINE_INFO 1 -#define JERRY_LOGGING 1 -#define JERRY_MEM_STATS 1 - - -/** - * Built-in configurations - * - * Allowed values for built-in defines: - * 0: Disable the given built-in. - * 1: Enable the given built-in. - */ -/* - * By default all built-ins are enabled if they are not defined. - */ -#ifndef JERRY_BUILTINS -# define JERRY_BUILTINS 1 -#endif /* !defined (JERRY_BUILTINS) */ - -#ifndef JERRY_BUILTIN_ANNEXB -# define JERRY_BUILTIN_ANNEXB JERRY_BUILTINS -#endif /* !defined (JERRY_BUILTIN_ANNEXB) */ - -#ifndef JERRY_BUILTIN_ARRAY -# define JERRY_BUILTIN_ARRAY JERRY_BUILTINS -#endif /* !defined (JERRY_BUILTIN_ARRAY) */ - -#ifndef JERRY_BUILTIN_BOOLEAN -# define JERRY_BUILTIN_BOOLEAN JERRY_BUILTINS -#endif /* !defined (JERRY_BUILTIN_BOOLEAN) */ - -#ifndef JERRY_BUILTIN_DATE -# define JERRY_BUILTIN_DATE JERRY_BUILTINS -#endif /* !defined (JERRY_BUILTIN_DATE) */ - -#ifndef JERRY_BUILTIN_ERRORS -# define JERRY_BUILTIN_ERRORS JERRY_BUILTINS -#endif /* !defined (JERRY_BUILTIN_ERRORS) */ - -#ifndef JERRY_BUILTIN_JSON -# define JERRY_BUILTIN_JSON JERRY_BUILTINS -#endif /* !defined (JERRY_BUILTIN_JSON) */ - -#ifndef JERRY_BUILTIN_MATH -# define JERRY_BUILTIN_MATH JERRY_BUILTINS -#endif /* !defined (JERRY_BUILTIN_MATH) */ - -#ifndef JERRY_BUILTIN_NUMBER -# define JERRY_BUILTIN_NUMBER JERRY_BUILTINS -#endif /* !defined (JERRY_BUILTIN_NUMBER) */ - -#ifndef JERRY_BUILTIN_REGEXP -# define JERRY_BUILTIN_REGEXP JERRY_BUILTINS -#endif /* !defined (JERRY_BUILTIN_REGEXP) */ - -#ifndef JERRY_BUILTIN_STRING -# define JERRY_BUILTIN_STRING JERRY_BUILTINS -#endif /* !defined (JERRY_BUILTIN_STRING) */ - -/** - * ES2015+ related features, by default all of them are enabled. - */ -#ifndef JERRY_ESNEXT -# define JERRY_ESNEXT 1 -#endif /* !defined (JERRY_ESNEXT) */ - -#ifndef JERRY_BUILTIN_BIGINT -# define JERRY_BUILTIN_BIGINT JERRY_ESNEXT -#endif /* !defined (JERRY_BUILTIN_BIGINT) */ - -#ifndef JERRY_BUILTIN_DATAVIEW -# define JERRY_BUILTIN_DATAVIEW JERRY_ESNEXT -#endif /* !defined (JERRY_BUILTIN_DATAVIEW) */ - -#ifndef JERRY_BUILTIN_MAP -# define JERRY_BUILTIN_MAP JERRY_ESNEXT -#endif /* !defined (JERRY_BUILTIN_MAP) */ - -#ifndef JERRY_BUILTIN_PROMISE -# define JERRY_BUILTIN_PROMISE JERRY_ESNEXT -#endif /* !defined (JERRY_BUILTIN_PROMISE) */ - -#ifndef JERRY_BUILTIN_PROXY -# define JERRY_BUILTIN_PROXY JERRY_ESNEXT -#endif /* !defined (JERRY_BUILTIN_PROXY) */ - -#ifndef JERRY_BUILTIN_REALMS -# define JERRY_BUILTIN_REALMS JERRY_ESNEXT -#endif /* !defined (JERRY_BUILTIN_REALMS) */ - -#ifndef JERRY_BUILTIN_REFLECT -# define JERRY_BUILTIN_REFLECT JERRY_ESNEXT -#endif /* !defined (JERRY_BUILTIN_REFLECT) */ - -#ifndef JERRY_BUILTIN_SET -# define JERRY_BUILTIN_SET JERRY_ESNEXT -#endif /* !defined (JERRY_BUILTIN_SET) */ - -#ifndef JERRY_BUILTIN_TYPEDARRAY -# define JERRY_BUILTIN_TYPEDARRAY JERRY_ESNEXT -#endif /* !defined (JERRY_BUILTIN_TYPEDARRAY) */ - -#ifndef JERRY_BUILTIN_WEAKMAP -# define JERRY_BUILTIN_WEAKMAP JERRY_ESNEXT -#endif /* !defined (JERRY_BUILTIN_WEAKMAP) */ - -#ifndef JERRY_BUILTIN_WEAKSET -# define JERRY_BUILTIN_WEAKSET JERRY_ESNEXT -#endif /* !defined (JERRY_BUILTIN_WEAKSET) */ - -#ifndef JERRY_MODULE_SYSTEM -# define JERRY_MODULE_SYSTEM JERRY_ESNEXT -#endif /* !defined (JERRY_MODULE_SYSTEM) */ - -/** - * Engine internal and misc configurations. - */ - -/** - * Specifies the compressed pointer representation - * - * Allowed values: - * 0: use 16 bit representation - * 1: use 32 bit representation - * - * Default value: 0 - * For more details see: jmem/jmem.h - */ -#ifndef JERRY_CPOINTER_32_BIT -# define JERRY_CPOINTER_32_BIT 0 -#endif /* !defined (JERRY_CPOINTER_32_BIT) */ - -/** - * Enable/Disable the engine's JavaScript debugger interface - * - * Allowed values: - * 0: Disable the debugger parts. - * 1: Enable the debugger. - */ -#ifndef JERRY_DEBUGGER -# define JERRY_DEBUGGER 0 -#endif /* !defined (JERRY_DEBUGGER) */ - -/** - * Enable/Disable built-in error messages for error objects. - * - * Allowed values: - * 0: Disable error messages. - * 1: Enable error message. - * - * Default value: 0 - */ -#ifndef JERRY_ERROR_MESSAGES -# define JERRY_ERROR_MESSAGES 0 -#endif /* !defined (JERRY_ERROR_MESSAGES) */ - -/** - * Enable/Disable external context. - * - * Allowed values: - * 0: Disable external context. - * 1: Enable external context support. - * - * Default value: 0 - */ -#ifndef JERRY_EXTERNAL_CONTEXT -# define JERRY_EXTERNAL_CONTEXT 0 -#endif /* !defined (JERRY_EXTERNAL_CONTEXT) */ - -/** - * Maximum size of heap in kilobytes - * - * Default value: 512 KiB - */ -#ifndef JERRY_GLOBAL_HEAP_SIZE -# define JERRY_GLOBAL_HEAP_SIZE (512) -#endif /* !defined (JERRY_GLOBAL_HEAP_SIZE) */ - -/** - * The allowed heap usage limit until next garbage collection, in bytes. - * - * If value is 0, the default is 1/32 of JERRY_HEAP_SIZE - */ -#ifndef JERRY_GC_LIMIT -# define JERRY_GC_LIMIT 0 -#endif /* !defined (JERRY_GC_LIMIT) */ - -/** - * Maximum stack usage size in kilobytes - * - * Note: This feature cannot be used when 'detect_stack_use_after_return=1' ASAN option is enabled. - * For more detailed description: - * - https://github.com/google/sanitizers/wiki/AddressSanitizerUseAfterReturn#compatibility - * - * Default value: 0, unlimited - */ -#ifndef JERRY_STACK_LIMIT -# define JERRY_STACK_LIMIT (0) -#endif /* !defined (JERRY_STACK_LIMIT) */ - -/** - * Maximum depth of recursion during GC mark phase - * - * Default value: 8 - */ -#ifndef JERRY_GC_MARK_LIMIT -# define JERRY_GC_MARK_LIMIT (8) -#endif /* !defined (JERRY_GC_MARK_LIMIT) */ - -/** - * Enable/Disable property lookup cache. - * - * Allowed values: - * 0: Disable lookup cache. - * 1: Enable lookup cache. - * - * Default value: 1 - */ -#ifndef JERRY_LCACHE -# define JERRY_LCACHE 1 -#endif /* !defined (JERRY_LCACHE) */ - -/** - * Enable/Disable line-info management inside the engine. - * - * Allowed values: - * 0: Disable line-info in the engine. - * 1: Enable line-info management. - * - * Default value: 0 - */ -#ifndef JERRY_LINE_INFO -# define JERRY_LINE_INFO 0 -#endif /* !defined (JERRY_LINE_INFO) */ - -/** - * Enable/Disable logging inside the engine. - * - * Allowed values: - * 0: Disable internal logging. - * 1: Enable internal logging. - * - * Default value: 0 - */ -#ifndef JERRY_LOGGING -# define JERRY_LOGGING 0 -#endif /* !defined (JERRY_LOGGING) */ - -/** - * Enable/Disable gc call before every allocation. - * - * Allowed values: - * 0: Disable gc call before each allocation. - * 1: Enable and force gc call before each allocation. - * - * Default value: 0 - * Warning!: This is an advanced option and will slow down the engine! - * Only enable it for debugging purposes. - */ -#ifndef JERRY_MEM_GC_BEFORE_EACH_ALLOC -# define JERRY_MEM_GC_BEFORE_EACH_ALLOC 0 -#endif /* !defined (JERRY_MEM_GC_BEFORE_EACH_ALLOC) */ - -/** - * Enable/Disable the collection if run-time memory statistics. - * - * Allowed values: - * 0: Disable run-time memory information collection. - * 1: Enable run-time memory statistics collection. - * - * Default value: 0 - */ -#ifndef JERRY_MEM_STATS -# define JERRY_MEM_STATS 0 -#endif /* !defined (JERRY_MEM_STATS) */ - -/** - * Use 32-bit/64-bit float for ecma-numbers - * This option is for expert use only! - * - * Allowed values: - * 1: use 64-bit floating point number mode - * 0: use 32-bit floating point number mode - * - * Default value: 1 - */ -#ifndef JERRY_NUMBER_TYPE_FLOAT64 -# define JERRY_NUMBER_TYPE_FLOAT64 1 -#endif /* !defined (JERRY_NUMBER_TYPE_FLOAT64 */ - -/** - * Enable/Disable the JavaScript parser. - * - * Allowed values: - * 0: Disable the JavaScript parser and all related functionallity. - * 1: Enable the JavaScript parser. - * - * Default value: 1 - */ -#ifndef JERRY_PARSER -# define JERRY_PARSER 1 -#endif /* !defined (JERRY_PARSER) */ - -/** - * Enable/Disable JerryScript byte code dump functions during parsing. - * To dump the JerryScript byte code the engine must be initialized with opcodes - * display flag. This option does not influence RegExp byte code dumps. - * - * Allowed values: - * 0: Disable all bytecode dump functions. - * 1: Enable bytecode dump functions. - * - * Default value: 0 - */ -#ifndef JERRY_PARSER_DUMP_BYTE_CODE -# define JERRY_PARSER_DUMP_BYTE_CODE 0 -#endif /* defined (JERRY_PARSER_DUMP_BYTE_CODE) */ - -/** - * Enable/Disable ECMA property hashmap. - * - * Allowed values: - * 0: Disable property hasmap. - * 1: Enable property hashmap. - * - * Default value: 1 - */ -#ifndef JERRY_PROPRETY_HASHMAP -# define JERRY_PROPRETY_HASHMAP 1 -#endif /* !defined (JERRY_PROPRETY_HASHMAP) */ - -/** - * Enable/Disable byte code dump functions for RegExp objects. - * To dump the RegExp byte code the engine must be initialized with - * regexp opcodes display flag. This option does not influence the - * JerryScript byte code dumps. - * - * Allowed values: - * 0: Disable all bytecode dump functions. - * 1: Enable bytecode dump functions. - * - * Default value: 0 - */ -#ifndef JERRY_REGEXP_DUMP_BYTE_CODE -# define JERRY_REGEXP_DUMP_BYTE_CODE 0 -#endif /* !defined (JERRY_REGEXP_DUMP_BYTE_CODE) */ - -/** - * Enables/disables the RegExp strict mode - * - * Default value: 0 - */ -#ifndef JERRY_REGEXP_STRICT_MODE -# define JERRY_REGEXP_STRICT_MODE 0 -#endif /* !defined (JERRY_REGEXP_STRICT_MODE) */ - -/** - * Enable/Disable the snapshot execution functions. - * - * Allowed values: - * 0: Disable snapshot execution. - * 1: Enable snapshot execution. - * - * Default value: 0 - */ -#ifndef JERRY_SNAPSHOT_EXEC -# define JERRY_SNAPSHOT_EXEC 0 -#endif /* !defined (JERRY_SNAPSHOT_EXEC) */ - -/** - * Enable/Disable the snapshot save functions. - * - * Allowed values: - * 0: Disable snapshot save functions. - * 1: Enable snapshot save functions. - */ -#ifndef JERRY_SNAPSHOT_SAVE -# define JERRY_SNAPSHOT_SAVE 0 -#endif /* !defined (JERRY_SNAPSHOT_SAVE) */ - -/** - * Enable/Disable usage of system allocator. - * - * Allowed values: - * 0: Disable usage of system allocator. - * 1: Enable usage of system allocator. - * - * Default value: 0 - */ -#ifndef JERRY_SYSTEM_ALLOCATOR -# define JERRY_SYSTEM_ALLOCATOR 0 -#endif /* !defined (JERRY_SYSTEM_ALLOCATOR) */ - -/** - * Enables/disables the unicode case conversion in the engine. - * By default Unicode case conversion is enabled. - */ -#ifndef JERRY_UNICODE_CASE_CONVERSION -# define JERRY_UNICODE_CASE_CONVERSION 1 -#endif /* !defined (JERRY_UNICODE_CASE_CONVERSION) */ - -/** - * Configures if the internal memory allocations are exposed to Valgrind or not. - * - * Allowed values: - * 0: Disable the Valgrind specific memory allocation notifications. - * 1: Enable the Valgrind specific allocation notifications. - */ -#ifndef JERRY_VALGRIND -# define JERRY_VALGRIND 0 -#endif /* !defined (JERRY_VALGRIND) */ - -/** - * Enable/Disable the vm execution stop callback function. - * - * Allowed values: - * 0: Disable vm exec stop callbacks. - * 1: Enable vm exec stop callback functionality. - */ -#ifndef JERRY_VM_EXEC_STOP -# define JERRY_VM_EXEC_STOP 0 -#endif /* !defined (JERRY_VM_EXEC_STOP) */ - -/** - * Advanced section configurations. - */ - -/** - * Allow configuring attributes on a few constant data inside the engine. - * - * One of the main usages: - * Normally compilers store const(ant)s in ROM. Thus saving RAM. - * But if your compiler does not support it then the directive below can force it. - * - * For the moment it is mainly meant for the following targets: - * - ESP8266 - * - * Example configuration for moving (some) constatns into a given section: - * # define JERRY_ATTR_CONST_DATA __attribute__((section(".rodata.const"))) - */ -#ifndef JERRY_ATTR_CONST_DATA -# define JERRY_ATTR_CONST_DATA -#endif /* !defined (JERRY_ATTR_CONST_DATA) */ - -/** - * The JERRY_ATTR_GLOBAL_HEAP allows adding extra attributes for the Jerry global heap. - * - * Example on how to move the global heap into it's own section: - * #define JERRY_ATTR_GLOBAL_HEAP __attribute__((section(".text.globalheap"))) - */ -#ifndef JERRY_ATTR_GLOBAL_HEAP -# define JERRY_ATTR_GLOBAL_HEAP -#endif /* !defined (JERRY_ATTR_GLOBAL_HEAP) */ - -/** - * Sanity check for macros to see if the values are 0 or 1 - * - * If a new feature is added this should be updated. - */ -/** - * Check base builtins. - */ -#if !defined (JERRY_BUILTIN_ANNEXB) \ -|| ((JERRY_BUILTIN_ANNEXB != 0) && (JERRY_BUILTIN_ANNEXB != 1)) -# error "Invalid value for JERRY_BUILTIN_ANNEXB macro." -#endif -#if !defined (JERRY_BUILTIN_ARRAY) \ -|| ((JERRY_BUILTIN_ARRAY != 0) && (JERRY_BUILTIN_ARRAY != 1)) -# error "Invalid value for JERRY_BUILTIN_ARRAY macro." -#endif -#if !defined (JERRY_BUILTIN_BOOLEAN) \ -|| ((JERRY_BUILTIN_BOOLEAN != 0) && (JERRY_BUILTIN_BOOLEAN != 1)) -# error "Invalid value for JERRY_BUILTIN_BOOLEAN macro." -#endif -#if !defined (JERRY_BUILTIN_DATE) \ -|| ((JERRY_BUILTIN_DATE != 0) && (JERRY_BUILTIN_DATE != 1)) -# error "Invalid value for JERRY_BUILTIN_DATE macro." -#endif -#if !defined (JERRY_BUILTIN_ERRORS) \ -|| ((JERRY_BUILTIN_ERRORS != 0) && (JERRY_BUILTIN_ERRORS != 1)) -# error "Invalid value for JERRY_BUILTIN_ERRORS macro." -#endif -#if !defined (JERRY_BUILTIN_JSON) \ -|| ((JERRY_BUILTIN_JSON != 0) && (JERRY_BUILTIN_JSON != 1)) -# error "Invalid value for JERRY_BUILTIN_JSON macro." -#endif -#if !defined (JERRY_BUILTIN_MATH) \ -|| ((JERRY_BUILTIN_MATH != 0) && (JERRY_BUILTIN_MATH != 1)) -# error "Invalid value for JERRY_BUILTIN_MATH macro." -#endif -#if !defined (JERRY_BUILTIN_NUMBER) \ -|| ((JERRY_BUILTIN_NUMBER != 0) && (JERRY_BUILTIN_NUMBER != 1)) -# error "Invalid value for JERRY_BUILTIN_NUMBER macro." -#endif -#if !defined (JERRY_BUILTIN_REGEXP) \ -|| ((JERRY_BUILTIN_REGEXP != 0) && (JERRY_BUILTIN_REGEXP != 1)) -# error "Invalid value for JERRY_BUILTIN_REGEXP macro." -#endif -#if !defined (JERRY_BUILTIN_STRING) \ -|| ((JERRY_BUILTIN_STRING != 0) && (JERRY_BUILTIN_STRING != 1)) -# error "Invalid value for JERRY_BUILTIN_STRING macro." -#endif -#if !defined (JERRY_BUILTINS) \ -|| ((JERRY_BUILTINS != 0) && (JERRY_BUILTINS != 1)) -# error "Invalid value for JERRY_BUILTINS macro." -#endif - -/** - * Check ES2015+ features - */ -#if !defined (JERRY_ESNEXT) \ -|| ((JERRY_ESNEXT != 0) && (JERRY_ESNEXT != 1)) -# error "Invalid value for JERRY_ESNEXT macro." -#endif -#if !defined (JERRY_BUILTIN_REALMS) \ -|| ((JERRY_BUILTIN_REALMS != 0) && (JERRY_BUILTIN_REALMS != 1)) -# error "Invalid value for JERRY_BUILTIN_REALMS macro." -#endif -#if !defined (JERRY_BUILTIN_DATAVIEW) \ -|| ((JERRY_BUILTIN_DATAVIEW != 0) && (JERRY_BUILTIN_DATAVIEW != 1)) -# error "Invalid value for JERRY_BUILTIN_DATAVIEW macro." -#endif -#if !defined (JERRY_BUILTIN_MAP) \ -|| ((JERRY_BUILTIN_MAP != 0) && (JERRY_BUILTIN_MAP != 1)) -# error "Invalid value for JERRY_BUILTIN_MAP macro." -#endif -#if !defined (JERRY_BUILTIN_REFLECT) \ -|| ((JERRY_BUILTIN_REFLECT != 0) && (JERRY_BUILTIN_REFLECT != 1)) -# error "Invalid value for JERRY_BUILTIN_REFLECT macro." -#endif -#if !defined (JERRY_BUILTIN_SET) \ -|| ((JERRY_BUILTIN_SET != 0) && (JERRY_BUILTIN_SET != 1)) -# error "Invalid value for JERRY_BUILTIN_SET macro." -#endif -#if !defined (JERRY_BUILTIN_WEAKMAP) \ -|| ((JERRY_BUILTIN_WEAKMAP != 0) && (JERRY_BUILTIN_WEAKMAP != 1)) -# error "Invalid value for JERRY_BUILTIN_WEAKMAP macro." -#endif -#if !defined (JERRY_BUILTIN_WEAKSET) \ -|| ((JERRY_BUILTIN_WEAKSET != 0) && (JERRY_BUILTIN_WEAKSET != 1)) -# error "Invalid value for JERRY_BUILTIN_WEAKSET macro." -#endif -#if !defined (JERRY_BUILTIN_PROMISE) \ -|| ((JERRY_BUILTIN_PROMISE != 0) && (JERRY_BUILTIN_PROMISE != 1)) -# error "Invalid value for JERRY_BUILTIN_PROMISE macro." -#endif -#if !defined (JERRY_BUILTIN_PROXY) \ -|| ((JERRY_BUILTIN_PROXY != 0) && (JERRY_BUILTIN_PROXY != 1)) -# error "Invalid value for JERRY_BUILTIN_PROXY macro." -#endif -#if !defined (JERRY_BUILTIN_TYPEDARRAY) \ -|| ((JERRY_BUILTIN_TYPEDARRAY != 0) && (JERRY_BUILTIN_TYPEDARRAY != 1)) -# error "Invalid value for JERRY_BUILTIN_TYPEDARRAY macro." -#endif -#if !defined (JERRY_BUILTIN_BIGINT) \ -|| ((JERRY_BUILTIN_BIGINT != 0) && (JERRY_BUILTIN_BIGINT != 1)) -# error "Invalid value for JERRY_BUILTIN_BIGINT macro." -#endif -#if !defined (JERRY_MODULE_SYSTEM) \ -|| ((JERRY_MODULE_SYSTEM != 0) && (JERRY_MODULE_SYSTEM != 1)) -# error "Invalid value for JERRY_MODULE_SYSTEM macro." -#endif -#if (JERRY_ESNEXT == 0) \ -&& ((JERRY_BUILTIN_DATAVIEW == 1) \ -|| (JERRY_BUILTIN_MAP == 1) \ -|| (JERRY_BUILTIN_SET == 1) \ -|| (JERRY_BUILTIN_WEAKMAP == 1) \ -|| (JERRY_BUILTIN_WEAKSET == 1) \ -|| (JERRY_BUILTIN_PROMISE == 1) \ -|| (JERRY_BUILTIN_PROXY == 1) \ -|| (JERRY_BUILTIN_REFLECT == 1) \ -|| (JERRY_BUILTIN_TYPEDARRAY == 1)) -# error "JERRY_ESNEXT should be enabled too to enable JERRY_BUILTIN_xxxxx macro." -#endif -#if (JERRY_ESNEXT == 0) && (JERRY_MODULE_SYSTEM == 1) -# error "JERRY_ESNEXT should be enabled too to enable JERRY_MODULE_SYSTEM macro." -#endif - -/** - * Internal options. - */ -#if !defined (JERRY_CPOINTER_32_BIT) \ -|| ((JERRY_CPOINTER_32_BIT != 0) && (JERRY_CPOINTER_32_BIT != 1)) -# error "Invalid value for 'JERRY_CPOINTER_32_BIT' macro." -#endif -#if !defined (JERRY_DEBUGGER) \ -|| ((JERRY_DEBUGGER != 0) && (JERRY_DEBUGGER != 1)) -# error "Invalid value for 'JERRY_DEBUGGER' macro." -#endif -#if !defined (JERRY_ERROR_MESSAGES) \ -|| ((JERRY_ERROR_MESSAGES != 0) && (JERRY_ERROR_MESSAGES != 1)) -# error "Invalid value for 'JERRY_ERROR_MESSAGES' macro." -#endif -#if !defined (JERRY_EXTERNAL_CONTEXT) \ -|| ((JERRY_EXTERNAL_CONTEXT != 0) && (JERRY_EXTERNAL_CONTEXT != 1)) -# error "Invalid value for 'JERRY_EXTERNAL_CONTEXT' macro." -#endif -#if !defined (JERRY_GLOBAL_HEAP_SIZE) || (JERRY_GLOBAL_HEAP_SIZE <= 0) -# error "Invalid value for 'JERRY_GLOBAL_HEAP_SIZE' macro." -#endif -#if !defined (JERRY_GC_LIMIT) || (JERRY_GC_LIMIT < 0) -# error "Invalid value for 'JERRY_GC_LIMIT' macro." -#endif -#if !defined (JERRY_STACK_LIMIT) || (JERRY_STACK_LIMIT < 0) -# error "Invalid value for 'JERRY_STACK_LIMIT' macro." -#endif -#if !defined (JERRY_GC_MARK_LIMIT) || (JERRY_GC_MARK_LIMIT < 0) -# error "Invalid value for 'JERRY_GC_MARK_LIMIT' macro." -#endif -#if !defined (JERRY_LCACHE) \ -|| ((JERRY_LCACHE != 0) && (JERRY_LCACHE != 1)) -# error "Invalid value for 'JERRY_LCACHE' macro." -#endif -#if !defined (JERRY_LINE_INFO) \ -|| ((JERRY_LINE_INFO != 0) && (JERRY_LINE_INFO != 1)) -# error "Invalid value for 'JERRY_LINE_INFO' macro." -#endif -#if !defined (JERRY_LOGGING) \ -|| ((JERRY_LOGGING != 0) && (JERRY_LOGGING != 1)) -# error "Invalid value for 'JERRY_LOGGING' macro." -#endif -#if !defined (JERRY_MEM_GC_BEFORE_EACH_ALLOC) \ -|| ((JERRY_MEM_GC_BEFORE_EACH_ALLOC != 0) && (JERRY_MEM_GC_BEFORE_EACH_ALLOC != 1)) -# error "Invalid value for 'JERRY_MEM_GC_BEFORE_EACH_ALLOC' macro." -#endif -#if !defined (JERRY_MEM_STATS) \ -|| ((JERRY_MEM_STATS != 0) && (JERRY_MEM_STATS != 1)) -# error "Invalid value for 'JERRY_MEM_STATS' macro." -#endif -#if !defined (JERRY_NUMBER_TYPE_FLOAT64) \ -|| ((JERRY_NUMBER_TYPE_FLOAT64 != 0) && (JERRY_NUMBER_TYPE_FLOAT64 != 1)) -# error "Invalid value for 'JERRY_NUMBER_TYPE_FLOAT64' macro." -#endif -#if !defined (JERRY_PARSER) \ -|| ((JERRY_PARSER != 0) && (JERRY_PARSER != 1)) -# error "Invalid value for 'JERRY_PARSER' macro." -#endif -#if !defined (JERRY_PARSER_DUMP_BYTE_CODE) \ -|| ((JERRY_PARSER_DUMP_BYTE_CODE != 0) && (JERRY_PARSER_DUMP_BYTE_CODE != 1)) -# error "Invalid value for 'JERRY_PARSER_DUMP_BYTE_CODE' macro." -#endif -#if !defined (JERRY_PROPRETY_HASHMAP) \ -|| ((JERRY_PROPRETY_HASHMAP != 0) && (JERRY_PROPRETY_HASHMAP != 1)) -# error "Invalid value for 'JERRY_PROPRETY_HASHMAP' macro." -#endif -#if !defined (JERRY_REGEXP_DUMP_BYTE_CODE) \ -|| ((JERRY_REGEXP_DUMP_BYTE_CODE != 0) && (JERRY_REGEXP_DUMP_BYTE_CODE != 1)) -# error "Invalid value for 'JERRY_REGEXP_DUMP_BYTE_CODE' macro." -#endif -#if !defined (JERRY_REGEXP_STRICT_MODE) \ -|| ((JERRY_REGEXP_STRICT_MODE != 0) && (JERRY_REGEXP_STRICT_MODE != 1)) -# error "Invalid value for 'JERRY_REGEXP_STRICT_MODE' macro." -#endif -#if !defined (JERRY_SNAPSHOT_EXEC) \ -|| ((JERRY_SNAPSHOT_EXEC != 0) && (JERRY_SNAPSHOT_EXEC != 1)) -# error "Invalid value for 'JERRY_SNAPSHOT_EXEC' macro." -#endif -#if !defined (JERRY_SNAPSHOT_SAVE) \ -|| ((JERRY_SNAPSHOT_SAVE != 0) && (JERRY_SNAPSHOT_SAVE != 1)) -# error "Invalid value for 'JERRY_SNAPSHOT_SAVE' macro." -#endif -#if !defined (JERRY_SYSTEM_ALLOCATOR) \ -|| ((JERRY_SYSTEM_ALLOCATOR != 0) && (JERRY_SYSTEM_ALLOCATOR != 1)) -# error "Invalid value for 'JERRY_SYSTEM_ALLOCATOR' macro." -#endif -#if !defined (JERRY_UNICODE_CASE_CONVERSION) \ -|| ((JERRY_UNICODE_CASE_CONVERSION != 0) && (JERRY_UNICODE_CASE_CONVERSION != 1)) -# error "Invalid value for 'JERRY_UNICODE_CASE_CONVERSION' macro." -#endif -#if !defined (JERRY_VALGRIND) \ -|| ((JERRY_VALGRIND != 0) && (JERRY_VALGRIND != 1)) -# error "Invalid value for 'JERRY_VALGRIND' macro." -#endif -#if !defined (JERRY_VM_EXEC_STOP) \ -|| ((JERRY_VM_EXEC_STOP != 0) && (JERRY_VM_EXEC_STOP != 1)) -# error "Invalid value for 'JERRY_VM_EXEC_STOP' macro." -#endif - -#define ENABLED(FEATURE) ((FEATURE) == 1) -#define DISABLED(FEATURE) ((FEATURE) != 1) - -/** - * Cross component requirements check. - */ -/** - * The date module can only use the float 64 number types. - * Do a check for this. - */ -#if ENABLED (JERRY_BUILTIN_DATE) && !ENABLED (JERRY_NUMBER_TYPE_FLOAT64) -# error "Date does not support float32" -#endif - -/** - * Wrap container types into a single guard - */ -#if ENABLED (JERRY_BUILTIN_MAP) || ENABLED (JERRY_BUILTIN_SET) \ -|| ENABLED (JERRY_BUILTIN_WEAKMAP) || ENABLED (JERRY_BUILTIN_WEAKSET) -# define JERRY_BUILTIN_CONTAINER 1 -#else -# define JERRY_BUILTIN_CONTAINER 0 -#endif - -/** - * Resource name related types into a single guard - */ -#if ENABLED (JERRY_LINE_INFO) || ENABLED (JERRY_ERROR_MESSAGES) || ENABLED (JERRY_MODULE_SYSTEM) -# define JERRY_RESOURCE_NAME 1 -#else -# define JERRY_RESOURCE_NAME 0 -#endif - -#endif /* !JERRYSCRIPT_CONFIG_H */ diff --git a/firmware/spade/src/rpi/jerry/include/jerryscript-core.h b/firmware/spade/src/rpi/jerry/include/jerryscript-core.h deleted file mode 100644 index fe7d2ff2e8..0000000000 --- a/firmware/spade/src/rpi/jerry/include/jerryscript-core.h +++ /dev/null @@ -1,865 +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_CORE_H -#define JERRYSCRIPT_CORE_H - -#include -#include -#include - -#include "jerryscript-compiler.h" - -#ifdef __cplusplus -extern "C" -{ -#endif /* __cplusplus */ - -/** \addtogroup jerry Jerry engine interface - * @{ - */ - -/** - * Major version of JerryScript API. - */ -#define JERRY_API_MAJOR_VERSION 2 - -/** - * Minor version of JerryScript API. - */ -#define JERRY_API_MINOR_VERSION 4 - -/** - * Patch version of JerryScript API. - */ -#define JERRY_API_PATCH_VERSION 0 - -/** - * JerryScript init flags. - */ -typedef enum -{ - JERRY_INIT_EMPTY = (0u), /**< empty flag set */ - JERRY_INIT_SHOW_OPCODES = (1u << 0), /**< dump byte-code to log after parse */ - JERRY_INIT_SHOW_REGEXP_OPCODES = (1u << 1), /**< dump regexp byte-code to log after compilation */ - JERRY_INIT_MEM_STATS = (1u << 2), /**< dump memory statistics */ - JERRY_INIT_MEM_STATS_SEPARATE = (1u << 3), /**< deprecated, an unused placeholder now */ - JERRY_INIT_DEBUGGER = (1u << 4), /**< deprecated, an unused placeholder now */ -} jerry_init_flag_t; - -/** - * JerryScript API Error object types. - */ -typedef enum -{ - JERRY_ERROR_NONE = 0, /**< No Error */ - - JERRY_ERROR_COMMON, /**< Error */ - JERRY_ERROR_EVAL, /**< EvalError */ - JERRY_ERROR_RANGE, /**< RangeError */ - JERRY_ERROR_REFERENCE, /**< ReferenceError */ - JERRY_ERROR_SYNTAX, /**< SyntaxError */ - JERRY_ERROR_TYPE, /**< TypeError */ - JERRY_ERROR_URI /**< URIError */ -} jerry_error_t; - -/** - * JerryScript feature types. - */ -typedef enum -{ - JERRY_FEATURE_CPOINTER_32_BIT, /**< 32 bit compressed pointers */ - JERRY_FEATURE_ERROR_MESSAGES, /**< error messages */ - JERRY_FEATURE_JS_PARSER, /**< js-parser */ - JERRY_FEATURE_MEM_STATS, /**< memory statistics */ - JERRY_FEATURE_PARSER_DUMP, /**< parser byte-code dumps */ - JERRY_FEATURE_REGEXP_DUMP, /**< regexp byte-code dumps */ - JERRY_FEATURE_SNAPSHOT_SAVE, /**< saving snapshot files */ - JERRY_FEATURE_SNAPSHOT_EXEC, /**< executing snapshot files */ - JERRY_FEATURE_DEBUGGER, /**< debugging */ - JERRY_FEATURE_VM_EXEC_STOP, /**< stopping ECMAScript execution */ - JERRY_FEATURE_JSON, /**< JSON support */ - JERRY_FEATURE_PROMISE, /**< promise support */ - JERRY_FEATURE_TYPEDARRAY, /**< Typedarray support */ - JERRY_FEATURE_DATE, /**< Date support */ - JERRY_FEATURE_REGEXP, /**< Regexp support */ - JERRY_FEATURE_LINE_INFO, /**< line info available */ - JERRY_FEATURE_LOGGING, /**< logging */ - JERRY_FEATURE_SYMBOL, /**< symbol support */ - JERRY_FEATURE_DATAVIEW, /**< DataView support */ - JERRY_FEATURE_PROXY, /**< Proxy support */ - JERRY_FEATURE_MAP, /**< Map support */ - JERRY_FEATURE_SET, /**< Set support */ - JERRY_FEATURE_WEAKMAP, /**< WeakMap support */ - JERRY_FEATURE_WEAKSET, /**< WeakSet support */ - JERRY_FEATURE_BIGINT, /**< BigInt support */ - JERRY_FEATURE_REALM, /**< realm support */ - JERRY_FEATURE__COUNT /**< number of features. NOTE: must be at the end of the list */ -} jerry_feature_t; - -/** - * Option flags for jerry_parse and jerry_parse_function functions. - */ -typedef enum -{ - JERRY_PARSE_NO_OPTS = 0, /**< no options passed */ - JERRY_PARSE_STRICT_MODE = (1 << 0), /**< enable strict mode */ - JERRY_PARSE_MODULE = (1 << 1) /**< parse source as an ECMAScript module */ -} jerry_parse_opts_t; - -/** - * GC operational modes. - */ -typedef enum -{ - JERRY_GC_PRESSURE_LOW, /**< free unused objects, but keep memory - * allocated for performance improvements - * such as property hash tables for large objects */ - JERRY_GC_PRESSURE_HIGH /**< free as much memory as possible */ -} jerry_gc_mode_t; - -/** - * Jerry regexp flags. - */ -typedef enum -{ - JERRY_REGEXP_FLAG_GLOBAL = (1u << 1), /**< Globally scan string */ - JERRY_REGEXP_FLAG_IGNORE_CASE = (1u << 2), /**< Ignore case */ - JERRY_REGEXP_FLAG_MULTILINE = (1u << 3), /**< Multiline string scan */ - JERRY_REGEXP_FLAG_STICKY = (1u << 4), /**< ECMAScript v11, 21.2.5.14 */ - JERRY_REGEXP_FLAG_UNICODE = (1u << 5), /**< ECMAScript v11, 21.2.5.17 */ - JERRY_REGEXP_FLAG_DOTALL = (1u << 6) /**< ECMAScript v11, 21.2.5.3 */ -} jerry_regexp_flags_t; - -/** - * Character type of JerryScript. - */ -typedef uint8_t jerry_char_t; - -/** - * Size type of JerryScript. - */ -typedef uint32_t jerry_size_t; - -/** - * Length type of JerryScript. - */ -typedef uint32_t jerry_length_t; - -/** - * Description of a JerryScript value. - */ -typedef uint32_t jerry_value_t; - -/** - * Description of ECMA property descriptor. - */ -typedef struct -{ - /** Is [[Value]] defined? */ - bool is_value_defined; - - /** Is [[Get]] defined? */ - bool is_get_defined; - - /** Is [[Set]] defined? */ - bool is_set_defined; - - /** Is [[Writable]] defined? */ - bool is_writable_defined; - - /** [[Writable]] */ - bool is_writable; - - /** Is [[Enumerable]] defined? */ - bool is_enumerable_defined; - - /** [[Enumerable]] */ - bool is_enumerable; - - /** Is [[Configurable]] defined? */ - bool is_configurable_defined; - - /** [[Configurable]] */ - bool is_configurable; - - /** [[Value]] */ - jerry_value_t value; - - /** [[Get]] */ - jerry_value_t getter; - - /** [[Set]] */ - jerry_value_t setter; -} jerry_property_descriptor_t; - -/** - * Description of JerryScript heap memory stats. - * It is for memory profiling. - */ -typedef struct -{ - size_t version; /**< the version of the stats struct */ - size_t size; /**< heap total size */ - size_t allocated_bytes; /**< currently allocated bytes */ - size_t peak_allocated_bytes; /**< peak allocated bytes */ - size_t reserved[4]; /**< padding for future extensions */ -} jerry_heap_stats_t; - -/** - * Type of an external function handler. - */ -typedef jerry_value_t (*jerry_external_handler_t) (const jerry_value_t function_obj, - const jerry_value_t this_val, - const jerry_value_t args_p[], - const jerry_length_t args_count); - -/** - * Native free callback of an object. - */ -typedef void (*jerry_object_native_free_callback_t) (void *native_p); - -/** - * Decorator callback for Error objects. The decorator can create - * or update any properties of the newly created Error object. - */ -typedef void (*jerry_error_object_created_callback_t) (const jerry_value_t error_object, void *user_p); - -/** - * Callback which tells whether the ECMAScript execution should be stopped. - * - * As long as the function returns with undefined the execution continues. - * When a non-undefined value is returned the execution stops and the value - * is thrown by the engine (if the error flag is not set for the returned - * value the engine automatically sets it). - * - * Note: if the function returns with a non-undefined value it - * must return with the same value for future calls. - */ -typedef jerry_value_t (*jerry_vm_exec_stop_callback_t) (void *user_p); - -/** - * Function type applied for each data property of an object. - */ -typedef bool (*jerry_object_property_foreach_t) (const jerry_value_t property_name, - const jerry_value_t property_value, - void *user_data_p); -/** - * Function type applied for each object in the engine. - */ -typedef bool (*jerry_objects_foreach_t) (const jerry_value_t object, - void *user_data_p); - -/** - * Function type applied for each matching object in the engine. - */ -typedef bool (*jerry_objects_foreach_by_native_info_t) (const jerry_value_t object, - void *object_data_p, - void *user_data_p); - -/** - * User context item manager - */ -typedef struct -{ - /** - * Callback responsible for initializing a context item, or NULL to zero out the memory. This is called lazily, the - * first time jerry_get_context_data () is called with this manager. - * - * @param [in] data The buffer that JerryScript allocated for the manager. The buffer is zeroed out. The size is - * determined by the bytes_needed field. The buffer is kept alive until jerry_cleanup () is called. - */ - void (*init_cb) (void *data); - - /** - * Callback responsible for deinitializing a context item, or NULL. This is called as part of jerry_cleanup (), - * right *before* the VM has been cleaned up. This is a good place to release strong references to jerry_value_t's - * that the manager may be holding. - * Note: because the VM has not been fully cleaned up yet, jerry_object_native_info_t free_cb's can still get called - * *after* all deinit_cb's have been run. See finalize_cb for a callback that is guaranteed to run *after* all - * free_cb's have been run. - * - * @param [in] data The buffer that JerryScript allocated for the manager. - */ - void (*deinit_cb) (void *data); - - /** - * Callback responsible for finalizing a context item, or NULL. This is called as part of jerry_cleanup (), - * right *after* the VM has been cleaned up and destroyed and jerry_... APIs cannot be called any more. At this point, - * all values in the VM have been cleaned up. This is a good place to clean up native state that can only be cleaned - * up at the very end when there are no more VM values around that may need to access that state. - * - * @param [in] data The buffer that JerryScript allocated for the manager. After returning from this callback, - * the data pointer may no longer be used. - */ - void (*finalize_cb) (void *data); - - /** - * Number of bytes to allocate for this manager. This is the size of the buffer that JerryScript will allocate on - * behalf of the manager. The pointer to this buffer is passed into init_cb, deinit_cb and finalize_cb. It is also - * returned from the jerry_get_context_data () API. - */ - size_t bytes_needed; -} jerry_context_data_manager_t; - -/** - * Function type for allocating buffer for JerryScript context. - */ -typedef void *(*jerry_context_alloc_t) (size_t size, void *cb_data_p); - -/** - * Type information of a native pointer. - */ -typedef struct -{ - jerry_object_native_free_callback_t free_cb; /**< the free callback of the native pointer */ -} jerry_object_native_info_t; - -/** - * An opaque declaration of the JerryScript context structure. - */ -typedef struct jerry_context_t jerry_context_t; - -/** - * Enum that contains the supported binary operation types - */ -typedef enum -{ - JERRY_BIN_OP_EQUAL = 0u, /**< equal comparison (==) */ - JERRY_BIN_OP_STRICT_EQUAL, /**< strict equal comparison (===) */ - JERRY_BIN_OP_LESS, /**< less relation (<) */ - JERRY_BIN_OP_LESS_EQUAL, /**< less or equal relation (<=) */ - JERRY_BIN_OP_GREATER, /**< greater relation (>) */ - JERRY_BIN_OP_GREATER_EQUAL, /**< greater or equal relation (>=)*/ - JERRY_BIN_OP_INSTANCEOF, /**< instanceof operation */ - JERRY_BIN_OP_ADD, /**< addition operator (+) */ - JERRY_BIN_OP_SUB, /**< subtraction operator (-) */ - JERRY_BIN_OP_MUL, /**< multiplication operator (*) */ - JERRY_BIN_OP_DIV, /**< division operator (/) */ - JERRY_BIN_OP_REM, /**< remainder operator (%) */ -} jerry_binary_operation_t; - -/** - * General engine functions. - */ -void jerry_init (jerry_init_flag_t flags); -void jerry_cleanup (void); -void jerry_register_magic_strings (const jerry_char_t * const *ex_str_items_p, - uint32_t count, - const jerry_length_t *str_lengths_p); -void jerry_gc (jerry_gc_mode_t mode); -void *jerry_get_context_data (const jerry_context_data_manager_t *manager_p); - -bool jerry_get_memory_stats (jerry_heap_stats_t *out_stats_p); - -/** - * Parser and executor functions. - */ -bool jerry_run_simple (const jerry_char_t *script_source_p, size_t script_source_size, jerry_init_flag_t flags); -jerry_value_t jerry_parse (const jerry_char_t *resource_name_p, size_t resource_name_length, - const jerry_char_t *source_p, size_t source_size, uint32_t parse_opts); -jerry_value_t jerry_parse_function (const jerry_char_t *resource_name_p, size_t resource_name_length, - const jerry_char_t *arg_list_p, size_t arg_list_size, - const jerry_char_t *source_p, size_t source_size, uint32_t parse_opts); -jerry_value_t jerry_run (const jerry_value_t func_val); -jerry_value_t jerry_eval (const jerry_char_t *source_p, size_t source_size, uint32_t parse_opts); - -jerry_value_t jerry_run_all_enqueued_jobs (void); - -/** - * Get the global context. - */ -jerry_value_t jerry_get_global_object (void); - -/** - * Checker functions of 'jerry_value_t'. - */ -bool jerry_value_is_abort (const jerry_value_t value); -bool jerry_value_is_array (const jerry_value_t value); -bool jerry_value_is_boolean (const jerry_value_t value); -bool jerry_value_is_constructor (const jerry_value_t value); -bool jerry_value_is_error (const jerry_value_t value); -bool jerry_value_is_function (const jerry_value_t value); -bool jerry_value_is_async_function (const jerry_value_t value); -bool jerry_value_is_number (const jerry_value_t value); -bool jerry_value_is_null (const jerry_value_t value); -bool jerry_value_is_object (const jerry_value_t value); -bool jerry_value_is_promise (const jerry_value_t value); -bool jerry_value_is_proxy (const jerry_value_t value); -bool jerry_value_is_string (const jerry_value_t value); -bool jerry_value_is_symbol (const jerry_value_t value); -bool jerry_value_is_bigint (const jerry_value_t value); -bool jerry_value_is_undefined (const jerry_value_t value); - -/** - * JerryScript API value type information. - */ -typedef enum -{ - JERRY_TYPE_NONE = 0u, /**< no type information */ - JERRY_TYPE_UNDEFINED, /**< undefined type */ - JERRY_TYPE_NULL, /**< null type */ - JERRY_TYPE_BOOLEAN, /**< boolean type */ - JERRY_TYPE_NUMBER, /**< number type */ - JERRY_TYPE_STRING, /**< string type */ - JERRY_TYPE_OBJECT, /**< object type */ - JERRY_TYPE_FUNCTION, /**< function type */ - JERRY_TYPE_ERROR, /**< error/abort type */ - JERRY_TYPE_SYMBOL, /**< symbol type */ - JERRY_TYPE_BIGINT, /**< bigint type */ -} jerry_type_t; - -/** - * JerryScript object type information. - */ -typedef enum -{ - JERRY_OBJECT_TYPE_NONE = 0u, /**< Non object type */ - JERRY_OBJECT_TYPE_GENERIC, /**< Generic JavaScript object without any internal property */ - JERRY_OBJECT_TYPE_ARRAY, /**< Array object */ - JERRY_OBJECT_TYPE_PROXY, /**< Proxy object */ - JERRY_OBJECT_TYPE_FUNCTION, /**< Function object (see jerry_function_get_type) */ - JERRY_OBJECT_TYPE_TYPEDARRAY, /**< %TypedArray% object (see jerry_get_typedarray_type) */ - JERRY_OBJECT_TYPE_ITERATOR, /**< Iterator object (see jerry_iterator_get_type) */ - JERRY_OBJECT_TYPE_CONTAINER, /**< Container object (see jerry_container_get_type) */ - - JERRY_OBJECT_TYPE_ARGUMENTS, /**< Arguments object */ - JERRY_OBJECT_TYPE_BOOLEAN, /**< Boolean object */ - JERRY_OBJECT_TYPE_DATE, /**< Date object */ - JERRY_OBJECT_TYPE_NUMBER, /**< Number object */ - JERRY_OBJECT_TYPE_REGEXP, /**< RegExp object */ - JERRY_OBJECT_TYPE_STRING, /**< String object */ - JERRY_OBJECT_TYPE_SYMBOL, /**< Symbol object */ - JERRY_OBJECT_TYPE_GENERATOR, /**< Generator object */ - JERRY_OBJECT_TYPE_BIGINT, /**< BigInt object */ -} jerry_object_type_t; - -/** - * JerryScript function object type information. - */ -typedef enum -{ - JERRY_FUNCTION_TYPE_NONE = 0u, /**< Non function type */ - JERRY_FUNCTION_TYPE_GENERIC, /**< Generic JavaScript function */ - JERRY_FUNCTION_TYPE_ACCESSOR, /**< Accessor function */ - JERRY_FUNCTION_TYPE_BOUND, /**< Bound function */ - JERRY_FUNCTION_TYPE_ARROW, /**< Arrow fuction */ - JERRY_FUNCTION_TYPE_GENERATOR, /**< Generator function */ -} jerry_function_type_t; - -/** - * JerryScript iterator object type information. - */ -typedef enum -{ - JERRY_ITERATOR_TYPE_NONE = 0u, /**< Non iterator type */ - JERRY_ITERATOR_TYPE_ARRAY, /**< Array iterator */ - JERRY_ITERATOR_TYPE_STRING, /**< String iterator */ - JERRY_ITERATOR_TYPE_MAP, /**< Map iterator */ - JERRY_ITERATOR_TYPE_SET, /**< Set iterator */ -} jerry_iterator_type_t; - -/** - * JerryScript object property filter options. - */ -typedef enum -{ - JERRY_PROPERTY_FILTER_ALL = 0, /**< List all property keys independently - * from key type or property value attributes - * (equivalent to Reflect.ownKeys call) */ - JERRY_PROPERTY_FILTER_TRAVERSE_PROTOTYPE_CHAIN = (1 << 0), /**< Include keys from the objects's - * prototype chain as well */ - JERRY_PROPERTY_FILTER_EXLCUDE_NON_CONFIGURABLE = (1 << 1), /**< Exclude property key if - * the property is non-configurable */ - JERRY_PROPERTY_FILTER_EXLCUDE_NON_ENUMERABLE = (1 << 2), /**< Exclude property key if - * the property is non-enumerable */ - JERRY_PROPERTY_FILTER_EXLCUDE_NON_WRITABLE = (1 << 3), /**< Exclude property key if - * the property is non-writable */ - JERRY_PROPERTY_FILTER_EXLCUDE_STRINGS = (1 << 4), /**< Exclude property key if it is a string */ - JERRY_PROPERTY_FILTER_EXLCUDE_SYMBOLS = (1 << 5), /**< Exclude property key if it is a symbol */ - JERRY_PROPERTY_FILTER_EXLCUDE_INTEGER_INDICES = (1 << 6), /**< Exclude property key if it is an integer index */ - JERRY_PROPERTY_FILTER_INTEGER_INDICES_AS_NUMBER = (1 << 7), /**< By default integer index property keys are - * converted to string. Enabling this flags keeps - * integer index property keys as numbers. */ -} jerry_property_filter_t; - -jerry_type_t jerry_value_get_type (const jerry_value_t value); -jerry_object_type_t jerry_object_get_type (const jerry_value_t value); -jerry_function_type_t jerry_function_get_type (const jerry_value_t value); -jerry_iterator_type_t jerry_iterator_get_type (const jerry_value_t value); - -/** - * Checker function of whether the specified compile feature is enabled. - */ -bool jerry_is_feature_enabled (const jerry_feature_t feature); - -/** - * Binary operations - */ -jerry_value_t jerry_binary_operation (jerry_binary_operation_t op, - const jerry_value_t lhs, - const jerry_value_t rhs); - -/** - * Error manipulation functions. - */ -jerry_value_t jerry_create_abort_from_value (jerry_value_t value, bool release); -jerry_value_t jerry_create_error_from_value (jerry_value_t value, bool release); -jerry_value_t jerry_get_value_from_error (jerry_value_t value, bool release); -void jerry_set_error_object_created_callback (jerry_error_object_created_callback_t callback, void *user_p); - -/** - * Error object function(s). - */ -jerry_error_t jerry_get_error_type (jerry_value_t value); - -/** - * Getter functions of 'jerry_value_t'. - */ -bool jerry_get_boolean_value (const jerry_value_t value); -double jerry_get_number_value (const jerry_value_t value); - -/** - * Functions for string values. - */ -jerry_size_t jerry_get_string_size (const jerry_value_t value); -jerry_size_t jerry_get_utf8_string_size (const jerry_value_t value); -jerry_length_t jerry_get_string_length (const jerry_value_t value); -jerry_length_t jerry_get_utf8_string_length (const jerry_value_t value); -jerry_size_t jerry_string_to_char_buffer (const jerry_value_t value, jerry_char_t *buffer_p, jerry_size_t buffer_size); -jerry_size_t jerry_string_to_utf8_char_buffer (const jerry_value_t value, - jerry_char_t *buffer_p, - jerry_size_t buffer_size); -jerry_size_t jerry_substring_to_char_buffer (const jerry_value_t value, - jerry_length_t start_pos, - jerry_length_t end_pos, - jerry_char_t *buffer_p, - jerry_size_t buffer_size); -jerry_size_t jerry_substring_to_utf8_char_buffer (const jerry_value_t value, - jerry_length_t start_pos, - jerry_length_t end_pos, - jerry_char_t *buffer_p, - jerry_size_t buffer_size); - -/** - * Functions for array object values. - */ -uint32_t jerry_get_array_length (const jerry_value_t value); - -/** - * Converters of 'jerry_value_t'. - */ -bool jerry_value_to_boolean (const jerry_value_t value); -jerry_value_t jerry_value_to_number (const jerry_value_t value); -jerry_value_t jerry_value_to_object (const jerry_value_t value); -jerry_value_t jerry_value_to_primitive (const jerry_value_t value); -jerry_value_t jerry_value_to_string (const jerry_value_t value); -jerry_value_t jerry_value_to_bigint (const jerry_value_t value); -double jerry_value_as_integer (const jerry_value_t value); -int32_t jerry_value_as_int32 (const jerry_value_t value); -uint32_t jerry_value_as_uint32 (const jerry_value_t value); - -/** - * Acquire types with reference counter (increase the references). - */ -jerry_value_t jerry_acquire_value (jerry_value_t value); - -/** - * Release the referenced values. - */ -void jerry_release_value (jerry_value_t value); - -/** - * Create functions of API values. - */ -jerry_value_t jerry_create_array (uint32_t size); -jerry_value_t jerry_create_boolean (bool value); -jerry_value_t jerry_create_error (jerry_error_t error_type, const jerry_char_t *message_p); -jerry_value_t jerry_create_error_sz (jerry_error_t error_type, const jerry_char_t *message_p, - jerry_size_t message_size); -jerry_value_t jerry_create_external_function (jerry_external_handler_t handler_p); -jerry_value_t jerry_create_number (double value); -jerry_value_t jerry_create_number_infinity (bool sign); -jerry_value_t jerry_create_number_nan (void); -jerry_value_t jerry_create_null (void); -jerry_value_t jerry_create_object (void); -jerry_value_t jerry_create_promise (void); -jerry_value_t jerry_create_proxy (const jerry_value_t target, const jerry_value_t handler); -jerry_value_t jerry_create_regexp (const jerry_char_t *pattern, uint16_t flags); -jerry_value_t jerry_create_regexp_sz (const jerry_char_t *pattern, jerry_size_t pattern_size, uint16_t flags); -jerry_value_t jerry_create_string_from_utf8 (const jerry_char_t *str_p); -jerry_value_t jerry_create_string_sz_from_utf8 (const jerry_char_t *str_p, jerry_size_t str_size); -jerry_value_t jerry_create_string (const jerry_char_t *str_p); -jerry_value_t jerry_create_string_sz (const jerry_char_t *str_p, jerry_size_t str_size); -jerry_value_t jerry_create_external_string (const jerry_char_t *str_p, - jerry_object_native_free_callback_t free_cb); -jerry_value_t jerry_create_external_string_sz (const jerry_char_t *str_p, jerry_size_t str_size, - jerry_object_native_free_callback_t free_cb); -jerry_value_t jerry_create_symbol (const jerry_value_t value); -jerry_value_t jerry_create_bigint (const uint64_t *digits_p, uint32_t size, bool sign); -jerry_value_t jerry_create_undefined (void); -jerry_value_t jerry_create_realm (void); - -/** - * General API functions of JS objects. - */ -jerry_value_t jerry_has_property (const jerry_value_t obj_val, const jerry_value_t prop_name_val); -jerry_value_t jerry_has_own_property (const jerry_value_t obj_val, const jerry_value_t prop_name_val); -bool jerry_has_internal_property (const jerry_value_t obj_val, const jerry_value_t prop_name_val); -bool jerry_delete_property (const jerry_value_t obj_val, const jerry_value_t prop_name_val); -bool jerry_delete_property_by_index (const jerry_value_t obj_val, uint32_t index); -bool jerry_delete_internal_property (const jerry_value_t obj_val, const jerry_value_t prop_name_val); - -jerry_value_t jerry_get_property (const jerry_value_t obj_val, const jerry_value_t prop_name_val); -jerry_value_t jerry_get_property_by_index (const jerry_value_t obj_val, uint32_t index); -jerry_value_t jerry_get_internal_property (const jerry_value_t obj_val, const jerry_value_t prop_name_val); -jerry_value_t jerry_set_property (const jerry_value_t obj_val, const jerry_value_t prop_name_val, - const jerry_value_t value_to_set); -jerry_value_t jerry_set_property_by_index (const jerry_value_t obj_val, uint32_t index, - const jerry_value_t value_to_set); -bool jerry_set_internal_property (const jerry_value_t obj_val, const jerry_value_t prop_name_val, - const jerry_value_t value_to_set); - -void jerry_init_property_descriptor_fields (jerry_property_descriptor_t *prop_desc_p); -jerry_value_t jerry_define_own_property (const jerry_value_t obj_val, - const jerry_value_t prop_name_val, - const jerry_property_descriptor_t *prop_desc_p); - -bool jerry_get_own_property_descriptor (const jerry_value_t obj_val, - const jerry_value_t prop_name_val, - jerry_property_descriptor_t *prop_desc_p); -void jerry_free_property_descriptor_fields (const jerry_property_descriptor_t *prop_desc_p); - -jerry_value_t jerry_call_function (const jerry_value_t func_obj_val, const jerry_value_t this_val, - const jerry_value_t args_p[], jerry_size_t args_count); -jerry_value_t jerry_construct_object (const jerry_value_t func_obj_val, const jerry_value_t args_p[], - jerry_size_t args_count); - -jerry_value_t jerry_get_object_keys (const jerry_value_t obj_val); -jerry_value_t jerry_get_prototype (const jerry_value_t obj_val); -jerry_value_t jerry_set_prototype (const jerry_value_t obj_val, const jerry_value_t proto_obj_val); - -bool jerry_get_object_native_pointer (const jerry_value_t obj_val, - void **out_native_pointer_p, - const jerry_object_native_info_t *native_pointer_info_p); -void jerry_set_object_native_pointer (const jerry_value_t obj_val, - void *native_pointer_p, - const jerry_object_native_info_t *native_info_p); -bool jerry_delete_object_native_pointer (const jerry_value_t obj_val, - const jerry_object_native_info_t *native_info_p); - -bool jerry_objects_foreach (jerry_objects_foreach_t foreach_p, - void *user_data); -bool jerry_objects_foreach_by_native_info (const jerry_object_native_info_t *native_info_p, - jerry_objects_foreach_by_native_info_t foreach_p, - void *user_data_p); - -bool jerry_foreach_object_property (const jerry_value_t obj_val, jerry_object_property_foreach_t foreach_p, - void *user_data_p); - -jerry_value_t jerry_object_get_property_names (const jerry_value_t obj_val, jerry_property_filter_t filter); -jerry_value_t jerry_from_property_descriptor (const jerry_property_descriptor_t *src_prop_desc_p); -jerry_value_t jerry_to_property_descriptor (jerry_value_t obj_value, jerry_property_descriptor_t *out_prop_desc_p); -/** - * Promise functions. - */ -jerry_value_t jerry_resolve_or_reject_promise (jerry_value_t promise, jerry_value_t argument, bool is_resolve); - -/** - * Enum values representing various Promise states. - */ -typedef enum -{ - JERRY_PROMISE_STATE_NONE = 0u, /**< Invalid/Unknown state (possibly called on a non-promise object). */ - JERRY_PROMISE_STATE_PENDING, /**< Promise is in "Pending" state. */ - JERRY_PROMISE_STATE_FULFILLED, /**< Promise is in "Fulfilled" state. */ - JERRY_PROMISE_STATE_REJECTED, /**< Promise is in "Rejected" state. */ -} jerry_promise_state_t; - -jerry_value_t jerry_get_promise_result (const jerry_value_t promise); -jerry_promise_state_t jerry_get_promise_state (const jerry_value_t promise); - -/** - * Symbol functions. - */ - -/** - * List of well-known symbols. - */ -typedef enum -{ - JERRY_SYMBOL_ASYNC_ITERATOR, /**< @@asyncIterator well-known symbol */ - JERRY_SYMBOL_HAS_INSTANCE, /**< @@hasInstance well-known symbol */ - JERRY_SYMBOL_IS_CONCAT_SPREADABLE, /**< @@isConcatSpreadable well-known symbol */ - JERRY_SYMBOL_ITERATOR, /**< @@iterator well-known symbol */ - JERRY_SYMBOL_MATCH, /**< @@match well-known symbol */ - JERRY_SYMBOL_REPLACE, /**< @@replace well-known symbol */ - JERRY_SYMBOL_SEARCH, /**< @@search well-known symbol */ - JERRY_SYMBOL_SPECIES, /**< @@species well-known symbol */ - JERRY_SYMBOL_SPLIT, /**< @@split well-known symbol */ - JERRY_SYMBOL_TO_PRIMITIVE, /**< @@toPrimitive well-known symbol */ - JERRY_SYMBOL_TO_STRING_TAG, /**< @@toStringTag well-known symbol */ - JERRY_SYMBOL_UNSCOPABLES, /**< @@unscopables well-known symbol */ - JERRY_SYMBOL_MATCH_ALL, /**< @@matchAll well-known symbol */ -} jerry_well_known_symbol_t; - -jerry_value_t jerry_get_well_known_symbol (jerry_well_known_symbol_t symbol); -jerry_value_t jerry_get_symbol_description (const jerry_value_t symbol); -jerry_value_t jerry_get_symbol_descriptive_string (const jerry_value_t symbol); - -/** - * Realm functions. - */ -jerry_value_t jerry_set_realm (jerry_value_t realm_value); -jerry_value_t jerry_realm_get_this (jerry_value_t realm_value); -jerry_value_t jerry_realm_set_this (jerry_value_t realm_value, jerry_value_t this_value); - -/** - * BigInt functions. - */ -uint32_t jerry_get_bigint_size_in_digits (jerry_value_t value); -void jerry_get_bigint_digits (jerry_value_t value, uint64_t *digits_p, uint32_t size, bool *sign_p); - -/** - * Proxy functions. - */ -jerry_value_t jerry_get_proxy_target (jerry_value_t proxy_value); - -/** - * Input validator functions. - */ -bool jerry_is_valid_utf8_string (const jerry_char_t *utf8_buf_p, jerry_size_t buf_size); -bool jerry_is_valid_cesu8_string (const jerry_char_t *cesu8_buf_p, jerry_size_t buf_size); - -/* - * Dynamic memory management functions. - */ -void *jerry_heap_alloc (size_t size); -void jerry_heap_free (void *mem_p, size_t size); - -/* - * External context functions. - */ -jerry_context_t *jerry_create_context (uint32_t heap_size, jerry_context_alloc_t alloc, void *cb_data_p); - -/** - * Miscellaneous functions. - */ -void jerry_set_vm_exec_stop_callback (jerry_vm_exec_stop_callback_t stop_cb, void *user_p, uint32_t frequency); -jerry_value_t jerry_get_backtrace (uint32_t max_depth); -jerry_value_t jerry_get_backtrace_from (uint32_t max_depth, jerry_value_t ignored_function); -jerry_value_t jerry_get_resource_name (const jerry_value_t value); -jerry_value_t jerry_get_new_target (void); - -/** - * Array buffer components. - */ -bool jerry_value_is_arraybuffer (const jerry_value_t value); -jerry_value_t jerry_create_arraybuffer (const jerry_length_t size); -jerry_value_t jerry_create_arraybuffer_external (const jerry_length_t size, - uint8_t *buffer_p, - jerry_object_native_free_callback_t free_cb); -jerry_length_t jerry_arraybuffer_write (const jerry_value_t value, - jerry_length_t offset, - const uint8_t *buf_p, - jerry_length_t buf_size); -jerry_length_t jerry_arraybuffer_read (const jerry_value_t value, - jerry_length_t offset, - uint8_t *buf_p, - jerry_length_t buf_size); -jerry_length_t jerry_get_arraybuffer_byte_length (const jerry_value_t value); -uint8_t *jerry_get_arraybuffer_pointer (const jerry_value_t value); -jerry_value_t jerry_is_arraybuffer_detachable (const jerry_value_t value); -jerry_value_t jerry_detach_arraybuffer (const jerry_value_t value); - -/** - * DataView functions. - */ -jerry_value_t -jerry_create_dataview (const jerry_value_t value, - const jerry_length_t byte_offset, - const jerry_length_t byte_length); - -bool -jerry_value_is_dataview (const jerry_value_t value); - -jerry_value_t -jerry_get_dataview_buffer (const jerry_value_t dataview, - jerry_length_t *byte_offset, - jerry_length_t *byte_length); - -/** - * TypedArray functions. - */ - -/** - * TypedArray types. - */ -typedef enum -{ - JERRY_TYPEDARRAY_INVALID = 0, - JERRY_TYPEDARRAY_UINT8, - JERRY_TYPEDARRAY_UINT8CLAMPED, - JERRY_TYPEDARRAY_INT8, - JERRY_TYPEDARRAY_UINT16, - JERRY_TYPEDARRAY_INT16, - JERRY_TYPEDARRAY_UINT32, - JERRY_TYPEDARRAY_INT32, - JERRY_TYPEDARRAY_FLOAT32, - JERRY_TYPEDARRAY_FLOAT64, - JERRY_TYPEDARRAY_BIGINT64, - JERRY_TYPEDARRAY_BIGUINT64, -} jerry_typedarray_type_t; - -/** - * Container types. - */ -typedef enum -{ - JERRY_CONTAINER_TYPE_INVALID = 0, /**< Invalid container */ - JERRY_CONTAINER_TYPE_MAP, /**< Map type */ - JERRY_CONTAINER_TYPE_SET, /**< Set type */ - JERRY_CONTAINER_TYPE_WEAKMAP, /**< WeakMap type */ - JERRY_CONTAINER_TYPE_WEAKSET, /**< WeakSet type */ -} jerry_container_type_t; - -bool jerry_value_is_typedarray (jerry_value_t value); -jerry_value_t jerry_create_typedarray (jerry_typedarray_type_t type_name, jerry_length_t length); -jerry_value_t jerry_create_typedarray_for_arraybuffer_sz (jerry_typedarray_type_t type_name, - const jerry_value_t arraybuffer, - jerry_length_t byte_offset, - jerry_length_t length); -jerry_value_t jerry_create_typedarray_for_arraybuffer (jerry_typedarray_type_t type_name, - const jerry_value_t arraybuffer); -jerry_typedarray_type_t jerry_get_typedarray_type (jerry_value_t value); -jerry_length_t jerry_get_typedarray_length (jerry_value_t value); -jerry_value_t jerry_get_typedarray_buffer (jerry_value_t value, - jerry_length_t *byte_offset, - jerry_length_t *byte_length); -jerry_value_t jerry_json_parse (const jerry_char_t *string_p, jerry_size_t string_size); -jerry_value_t jerry_json_stringify (const jerry_value_t object_to_stringify); -jerry_value_t jerry_create_container (jerry_container_type_t container_type, - const jerry_value_t *arguments_list_p, - jerry_length_t arguments_list_len); -jerry_container_type_t jerry_get_container_type (const jerry_value_t value); - -/** - * @} - */ - -#ifdef __cplusplus -} -#endif /* __cplusplus */ -#endif /* !JERRYSCRIPT_CORE_H */ diff --git a/firmware/spade/src/rpi/jerry/include/jerryscript-debugger-transport.h b/firmware/spade/src/rpi/jerry/include/jerryscript-debugger-transport.h deleted file mode 100644 index f6f9acaaa5..0000000000 --- a/firmware/spade/src/rpi/jerry/include/jerryscript-debugger-transport.h +++ /dev/null @@ -1,107 +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_DEBUGGER_TRANSPORT_H -#define JERRYSCRIPT_DEBUGGER_TRANSPORT_H - -#include -#include -#include - -#ifdef __cplusplus -extern "C" -{ -#endif /* __cplusplus */ - -/** \addtogroup jerry-debugger-transport Jerry engine debugger interface - transport control - * @{ - */ - -/** - * Maximum number of bytes transmitted or received. - */ -#define JERRY_DEBUGGER_TRANSPORT_MAX_BUFFER_SIZE 128 - -/** - * Receive message context. - */ -typedef struct -{ - uint8_t *buffer_p; /**< buffer for storing the received data */ - size_t received_length; /**< number of currently received bytes */ - uint8_t *message_p; /**< start of the received message */ - size_t message_length; /**< length of the received message */ - size_t message_total_length; /**< total length for datagram protocols, - * 0 for stream protocols */ -} jerry_debugger_transport_receive_context_t; - -/** - * Forward definition of jerry_debugger_transport_header_t. - */ -struct jerry_debugger_transport_interface_t; - -/** - * Close connection callback. - */ -typedef void (*jerry_debugger_transport_close_t) (struct jerry_debugger_transport_interface_t *header_p); - -/** - * Send data callback. - */ -typedef bool (*jerry_debugger_transport_send_t) (struct jerry_debugger_transport_interface_t *header_p, - uint8_t *message_p, size_t message_length); - -/** - * Receive data callback. - */ -typedef bool (*jerry_debugger_transport_receive_t) (struct jerry_debugger_transport_interface_t *header_p, - jerry_debugger_transport_receive_context_t *context_p); - -/** - * Transport layer header. - */ -typedef struct jerry_debugger_transport_interface_t -{ - /* The following fields must be filled before calling jerry_debugger_transport_add(). */ - jerry_debugger_transport_close_t close; /**< close connection callback */ - jerry_debugger_transport_send_t send; /**< send data callback */ - jerry_debugger_transport_receive_t receive; /**< receive data callback */ - - /* The following fields are filled by jerry_debugger_transport_add(). */ - struct jerry_debugger_transport_interface_t *next_p; /**< next transport layer */ -} jerry_debugger_transport_header_t; - -void jerry_debugger_transport_add (jerry_debugger_transport_header_t *header_p, - size_t send_message_header_size, size_t max_send_message_size, - size_t receive_message_header_size, size_t max_receive_message_size); -void jerry_debugger_transport_start (void); - -bool jerry_debugger_transport_is_connected (void); -void jerry_debugger_transport_close (void); - -bool jerry_debugger_transport_send (const uint8_t *message_p, size_t message_length); -bool jerry_debugger_transport_receive (jerry_debugger_transport_receive_context_t *context_p); -void jerry_debugger_transport_receive_completed (jerry_debugger_transport_receive_context_t *context_p); - -void jerry_debugger_transport_sleep (void); - -/** - * @} - */ - -#ifdef __cplusplus -} -#endif /* __cplusplus */ -#endif /* !JERRYSCRIPT_DEBUGGER_TRANSPORT_H */ diff --git a/firmware/spade/src/rpi/jerry/include/jerryscript-debugger.h b/firmware/spade/src/rpi/jerry/include/jerryscript-debugger.h deleted file mode 100644 index 759bd4e8f0..0000000000 --- a/firmware/spade/src/rpi/jerry/include/jerryscript-debugger.h +++ /dev/null @@ -1,79 +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_DEBUGGER_H -#define JERRYSCRIPT_DEBUGGER_H - -#include "jerryscript-core.h" -#include "jerryscript-port.h" - -#ifdef __cplusplus -extern "C" -{ -#endif /* __cplusplus */ - -/** \addtogroup jerry-debugger Jerry engine interface - Debugger feature - * @{ - */ - -/** - * JerryScript debugger protocol version. - */ -#define JERRY_DEBUGGER_VERSION (9) - -/** - * Types for the client source wait and run method. - */ -typedef enum -{ - JERRY_DEBUGGER_SOURCE_RECEIVE_FAILED = 0, /**< source is not received */ - JERRY_DEBUGGER_SOURCE_RECEIVED = 1, /**< a source has been received */ - JERRY_DEBUGGER_SOURCE_END = 2, /**< the end of the sources signal received */ - JERRY_DEBUGGER_CONTEXT_RESET_RECEIVED, /**< the context reset request has been received */ -} jerry_debugger_wait_for_source_status_t; - -/** - * Callback for jerry_debugger_wait_and_run_client_source - * - * The callback receives the resource name, source code and a user pointer. - * - * @return this value is passed back by jerry_debugger_wait_and_run_client_source - */ -typedef jerry_value_t (*jerry_debugger_wait_for_source_callback_t) (const jerry_char_t *resource_name_p, - size_t resource_name_size, - const jerry_char_t *source_p, - size_t source_size, void *user_p); - -/** - * Engine debugger functions. - */ -bool jerry_debugger_is_connected (void); -void jerry_debugger_stop (void); -void jerry_debugger_continue (void); -void jerry_debugger_stop_at_breakpoint (bool enable_stop_at_breakpoint); -jerry_debugger_wait_for_source_status_t -jerry_debugger_wait_for_client_source (jerry_debugger_wait_for_source_callback_t callback_p, - void *user_p, jerry_value_t *return_value); -void jerry_debugger_send_output (const jerry_char_t *buffer, jerry_size_t str_size); -void jerry_debugger_send_log (jerry_log_level_t level, const jerry_char_t *buffer, jerry_size_t str_size); - -/** - * @} - */ - -#ifdef __cplusplus -} -#endif /* __cplusplus */ -#endif /* !JERRYSCRIPT_DEBUGGER_H */ diff --git a/firmware/spade/src/rpi/jerry/include/jerryscript-ext/arg.h b/firmware/spade/src/rpi/jerry/include/jerryscript-ext/arg.h deleted file mode 100644 index 8171bcf3c2..0000000000 --- a/firmware/spade/src/rpi/jerry/include/jerryscript-ext/arg.h +++ /dev/null @@ -1,198 +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 JERRYX_ARG_H -#define JERRYX_ARG_H - -#include -#include -#include -#include "jerryscript.h" - -#ifdef __cplusplus -extern "C" -{ -#endif /* __cplusplus */ - -/** - * The forward declaration of jerryx_arg_t. - */ -typedef struct jerryx_arg_t jerryx_arg_t; - -/** - * The forward declaration of jerryx_arg_js_iterator_t - */ -typedef struct jerryx_arg_js_iterator_t jerryx_arg_js_iterator_t; - -/** - * Signature of the transform function. - */ -typedef jerry_value_t (*jerryx_arg_transform_func_t) (jerryx_arg_js_iterator_t *js_arg_iter_p, /**< available JS args */ - const jerryx_arg_t *c_arg_p); /**< native arg */ - -/** - * The structure used in jerryx_arg_object_properties - */ -typedef struct -{ - const jerry_char_t **name_p; /**< property name list of the JS object */ - jerry_length_t name_cnt; /**< count of the name list */ - const jerryx_arg_t *c_arg_p; /**< points to the array of transformation steps */ - jerry_length_t c_arg_cnt; /**< the count of the `c_arg_p` array */ -} jerryx_arg_object_props_t; - -/** - * The structure used in jerryx_arg_array - */ -typedef struct -{ - const jerryx_arg_t *c_arg_p; /**< points to the array of transformation steps */ - jerry_length_t c_arg_cnt; /**< the count of the `c_arg_p` array */ -} jerryx_arg_array_items_t; - -/** - * The structure defining a single validation & transformation step. - */ -struct jerryx_arg_t -{ - jerryx_arg_transform_func_t func; /**< the transform function */ - void *dest; /**< pointer to destination where func should store the result */ - uintptr_t extra_info; /**< extra information, specific to func */ -}; - -jerry_value_t jerryx_arg_transform_this_and_args (const jerry_value_t this_val, - const jerry_value_t *js_arg_p, - const jerry_length_t js_arg_cnt, - const jerryx_arg_t *c_arg_p, - jerry_length_t c_arg_cnt); - -jerry_value_t jerryx_arg_transform_args (const jerry_value_t *js_arg_p, - const jerry_length_t js_arg_cnt, - const jerryx_arg_t *c_arg_p, - jerry_length_t c_arg_cnt); - -jerry_value_t jerryx_arg_transform_object_properties (const jerry_value_t obj_val, - const jerry_char_t **name_p, - const jerry_length_t name_cnt, - const jerryx_arg_t *c_arg_p, - jerry_length_t c_arg_cnt); -jerry_value_t jerryx_arg_transform_array (const jerry_value_t array_val, - const jerryx_arg_t *c_arg_p, - jerry_length_t c_arg_cnt); - -/** - * Indicates whether an argument is allowed to be coerced into the expected JS type. - */ -typedef enum -{ - JERRYX_ARG_COERCE, /**< the transform inside will invoke toNumber, toBoolean or toString */ - JERRYX_ARG_NO_COERCE /**< the type coercion is not allowed. */ -} jerryx_arg_coerce_t; - -/** - * Indicates whether an argument is optional or required. - */ -typedef enum -{ - /** - * The argument is optional. If the argument is `undefined` the transform is - * successful and `c_arg_p->dest` remains untouched. - */ - JERRYX_ARG_OPTIONAL, - /** - * The argument is required. If the argument is `undefined` the transform - * will fail and `c_arg_p->dest` remains untouched. - */ - JERRYX_ARG_REQUIRED -} jerryx_arg_optional_t; - -/** - * Indicates the rounding policy which will be chosen to transform an integer. - */ -typedef enum -{ - JERRYX_ARG_ROUND, /**< round */ - JERRYX_ARG_FLOOR, /**< floor */ - JERRYX_ARG_CEIL /**< ceil */ -} jerryx_arg_round_t; - -/** - * Indicates the clamping policy which will be chosen to transform an integer. - * If the policy is NO_CLAMP, and the number is out of range, - * then the transformer will throw a range error. - */ -typedef enum -{ - JERRYX_ARG_CLAMP,/**< clamp the number when it is out of range */ - JERRYX_ARG_NO_CLAMP /**< throw a range error */ -} jerryx_arg_clamp_t; - -/* Inline functions for initializing jerryx_arg_t */ - -#define JERRYX_ARG_INTEGER(type) \ - static inline jerryx_arg_t \ - jerryx_arg_ ## type (type ## _t *dest, \ - jerryx_arg_round_t round_flag, \ - jerryx_arg_clamp_t clamp_flag, \ - jerryx_arg_coerce_t coerce_flag, \ - jerryx_arg_optional_t opt_flag); - -JERRYX_ARG_INTEGER (uint8) -JERRYX_ARG_INTEGER (int8) -JERRYX_ARG_INTEGER (uint16) -JERRYX_ARG_INTEGER (int16) -JERRYX_ARG_INTEGER (uint32) -JERRYX_ARG_INTEGER (int32) - -#undef JERRYX_ARG_INTEGER - -static inline jerryx_arg_t -jerryx_arg_number (double *dest, jerryx_arg_coerce_t coerce_flag, jerryx_arg_optional_t opt_flag); -static inline jerryx_arg_t -jerryx_arg_boolean (bool *dest, jerryx_arg_coerce_t coerce_flag, jerryx_arg_optional_t opt_flag); -static inline jerryx_arg_t -jerryx_arg_string (char *dest, uint32_t size, jerryx_arg_coerce_t coerce_flag, jerryx_arg_optional_t opt_flag); -static inline jerryx_arg_t -jerryx_arg_utf8_string (char *dest, uint32_t size, jerryx_arg_coerce_t coerce_flag, jerryx_arg_optional_t opt_flag); -static inline jerryx_arg_t -jerryx_arg_function (jerry_value_t *dest, jerryx_arg_optional_t opt_flag); -static inline jerryx_arg_t -jerryx_arg_native_pointer (void **dest, const jerry_object_native_info_t *info_p, jerryx_arg_optional_t opt_flag); -static inline jerryx_arg_t -jerryx_arg_ignore (void); -static inline jerryx_arg_t -jerryx_arg_custom (void *dest, uintptr_t extra_info, jerryx_arg_transform_func_t func); -static inline jerryx_arg_t -jerryx_arg_object_properties (const jerryx_arg_object_props_t *object_props_p, jerryx_arg_optional_t opt_flag); -static inline jerryx_arg_t -jerryx_arg_array (const jerryx_arg_array_items_t *array_items_p, jerryx_arg_optional_t opt_flag); - -jerry_value_t -jerryx_arg_transform_optional (jerryx_arg_js_iterator_t *js_arg_iter_p, - const jerryx_arg_t *c_arg_p, - jerryx_arg_transform_func_t func); - -/* Helper functions for transform functions. */ -jerry_value_t jerryx_arg_js_iterator_pop (jerryx_arg_js_iterator_t *js_arg_iter_p); -jerry_value_t jerryx_arg_js_iterator_restore (jerryx_arg_js_iterator_t *js_arg_iter_p); -jerry_value_t jerryx_arg_js_iterator_peek (jerryx_arg_js_iterator_t *js_arg_iter_p); -jerry_length_t jerryx_arg_js_iterator_index (jerryx_arg_js_iterator_t *js_arg_iter_p); - -#include "arg.impl.h" - -#ifdef __cplusplus -} -#endif /* __cplusplus */ -#endif /* !JERRYX_ARG_H */ diff --git a/firmware/spade/src/rpi/jerry/include/jerryscript-ext/arg.impl.h b/firmware/spade/src/rpi/jerry/include/jerryscript-ext/arg.impl.h deleted file mode 100644 index 1b3111e5af..0000000000 --- a/firmware/spade/src/rpi/jerry/include/jerryscript-ext/arg.impl.h +++ /dev/null @@ -1,443 +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 JERRYX_ARG_IMPL_H -#define JERRYX_ARG_IMPL_H - -/* transform functions for each type. */ - -#define JERRYX_ARG_TRANSFORM_FUNC_WITH_OPTIONAL(type) \ - jerry_value_t jerryx_arg_transform_ ## type (jerryx_arg_js_iterator_t *js_arg_iter_p, \ - const jerryx_arg_t *c_arg_p); \ - jerry_value_t jerryx_arg_transform_ ## type ## _optional (jerryx_arg_js_iterator_t *js_arg_iter_p, \ - const jerryx_arg_t *c_arg_p); - -#define JERRYX_ARG_TRANSFORM_FUNC_WITH_OPTIONAL_AND_STRICT(type) \ - JERRYX_ARG_TRANSFORM_FUNC_WITH_OPTIONAL (type) \ - JERRYX_ARG_TRANSFORM_FUNC_WITH_OPTIONAL (type ## _strict) - -JERRYX_ARG_TRANSFORM_FUNC_WITH_OPTIONAL_AND_STRICT (uint8) -JERRYX_ARG_TRANSFORM_FUNC_WITH_OPTIONAL_AND_STRICT (int8) -JERRYX_ARG_TRANSFORM_FUNC_WITH_OPTIONAL_AND_STRICT (uint16) -JERRYX_ARG_TRANSFORM_FUNC_WITH_OPTIONAL_AND_STRICT (int16) -JERRYX_ARG_TRANSFORM_FUNC_WITH_OPTIONAL_AND_STRICT (uint32) -JERRYX_ARG_TRANSFORM_FUNC_WITH_OPTIONAL_AND_STRICT (int32) -JERRYX_ARG_TRANSFORM_FUNC_WITH_OPTIONAL_AND_STRICT (number) -JERRYX_ARG_TRANSFORM_FUNC_WITH_OPTIONAL_AND_STRICT (string) -JERRYX_ARG_TRANSFORM_FUNC_WITH_OPTIONAL_AND_STRICT (utf8_string) -JERRYX_ARG_TRANSFORM_FUNC_WITH_OPTIONAL_AND_STRICT (boolean) - -JERRYX_ARG_TRANSFORM_FUNC_WITH_OPTIONAL (function) -JERRYX_ARG_TRANSFORM_FUNC_WITH_OPTIONAL (native_pointer) -JERRYX_ARG_TRANSFORM_FUNC_WITH_OPTIONAL (object_props) -JERRYX_ARG_TRANSFORM_FUNC_WITH_OPTIONAL (array_items) - -jerry_value_t jerryx_arg_transform_ignore (jerryx_arg_js_iterator_t *js_arg_iter_p, - const jerryx_arg_t *c_arg_p); - -#undef JERRYX_ARG_TRANSFORM_FUNC_WITH_OPTIONAL -#undef JERRYX_ARG_TRANSFORM_FUNC_WITH_OPTIONAL_AND_STRICT - -/** - * The structure indicates the options used to transform integer argument. - * It will be passed into jerryx_arg_t's extra_info field. - */ -typedef struct -{ - uint8_t round; /**< rounding policy */ - uint8_t clamp; /**< clamping policy */ -} jerryx_arg_int_option_t; - -/** - * The macro used to generate jerryx_arg_xxx for int type. - */ -#define JERRYX_ARG_INT(type) \ - static inline jerryx_arg_t \ - jerryx_arg_ ## type (type ## _t *dest, \ - jerryx_arg_round_t round_flag, \ - jerryx_arg_clamp_t clamp_flag, \ - jerryx_arg_coerce_t coerce_flag, \ - jerryx_arg_optional_t opt_flag) \ - { \ - jerryx_arg_transform_func_t func; \ - if (coerce_flag == JERRYX_ARG_NO_COERCE) \ - { \ - if (opt_flag == JERRYX_ARG_OPTIONAL) \ - { \ - func = jerryx_arg_transform_ ## type ## _strict_optional; \ - } \ - else \ - { \ - func = jerryx_arg_transform_ ## type ## _strict; \ - } \ - } \ - else \ - { \ - if (opt_flag == JERRYX_ARG_OPTIONAL) \ - { \ - func = jerryx_arg_transform_ ## type ## _optional; \ - } \ - else \ - { \ - func = jerryx_arg_transform_ ## type; \ - } \ - } \ - union \ - { \ - jerryx_arg_int_option_t int_option; \ - uintptr_t extra_info; \ - } u = { .int_option = { .round = (uint8_t) round_flag, .clamp = (uint8_t) clamp_flag } }; \ - return (jerryx_arg_t) \ - { \ - .func = func, \ - .dest = (void *) dest, \ - .extra_info = u.extra_info \ - }; \ - } - -JERRYX_ARG_INT (uint8) -JERRYX_ARG_INT (int8) -JERRYX_ARG_INT (uint16) -JERRYX_ARG_INT (int16) -JERRYX_ARG_INT (uint32) -JERRYX_ARG_INT (int32) - -#undef JERRYX_ARG_INT - -/** - * Create a validation/transformation step (`jerryx_arg_t`) that expects to - * consume one `number` JS argument and stores it into a C `double`. - * - * @return a jerryx_arg_t instance. - */ -static inline jerryx_arg_t -jerryx_arg_number (double *dest, /**< pointer to the double where the result should be stored */ - jerryx_arg_coerce_t coerce_flag, /**< whether type coercion is allowed */ - jerryx_arg_optional_t opt_flag) /**< whether the argument is optional */ -{ - jerryx_arg_transform_func_t func; - - if (coerce_flag == JERRYX_ARG_NO_COERCE) - { - if (opt_flag == JERRYX_ARG_OPTIONAL) - { - func = jerryx_arg_transform_number_strict_optional; - } - else - { - func = jerryx_arg_transform_number_strict; - } - } - else - { - if (opt_flag == JERRYX_ARG_OPTIONAL) - { - func = jerryx_arg_transform_number_optional; - } - else - { - func = jerryx_arg_transform_number; - } - } - - return (jerryx_arg_t) - { - .func = func, - .dest = (void *) dest - }; -} /* jerryx_arg_number */ - -/** - * Create a validation/transformation step (`jerryx_arg_t`) that expects to - * consume one `boolean` JS argument and stores it into a C `bool`. - * - * @return a jerryx_arg_t instance. - */ -static inline jerryx_arg_t -jerryx_arg_boolean (bool *dest, /**< points to the native bool */ - jerryx_arg_coerce_t coerce_flag, /**< whether type coercion is allowed */ - jerryx_arg_optional_t opt_flag) /**< whether the argument is optional */ -{ - jerryx_arg_transform_func_t func; - - if (coerce_flag == JERRYX_ARG_NO_COERCE) - { - if (opt_flag == JERRYX_ARG_OPTIONAL) - { - func = jerryx_arg_transform_boolean_strict_optional; - } - else - { - func = jerryx_arg_transform_boolean_strict; - } - } - else - { - if (opt_flag == JERRYX_ARG_OPTIONAL) - { - func = jerryx_arg_transform_boolean_optional; - } - else - { - func = jerryx_arg_transform_boolean; - } - } - - return (jerryx_arg_t) - { - .func = func, - .dest = (void *) dest - }; -} /* jerryx_arg_boolean */ - -/** - * Create a validation/transformation step (`jerryx_arg_t`) that expects to - * consume one `string` JS argument and stores it into a C `char` array. - * - * @return a jerryx_arg_t instance. - */ -static inline jerryx_arg_t -jerryx_arg_string (char *dest, /**< pointer to the native char array where the result should be stored */ - uint32_t size, /**< the size of native char array */ - jerryx_arg_coerce_t coerce_flag, /**< whether type coercion is allowed */ - jerryx_arg_optional_t opt_flag) /**< whether the argument is optional */ -{ - jerryx_arg_transform_func_t func; - - if (coerce_flag == JERRYX_ARG_NO_COERCE) - { - if (opt_flag == JERRYX_ARG_OPTIONAL) - { - func = jerryx_arg_transform_string_strict_optional; - } - else - { - func = jerryx_arg_transform_string_strict; - } - } - else - { - if (opt_flag == JERRYX_ARG_OPTIONAL) - { - func = jerryx_arg_transform_string_optional; - } - else - { - func = jerryx_arg_transform_string; - } - } - - return (jerryx_arg_t) - { - .func = func, - .dest = (void *) dest, - .extra_info = (uintptr_t) size - }; -} /* jerryx_arg_string */ - -/** - * Create a validation/transformation step (`jerryx_arg_t`) that expects to - * consume one `string` JS argument and stores it into a C utf8 `char` array. - * - * @return a jerryx_arg_t instance. - */ -static inline jerryx_arg_t -jerryx_arg_utf8_string (char *dest, /**< [out] pointer to the native char array where the result should be stored */ - uint32_t size, /**< the size of native char array */ - jerryx_arg_coerce_t coerce_flag, /**< whether type coercion is allowed */ - jerryx_arg_optional_t opt_flag) /**< whether the argument is optional */ -{ - jerryx_arg_transform_func_t func; - - if (coerce_flag == JERRYX_ARG_NO_COERCE) - { - if (opt_flag == JERRYX_ARG_OPTIONAL) - { - func = jerryx_arg_transform_utf8_string_strict_optional; - } - else - { - func = jerryx_arg_transform_utf8_string_strict; - } - } - else - { - if (opt_flag == JERRYX_ARG_OPTIONAL) - { - func = jerryx_arg_transform_utf8_string_optional; - } - else - { - func = jerryx_arg_transform_utf8_string; - } - } - - return (jerryx_arg_t) - { - .func = func, - .dest = (void *) dest, - .extra_info = (uintptr_t) size - }; -} /* jerryx_arg_utf8_string */ - -/** - * Create a validation/transformation step (`jerryx_arg_t`) that expects to - * consume one `function` JS argument and stores it into a C `jerry_value_t`. - * - * @return a jerryx_arg_t instance. - */ -static inline jerryx_arg_t -jerryx_arg_function (jerry_value_t *dest, /**< pointer to the jerry_value_t where the result should be stored */ - jerryx_arg_optional_t opt_flag) /**< whether the argument is optional */ -{ - jerryx_arg_transform_func_t func; - - if (opt_flag == JERRYX_ARG_OPTIONAL) - { - func = jerryx_arg_transform_function_optional; - } - else - { - func = jerryx_arg_transform_function; - } - - return (jerryx_arg_t) - { - .func = func, - .dest = (void *) dest - }; -} /* jerryx_arg_function */ - -/** - * Create a validation/transformation step (`jerryx_arg_t`) that expects to - * consume one `object` JS argument that is 'backed' with a native pointer with - * a given type info. In case the native pointer info matches, the transform - * will succeed and the object's native pointer will be assigned to *dest. - * - * @return a jerryx_arg_t instance. - */ -static inline jerryx_arg_t -jerryx_arg_native_pointer (void **dest, /**< pointer to where the resulting native pointer should be stored */ - const jerry_object_native_info_t *info_p, /**< expected the type info */ - jerryx_arg_optional_t opt_flag) /**< whether the argument is optional */ -{ - jerryx_arg_transform_func_t func; - - if (opt_flag == JERRYX_ARG_OPTIONAL) - { - func = jerryx_arg_transform_native_pointer_optional; - } - else - { - func = jerryx_arg_transform_native_pointer; - } - - return (jerryx_arg_t) - { - .func = func, - .dest = (void *) dest, - .extra_info = (uintptr_t) info_p - }; -} /* jerryx_arg_native_pointer */ - -/** - * Create a jerryx_arg_t instance for ignored argument. - * - * @return a jerryx_arg_t instance. - */ -static inline jerryx_arg_t -jerryx_arg_ignore (void) -{ - return (jerryx_arg_t) - { - .func = jerryx_arg_transform_ignore - }; -} /* jerryx_arg_ignore */ - -/** - * Create a jerryx_arg_t instance with custom transform. - * - * @return a jerryx_arg_t instance. - */ -static inline jerryx_arg_t -jerryx_arg_custom (void *dest, /**< pointer to the native argument where the result should be stored */ - uintptr_t extra_info, /**< the extra parameter, specific to the transform function */ - jerryx_arg_transform_func_t func) /**< the custom transform function */ -{ - return (jerryx_arg_t) - { - .func = func, - .dest = dest, - .extra_info = extra_info - }; -} /* jerryx_arg_custom */ - -/** - * Create a jerryx_arg_t instance for object properties. - * - * @return a jerryx_arg_t instance. - */ -static inline jerryx_arg_t -jerryx_arg_object_properties (const jerryx_arg_object_props_t *object_props, /**< pointer to object property mapping */ - jerryx_arg_optional_t opt_flag) /**< whether the argument is optional */ -{ - jerryx_arg_transform_func_t func; - - if (opt_flag == JERRYX_ARG_OPTIONAL) - { - func = jerryx_arg_transform_object_props_optional; - } - else - { - func = jerryx_arg_transform_object_props; - } - - return (jerryx_arg_t) - { - .func = func, - .dest = NULL, - .extra_info = (uintptr_t) object_props - }; -} /* jerryx_arg_object_properties */ - -/** - * Create a jerryx_arg_t instance for array. - * - * @return a jerryx_arg_t instance. - */ -static inline jerryx_arg_t -jerryx_arg_array (const jerryx_arg_array_items_t *array_items_p, /**< pointer to array items mapping */ - jerryx_arg_optional_t opt_flag) /**< whether the argument is optional */ -{ - jerryx_arg_transform_func_t func; - - if (opt_flag == JERRYX_ARG_OPTIONAL) - { - func = jerryx_arg_transform_array_items_optional; - } - else - { - func = jerryx_arg_transform_array_items; - } - - return (jerryx_arg_t) - { - .func = func, - .dest = NULL, - .extra_info = (uintptr_t) array_items_p - }; -} /* jerryx_arg_array */ - -#endif /* !JERRYX_ARG_IMPL_H */ diff --git a/firmware/spade/src/rpi/jerry/include/jerryscript-ext/autorelease.h b/firmware/spade/src/rpi/jerry/include/jerryscript-ext/autorelease.h deleted file mode 100644 index f7cf7dea1d..0000000000 --- a/firmware/spade/src/rpi/jerry/include/jerryscript-ext/autorelease.h +++ /dev/null @@ -1,54 +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 JERRYX_AUTORELEASE_H -#define JERRYX_AUTORELEASE_H - -#ifdef __cplusplus -extern "C" -{ -#endif /* __cplusplus */ - -#include "autorelease.impl.h" - -/* - * Macro for `const jerry_value_t` for which jerry_release_value () is - * automatically called when the variable goes out of scope. - * - * Example usage: - * static void foo (bool enable) - * { - * JERRYX_AR_VALUE_T bar = jerry_create_string (...); - * - * if (enable) { - * JERRYX_AR_VALUE_T baz = jerry_get_global_object (); - * - * // ... - * - * // jerry_release_value (baz) and jerry_release_value (bar) is called automatically before - * // returning, because `baz` and `bar` go out of scope. - * return; - * } - * - * // jerry_release_value (bar) is called automatically when the function returns, - * // because `bar` goes out of scope. - * } - */ -#define JERRYX_AR_VALUE_T __JERRYX_AR_VALUE_T_IMPL - -#ifdef __cplusplus -} -#endif /* __cplusplus */ -#endif /* !JERRYX_AUTORELEASE_H */ diff --git a/firmware/spade/src/rpi/jerry/include/jerryscript-ext/autorelease.impl.h b/firmware/spade/src/rpi/jerry/include/jerryscript-ext/autorelease.impl.h deleted file mode 100644 index 558b17095a..0000000000 --- a/firmware/spade/src/rpi/jerry/include/jerryscript-ext/autorelease.impl.h +++ /dev/null @@ -1,40 +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 JERRYX_AUTORELEASE_IMPL_H -#define JERRYX_AUTORELEASE_IMPL_H - -#include "jerryscript.h" - -#ifdef __GNUC__ -/* - * Calls jerry_release_value (*value). - * The GCC __cleanup__ function must take a pointer to the variable to clean up. - * - * @return void - */ -static inline void -jerryx_autorelease_cleanup (const jerry_value_t *value) /**< jerry value */ -{ - jerry_release_value (*value); -} /* jerryx_autorelease_cleanup */ - -#define __JERRYX_AR_VALUE_T_IMPL const jerry_value_t __attribute__ ((__cleanup__(jerryx_autorelease_cleanup))) -#else /* !__GNUC__ */ -/* TODO: for other compilers */ -#error "No autorelease implementation for your compiler!" -#endif /* __GNUC__ */ - -#endif /* !JERRYX_AUTORELEASE_IMPL_H */ diff --git a/firmware/spade/src/rpi/jerry/include/jerryscript-ext/debugger.h b/firmware/spade/src/rpi/jerry/include/jerryscript-ext/debugger.h deleted file mode 100644 index e229e25ec5..0000000000 --- a/firmware/spade/src/rpi/jerry/include/jerryscript-ext/debugger.h +++ /dev/null @@ -1,44 +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 JERRYX_DEBUGGER_H -#define JERRYX_DEBUGGER_H - -#include "jerryscript.h" -#include "jerryscript-debugger-transport.h" - -#ifdef __cplusplus -extern "C" -{ -#endif /* __cplusplus */ - -void jerryx_debugger_after_connect (bool success); - -/* - * Message transmission interfaces. - */ -bool jerryx_debugger_tcp_create (uint16_t port); -bool jerryx_debugger_serial_create (const char *config); - -/* - * Message encoding interfaces. - */ -bool jerryx_debugger_ws_create (void); -bool jerryx_debugger_rp_create (void); - -#ifdef __cplusplus -} -#endif /* __cplusplus */ -#endif /* !JERRYX_HANDLER_H */ diff --git a/firmware/spade/src/rpi/jerry/include/jerryscript-ext/handle-scope.h b/firmware/spade/src/rpi/jerry/include/jerryscript-ext/handle-scope.h deleted file mode 100644 index 95505f7b1a..0000000000 --- a/firmware/spade/src/rpi/jerry/include/jerryscript-ext/handle-scope.h +++ /dev/null @@ -1,128 +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 JERRYX_HANDLE_SCOPE_H -#define JERRYX_HANDLE_SCOPE_H - -#include "jerryscript.h" - -#ifdef __cplusplus -extern "C" -{ -#endif /* __cplusplus */ - -#ifndef JERRYX_HANDLE_PRELIST_SIZE -#define JERRYX_HANDLE_PRELIST_SIZE 20 -#endif - -#ifndef JERRYX_SCOPE_PRELIST_SIZE -#define JERRYX_SCOPE_PRELIST_SIZE 20 -#endif - -typedef struct jerryx_handle_t jerryx_handle_t; -/** - * Dynamically allocated handle in the scopes. - * Scopes has it's own size-limited linear storage of handles. Still there - * might be not enough space left for new handles, dynamically allocated - * `jerryx_handle_t` could ease the pre-allocated linear memory burden. - */ -struct jerryx_handle_t -{ - jerry_value_t jval; /**< jerry value of the handle bound to */ - jerryx_handle_t *sibling; /**< next sibling the the handle */ -}; - -#define JERRYX_HANDLE_SCOPE_FIELDS \ - jerry_value_t handle_prelist[JERRYX_HANDLE_PRELIST_SIZE]; \ - uint8_t prelist_handle_count; \ - bool escaped; \ - jerryx_handle_t *handle_ptr - -typedef struct jerryx_handle_scope_s jerryx_handle_scope_t; -typedef jerryx_handle_scope_t *jerryx_handle_scope; -typedef jerryx_handle_scope_t *jerryx_escapable_handle_scope; -/** - * Inlined simple handle scope type. - */ -struct jerryx_handle_scope_s -{ - JERRYX_HANDLE_SCOPE_FIELDS; /**< common handle scope fields */ -}; - -typedef struct jerryx_handle_scope_dynamic_s jerryx_handle_scope_dynamic_t; -/** - * Dynamically allocated handle scope type. - */ -struct jerryx_handle_scope_dynamic_s -{ - JERRYX_HANDLE_SCOPE_FIELDS; /**< common handle scope fields */ - jerryx_handle_scope_dynamic_t *child; /**< child dynamically allocated handle scope */ - jerryx_handle_scope_dynamic_t *parent; /**< parent dynamically allocated handle scope */ -}; - -#undef JERRYX_HANDLE_SCOPE_FIELDS - -typedef enum -{ - jerryx_handle_scope_ok = 0, - - jerryx_escape_called_twice, - jerryx_handle_scope_mismatch, -} jerryx_handle_scope_status; - -jerryx_handle_scope_status -jerryx_open_handle_scope (jerryx_handle_scope *result); - -jerryx_handle_scope_status -jerryx_close_handle_scope (jerryx_handle_scope scope); - -jerryx_handle_scope_status -jerryx_open_escapable_handle_scope (jerryx_handle_scope *result); - -jerryx_handle_scope_status -jerryx_close_escapable_handle_scope (jerryx_handle_scope scope); - -jerryx_handle_scope_status -jerryx_escape_handle (jerryx_escapable_handle_scope scope, - jerry_value_t escapee, - jerry_value_t *result); - -/** - * Completely escape a handle from handle scope, - * leave life time management totally up to user. - */ -jerryx_handle_scope_status -jerryx_remove_handle (jerryx_escapable_handle_scope scope, - jerry_value_t escapee, - jerry_value_t *result); - -jerry_value_t -jerryx_create_handle (jerry_value_t jval); - -jerry_value_t -jerryx_create_handle_in_scope (jerry_value_t jval, jerryx_handle_scope scope); - -/** MARK: - handle-scope-allocator.c */ -jerryx_handle_scope_t * -jerryx_handle_scope_get_current (void); - -jerryx_handle_scope_t * -jerryx_handle_scope_get_root (void); -/** MARK: - END handle-scope-allocator.c */ - -#ifdef __cplusplus -} -#endif /* __cplusplus */ -#endif /* !JERRYX_HANDLE_SCOPE_H */ diff --git a/firmware/spade/src/rpi/jerry/include/jerryscript-ext/handler.h b/firmware/spade/src/rpi/jerry/include/jerryscript-ext/handler.h deleted file mode 100644 index c36b6b8717..0000000000 --- a/firmware/spade/src/rpi/jerry/include/jerryscript-ext/handler.h +++ /dev/null @@ -1,103 +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 JERRYX_HANDLER_H -#define JERRYX_HANDLER_H - -#include "jerryscript.h" - -#ifdef __cplusplus -extern "C" -{ -#endif /* __cplusplus */ - -/* - * Handler registration helper - */ - -jerry_value_t jerryx_handler_register_global (const jerry_char_t *name_p, - jerry_external_handler_t handler_p); - -/* - * Common external function handlers - */ - -jerry_value_t jerryx_handler_assert_fatal (const jerry_value_t func_obj_val, const jerry_value_t this_p, - const jerry_value_t args_p[], const jerry_length_t args_cnt); -jerry_value_t jerryx_handler_assert_throw (const jerry_value_t func_obj_val, const jerry_value_t this_p, - const jerry_value_t args_p[], const jerry_length_t args_cnt); -jerry_value_t jerryx_handler_assert (const jerry_value_t func_obj_val, const jerry_value_t this_p, - const jerry_value_t args_p[], const jerry_length_t args_cnt); -jerry_value_t jerryx_handler_gc (const jerry_value_t func_obj_val, const jerry_value_t this_p, - const jerry_value_t args_p[], const jerry_length_t args_cnt); -jerry_value_t jerryx_handler_print (const jerry_value_t func_obj_val, const jerry_value_t this_p, - const jerry_value_t args_p[], const jerry_length_t args_cnt); -jerry_value_t jerryx_handler_resource_name (const jerry_value_t func_obj_val, const jerry_value_t this_p, - const jerry_value_t args_p[], const jerry_length_t args_cnt); - -/** - * Struct used by the `jerryx_set_functions` method to - * register multiple methods for a given object. - */ -typedef struct -{ - const char *name; /**< name of the property to add */ - jerry_value_t value; /**< value of the property */ -} jerryx_property_entry; - -#define JERRYX_PROPERTY_NUMBER(NAME, NUMBER) (jerryx_property_entry) { NAME, jerry_create_number (NUMBER) } -#define JERRYX_PROPERTY_STRING(NAME, STR) \ - (jerryx_property_entry) { NAME, jerry_create_string_from_utf8 ((const jerry_char_t *) STR) } -#define JERRYX_PROPERTY_STRING_SZ(NAME, STR, SIZE) \ - (jerryx_property_entry) { NAME, jerry_create_string_sz_from_utf8 ((const jerry_char_t *) STR, SIZE) } -#define JERRYX_PROPERTY_BOOLEAN(NAME, VALUE) (jerryx_property_entry) { NAME, jerry_create_boolean (VALUE) } -#define JERRYX_PROPERTY_FUNCTION(NAME, FUNC) (jerryx_property_entry) { NAME, jerry_create_external_function (FUNC) } -#define JERRYX_PROPERTY_UNDEFINED(NAME) (jerryx_property_entry) { NAME, jerry_create_undefined() } -#define JERRYX_PROPERTY_LIST_END() (jerryx_property_entry) { NULL, 0 } - -/** - * Stores the result of property register operation. - */ -typedef struct -{ - jerry_value_t result; /**< result of property registraion (undefined or error object) */ - uint32_t registered; /**< number of successfully registered methods */ -} jerryx_register_result; - -jerryx_register_result -jerryx_set_properties (const jerry_value_t target_object, - const jerryx_property_entry entries[]); - -void -jerryx_release_property_entry (const jerryx_property_entry entries[], - const jerryx_register_result register_result); - -jerry_value_t -jerryx_set_property_str (const jerry_value_t target_object, - const char *name, - const jerry_value_t value); - -jerry_value_t -jerryx_get_property_str (const jerry_value_t target_object, - const char *name); - -bool -jerryx_has_property_str (const jerry_value_t target_object, - const char *name); - -#ifdef __cplusplus -} -#endif /* __cplusplus */ -#endif /* !JERRYX_HANDLER_H */ diff --git a/firmware/spade/src/rpi/jerry/include/jerryscript-ext/module.h b/firmware/spade/src/rpi/jerry/include/jerryscript-ext/module.h deleted file mode 100644 index 1c1025d563..0000000000 --- a/firmware/spade/src/rpi/jerry/include/jerryscript-ext/module.h +++ /dev/null @@ -1,151 +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 JERRYX_MODULE_H -#define JERRYX_MODULE_H - -#include "jerryscript.h" - -#ifdef __cplusplus -extern "C" -{ -#endif /* __cplusplus */ - -/** - * Declare the signature for the module initialization function. - */ -typedef jerry_value_t (*jerryx_native_module_on_resolve_t) (void); - -/** - * Declare the structure used to define a module. One should only make use of this structure via the - * JERRYX_NATIVE_MODULE macro declared below. - */ -typedef struct jerryx_native_module_t -{ - const jerry_char_t *name_p; /**< name of the module */ - const jerryx_native_module_on_resolve_t on_resolve_p; /**< function that returns a new instance of the module */ - struct jerryx_native_module_t *next_p; /**< pointer to next module in the list */ -} jerryx_native_module_t; - -/** - * Declare the constructor and destructor attributes. These evaluate to nothing if this extension is built without - * library constructor/destructor support. - */ -#ifdef ENABLE_INIT_FINI -#ifdef _MSC_VER -#error "`FEATURE_INIT_FINI` build flag isn't supported on Windows, because Microsoft Visual C/C++ Compiler \ -doesn't support library constructors and destructors." -#endif -#define JERRYX_MODULE_CONSTRUCTOR_ATTRIBUTE __attribute__((constructor)) -#define JERRYX_MODULE_DESTRUCTOR_ATTRIBUTE __attribute__((destructor)) -#define JERRYX_MODULE_REGISTRATION_QUALIFIER static -#else /* !ENABLE_INIT_FINI */ -#define JERRYX_MODULE_CONSTRUCTOR_ATTRIBUTE -#define JERRYX_MODULE_DESTRUCTOR_ATTRIBUTE -#define JERRYX_MODULE_REGISTRATION_QUALIFIER -#endif /* ENABLE_INIT_FINI */ - -/** - * Having two levels of macros allows strings to be used unquoted. - */ -#define JERRYX_NATIVE_MODULE(module_name, on_resolve_cb) \ - JERRYX_NATIVE_MODULE_IMPLEM(module_name, on_resolve_cb) - -#define JERRYX_NATIVE_MODULE_IMPLEM(module_name, on_resolve_cb) \ - static jerryx_native_module_t _ ## module_name ## _definition = \ - { \ - .name_p = (jerry_char_t *) #module_name, \ - .on_resolve_p = (on_resolve_cb), \ - .next_p = NULL \ - }; \ - \ - JERRYX_MODULE_REGISTRATION_QUALIFIER void \ - module_name ## _register (void) JERRYX_MODULE_CONSTRUCTOR_ATTRIBUTE; \ - JERRYX_MODULE_REGISTRATION_QUALIFIER void \ - module_name ## _register (void) \ - { \ - jerryx_native_module_register(&_##module_name##_definition); \ - } \ - \ - JERRYX_MODULE_REGISTRATION_QUALIFIER void \ - module_name ## _unregister (void) \ - JERRYX_MODULE_DESTRUCTOR_ATTRIBUTE; \ - JERRYX_MODULE_REGISTRATION_QUALIFIER void \ - module_name ## _unregister (void) \ - { \ - jerryx_native_module_unregister(&_##module_name##_definition); \ - } - -/** - * Register a native module. This makes it available for loading via jerryx_module_resolve, when - * jerryx_module_native_resolver is passed in as a possible resolver. - */ -void jerryx_native_module_register (jerryx_native_module_t *module_p); - -/** - * Unregister a native module. This removes the module from the list of available native modules, meaning that - * subsequent calls to jerryx_module_resolve with jerryx_module_native_resolver will not be able to find it. - */ -void jerryx_native_module_unregister (jerryx_native_module_t *module_p); - -/** - * Declare the function pointer type for canonical name resolution. - */ -typedef jerry_value_t (*jerryx_module_get_canonical_name_t) (const jerry_value_t name); /**< The name for which to - * compute the canonical - * name */ - -/** - * Declare the function pointer type for module resolution. - */ -typedef bool (*jerryx_module_resolve_t) (const jerry_value_t canonical_name, /**< The module's canonical name */ - jerry_value_t *result); /**< The resulting module, if the function returns - * true */ - -/** - * Declare the structure for module resolvers. - */ -typedef struct -{ - jerryx_module_get_canonical_name_t get_canonical_name_p; /**< function pointer to establish the canonical name of a - * module */ - jerryx_module_resolve_t resolve_p; /**< function pointer to resolve a module */ -} jerryx_module_resolver_t; - -/** - * Declare the JerryScript module resolver so that it may be added to an array of jerryx_module_resolver_t items and - * thus passed to jerryx_module_resolve. - */ -extern jerryx_module_resolver_t jerryx_module_native_resolver; - -/** - * Load a copy of a module into the current context using the provided module resolvers, or return one that was already - * loaded if it is found. - */ -jerry_value_t jerryx_module_resolve (const jerry_value_t name, - const jerryx_module_resolver_t **resolvers, - size_t count); - -/** - * Delete a module from the cache or, if name has the JavaScript value of undefined, clear the entire cache. - */ -void jerryx_module_clear_cache (const jerry_value_t name, - const jerryx_module_resolver_t **resolvers, - size_t count); - -#ifdef __cplusplus -} -#endif /* __cplusplus */ -#endif /* !JERRYX_MODULE_H */ diff --git a/firmware/spade/src/rpi/jerry/include/jerryscript-port-default.h b/firmware/spade/src/rpi/jerry/include/jerryscript-port-default.h deleted file mode 100644 index c869b9b403..0000000000 --- a/firmware/spade/src/rpi/jerry/include/jerryscript-port-default.h +++ /dev/null @@ -1,46 +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_PORT_DEFAULT_H -#define JERRYSCRIPT_PORT_DEFAULT_H - -#include - -#include "jerryscript.h" -#include "jerryscript-port.h" - -#ifdef __cplusplus -extern "C" -{ -#endif /* __cplusplus */ - -/** \addtogroup jerry_port_default Default Jerry engine port API - * These functions are only available if the default port of Jerry is used. - * @{ - */ - -jerry_log_level_t jerry_port_default_get_log_level (void); -void jerry_port_default_set_log_level (jerry_log_level_t level); - -void jerry_port_default_set_current_context (jerry_context_t *context_p); - -/** - * @} - */ - -#ifdef __cplusplus -} -#endif /* __cplusplus */ -#endif /* !JERRYSCRIPT_PORT_DEFAULT_H */ diff --git a/firmware/spade/src/rpi/jerry/include/jerryscript-port.h b/firmware/spade/src/rpi/jerry/include/jerryscript-port.h deleted file mode 100644 index 1f22ef080d..0000000000 --- a/firmware/spade/src/rpi/jerry/include/jerryscript-port.h +++ /dev/null @@ -1,284 +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_PORT_H -#define JERRYSCRIPT_PORT_H - -#include -#include -#include - -#include "jerryscript-compiler.h" -#include "jerryscript-core.h" - -#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_REF_COUNT_LIMIT = 12, - ERR_DISABLED_BYTE_CODE = 13, - ERR_UNTERMINATED_GC_LOOPS = 14, - 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_ATTR_NORETURN jerry_port_fatal (jerry_fatal_code_t code); - -/* - * I/O Port API - */ - -/** - * 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. - * - * Note: - * This port function is called by jerry-core when JERRY_LOGGING is - * enabled. It is also common practice though to use this function in - * application code. - */ -void JERRY_ATTR_FORMAT (printf, 2, 3) jerry_port_log (jerry_log_level_t level, const char *format, ...); - -/* - * Date Port API - */ - -/** - * Get local time zone adjustment, in milliseconds, for the given timestamp. - * The timestamp can be specified in either UTC or local time, depending on - * the value of is_utc. Adding the value returned from this function to - * a timestamp in UTC time should result in local time for the current time - * zone, and subtracting it from a timestamp in local time should result in - * UTC time. - * - * Ideally, this function should satisfy the stipulations applied to LocalTZA - * in section 20.3.1.7 of the ECMAScript version 9.0 spec. - * - * See Also: - * ECMA-262 v9, 20.3.1.7 - * - * Note: - * This port function is called by jerry-core when - * JERRY_BUILTIN_DATE is defined to 1. Otherwise this function is - * not used. - * - * @param unix_ms The unix timestamp we want an offset for, given in - * millisecond precision (could be now, in the future, - * or in the past). As with all unix timestamps, 0 refers to - * 1970-01-01, a day is exactly 86 400 000 milliseconds, and - * leap seconds cause the same second to occur twice. - * @param is_utc Is the given timestamp in UTC time? If false, it is in local - * time. - * - * @return milliseconds between local time and UTC for the given timestamp, - * if available - *. 0 if not available / we are in UTC. - */ -double jerry_port_get_local_time_zone_adjustment (double unix_ms, bool is_utc); - -/** - * Get system time - * - * Note: - * This port function is called by jerry-core when - * JERRY_BUILTIN_DATE is defined to 1. It is also common practice - * in application code to use this function for the initialization of the - * random number generator. - * - * @return milliseconds since Unix epoch - */ -double jerry_port_get_current_time (void); - -/** - * Get the current context of the engine. Each port should provide its own - * implementation of this interface. - * - * Note: - * This port function is called by jerry-core when - * JERRY_EXTERNAL_CONTEXT is enabled. Otherwise this function is not - * used. - * - * @return the pointer to the engine context. - */ -struct jerry_context_t *jerry_port_get_current_context (void); - -/** - * Makes the process sleep for a given time. - * - * Note: - * This port function is called by jerry-core when JERRY_DEBUGGER is - * enabled (set to 1). Otherwise this function is not used. - * - * @param sleep_time milliseconds to sleep. - */ -void jerry_port_sleep (uint32_t sleep_time); - -/** - * Print a single character. - * - * Note: - * This port function is here so the jerry-ext components would have - * a common way to print out information. - * If possible do not use from the jerry-core. - * - * @param c the character to print. - */ -void jerry_port_print_char (char c); - -/** - * Open a source file and read its contents into a buffer. - * - * Note: - * This port function is called by jerry-core when JERRY_MODULE_SYSTEM - * is enabled. The path is specified in the import statement's 'from "..."' - * section. - * - * @param file_name_p Path that points to the EcmaScript file in the - * filesystem. - * @param out_size_p The opened file's size in bytes. - * - * @return the pointer to the buffer which contains the content of the file. - */ -uint8_t *jerry_port_read_source (const char *file_name_p, size_t *out_size_p); - -/** - * Frees the allocated buffer after the contents of the file are not needed - * anymore. - * - * @param buffer_p The pointer the allocated buffer. - */ -void jerry_port_release_source (uint8_t *buffer_p); - -/** - * Normalize a file path string. - * - * Note: - * This port function is called by jerry-core when JERRY_MODULE_SYSTEM - * is enabled. The normalized path is used to uniquely identify modules. - * - * @param in_path_p Input path as a zero terminated string. - * @param out_buf_p Pointer to the output buffer where the normalized path should be written. - * @param out_buf_size Size of the output buffer. - * @param base_file_p A file path that 'in_path_p' is relative to, usually the current module file. - * A NULL value represents that 'in_path_p' is relative to the current working directory. - * - * @return length of the string written to the output buffer - * zero, if the buffer was not sufficient or an error occured - */ -size_t jerry_port_normalize_path (const char *in_path_p, - char *out_buf_p, - size_t out_buf_size, - char *base_file_p); - -/** - * Get the module object of a native module. - * - * Note: - * This port function is called by jerry-core when JERRY_MODULE_SYSTEM - * is enabled. - * - * @param name String value of the module specifier. - * - * @return Undefined, if 'name' is not a native module - * jerry_value_t containing the module object, otherwise - */ -jerry_value_t jerry_port_get_native_module (jerry_value_t name); - -/** - * HostPromiseRejectionTracker operations - */ -typedef enum -{ - JERRY_PROMISE_REJECTION_OPERATION_REJECT, /**< promise is rejected without any handlers */ - JERRY_PROMISE_REJECTION_OPERATION_HANDLE, /**< handler is added to a rejected promise for the first time */ -} jerry_promise_rejection_operation_t; - -/** - * Track unhandled promise rejections. - * - * Note: - * This port function is called by jerry-core when JERRY_BUILTIN_PROMISE - * is enabled. - * - * @param promise rejected promise - * @param operation HostPromiseRejectionTracker operation - */ -void jerry_port_track_promise_rejection (const jerry_value_t promise, - const jerry_promise_rejection_operation_t operation); - -/** - * @} - */ - -#ifdef __cplusplus -} -#endif /* __cplusplus */ -#endif /* !JERRYSCRIPT_PORT_H */ diff --git a/firmware/spade/src/rpi/jerry/include/jerryscript-snapshot.h b/firmware/spade/src/rpi/jerry/include/jerryscript-snapshot.h deleted file mode 100644 index 831bb49220..0000000000 --- a/firmware/spade/src/rpi/jerry/include/jerryscript-snapshot.h +++ /dev/null @@ -1,82 +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_SNAPSHOT_H -#define JERRYSCRIPT_SNAPSHOT_H - -#include "jerryscript-core.h" - -#ifdef __cplusplus -extern "C" -{ -#endif /* __cplusplus */ - -/** \addtogroup jerry-snapshot Jerry engine interface - Snapshot feature - * @{ - */ - -/** - * Jerry snapshot format version. - */ -#define JERRY_SNAPSHOT_VERSION (63u) - -/** - * Flags for jerry_generate_snapshot and jerry_generate_function_snapshot. - */ -typedef enum -{ - JERRY_SNAPSHOT_SAVE_STATIC = (1u << 0), /**< static snapshot */ - JERRY_SNAPSHOT_SAVE_STRICT = (1u << 1), /**< strict mode code */ -} jerry_generate_snapshot_opts_t; - -/** - * Flags for jerry_exec_snapshot_at and jerry_load_function_snapshot_at. - */ -typedef enum -{ - JERRY_SNAPSHOT_EXEC_COPY_DATA = (1u << 0), /**< copy snashot data */ - JERRY_SNAPSHOT_EXEC_ALLOW_STATIC = (1u << 1), /**< static snapshots allowed */ -} jerry_exec_snapshot_opts_t; - -/** - * Snapshot functions. - */ -jerry_value_t jerry_generate_snapshot (const jerry_char_t *resource_name_p, size_t resource_name_length, - const jerry_char_t *source_p, size_t source_size, - uint32_t generate_snapshot_opts, uint32_t *buffer_p, size_t buffer_size); -jerry_value_t jerry_generate_function_snapshot (const jerry_char_t *resource_name_p, size_t resource_name_length, - const jerry_char_t *source_p, size_t source_size, - const jerry_char_t *args_p, size_t args_size, - uint32_t generate_snapshot_opts, uint32_t *buffer_p, - size_t buffer_size); - -jerry_value_t jerry_exec_snapshot (const uint32_t *snapshot_p, size_t snapshot_size, - size_t func_index, uint32_t exec_snapshot_opts); -jerry_value_t jerry_load_function_snapshot (const uint32_t *function_snapshot_p, - const size_t function_snapshot_size, - size_t func_index, uint32_t exec_snapshot_opts); - -size_t jerry_merge_snapshots (const uint32_t **inp_buffers_p, size_t *inp_buffer_sizes_p, size_t number_of_snapshots, - uint32_t *out_buffer_p, size_t out_buffer_size, const char **error_p); -size_t jerry_get_literals_from_snapshot (const uint32_t *snapshot_p, size_t snapshot_size, - jerry_char_t *lit_buf_p, size_t lit_buf_size, bool is_c_format); -/** - * @} - */ - -#ifdef __cplusplus -} -#endif /* __cplusplus */ -#endif /* !JERRYSCRIPT_SNAPSHOT_H */ diff --git a/firmware/spade/src/rpi/jerry/include/jerryscript.h b/firmware/spade/src/rpi/jerry/include/jerryscript.h deleted file mode 100644 index 041ac7ea37..0000000000 --- a/firmware/spade/src/rpi/jerry/include/jerryscript.h +++ /dev/null @@ -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_H -#define JERRYSCRIPT_H - -#include "jerryscript-core.h" -#include "jerryscript-debugger.h" -#include "jerryscript-snapshot.h" - -#endif /* !JERRYSCRIPT_H */ diff --git a/firmware/spade/src/rpi/jerry/lib/libjerry-port.a b/firmware/spade/src/rpi/jerry/lib/libjerry-port.a deleted file mode 100644 index 4786c9195a..0000000000 Binary files a/firmware/spade/src/rpi/jerry/lib/libjerry-port.a and /dev/null differ diff --git a/firmware/spade/src/rpi/jerry/refresh.sh b/firmware/spade/src/rpi/jerry/refresh.sh index b9b8f3ab9d..2eaa8db11f 100755 --- a/firmware/spade/src/rpi/jerry/refresh.sh +++ b/firmware/spade/src/rpi/jerry/refresh.sh @@ -1,11 +1,12 @@ cd ~/jerryscript_build rm -rf example-* -# CMAKE_ASM_COMPILER=arm-none-eabi-gcc -# CMAKE_C_COMPILER=arm-none-eabi-gcc -# CMAKE_CXX_COMPILER=arm-none-eabi-g++ -# CMAKE_LINKER=arm-none-eabi-ld -# CMAKE_OBJCOPY=arm-none-eabi-objcopy +export CC=arm-none-eabi-gcc +export CMAKE_ASM_COMPILER=arm-none-eabi-gcc +export CMAKE_C_COMPILER=arm-none-eabi-gcc +export CMAKE_CXX_COMPILER=arm-none-eabi-g++ +export CMAKE_LINKER=arm-none-eabi-ld +export CMAKE_OBJCOPY=arm-none-eabi-objcopy # --debug \ python3 jerryscript/tools/build.py \ @@ -22,7 +23,7 @@ python3 jerryscript/tools/build.py \ make -C $(pwd)/example_build install\ cd ~/spade/src/rpi/jerry -cp ~/jerryscript_build/example_build/lib/* lib/ +cp -r ~/jerryscript_build/example_build/lib/ lib/ # cp ~/jerryscript_build/example_install/include rm -rf include # cp ~/jerryscript_build/example_install/include ./ diff --git a/firmware/spade/src/rpi/main.c b/firmware/spade/src/rpi/main.c index fb4692b088..105a0bb53c 100644 --- a/firmware/spade/src/rpi/main.c +++ b/firmware/spade/src/rpi/main.c @@ -41,6 +41,10 @@ #include "shared/js_runtime/jerryxx.c" #include "shared/js_runtime/js.h" +// screen is 20 characters wide +#define SCREEN_WIDTH_CHARS 20 +#define SCREEN_HEIGHT_LINES 10 + // Externs for shared/ui/errorbuf.h char errorbuf[512] = ""; Color errorbuf_color; // Initialized in main() @@ -72,9 +76,22 @@ typedef struct { uint8_t last_state; uint8_t ring_i; } ButtonState; +// W, S, A, D, I, K, J, L uint button_pins[] = { 5, 7, 6, 8, 12, 14, 13, 15 }; static ButtonState button_states[ARR_LEN(button_pins)] = {0}; +typedef enum { + Button_W, + Button_S, + Button_A, + Button_D, + Button_I, + Button_K, + Button_J, + Button_L, + Button_None +} Button; + static bool button_history_read(ButtonState *bs, int i) { // We want to store bools compactly so we have to do some bit twiddling. int q = 1 << (i % 8); @@ -248,6 +265,204 @@ static int load_new_scripts(void) { } #endif +typedef enum { + NEW_SLOT, + GAME_MENU, + DELETE_CONFIRM, + RUN_GAME + } Welcome_Screen; + + int count_digits(uint32_t number) { + if (number < 10) return 1; + if (number < 100) return 2; + if (number < 1000) return 3; + if (number < 10000) return 4; + if (number < 100000) return 5; + if (number < 1000000) return 6; + if (number < 10000000) return 7; + if (number < 100000000) return 8; + if (number < 1000000000) return 9; + return 10; + } + + static Button get_button_press() { + if (!multicore_fifo_rvalid()) return Button_None; + + switch (multicore_fifo_pop_blocking()) { + case 5: + return Button_W; + case 7: + return Button_S; + case 6: + return Button_A; + case 8: + return Button_D; + case 12: + return Button_I; + case 14: + return Button_K; + case 13: + return Button_J; + case 15: + return Button_L; + } + } + +typedef struct { + Welcome_Screen screen; + int games_len; + int games_i; + Game* games; +} Welcome_State; + + const char delete_confirm_screen[] = " \n" + " \n" + " \n" + " \n" + " \n" + " Do you really \n" + " want to delete \n" + " this game? \n" + " \n" + " \n" + " W: confirm \n" + " S: exit \n" + " \n" + " \n" + " sprig.hackclub.com \n"; + + const char upload_game_screen[] = " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " Please upload \n" + " a game. \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " sprig.hackclub.com \n"; + +void render_game_menu_screen(char *buffer, Welcome_State welcome_state) { + // padding to be written after game num & size + char game_padding[] = " "; + char size_padding[] = " "; + + game_padding[ + SCREEN_WIDTH_CHARS + - count_digits(welcome_state.games_i + 1) + - count_digits(welcome_state.games_len) + - 8 // 7 chars used for " Game: " + account for slash + ] = '\0'; + + size_padding[ + SCREEN_WIDTH_CHARS + - count_digits(GAME_SLOTS(welcome_state.games[welcome_state.games_i].size_b)) + - count_digits(MAX_SLOTS) + - 8 // 7 chars used for " Size: " + account for slash + ] = '\0'; + + // 6lines, for game name + char game_split_lines[] = { + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + }; + + // buffer of 3 chars at beginning, subtract from total width + int chars_per_line = SCREEN_WIDTH_CHARS - 3; + unsigned int lines_used = strlen(welcome_state.games[welcome_state.games_i].name) / chars_per_line + 1; + for (int i = 0; i < lines_used; i++) { + // write to game_split_lines, segmented per line, + // +1 for the newline, +1 to get next open char + char *write_dest = &game_split_lines[i * (SCREEN_WIDTH_CHARS + 1) + 1]; + + // read from the game name, segmented by chars_per_line + char *game_line = &welcome_state.games[welcome_state.games_i].name[i * chars_per_line]; + + // write length is chars_per_line except if the last segment of game name is less than that + unsigned int write_length = chars_per_line; + if (strlen(welcome_state.games[welcome_state.games_i].name) - i * write_length < write_length) { + write_length = strlen(welcome_state.games[welcome_state.games_i].name) - i * chars_per_line; + } + + memcpy(write_dest, game_line, write_length); + } + + + sprintf(buffer, + " \n" + " \n" + "%s" + " \n" + " Game: %d/%d%s\n" + " Size: %lu/%d%s\n" + " \n" + " W: PLAY \n" + " S: DELETE \n" + " <- A , D -> \n", + game_split_lines, + welcome_state.games_i + 1, welcome_state.games_len, game_padding, + GAME_SLOTS(welcome_state.games[welcome_state.games_i].size_b), MAX_SLOTS, size_padding); +} + +void update_welcome_state(Welcome_State* welcome_state) { + welcome_state->games_len = get_games(&welcome_state->games); + + if (welcome_state->games_i >= welcome_state->games_len && welcome_state->games_i != 0) { + welcome_state->games_i = welcome_state->games_len - 1; + } + + if (welcome_state->screen == DELETE_CONFIRM) { + // no-op + } else if (welcome_state->games_len == 0) { + welcome_state->screen = NEW_SLOT; + } else { + welcome_state->screen = GAME_MENU; + set_game(welcome_state->games[welcome_state->games_i]); + } + + Button button_pressed = get_button_press(); + + if (welcome_state->screen == GAME_MENU) + switch (button_pressed) { + case Button_A: + if (welcome_state->games_i > 0) welcome_state->games_i--; + break; + case Button_D: + if (welcome_state->games_i < welcome_state->games_len - 1) welcome_state->games_i++; + break; + case Button_S: + welcome_state->screen = DELETE_CONFIRM; + break; + case Button_W: + welcome_state->screen = RUN_GAME; + break; + default: + break; + } + else if (welcome_state->screen == DELETE_CONFIRM) + switch (button_pressed) { + case Button_S: + welcome_state->screen = GAME_MENU; + break; + case Button_W: + delete_game(welcome_state->games[welcome_state->games_i]); + welcome_state->screen = GAME_MENU; + update_welcome_state(welcome_state); + break; + default: + break; + } +} + int main() { timer_hw->dbgpause = 0; @@ -265,74 +480,50 @@ int main() { jerry_init(JERRY_INIT_MEM_STATS); init(sprite_free_jerry_object); // TODO: document - while(!save_read()) { - // No game stored in memory - strcpy(errorbuf, " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " PLEASE UPLOAD \n" - " A GAME \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " sprig.hackclub.com \n"); - render_errorbuf(); - st7735_fill_start(); - render(st7735_fill_send); - st7735_fill_finish(); + // Start a core to listen for keypresses. + multicore_reset_core1(); - load_new_scripts(); - } + update_save_version(); // init here to avoid irqs on other core - // Start a core to listen for keypresses. - multicore_launch_core1(core1_entry); + multicore_launch_core1(core1_entry); - /** - * We get a bunch of fake keypresses at startup, so we need to - * drain them from the FIFO queue. - * - * What really needs to be done here is to have button_init - * record when it starts so that we can ignore keypresses after - * that timestamp. - */ - sleep_ms(50); - while (multicore_fifo_rvalid()) multicore_fifo_pop_blocking(); + /** + * We get a bunch of fake keypresses at startup, so we need to + * drain them from the FIFO queue. + * + * What really needs to be done here is to have button_init + * record when it starts so that we can ignore keypresses after + * that timestamp. + */ + sleep_ms(50); + while (multicore_fifo_rvalid()) multicore_fifo_pop_blocking(); - /** - * Wait for a keypress to start the game. - * - * This is important so games with e.g. infinite loops don't - * brick the device as soon as they start up. - */ - while(!multicore_fifo_rvalid()) { - strcpy(errorbuf, " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " PRESS ANY BUTTON \n" - " TO RUN \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " sprig.hackclub.com \n"); - render_errorbuf(); - st7735_fill_start(); - render(st7735_fill_send); - st7735_fill_finish(); + Welcome_State welcome_state = { + .screen = NEW_SLOT, + .games = malloc(METADATA_MAX_ENTRIES * sizeof(Game)), // leaks but it's fine since lifetime=program + .games_len = 0, + .games_i = 0 + }; - load_new_scripts(); - } + for (;;) { + update_welcome_state(&welcome_state); + + if (welcome_state.screen == RUN_GAME) + break; + else if (welcome_state.screen == NEW_SLOT) + strcpy(errorbuf, upload_game_screen); + else if (welcome_state.screen == GAME_MENU) + render_game_menu_screen(errorbuf, welcome_state); + else if (welcome_state.screen == DELETE_CONFIRM) + strcpy(errorbuf, delete_confirm_screen); + + render_errorbuf(); + st7735_fill_start(); + render(st7735_fill_send); + st7735_fill_finish(); + + load_new_scripts(); + } // Wow, we can actually run a game now! @@ -345,7 +536,7 @@ int main() { while (multicore_fifo_rvalid()) multicore_fifo_pop_blocking(); // Run the code! - js_run(save_read(), strlen(save_read())); + js_run(save_read(), !welcome_state.games[welcome_state.games_i].is_legacy); #ifdef SPADE_AUDIO // Initialize audio diff --git a/firmware/spade/src/rpi/upload.h b/firmware/spade/src/rpi/upload.h index 401572742a..2f6ddbdc86 100644 --- a/firmware/spade/src/rpi/upload.h +++ b/firmware/spade/src/rpi/upload.h @@ -1,28 +1,350 @@ -#include "shared/sprig_engine/script.h" #include "hardware/flash.h" +#include static void core1_entry(void); +typedef enum { + Location_FLASH + // TODO: will add SD + // TODO: swap games into SD if flash overfilled +} Game_Location; + +typedef struct { + char name[100]; // todo: we need to set frontend limits on game names + Game_Location location; + uint8_t slot; + uint32_t size_b; + uint8_t is_legacy; // legacy games moved over from firmware 1.0.0; includes engine script +} Game; + +Game current_game = (Game) {}; +int slot = 0; + // rationale: half engine, half games? // NOTE: this has to be a multiple of 4096 (FLASH_SECTOR_SIZE) -#define FLASH_TARGET_OFFSET (800 * 1024) +#define FLASH_TARGET_START (800*1024) + +#define MAX_SLOTS 150 +#define SLOT_SIZE FLASH_SECTOR_SIZE +#define FLASH_TARGET_OFFSET(slot_i) (FLASH_TARGET_START + (slot_i) * SLOT_SIZE) +#define FLASH_TARGET_CONTENTS(slot_i) ((const uint8_t *) (XIP_BASE + FLASH_TARGET_OFFSET(slot_i))) + +#define GAME_SLOTS(bytes) (((bytes) + FLASH_PAGE_SIZE) / SLOT_SIZE + 1) + +#define METADATA_MAX_ENTRIES 32 +#define METADATA_ENTRY_SIZE FLASH_PAGE_SIZE // you can program up to one page at a time. (256 bytes). +#define METADATA_OFFSET ((uint32_t) (FLASH_TARGET_START - METADATA_SIZE + METADATA_ENTRY_SIZE)) +#define METADATA_CONTENTS(index) ((const Game *) (XIP_BASE + FLASH_TARGET_START - METADATA_SIZE + METADATA_ENTRY_SIZE + (index) * METADATA_ENTRY_SIZE)) + +// we store the version one metadata slot before the first +#define METADATA_SIZE ((METADATA_MAX_ENTRIES+1) * METADATA_ENTRY_SIZE) +#define METADATA_START METADATA_CONTENTS(-1) +#define FLASH_VERSION ((const char *) METADATA_START) + +#define PTR_METADATA_CONTENTS(metadata_ptr, i) (((Game*) (metadata_ptr + METADATA_ENTRY_SIZE*i))) -const uint8_t *flash_target_contents = (const uint8_t *) (XIP_BASE + FLASH_TARGET_OFFSET); -uint16_t SPRIG_MAGIC[FLASH_PAGE_SIZE/2] = { 1337, 42, 69, 420, 420, 1337 }; +static const int memory_is_ones(const void *memory, size_t count) { + // this is taken from gcc libiberty + register const unsigned char *s = (const unsigned char*)memory; -static const char *save_read(void) { - if (memcmp(&SPRIG_MAGIC, flash_target_contents, sizeof(SPRIG_MAGIC)) != 0) { + while (count-- > 0) + { + if (*s++ != 0xFF) + return 0; + } + return 1; +} + +// sprig magic is still here because it's useful for debugging (binvis.io) + easier to not get rid of it lol +uint16_t SPRIG_MAGIC[6] = { 1337, 42, 69, 420, 420, 1337 }; + +static const char *save_read() { + if (memcmp(&SPRIG_MAGIC, FLASH_TARGET_CONTENTS(slot), sizeof(SPRIG_MAGIC)) != 0) { puts("no magic :("); return NULL; } // add a page to get what's after the magic - const char *save = flash_target_contents + FLASH_PAGE_SIZE; + const char *save = FLASH_TARGET_CONTENTS(slot) + FLASH_PAGE_SIZE; return save; } +// must be run with core 1 disabled - conflict risk +static void flash_write_version(const char* version) { + void *metadata_first_sector = malloc(FLASH_SECTOR_SIZE); + memcpy(metadata_first_sector, METADATA_START, FLASH_SECTOR_SIZE); + strcpy(metadata_first_sector, version); + + uint32_t interrupts = save_and_disable_interrupts(); + flash_range_erase(METADATA_OFFSET - METADATA_ENTRY_SIZE, FLASH_SECTOR_SIZE); + flash_range_program(METADATA_OFFSET - METADATA_ENTRY_SIZE, metadata_first_sector, FLASH_SECTOR_SIZE); + restore_interrupts(interrupts); + + free(metadata_first_sector); +} + +// save versions != spade versions +// increment in the value returned means different scheme for saving games +static int get_save_version(const char* version) { + if (memory_is_ones(version, METADATA_ENTRY_SIZE)) return 1; + if (strcmp(version, "2.0.0") == 0) return 2; + + // something weird happened!? + return -1; +} + +// must be run with core 1 disabled - conflict risk +static int update_save_version() { + int version = get_save_version(FLASH_VERSION); + if (version == get_save_version(SPADE_VERSION)) return 0; + + switch (version) { // recursive if need to update multiple versions. + case 1: // 1.0.0 or less + { + if (memcmp(&SPRIG_MAGIC, FLASH_TARGET_CONTENTS(0), sizeof(SPRIG_MAGIC)) == 0) { + // add flash metadata for first game + Game game = { + .slot = 0, + .size_b = strlen(FLASH_TARGET_CONTENTS(0) + FLASH_PAGE_SIZE), + .name = "Legacy Game", + .location = Location_FLASH, + .is_legacy = 1 + }; + + void *metadata_first_sector = malloc(FLASH_SECTOR_SIZE); + memcpy(metadata_first_sector, METADATA_START, FLASH_SECTOR_SIZE); + memcpy(metadata_first_sector + METADATA_ENTRY_SIZE, &game, sizeof(Game)); + + uint32_t interrupts = save_and_disable_interrupts(); + flash_range_erase(METADATA_OFFSET - METADATA_ENTRY_SIZE, FLASH_SECTOR_SIZE); + flash_range_program(METADATA_OFFSET - METADATA_ENTRY_SIZE, metadata_first_sector, + FLASH_SECTOR_SIZE); + restore_interrupts(interrupts); + + free(metadata_first_sector); + } + + flash_write_version("2.0.0"); + return update_save_version(); + } + default: + return 1; + } + +} + +// returns len of games. games should be pointer to array of games (Game**) w/ size METADATA_MAX_ENTRIES +static int get_games(Game** games) { + int games_i = 0; + + for (int i = 0; i < METADATA_MAX_ENTRIES; i++) { + + volatile int is_ones = memory_is_ones(METADATA_CONTENTS(i), METADATA_ENTRY_SIZE); + if (is_ones) continue; + + (*games)[games_i++] = *METADATA_CONTENTS(i); + } + + return games_i; +} + +static int get_available_flash_slots(int exclude) { + int available_flash_slots = MAX_SLOTS; + for (int i = 0; i < METADATA_MAX_ENTRIES; i++) { + if (i == exclude) continue; + volatile int is_ones = memory_is_ones(METADATA_CONTENTS(i), METADATA_ENTRY_SIZE); + if (!is_ones) + available_flash_slots -= (int) GAME_SLOTS(METADATA_CONTENTS(i)->size_b); + } + + return available_flash_slots; +} + +static int get_available_metadata_slots(int exclude) { + int available_slots = METADATA_MAX_ENTRIES; + for (int i = 0; i < METADATA_MAX_ENTRIES; i++) { + if (i == exclude) continue; + volatile int is_ones = memory_is_ones(METADATA_CONTENTS(i), METADATA_ENTRY_SIZE); + if (!is_ones) + available_slots--; + } + return available_slots; +} + +static int get_flash_region(int slots, int exclude) { + for (int i = -1; i < METADATA_MAX_ENTRIES; i++) { + int base_slot = 0; + if ( i != -1) { + if (i == exclude) continue; + if (memory_is_ones(METADATA_CONTENTS(i), METADATA_ENTRY_SIZE)) continue; + base_slot = METADATA_CONTENTS(i) -> slot + GAME_SLOTS(METADATA_CONTENTS(i)->size_b); + } + + int overlap = 0; + for (int j = 0; j < METADATA_MAX_ENTRIES; j++) { + if (j == exclude) continue; + if (memory_is_ones(METADATA_CONTENTS(i), METADATA_ENTRY_SIZE)) continue; + int second_slot = METADATA_CONTENTS(j)->slot; + int second_size = GAME_SLOTS(METADATA_CONTENTS(j)->size_b); + if ((base_slot <= second_size + second_slot - 1 && second_slot <= base_slot + slots - 1) + || base_slot + slots - 1 >= MAX_SLOTS - 1) { + overlap = 1; + break; + } + } + + if (!overlap) { + return base_slot; + } + } + return -1; +} + +static int get_first_open_metadata_slot() { + for (int i = 0; i < METADATA_MAX_ENTRIES; i++) { + if (memory_is_ones(METADATA_CONTENTS(i), METADATA_ENTRY_SIZE)) + return i; + } + + return -1; +} + +static void set_game(Game aGame) { + // this is fine for now. + // in future, include logic to swap games in SD to flash + current_game = aGame; + slot = aGame.slot; +} + +static int get_game_index_by_name(char* name) { + for (int i = 0; i < METADATA_MAX_ENTRIES; i++) { + if (!memory_is_ones(METADATA_CONTENTS(i), METADATA_ENTRY_SIZE) + && strcmp(METADATA_CONTENTS(i)->name, name) == 0) { + return i; + } + } + + return -1; +} + +static void delete_game(Game aGame) { + for (int i = 0; i < METADATA_MAX_ENTRIES; i++) { + if (memcmp(METADATA_CONTENTS(i), &aGame, sizeof(Game)) == 0) { // this is the metadata slot + char ones[METADATA_ENTRY_SIZE]; + for (int j = 0; j < METADATA_ENTRY_SIZE; j++) { + ones[j] = 0xFF; + } + + void *new_metadata = malloc(METADATA_SIZE); + memcpy(new_metadata, METADATA_START, METADATA_SIZE); + memcpy(new_metadata + METADATA_ENTRY_SIZE * (i + 1), &ones, METADATA_ENTRY_SIZE); + + multicore_reset_core1(); + uint32_t interrupts = save_and_disable_interrupts(); + + flash_range_erase(METADATA_OFFSET - METADATA_ENTRY_SIZE, METADATA_SIZE); + flash_range_program(METADATA_OFFSET - METADATA_ENTRY_SIZE, new_metadata, METADATA_SIZE); + + free(new_metadata); + restore_interrupts(interrupts); + multicore_launch_core1(core1_entry); + } + } +} + +// for some reason this hangs when just reading from flash +// fixed by changing to read from heap but don't know root cause +void consolidate_flash_games() { + void *new_metadata = malloc(METADATA_SIZE); + memcpy(new_metadata, METADATA_START, METADATA_SIZE); + + int prev_write = -1; + + for (;;) { + // infinite loop terminated by hitting end: + + // two-finger algo in which *read and *write both advance, consolidating by moving to leftmost position + int write = MAX_SLOTS; + + int read = MAX_SLOTS; + int read_metadata_i = 0; + + // loop to find earliest available write pos + for (int i = -1; i < METADATA_MAX_ENTRIES; i++) { + int base_slot = 0; + if (i != -1) { + if (memory_is_ones(PTR_METADATA_CONTENTS(new_metadata, i), METADATA_ENTRY_SIZE)) + continue; + + base_slot = PTR_METADATA_CONTENTS(new_metadata, i)->slot + GAME_SLOTS(PTR_METADATA_CONTENTS(new_metadata, i)->size_b); + } + + int empty = 1; + + // check if slot after current game is empty + for (int j = 0; j < METADATA_MAX_ENTRIES; j++) { + if (memory_is_ones(PTR_METADATA_CONTENTS(new_metadata, j), METADATA_ENTRY_SIZE)) + continue; + if (PTR_METADATA_CONTENTS(new_metadata, j)->slot == base_slot) { + empty = 0; + break; + } + } + + if (empty && base_slot < write) { // found un-consolidated slot + write = base_slot; // next open slot + } + } + + if (write == prev_write) { // we hit the end and can't advance anymore + + uint32_t interrupts = save_and_disable_interrupts(); + + flash_range_erase(METADATA_OFFSET - METADATA_ENTRY_SIZE, METADATA_SIZE); + flash_range_program(METADATA_OFFSET - METADATA_ENTRY_SIZE, new_metadata, METADATA_SIZE); + + restore_interrupts(interrupts); + + free(new_metadata); + return; + } + + prev_write = write; + + for (int j = 0; j < METADATA_MAX_ENTRIES; j++) { // find next filled slot to read from + if (memory_is_ones(PTR_METADATA_CONTENTS(new_metadata, j), METADATA_ENTRY_SIZE)) + continue; + if (PTR_METADATA_CONTENTS(new_metadata, j)->slot > write && PTR_METADATA_CONTENTS(new_metadata, j)->slot < read) { + read = PTR_METADATA_CONTENTS(new_metadata, j)->slot; + read_metadata_i = j; + } + } + + if (read == MAX_SLOTS) continue; // nowhere to read from + + // move game content slots leftwards + char* slot_buffer = malloc(SLOT_SIZE); + for (int i = 0; i < GAME_SLOTS(PTR_METADATA_CONTENTS(new_metadata, read_metadata_i)->size_b); i++) { + memcpy(slot_buffer, FLASH_TARGET_CONTENTS(read+i), SLOT_SIZE); + + uint32_t interrupts = save_and_disable_interrupts(); + + flash_range_erase(FLASH_TARGET_OFFSET(write + i), SLOT_SIZE); + + flash_range_program(FLASH_TARGET_OFFSET(write + i), slot_buffer, + SLOT_SIZE); + + restore_interrupts(interrupts); + } + free(slot_buffer); + + PTR_METADATA_CONTENTS(new_metadata, read_metadata_i)->slot = write; + + } +} typedef enum { + UplProg_Init, UplProg_Header, UplProg_Body, } UplProg; @@ -31,16 +353,20 @@ static struct { uint32_t len, len_i; char buf[256]; int page; + char name[100]; + uint8_t name_i; } upl_state = {0}; static void upl_flush_buf(void) { - uint32_t interrupts = save_and_disable_interrupts(); - flash_range_program(FLASH_TARGET_OFFSET + (upl_state.page++) * 256, + puts("wtf?? 6"); + + uint32_t interrupts = save_and_disable_interrupts(); + flash_range_program(FLASH_TARGET_OFFSET(slot) + (upl_state.page++) * 256, (void *)upl_state.buf, 256); restore_interrupts(interrupts); memset(upl_state.buf, 0, sizeof(upl_state.buf)); - printf("wrote page (%d/%d)\n", + printf("wrote page (%d/%lu)\n", upl_state.page, (upl_state.len/(FLASH_PAGE_SIZE + 1))); } @@ -49,58 +375,118 @@ static int upl_stdin_read(void) { memset(&upl_state, 0, sizeof(upl_state)); int timeout = 1000; // 1ms; we're already in upload mode + for (;;) { int c = getchar_timeout_us(timeout); if (c == PICO_ERROR_TIMEOUT) return 0; switch (upl_state.prog) { + case UplProg_Init: { + // irqs on other core? + multicore_reset_core1(); + + upl_state.prog = UplProg_Header; + } // falls through case UplProg_Header: { - ((char *)(&upl_state.len))[upl_state.len_i++] = c; - if (upl_state.len_i >= sizeof(uint32_t)) { - printf("ok reading %d chars\n", upl_state.len); - upl_state.prog = UplProg_Body; - upl_state.len_i = 0; - upl_state.page = 1; // skip first, that's for magic - - int char_len = upl_state.len + sizeof (engine_script); // sizeof script includes the null term, we still need to remove from script - upl_state.len = char_len; - // one to round up, one for magic - int page_len = (char_len/FLASH_PAGE_SIZE + 2) * FLASH_PAGE_SIZE ; - int sector_len = (page_len/FLASH_SECTOR_SIZE + 1) * FLASH_SECTOR_SIZE; - - // irqs on other core? - multicore_reset_core1(); - - uint32_t interrupts = save_and_disable_interrupts(); - flash_range_erase(FLASH_TARGET_OFFSET, sector_len); - restore_interrupts(interrupts); + puts("wahoo header"); - for (int i = 0; i < sizeof(engine_script) - 1; i++) { - upl_state.buf[upl_state.len_i++ % FLASH_PAGE_SIZE] = engine_script[i]; - if (upl_state.len_i % FLASH_PAGE_SIZE == 0) { - puts("flushin buf (wit da code!)"); - upl_flush_buf(); - } + if (upl_state.name_i < sizeof(upl_state.name) / sizeof(char)) // read game + { + ((char *) (&upl_state.name))[upl_state.name_i++] = c; + puts(upl_state.name); } + else { + ((char *) (&upl_state.len))[upl_state.len_i++] = c; + if (upl_state.len_i >= sizeof(uint32_t)) { + printf("ok reading %lu chars\n", upl_state.len); + upl_state.prog = UplProg_Body; + upl_state.len_i = 0; + upl_state.page = 1; // skip first, that's for magic - puts("cleared flash"); - } + { + Game game; + strcpy(game.name, upl_state.name); + game.size_b = upl_state.len; + game.location = Location_FLASH; + game.is_legacy = 0; + + int metadata_i; + int search_result = get_game_index_by_name(game.name); + int exclude = -1; + + if (search_result != -1) { + metadata_i = search_result; + exclude = metadata_i; + } else { + metadata_i = get_first_open_metadata_slot(); + } + + // not enough slots + if (get_available_flash_slots(exclude) < GAME_SLOTS(upl_state.len)) { + // OO_FLASH/{slots needed}/{slots available}/ + printf("OO_FLASH/%lu/%d/", GAME_SLOTS(upl_state.len), + get_available_flash_slots(exclude)); + multicore_launch_core1(core1_entry); + return 0; // ERROR! + } else if (!get_available_metadata_slots(exclude)) { + puts("OO_METADATA"); + multicore_launch_core1(core1_entry); + return 0; + } else if (get_flash_region(GAME_SLOTS(upl_state.len), exclude) == -1) { + puts("consolidating!"); + consolidate_flash_games(); + } + + game.slot = get_flash_region(GAME_SLOTS(upl_state.len), exclude); + slot = game.slot; + + void *new_metadata = malloc(METADATA_SIZE); + memcpy(new_metadata, METADATA_START, METADATA_SIZE); + memcpy(new_metadata + METADATA_ENTRY_SIZE * (metadata_i + 1), &game, sizeof(Game)); + + uint32_t interrupts = save_and_disable_interrupts(); + flash_range_erase(METADATA_OFFSET - METADATA_ENTRY_SIZE, METADATA_SIZE); + flash_range_program(METADATA_OFFSET - METADATA_ENTRY_SIZE, new_metadata, METADATA_SIZE); + restore_interrupts(interrupts); + + printf("metadata_i: %d,\n" + "slot: %d\n" + "size_b: %lu", metadata_i, slot, game.size_b); + + free(new_metadata); + } + + // one to round up, one for magic + uint32_t page_len = (upl_state.len / FLASH_PAGE_SIZE + 2) * FLASH_PAGE_SIZE; + uint32_t sector_len = (page_len / FLASH_SECTOR_SIZE + 1) * FLASH_SECTOR_SIZE; + + uint32_t interrupts = save_and_disable_interrupts(); + flash_range_erase(FLASH_TARGET_OFFSET(slot), sector_len); + restore_interrupts(interrupts); + + + + puts("cleared flash"); + } + } } break; case UplProg_Body: { - // printf("upl char (%d/%d)\n", upl_state.len_i, upl_state.len); + + // printf("upl char (%d/%d)\n", upl_state.len_i, upl_state.len); upl_state.buf[upl_state.len_i++ % FLASH_PAGE_SIZE] = c; + if (upl_state.len_i % FLASH_PAGE_SIZE == 0) { puts("flushin buf"); upl_flush_buf(); } - if (upl_state.len_i == upl_state.len - 1) { + if (upl_state.len_i == upl_state.len) { upl_flush_buf(); uint32_t interrupts = save_and_disable_interrupts(); - flash_range_program(FLASH_TARGET_OFFSET, (void *)SPRIG_MAGIC, FLASH_PAGE_SIZE); + flash_range_program(FLASH_TARGET_OFFSET(slot), (void *)SPRIG_MAGIC, FLASH_PAGE_SIZE); restore_interrupts(interrupts); - + // printf("read in %d chars\n", upl_state.len); puts("ALL_GOOD"); memset(&upl_state, 0, sizeof(upl_state)); diff --git a/firmware/spade/src/shared/js_runtime/jerryxx.c b/firmware/spade/src/shared/js_runtime/jerryxx.c index a0245223ae..0f41332f2a 100644 --- a/firmware/spade/src/shared/js_runtime/jerryxx.c +++ b/firmware/spade/src/shared/js_runtime/jerryxx.c @@ -189,17 +189,8 @@ static void strlcat_fixed_error(char *dest, jerry_value_t loc, size_t size) { } } - int engine_lines = 1; - for (int i = 0; i < sizeof(engine_script); i++) { - if (engine_script[i] == '\n') engine_lines++; - } - - if (line <= engine_lines) { - strlcat(dest, "engine:", size); - } else { - strlcat(dest, "game:", size); - line = line - engine_lines + 1; - } + strlcat(dest, "game:", size); + char line_str[7] = ""; sprintf(line_str, "%d", line); strlcat(dest, line_str, size); diff --git a/firmware/spade/src/shared/js_runtime/js.h b/firmware/spade/src/shared/js_runtime/js.h index 1abe410a6a..84e0bc7975 100644 --- a/firmware/spade/src/shared/js_runtime/js.h +++ b/firmware/spade/src/shared/js_runtime/js.h @@ -4,6 +4,7 @@ #include "jerryxx.h" #include "shared/sprig_engine/module_native.h" #include "shared/sprig_engine/base_engine.h" +#include "shared/sprig_engine/script.h" JERRYXX_FUN(console_log) { jerryxx_print_value(JERRYXX_GET_ARG(0)); @@ -13,9 +14,34 @@ static struct { jerry_value_t press_cb, frame_cb; } spade_state = {0}; -static void js_run(const jerry_char_t *script, jerry_length_t script_size) { +static void parse_and_run_code(const jerry_char_t *tag, const jerry_char_t *code, jerry_length_t code_len) { + jerry_value_t parsed_code = jerry_parse ( + (jerry_char_t *)tag, strlen(tag), + code, strlen(code), + JERRY_PARSE_STRICT_MODE + ); + + if (jerry_value_is_error (parsed_code)) { + yell("couldn't parse code :-O! error in:"); + yell(tag); + jerryxx_print_error(parsed_code, 1); + fatal_error(); + } + jerry_value_t ret_value = jerry_run (parsed_code); - // add shit to global scpoe + if (jerry_value_is_error (ret_value)) { + yell("couldn't run code :-(! error in:"); + yell(tag); + jerryxx_print_error(ret_value, 1); + fatal_error(); + } + + jerry_release_value (ret_value); + jerry_release_value (parsed_code); +} +static void js_run(const jerry_char_t *game_code, uint8_t include_engine) { + + // add shit to global scope { jerry_value_t global_object = jerry_get_global_object (); @@ -56,36 +82,15 @@ static void js_run(const jerry_char_t *script, jerry_length_t script_size) { dbgf(" sr->legend = %lu\n", sr->legend ); dbgf(" sr->legend_resized = %lu\n", sr->legend_resized ); - jerry_value_t parsed_code = jerry_parse ( - (jerry_char_t *)"src", sizeof("src")-1, - script, script_size, - JERRY_PARSE_STRICT_MODE - ); - - if (jerry_value_is_error (parsed_code)) { - yell("couldn't parse :("); - jerryxx_print_error(parsed_code, 1); - fatal_error(); - // abort(); + if(include_engine){ + parse_and_run_code("engine", engine_script, sizeof(engine_script)-1); } + puts("bouta run some code"); // Execute the parsed source code in the Global scope - jerry_value_t ret_value = jerry_run (parsed_code); - - if (jerry_value_is_error (ret_value)) { - yell("couldn't run :("); - jerryxx_print_error(ret_value, 1); - fatal_error(); - // abort(); - } - - // Returned value must be freed - jerry_release_value (ret_value); - - // Parsed source code must be freed - jerry_release_value (parsed_code); - + parse_and_run_code("game", game_code, strlen(game_code)); + // Cleanup engine // jerry_cleanup (); } diff --git a/firmware/spade/src/version.json b/firmware/spade/src/version.json index 688e939808..d707bf3559 100644 --- a/firmware/spade/src/version.json +++ b/firmware/spade/src/version.json @@ -1,3 +1,3 @@ { - "version": "1.0.0" + "version": "2.0.0" } \ No newline at end of file diff --git a/public/pico-os.uf2 b/public/pico-os.uf2 index 35a504f368..2377b73eca 100644 Binary files a/public/pico-os.uf2 and b/public/pico-os.uf2 differ diff --git a/scripts/gardenshed/gdb-server.sh b/scripts/gardenshed/gdb-server.sh index 664c4c99a3..112f404afc 100755 --- a/scripts/gardenshed/gdb-server.sh +++ b/scripts/gardenshed/gdb-server.sh @@ -1,3 +1,3 @@ #!/bin/bash -sudo openocd -f interface/cmsis-dap.cfg -f target/rp2040.cfg -c "adapter speed 5000" -c "program ./spade.elf verify reset" +sudo openocd -f interface/cmsis-dap.cfg -f target/rp2040.cfg -c "adapter speed 5000" -c "set USE_CORE 0" -c "program ./spade.elf verify reset" diff --git a/src/components/big-interactive-pages/editor.tsx b/src/components/big-interactive-pages/editor.tsx index 548b30d908..2103ada690 100644 --- a/src/components/big-interactive-pages/editor.tsx +++ b/src/components/big-interactive-pages/editor.tsx @@ -27,8 +27,9 @@ import { nanoid } from "nanoid"; import TutorialWarningModal from "../popups-etc/tutorial-warning"; import { editSessionLength, switchTheme, ThemeType, continueSaving, LAST_SAVED_SESSION_ID, showSaveConflictModal } from '../../lib/state' import SessionConflictWarningModal from '../popups-etc/session-conflict-warning-modal' -import {versionState} from "../../lib/upload"; +import {eotMessage, versionState} from "../../lib/upload"; import VersionWarningModal from "../popups-etc/version-warning"; +import OutOfSpaceModal from "../popups-etc/out-of-space"; import RoomPasswordPopup from "../popups-etc/room-password"; import KeyBindingsModal from '../popups-etc/KeyBindingsModal' @@ -737,6 +738,10 @@ export default function Editor({ persistenceState, cookies, roomState }: EditorP )} + {eotMessage.value && eotMessage.value.status != "ALL_GOOD" && ( + + )} + {showingTutorialWarning.value && ( exitTutorial(persistenceState, sessionId)} diff --git a/src/components/navbar-editor.tsx b/src/components/navbar-editor.tsx index c7229dcb39..fa4eea8b84 100644 --- a/src/components/navbar-editor.tsx +++ b/src/components/navbar-editor.tsx @@ -28,6 +28,7 @@ import { IoSaveOutline, IoShareOutline, IoShuffle, + IoWarning, } from "react-icons/io5"; import { FaBrush } from "react-icons/fa"; import { usePopupCloseClick } from "../lib/utils/popup-close-click"; @@ -380,22 +381,28 @@ export default function EditorNavbar(props: EditorNavbarProps) { {showDropdown.value && (
-
@@ -621,7 +628,7 @@ export default function EditorNavbar(props: EditorNavbarProps) { <>
  • (shareRoomPopup.value = true)} @@ -676,7 +683,7 @@ export default function EditorNavbar(props: EditorNavbarProps) {