Просмотр исходного кода

update SConscript and port

Signed-off-by: yangfasheng <yangfasheng@rt-thread.com>
yangfasheng 7 лет назад
Родитель
Сommit
7ec11ade8a
4 измененных файлов с 31 добавлено и 22 удалено
  1. 8 2
      SConscript
  2. 3 3
      rtthread-port/jerry_buffer.c
  3. 4 6
      rtthread-port/jerry_main.c
  4. 16 11
      rtthread-port/port.c

+ 8 - 2
SConscript

@@ -76,10 +76,16 @@ import rtconfig
 if rtconfig.CROSS_TOOL == 'keil':
     LOCAL_CCFLAGS += ' --gnu'
 
-LOCAL_CPPDEFINES = ['JERRY_JS_PARSER', 'JERRY_ENABLE_ERROR_MESSAGES']
+CPPDEFINES = ['JERRY_JS_PARSER', 'JERRY_ENABLE_ERROR_MESSAGES']
+
+if GetDepend('PKG_JERRY_ENABLE_LOGGING'):
+    CPPDEFINES += ['JERRY_ENABLE_LOGGING']
+    
+if GetDepend('PKG_JMEM_STATS'):
+    CPPDEFINES += ['JMEM_STATS']
 
 group = DefineGroup('JerryScript', src, depend = ['PKG_USING_JERRYSCRIPT'], CPPPATH = path, 
-    LOCAL_CPPDEFINES = LOCAL_CPPDEFINES, LOCAL_CCFLAGS = LOCAL_CCFLAGS)
+    CPPDEFINES = CPPDEFINES, LOCAL_CCFLAGS = LOCAL_CCFLAGS)
 
 list = os.listdir(cwd)
 

+ 3 - 3
rtthread-port/jerry_buffer.c

@@ -786,7 +786,7 @@ DECLARE_HANDLER(Buffer)
 
     if (jerry_value_is_object(args[0]))
     {
-        jerry_value_t stringified = jerry_json_stringfy((jerry_value_t)(args[0]));
+        jerry_value_t stringified = jerry_json_stringfy(args[0]);
         if (!jerry_value_is_error(stringified))
         {
             char *json_string = js_value_to_string(stringified);
@@ -799,11 +799,11 @@ DECLARE_HANDLER(Buffer)
                     memcpy(buf->buffer, json_string, strlen(json_string));
                 }
                 free(json_string);
-
+                jerry_release_value(stringified);
                 return new_buf;
             }
-            jerry_release_value(stringified);
         }
+        jerry_release_value(stringified);
     }
     else if (jerry_value_is_number(args[0]))
     {

+ 4 - 6
rtthread-port/jerry_main.c

@@ -12,11 +12,11 @@
 #define malloc	rt_malloc
 #define free	rt_free
 
-extern void jerry_port_default_set_instance(jerry_instance_t *instance_p);
+extern void jerry_port_set_default_context(jerry_context_t *context);
 
 static rt_mq_t _js_mq = NULL;
 
-static void *instance_alloc(size_t size, void *cb_data_p)
+static void *context_alloc(size_t size, void *cb_data_p)
 {
     return rt_calloc(1, size);
 }
@@ -56,7 +56,7 @@ static void jerry_thread_entry(void* parameter)
     if (length > 0)
     {
         /* JERRY_ENABLE_EXTERNAL_CONTEXT */
-        jerry_port_default_set_instance(jerry_create_instance(32 * 1024, instance_alloc, NULL));
+        jerry_port_set_default_context(jerry_create_context(32 * 1024, context_alloc, NULL));
 
         /* Initialize engine */
         jerry_init(JERRY_INIT_EMPTY);
@@ -138,10 +138,8 @@ static void jerry_thread_entry(void* parameter)
         /* Cleanup engine */
         jerry_cleanup();
 
-        rt_free((void *)jerry_port_get_current_instance());
+        rt_free((void *)jerry_port_get_current_context());
     }
-
-    return 0;
 }
 
 int jerry_main(int argc, char** argv)

+ 16 - 11
rtthread-port/port.c

@@ -143,27 +143,32 @@ double jerry_port_get_current_time (void)
  * 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;
+static jerry_context_t *jerry_default_context = NULL;
 
 /**
- * Set the current_instance_p as the passed pointer.
+ * Set the jerry_default_context as the passed pointer.
  */
 void
-jerry_port_default_set_instance (jerry_instance_t *instance_p) /**< points to the created instance */
+jerry_port_set_default_context(jerry_context_t *context)
 {
-    current_instance_p = instance_p;
-} /* jerry_port_default_set_instance */
+    jerry_default_context = context;
+}
 
 /**
- * Get the current instance.
+ * 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_ENABLE_EXTERNAL_CONTEXT is defined. Otherwise this function is not
+ *      used.
  *
- * @return the pointer to the current instance
+ * @return the pointer to the engine context.
  */
-jerry_instance_t *
-jerry_port_get_current_instance (void)
+struct jerry_context_t *jerry_port_get_current_context(void)
 {
-    return current_instance_p;
-} /* jerry_port_get_current_instance */
+    return jerry_default_context;
+}
 
 void jerry_port_sleep(uint32_t sleep_time)
 {