yangfasheng пре 7 година
родитељ
комит
acdedf08f3
4 измењених фајлова са 140 додато и 3 уклоњено
  1. 0 1
      SConscript
  2. 108 0
      rtthread-port/config.h
  3. 0 2
      rtthread-port/jerry_main.c
  4. 32 0
      rtthread-port/port.c

+ 0 - 1
SConscript

@@ -50,7 +50,6 @@ src = jerry_core + jerry_ext
 
 path = [cwd]
 path += [cwd + '/rtthread-port']
-path += [jerry_core_dir]
 path += [jerry_core_dir + '/api']
 path += [jerry_core_dir + '/debugger']
 path += [jerry_core_dir + '/ecma/base']

+ 108 - 0
rtthread-port/config.h

@@ -0,0 +1,108 @@
+/* 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 CONFIG_H
+#define CONFIG_H
+
+/**
+ * Group of builtin-related features that can be disabled together.
+ */
+#ifdef CONFIG_DISABLE_BUILTINS
+# define CONFIG_DISABLE_ANNEXB_BUILTIN
+# define CONFIG_DISABLE_ARRAY_BUILTIN
+# define CONFIG_DISABLE_BOOLEAN_BUILTIN
+# define CONFIG_DISABLE_DATE_BUILTIN
+# define CONFIG_DISABLE_ERROR_BUILTINS
+# define CONFIG_DISABLE_JSON_BUILTIN
+# define CONFIG_DISABLE_MATH_BUILTIN
+# define CONFIG_DISABLE_NUMBER_BUILTIN
+# define CONFIG_DISABLE_REGEXP_BUILTIN
+# define CONFIG_DISABLE_STRING_BUILTIN
+#endif /* CONFIG_DISABLE_BUILTINS */
+
+/**
+ * Group of ES2015-related features that can be disabled together.
+ */
+#ifdef CONFIG_DISABLE_ES2015
+# define CONFIG_DISABLE_ES2015_ARROW_FUNCTION
+# define CONFIG_DISABLE_ES2015_CLASS
+# define CONFIG_DISABLE_ES2015_BUILTIN
+# define CONFIG_DISABLE_ES2015_PROMISE_BUILTIN
+# define CONFIG_DISABLE_ES2015_TEMPLATE_STRINGS
+# define CONFIG_DISABLE_ES2015_TYPEDARRAY_BUILTIN
+#endif /* CONFIG_DISABLE_ES2015 */
+
+/**
+ * Size of heap
+ */
+#ifndef CONFIG_MEM_HEAP_AREA_SIZE
+# define CONFIG_MEM_HEAP_AREA_SIZE (512 * 1024)
+#endif /* !CONFIG_MEM_HEAP_AREA_SIZE */
+
+/**
+ * Max heap usage limit
+ */
+#define CONFIG_MEM_HEAP_MAX_LIMIT 8192
+
+/**
+ * Desired limit of heap usage
+ */
+#define CONFIG_MEM_HEAP_DESIRED_LIMIT (JERRY_MIN (CONFIG_MEM_HEAP_AREA_SIZE / 32, CONFIG_MEM_HEAP_MAX_LIMIT))
+
+/**
+ * Use 32-bit/64-bit float for ecma-numbers
+ */
+#define CONFIG_ECMA_NUMBER_FLOAT32 (1u) /* 32-bit float */
+#define CONFIG_ECMA_NUMBER_FLOAT64 (2u) /* 64-bit float */
+
+#ifndef CONFIG_ECMA_NUMBER_TYPE
+# define CONFIG_ECMA_NUMBER_TYPE CONFIG_ECMA_NUMBER_FLOAT64
+#else /* CONFIG_ECMA_NUMBER_TYPE */
+# if (CONFIG_ECMA_NUMBER_TYPE != CONFIG_ECMA_NUMBER_FLOAT32 \
+      && CONFIG_ECMA_NUMBER_TYPE != CONFIG_ECMA_NUMBER_FLOAT64)
+#  error "ECMA-number storage is configured incorrectly"
+# endif /* CONFIG_ECMA_NUMBER_TYPE != CONFIG_ECMA_NUMBER_FLOAT32
+           && CONFIG_ECMA_NUMBER_TYPE != CONFIG_ECMA_NUMBER_FLOAT64 */
+#endif /* !CONFIG_ECMA_NUMBER_TYPE */
+
+#if (!defined (CONFIG_DISABLE_DATE_BUILTIN) && (CONFIG_ECMA_NUMBER_TYPE == CONFIG_ECMA_NUMBER_FLOAT32))
+#  error "Date does not support float32"
+#endif
+
+/**
+ * Disable ECMA lookup cache
+ */
+// #define CONFIG_ECMA_LCACHE_DISABLE
+
+/**
+ * Disable ECMA property hashmap
+ */
+// #define CONFIG_ECMA_PROPERTY_HASHMAP_DISABLE
+
+/**
+ * Share of newly allocated since last GC objects among all currently allocated objects,
+ * after achieving which, GC is started upon low severity try-give-memory-back requests.
+ *
+ * Share is calculated as the following:
+ *                1.0 / CONFIG_ECMA_GC_NEW_OBJECTS_SHARE_TO_START_GC
+ */
+#define CONFIG_ECMA_GC_NEW_OBJECTS_SHARE_TO_START_GC (16)
+
+ /**
+ * Jerry instance for external context.
+ */
+#define JERRY_ENABLE_EXTERNAL_CONTEXT
+
+#endif /* !CONFIG_H */

+ 0 - 2
rtthread-port/jerry_main.c

@@ -47,8 +47,6 @@ int jerry_main(int argc, char** argv)
             jerry_value_t ret = jerry_run(parsed_code);
             if (jerry_value_is_error (ret))
             {
-                jerry_value_clear_error_flag (&ret);
-
                 jerry_value_t err_str_val = jerry_value_to_string (ret);
                 char *err_string = js_value_to_string(err_str_val);
                 if (err_string)

+ 32 - 0
rtthread-port/port.c

@@ -117,3 +117,35 @@ double jerry_port_get_current_time (void)
 {
     return rt_tick_get() * RT_TICK_PER_SECOND / 1000;
 }
+
+/**
+ * Pointer to the current instance.
+ * Note that it is a global variable, and is not a thread safe implementation.
+ */
+static jerry_instance_t *current_instance_p = NULL;
+
+/**
+ * Set the current_instance_p as the passed pointer.
+ */
+void
+jerry_port_default_set_instance (jerry_instance_t *instance_p) /**< points to the created instance */
+{
+    current_instance_p = instance_p;
+} /* jerry_port_default_set_instance */
+
+/**
+ * Get the current instance.
+ *
+ * @return the pointer to the current instance
+ */
+jerry_instance_t *
+jerry_port_get_current_instance (void)
+{
+    return current_instance_p;
+} /* jerry_port_get_current_instance */
+
+
+void jerry_port_sleep(uint32_t sleep_time)
+{
+    rt_thread_delay(rt_tick_from_millisecond(sleep_time));
+}